|
@@ -4,24 +4,34 @@ import cache from 'src/background/utils/cache';
|
|
|
|
|
|
|
|
test.onFinish(cache.destroy);
|
|
test.onFinish(cache.destroy);
|
|
|
|
|
|
|
|
|
|
+function buildScript(props) {
|
|
|
|
|
+ return Object.assign({
|
|
|
|
|
+ custom: {
|
|
|
|
|
+ origInclude: true,
|
|
|
|
|
+ origExclude: true,
|
|
|
|
|
+ origMatch: true,
|
|
|
|
|
+ origExcludeMatch: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ meta: {},
|
|
|
|
|
+ }, props);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
test('scheme', t => {
|
|
test('scheme', t => {
|
|
|
t.test('should match all', q => {
|
|
t.test('should match all', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `http | https`');
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `http | https`');
|
|
|
q.notOk(testScript('file:///Users/Gerald/file', script), 'should not match `file`');
|
|
q.notOk(testScript('file:///Users/Gerald/file', script), 'should not match `file`');
|
|
|
q.end();
|
|
q.end();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should match exact', q => {
|
|
t.test('should match exact', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'http://*/*',
|
|
'http://*/*',
|
|
@@ -29,7 +39,7 @@ test('scheme', t => {
|
|
|
'file:///*',
|
|
'file:///*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('http://www.google.com/', script), 'should match `http`');
|
|
q.ok(testScript('http://www.google.com/', script), 'should match `http`');
|
|
|
q.notOk(testScript('https://www.google.com/', script), 'should not match `https`');
|
|
q.notOk(testScript('https://www.google.com/', script), 'should not match `https`');
|
|
|
q.ok(testScript('file:///Users/Gerald/file', script), 'should match `file`');
|
|
q.ok(testScript('file:///Users/Gerald/file', script), 'should match `file`');
|
|
@@ -42,14 +52,13 @@ test('scheme', t => {
|
|
|
|
|
|
|
|
test('host', t => {
|
|
test('host', t => {
|
|
|
t.test('should match domain', q => {
|
|
t.test('should match domain', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://docs.google.com/',
|
|
'*://docs.google.com/',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://docs.google.com/', script), 'should match exact domain name');
|
|
q.ok(testScript('https://docs.google.com/', script), 'should match exact domain name');
|
|
|
q.notOk(testScript('https://sub.docs.google.com/', script), 'should not match subdomains');
|
|
q.notOk(testScript('https://sub.docs.google.com/', script), 'should not match subdomains');
|
|
|
q.notOk(testScript('https://docs.google.com.cn/', script), 'should not match suffixed domains');
|
|
q.notOk(testScript('https://docs.google.com.cn/', script), 'should not match suffixed domains');
|
|
@@ -57,14 +66,13 @@ test('host', t => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should match subdomains', q => {
|
|
t.test('should match subdomains', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*.google.com/',
|
|
'*://*.google.com/',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/', script), 'should match subdomains');
|
|
q.ok(testScript('https://www.google.com/', script), 'should match subdomains');
|
|
|
q.ok(testScript('https://a.b.google.com/', script), 'should match subdomains');
|
|
q.ok(testScript('https://a.b.google.com/', script), 'should match subdomains');
|
|
|
q.ok(testScript('https://google.com/', script), 'should match specified domain');
|
|
q.ok(testScript('https://google.com/', script), 'should match specified domain');
|
|
@@ -77,28 +85,26 @@ test('host', t => {
|
|
|
|
|
|
|
|
test('path', t => {
|
|
test('path', t => {
|
|
|
t.test('should match any', q => {
|
|
t.test('should match any', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'https://www.google.com/*',
|
|
'https://www.google.com/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `/`');
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `/`');
|
|
|
q.ok(testScript('https://www.google.com/hello/world', script), 'should match any');
|
|
q.ok(testScript('https://www.google.com/hello/world', script), 'should match any');
|
|
|
q.end();
|
|
q.end();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should match exact', q => {
|
|
t.test('should match exact', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'https://www.google.com/a/b/c',
|
|
'https://www.google.com/a/b/c',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/a/b/c', script), 'should match exact');
|
|
q.ok(testScript('https://www.google.com/a/b/c', script), 'should match exact');
|
|
|
q.notOk(testScript('https://www.google.com/a/b/c/d', script), 'should match exact');
|
|
q.notOk(testScript('https://www.google.com/a/b/c/d', script), 'should match exact');
|
|
|
q.end();
|
|
q.end();
|
|
@@ -109,29 +115,27 @@ test('path', t => {
|
|
|
|
|
|
|
|
test('include', t => {
|
|
test('include', t => {
|
|
|
t.test('should include any', q => {
|
|
t.test('should include any', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
include: [
|
|
include: [
|
|
|
'*',
|
|
'*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `http | https`');
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `http | https`');
|
|
|
q.ok(testScript('file:///Users/Gerald/file', script), 'should match `file`');
|
|
q.ok(testScript('file:///Users/Gerald/file', script), 'should match `file`');
|
|
|
q.end();
|
|
q.end();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should include by regexp', q => {
|
|
t.test('should include by regexp', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
include: [
|
|
include: [
|
|
|
'https://www.google.com/*',
|
|
'https://www.google.com/*',
|
|
|
'https://twitter.com/*',
|
|
'https://twitter.com/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `/`');
|
|
q.ok(testScript('https://www.google.com/', script), 'should match `/`');
|
|
|
q.ok(testScript('https://www.google.com/hello/world', script), 'include by prefix');
|
|
q.ok(testScript('https://www.google.com/hello/world', script), 'include by prefix');
|
|
|
q.notOk(testScript('https://www.hello.com/', script), 'not include by prefix');
|
|
q.notOk(testScript('https://www.hello.com/', script), 'not include by prefix');
|
|
@@ -141,8 +145,7 @@ test('include', t => {
|
|
|
|
|
|
|
|
test('exclude', t => {
|
|
test('exclude', t => {
|
|
|
t.test('should exclude any', q => {
|
|
t.test('should exclude any', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
@@ -151,14 +154,13 @@ test('exclude', t => {
|
|
|
'*',
|
|
'*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `http | https`');
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `http | https`');
|
|
|
q.end();
|
|
q.end();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should include by regexp', q => {
|
|
t.test('should include by regexp', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
@@ -168,7 +170,7 @@ test('exclude', t => {
|
|
|
'https://twitter.com/*',
|
|
'https://twitter.com/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `/`');
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `/`');
|
|
|
q.notOk(testScript('https://www.google.com/hello/world', script), 'exclude by prefix');
|
|
q.notOk(testScript('https://www.google.com/hello/world', script), 'exclude by prefix');
|
|
|
q.ok(testScript('https://www.hello.com/', script), 'not exclude by prefix');
|
|
q.ok(testScript('https://www.hello.com/', script), 'not exclude by prefix');
|
|
@@ -178,8 +180,7 @@ test('exclude', t => {
|
|
|
|
|
|
|
|
test('exclude-match', t => {
|
|
test('exclude-match', t => {
|
|
|
t.test('should exclude any', q => {
|
|
t.test('should exclude any', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
@@ -188,14 +189,13 @@ test('exclude-match', t => {
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `http | https`');
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `http | https`');
|
|
|
q.end();
|
|
q.end();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
t.test('should include by regexp', q => {
|
|
t.test('should include by regexp', q => {
|
|
|
- const script = {
|
|
|
|
|
- custom: {},
|
|
|
|
|
|
|
+ const script = buildScript({
|
|
|
meta: {
|
|
meta: {
|
|
|
match: [
|
|
match: [
|
|
|
'*://*/*',
|
|
'*://*/*',
|
|
@@ -205,7 +205,7 @@ test('exclude-match', t => {
|
|
|
'https://twitter.com/*',
|
|
'https://twitter.com/*',
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `/`');
|
|
q.notOk(testScript('https://www.google.com/', script), 'should exclude `/`');
|
|
|
q.notOk(testScript('https://www.google.com/hello/world', script), 'exclude by prefix');
|
|
q.notOk(testScript('https://www.google.com/hello/world', script), 'exclude by prefix');
|
|
|
q.ok(testScript('https://www.hello.com/', script), 'not exclude by prefix');
|
|
q.ok(testScript('https://www.hello.com/', script), 'not exclude by prefix');
|
|
@@ -213,6 +213,26 @@ test('exclude-match', t => {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+test('custom', t => {
|
|
|
|
|
+ t.test('should ignore original rules', q => {
|
|
|
|
|
+ const script = buildScript({
|
|
|
|
|
+ custom: {
|
|
|
|
|
+ match: [
|
|
|
|
|
+ 'https://twitter.com/*',
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ match: [
|
|
|
|
|
+ 'https://www.google.com/*',
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ q.ok(testScript('https://twitter.com/', script), 'should match custom rules');
|
|
|
|
|
+ q.notOk(testScript('https://www.google.com/', script), 'should not match original rules');
|
|
|
|
|
+ q.end();
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
test('blacklist', t => {
|
|
test('blacklist', t => {
|
|
|
t.test('should exclude match rules', q => {
|
|
t.test('should exclude match rules', q => {
|
|
|
resetBlacklist(`\
|
|
resetBlacklist(`\
|