From c24af43690a9c7ead3adb8c173d76038cdd0ca86 Mon Sep 17 00:00:00 2001 From: Sam Macbeth Date: Thu, 5 Oct 2023 12:22:03 +0200 Subject: [PATCH] Add tests for handling of invalid rules. --- .../Resources/test_rules_blocking.json | 10 +++ .../tests/test.declarativeNetRequest.js | 84 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/Shared (Extension)/Resources/test_rules_blocking.json b/Shared (Extension)/Resources/test_rules_blocking.json index 028266d..239ba67 100644 --- a/Shared (Extension)/Resources/test_rules_blocking.json +++ b/Shared (Extension)/Resources/test_rules_blocking.json @@ -8,5 +8,15 @@ "condition": { "urlFilter": "||bad.third-party.site/*" } + }, + { + "id": 10001, + "priority": 1, + "action": { + "type": "invalid" + }, + "condition": { + "urlFilter": "||example.com" + } } ] \ No newline at end of file diff --git a/Shared (Extension)/Resources/tests/test.declarativeNetRequest.js b/Shared (Extension)/Resources/tests/test.declarativeNetRequest.js index e4037fc..2971805 100644 --- a/Shared (Extension)/Resources/tests/test.declarativeNetRequest.js +++ b/Shared (Extension)/Resources/tests/test.declarativeNetRequest.js @@ -790,4 +790,88 @@ describe("chrome.declarativeNetRequest", () => { } ); }); + + it('adding unsupported DNR rules dynamically', async () => { + try { + await chrome.declarativeNetRequest.updateDynamicRules({ + addRules: [ + { + "id": 990, + "priority": 1, + "action": { + "type": "block" + }, + "condition": { + "urlFilter": "||bad.third-party.site/*" + } + }, + { + "id": 999, + "priority": 1, + "action": { + "type": "invalid" + }, + "condition": { + "urlFilter": "||" + } + }, + { + "id": 1000, + "priority": 1, + "action": { + "type": "block" + }, + "condition": { + "urlFilter": "||bad.third-party.site/hello" + } + } + ]}) + expect.fail('updateDynamicRules should throw') + } catch(e) { + console.log(e) + expect(await chrome.declarativeNetRequest.getDynamicRules()).to.have.length(0) + } + }) + + it('adding invalid DNR rules dynamically', async () => { + try { + await chrome.declarativeNetRequest.updateDynamicRules({ + addRules: [ + { + "id": 990, + "priority": 1, + "action": { + "type": "block" + }, + "condition": { + "urlFilter": "||bad.third-party.site/*" + } + }, + { + "id": 1000, + "priority": 1, + "action": { + "type": "block" + }, + "condition": { + "urlFilter": "||" + } + }, + { + "id": 1000, + "priority": 1, + "action": { + "type": "block" + }, + "condition": { + "urlFilter": "||bad.third-party.site/hello" + } + } + ]}) + expect.fail('updateDynamicRules should throw') + } catch(e) { + console.log(e) + expect(await chrome.declarativeNetRequest.getDynamicRules()).to.have.length(0) + } + }) });