refactor(StorageCleaner): 移动 isRestrictedUrl 函数到独立模块并更新相关引用
- 将 isRestrictedUrl 函数从 storageCleaner 移动到 restrictedUrls 模块,优化代码结构。 - 更新相关文件以引用新的位置,移除冗余的测试用例。
This commit is contained in:
@@ -12,7 +12,6 @@ vi.mock('@/utils/chromeStorage', () => ({
|
|||||||
|
|
||||||
vi.mock('@/utils/storageCleaner', () => ({
|
vi.mock('@/utils/storageCleaner', () => ({
|
||||||
getCurrentTab: vi.fn().mockResolvedValue({ id: 1, url: 'https://example.com' }),
|
getCurrentTab: vi.fn().mockResolvedValue({ id: 1, url: 'https://example.com' }),
|
||||||
isRestrictedUrl: vi.fn().mockReturnValue(false),
|
|
||||||
getCookieSize: vi.fn().mockResolvedValue(0),
|
getCookieSize: vi.fn().mockResolvedValue(0),
|
||||||
getLocalStorageSize: vi.fn().mockResolvedValue(0),
|
getLocalStorageSize: vi.fn().mockResolvedValue(0),
|
||||||
getSessionStorageSize: vi.fn().mockResolvedValue(0),
|
getSessionStorageSize: vi.fn().mockResolvedValue(0),
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import {
|
|||||||
getOriginStorageEstimate,
|
getOriginStorageEstimate,
|
||||||
getServiceWorkerCount,
|
getServiceWorkerCount,
|
||||||
getSessionStorageSize,
|
getSessionStorageSize,
|
||||||
isRestrictedUrl,
|
|
||||||
} from '@/utils/storageCleaner';
|
} from '@/utils/storageCleaner';
|
||||||
|
import { isRestrictedUrl } from '@/utils/restrictedUrls';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
const DEFAULT_OPTIONS: StorageCleanerOptions = {
|
const DEFAULT_OPTIONS: StorageCleanerOptions = {
|
||||||
|
|||||||
@@ -1,54 +1,8 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { clearCookies, isRestrictedUrl } from '@/utils/storageCleaner';
|
import { clearCookies } from '@/utils/storageCleaner';
|
||||||
import { formatBytes } from '@/utils/format';
|
import { formatBytes } from '@/utils/format';
|
||||||
|
|
||||||
describe('storageCleaner utils', () => {
|
describe('storageCleaner utils', () => {
|
||||||
describe('isRestrictedUrl', () => {
|
|
||||||
it('should return true for chrome:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('chrome://settings')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for chrome-extension:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('chrome-extension://abc123/background.html')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for about:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('about:blank')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for edge:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('edge://settings')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for view-source:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('view-source:https://example.com')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for file:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('file:///path/to/file')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for data:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('data:text/html,<h1>Hello</h1>')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for http:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('http://example.com')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for https:// URLs', () => {
|
|
||||||
expect(isRestrictedUrl('https://example.com')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for undefined URL', () => {
|
|
||||||
expect(isRestrictedUrl(undefined)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for empty string', () => {
|
|
||||||
expect(isRestrictedUrl('')).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('formatBytes', () => {
|
describe('formatBytes', () => {
|
||||||
it('should return "0 B" for 0 bytes', () => {
|
it('should return "0 B" for 0 bytes', () => {
|
||||||
expect(formatBytes(0)).toBe('0 B');
|
expect(formatBytes(0)).toBe('0 B');
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { CleaningResult, StorageCleanerOptions, StorageCleanResult } from '@/types/storage';
|
import type { CleaningResult, StorageCleanerOptions, StorageCleanResult } from '@/types/storage';
|
||||||
import { CLEAN_OPTION_KEYS, OPTION_LABELS } from '@/pages/StorageCleaner/constants';
|
import { CLEAN_OPTION_KEYS, OPTION_LABELS } from '@/pages/StorageCleaner/constants';
|
||||||
export { isRestrictedUrl } from '@/utils/restrictedUrls';
|
|
||||||
|
|
||||||
export async function getCurrentTab() {
|
export async function getCurrentTab() {
|
||||||
// For popup pages, we need to get the active tab from the browser window that triggered the popup.
|
// For popup pages, we need to get the active tab from the browser window that triggered the popup.
|
||||||
|
|||||||
Reference in New Issue
Block a user