Skip to content

Commit

Permalink
improve set-cookie-reload compatibility. #332 AG-23321
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 421e0fe
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Feb 9 19:30:48 2024 +0200

    add set-cookie-reload aliases

commit e90bf17
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Feb 9 19:30:20 2024 +0200

    update compatibility table
  • Loading branch information
slavaleleka committed Feb 12, 2024
1 parent e58e25c commit 60a20ac
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
24 changes: 11 additions & 13 deletions scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"adg": "adjust-setTimeout",
"ubo": "adjust-setTimeout.js (nano-setTimeout-booster.js, nano-stb.js)"
},
{
"adg": "call-nothrow",
"ubo": "call-nothrow.js"
},
{
"adg": "close-window",
"ubo": "close-window.js (window-close-if.js)"
Expand Down Expand Up @@ -168,7 +172,8 @@
"ubo": "set-cookie.js"
},
{
"adg": "set-cookie-reload"
"adg": "set-cookie-reload",
"ubo": "set-cookie-reload.js"
},
{
"adg": "set-local-storage-item",
Expand All @@ -181,6 +186,10 @@
"adg": "set-session-storage-item",
"ubo": "set-session-storage-item.js"
},
{
"adg": "spoof-css",
"ubo": "spoof-css.js"
},
{
"adg": "xml-prune",
"ubo": "xml-prune.js"
Expand All @@ -200,10 +209,6 @@
{
"ubo": "href-sanitizer.js"
},
{
"adg": "call-nothrow",
"ubo": "call-nothrow.js"
},
{
"abp": "abort-on-iframe-property-read"
},
Expand Down Expand Up @@ -270,10 +275,6 @@
{
"ubo": "window.name-defuser.js"
},
{
"adg": "spoof-css",
"ubo": "spoof-css.js"
},
{
"ubo": "trusted-set-constant.js (trusted-set.js)"
},
Expand Down Expand Up @@ -301,9 +302,6 @@
{
"ubo": "prevent-canvas.js"
},
{
"ubo": "set-cookie-reload.js"
},
{
"ubo": "trusted-set-cookie-reload.js"
},
Expand Down Expand Up @@ -536,4 +534,4 @@
"ubo": "noop-0.5s.mp3"
}
]
}
}
4 changes: 4 additions & 0 deletions src/scriptlets/set-cookie-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export function setCookieReload(source, name, value, path = '/') {

setCookieReload.names = [
'set-cookie-reload',
// aliases are needed for matching the related scriptlet converted into our syntax
'set-cookie-reload.js',
'ubo-set-cookie-reload.js',
'ubo-set-cookie-reload',
];

setCookieReload.injections = [
Expand Down
8 changes: 8 additions & 0 deletions tests/api/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ describe('Test scriptlet api methods', () => {
actual: 'example.com##+js(set-cookie, CookieConsent, true)',
expected: "example.com#%#//scriptlet('ubo-set-cookie.js', 'CookieConsent', 'true')",
},
{
actual: 'example.com##+js(set-cookie-reload, isSet, 1)',
expected: "example.com#%#//scriptlet('ubo-set-cookie-reload.js', 'isSet', '1')",
},
{
actual: 'example.com##+js(set-local-storage-item, gdpr_popup, true)',
expected: "example.com#%#//scriptlet('ubo-set-local-storage-item.js', 'gdpr_popup', 'true')",
Expand Down Expand Up @@ -326,6 +330,10 @@ describe('Test scriptlet api methods', () => {
actual: "example.com#%#//scriptlet('spoof-css', '.adsbygoogle, #ads, .adTest', 'visibility', 'visible')",
expected: 'example.com##+js(spoof-css, .adsbygoogle\\, #ads\\, .adTest, visibility, visible)',
},
{
actual: "example.com#%#//scriptlet('set-cookie-reload', 'consent', 'true')",
expected: 'example.com##+js(set-cookie-reload, consent, true)',
},
];
test.each(testCases)('$actual', ({ actual, expected }) => {
expect(convertAdgScriptletToUbo(actual)).toStrictEqual(expected);
Expand Down
35 changes: 35 additions & 0 deletions tests/scriptlets/set-cookie-reload.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable no-underscore-dangle */
import { clearGlobalProps } from '../helpers';

const { test, module } = QUnit;
const name = 'set-cookie-reload';

const beforeEach = () => {
window.__debug = () => {
window.hit = 'FIRED';
};
};

const afterEach = () => {
clearGlobalProps('hit', '__debug');
};

module(name, { beforeEach, afterEach });

test('Checking if alias name works', (assert) => {
const adgParams = {
name,
engine: 'test',
verbose: true,
};
const uboParams = {
name: 'ubo-set-cookie-reload.js',
engine: 'test',
verbose: true,
};

const codeByAdgParams = window.scriptlets.invoke(adgParams);
const codeByUboParams = window.scriptlets.invoke(uboParams);

assert.strictEqual(codeByAdgParams, codeByUboParams, 'ubo name - ok');
});
7 changes: 3 additions & 4 deletions wiki/compatibility-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| [abort-on-stack-trace](../wiki/about-scriptlets.md#abort-on-stack-trace) | abort-on-stack-trace.js (aost.js) | |
| [adjust-setInterval](../wiki/about-scriptlets.md#adjust-setInterval) | adjust-setInterval.js (nano-setInterval-booster.js, nano-sib.js) | |
| [adjust-setTimeout](../wiki/about-scriptlets.md#adjust-setTimeout) | adjust-setTimeout.js (nano-setTimeout-booster.js, nano-stb.js) | |
| [call-nothrow](../wiki/about-scriptlets.md#call-nothrow) | call-nothrow.js | |
| [close-window](../wiki/about-scriptlets.md#close-window) | close-window.js (window-close-if.js) | |
| [debug-current-inline-script](../wiki/about-scriptlets.md#debug-current-inline-script) | | |
| [debug-on-property-read](../wiki/about-scriptlets.md#debug-on-property-read) | | |
Expand Down Expand Up @@ -51,17 +52,17 @@
| [set-attr](../wiki/about-scriptlets.md#set-attr) | set-attr.js | |
| [set-constant](../wiki/about-scriptlets.md#set-constant) | set-constant.js (set.js) | override-property-read |
| [set-cookie](../wiki/about-scriptlets.md#set-cookie) | set-cookie.js | |
| [set-cookie-reload](../wiki/about-scriptlets.md#set-cookie-reload) | | |
| [set-cookie-reload](../wiki/about-scriptlets.md#set-cookie-reload) | set-cookie-reload.js | |
| [set-local-storage-item](../wiki/about-scriptlets.md#set-local-storage-item) | set-local-storage-item.js | |
| [set-popads-dummy](../wiki/about-scriptlets.md#set-popads-dummy) | | |
| [set-session-storage-item](../wiki/about-scriptlets.md#set-session-storage-item) | set-session-storage-item.js | |
| [spoof-css](../wiki/about-scriptlets.md#spoof-css) | spoof-css.js | |
| [xml-prune](../wiki/about-scriptlets.md#xml-prune) | xml-prune.js | |
| | webrtc-if.js | |
| | overlay-buster.js | |
| | alert-buster.js | |
| | golem.de.js (removed) | |
| | href-sanitizer.js | |
| [call-nothrow](../wiki/about-scriptlets.md#call-nothrow) | call-nothrow.js | |
| | | abort-on-iframe-property-read |
| | | abort-on-iframe-property-write |
| | | freeze-element |
Expand All @@ -84,7 +85,6 @@
| | | trace |
| | | race |
| | window.name-defuser.js | |
| [spoof-css](../wiki/about-scriptlets.md#spoof-css) | spoof-css.js | |
| | trusted-set-constant.js (trusted-set.js) | |
| | trusted-set-cookie.js | |
| | trusted-set-local-storage-item.js | |
Expand All @@ -94,7 +94,6 @@
| | trusted-replace-xhr-response.js | |
| | multiup.js | |
| | prevent-canvas.js | |
| | set-cookie-reload.js | |
| | trusted-set-cookie-reload.js | |
| | trusted-click-element.js | |
| | trusted-prune-inbound-object.js | |
Expand Down

0 comments on commit 60a20ac

Please sign in to comment.