Skip to content

Commit

Permalink
Add tests for handling of invalid rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
sammacbeth committed Oct 5, 2023
1 parent f9808c3 commit c24af43
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Shared (Extension)/Resources/test_rules_blocking.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@
"condition": {
"urlFilter": "||bad.third-party.site/*"
}
},
{
"id": 10001,
"priority": 1,
"action": {
"type": "invalid"
},
"condition": {
"urlFilter": "||example.com"
}
}
]
84 changes: 84 additions & 0 deletions Shared (Extension)/Resources/tests/test.declarativeNetRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
});

0 comments on commit c24af43

Please sign in to comment.