Skip to content

Commit

Permalink
fix google-ima3 compatibility. #272 AG-18460
Browse files Browse the repository at this point in the history
related: AdguardTeam/FiltersCompiler#167

Squashed commit of the following:

commit f9d1c8b
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Dec 21 21:03:15 2022 +0200

    update changelog

commit 8bdc932
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Dec 21 21:02:34 2022 +0200

    update compatibility-table

commit 2538a5b
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Dec 21 21:01:25 2022 +0200

    fix google-ima3 conversion

commit 5e990c4
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Dec 21 21:00:46 2022 +0200

    add alias for google-ima3
  • Loading branch information
slavaleleka committed Dec 22, 2022
1 parent 049012a commit c44e89c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Scriptlets and Redirect Resources Changelog

## Unreleased
## Unreleased 1.7.x

### Fixed

- `prevent-addEventListener` and `log-addEventListener` loosing context when encountering already bound `.addEventListener`
- `google-ima3` conversion

## v1.7.14

Expand Down
7 changes: 4 additions & 3 deletions scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@
"adg": "google-analytics-ga",
"ubo": "google-analytics_ga.js"
},
{
"adg": "google-ima3",
"ubo": "google-ima.js"
},
{
"adg": "googlesyndication-adsbygoogle",
"ubo": "googlesyndication_adsbygoogle.js"
Expand Down Expand Up @@ -444,9 +448,6 @@
{
"ubo": "mxpnl_mixpanel.js"
},
{
"ubo": "google-ima.js"
},
{
"ubo": "noop-0.5s.mp3"
}
Expand Down
1 change: 1 addition & 0 deletions src/helpers/compatibility-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const redirects = [
},
{
adg: 'google-ima3',
ubo: 'google-ima.js',
},
{
adg: 'gemius',
Expand Down
8 changes: 7 additions & 1 deletion src/redirects/google-ima3.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,13 @@ export function GoogleIma3(source) {
hit(source);
}

GoogleIma3.names = ['google-ima3'];
GoogleIma3.names = [
'google-ima3',
// prefixed name
'ubo-google-ima.js',
// original ubo name
'google-ima.js',
];

GoogleIma3.injections = [
hit,
Expand Down
8 changes: 8 additions & 0 deletions tests/lib-tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ test('Test REDIRECT converting - UBO -> ADG', (assert) => {
uboRule = '||g9g.eu^*fa.js$script,redirect=fuckadblock.js-3.2.0';
expectedAdgRule = '||g9g.eu^*fa.js$script,redirect=prevent-fab-3.2.0';
assert.strictEqual(convertRedirectToAdg(uboRule), expectedAdgRule);

uboRule = '||imasdk.googleapis.com/js/sdkloader/ima3.js$script,important,redirect=google-ima.js,domain=example.org';
expectedAdgRule = '||imasdk.googleapis.com/js/sdkloader/ima3.js$script,important,redirect=google-ima3,domain=example.org';
assert.strictEqual(convertRedirectToAdg(uboRule), expectedAdgRule);
});

test('Test REDIRECT-RULE converting - UBO -> ADG', (assert) => {
Expand Down Expand Up @@ -555,6 +559,10 @@ test('Test REDIRECT converting - ADG -> UBO', (assert) => {
new RegExp('Unable to convert for uBO'), // specific error matcher
'no TYPES to specify, ABSENT_SOURCE_TYPE_REPLACEMENT should be updated',
);

adgRule = '||imasdk.googleapis.com/js/sdkloader/ima3.js$script,important,redirect=google-ima3,domain=example.org';
expectedUboRule = '||imasdk.googleapis.com/js/sdkloader/ima3.js$script,important,redirect=google-ima.js,domain=example.org';
assert.strictEqual(convertAdgRedirectToUbo(adgRule), expectedUboRule);
});

test('Test REDIRECT-RULE converting - ADG -> UBO', (assert) => {
Expand Down
18 changes: 18 additions & 0 deletions tests/redirects/google-ima3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ const afterEach = () => {

module(name, { beforeEach, afterEach });

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

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

assert.strictEqual(codeByAdgParams, codeByUboParams, 'ubo name - ok');
});

test('Ima mocked', (assert) => {
assert.expect(28);

Expand Down
2 changes: 1 addition & 1 deletion wiki/compatibility-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
| [fingerprint3js](../wiki/about-redirects.md#fingerprint3js) | fingerprint3.js | |
| [google-analytics](../wiki/about-redirects.md#google-analytics) | google-analytics_analytics.js | |
| [google-analytics-ga](../wiki/about-redirects.md#google-analytics-ga) | google-analytics_ga.js | |
| [google-ima3](../wiki/about-redirects.md#google-ima3) | google-ima.js | |
| [googlesyndication-adsbygoogle](../wiki/about-redirects.md#googlesyndication-adsbygoogle) | googlesyndication_adsbygoogle.js | |
| [googletagservices-gpt](../wiki/about-redirects.md#googletagservices-gpt) | googletagservices_gpt.js | |
| [gemius](../wiki/about-redirects.md#gemius) | | |
Expand Down Expand Up @@ -133,5 +134,4 @@
| | window.open-defuser.js | |
| | noeval.js | |
| | mxpnl_mixpanel.js | |
| | google-ima.js | |
| | noop-0.5s.mp3 | |

0 comments on commit c44e89c

Please sign in to comment.