Skip to content

Commit

Permalink
change IMA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scripthunter7 committed Jul 18, 2023
1 parent d01672f commit 766dfb4
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions tests/redirects/google-ima3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,45 +88,29 @@ test('Ima - run requestAds function twice', (assert) => {
});
});

test('Ima - check if google.ima.dai was NOT overwritten', (assert) => {
// Test for https://github.com/AdguardTeam/Scriptlets/issues/331
const done = assert.async();

// https://github.com/AdguardTeam/Scriptlets/issues/331
test('Ima - check if DAI API is not discarded by the redirect', (assert) => {
// Define some dummy DAI API which cannot be discarded by the redirect
window.google = {
ima: {
// should be kept
dai: {
api: {
StreamManager() { },
foo: 'bar',
},
},
shouldBeDiscarded: true,
// should be discarded
bar: 'foo',
},
};

runRedirect(name);

let number = 0;
const test = () => {
number += 1;
};
const { ima } = window.google;
const AdsLoader = new ima.AdsLoader();
AdsLoader.addEventListener(ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, test);

assert.ok(
typeof window.google.ima.dai.api.StreamManager === 'function',
'window.google.ima.dai.api.StreamManager was not overwritten',
);
// check if DAI API is not discarded by the redirect
assert.ok(window.google.ima.dai, 'window.google.ima.dai exists');
assert.ok(window.google.ima.dai.api, 'window.google.ima.dai.api exists');
assert.strictEqual(window.google.ima.dai.api.foo, 'bar', 'window.google.ima.dai.api.foo is equal to "bar"');

// Only google.ima.dai should not be overwritten
assert.strictEqual(
window.google.ima.shouldBeDiscarded, undefined,
'google.ima.shouldBeDiscarded is undefined',
);

AdsLoader.requestAds();
requestAnimationFrame(() => {
assert.strictEqual(number, 1, 'number is equal to 1');
done();
});
// other properties should be discarded
assert.strictEqual(window.google.ima.bar, undefined, 'window.google.ima.bar is undefined');
});

0 comments on commit 766dfb4

Please sign in to comment.