Skip to content

Commit 9dca7a3

Browse files
committed
Tests
1 parent 64565d1 commit 9dca7a3

File tree

8 files changed

+93
-39
lines changed

8 files changed

+93
-39
lines changed

injected/integration-test/duckplayer-native.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,19 @@ test.describe('Duck Player Native messaging', () => {
2828
await duckPlayer.didSendCurrentTimestamp();
2929
});
3030
});
31+
32+
test.describe('Duck Player Native thumbnail overlay', () => {
33+
test('Shows overlay on YouTube player page', async ({ page }, workerInfo) => {
34+
const duckPlayer = DuckPlayerNative.create(page, workerInfo);
35+
36+
// Given the duckPlayerNative feature is enabled
37+
await duckPlayer.withRemoteConfig();
38+
39+
// When I go to a YouTube page
40+
await duckPlayer.gotoYouTubePage();
41+
await duckPlayer.sendOnMediaControl();
42+
43+
// Then I should see the thumbnail overlay in the page
44+
await duckPlayer.didShowThumbnailOverlay();
45+
});
46+
});

injected/integration-test/page-objects/duckplayer-native.js

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class DuckPlayerNative {
7676
const urlParams = new URLSearchParams([
7777
['v', videoID],
7878
['variant', variant],
79-
['pageType', pageType],
8079
]);
8180

8281
const page = this.pages[pageType];
@@ -110,6 +109,66 @@ export class DuckPlayerNative {
110109
});
111110
}
112111

112+
/**
113+
* @param {string} name
114+
* @param {Record<string, any>} payload
115+
*/
116+
async simulateSubscriptionMessage(name, payload) {
117+
await this.collector.simulateSubscriptionMessage('duckPlayerNative', name, payload);
118+
}
119+
120+
/**
121+
* Helper for creating an instance per platform
122+
* @param {import("@playwright/test").Page} page
123+
* @param {import("@playwright/test").TestInfo} testInfo
124+
*/
125+
static create(page, testInfo) {
126+
// Read the configuration object to determine which platform we're testing against
127+
const { platformInfo, build } = perPlatform(testInfo.project.use);
128+
return new DuckPlayerNative(page, build, platformInfo);
129+
}
130+
131+
/**
132+
* @return {Promise<string>}
133+
*/
134+
requestWillFail() {
135+
return new Promise((resolve, reject) => {
136+
// on windows it will be a failed request
137+
const timer = setTimeout(() => {
138+
reject(new Error('timed out'));
139+
}, 5000);
140+
this.page.on('framenavigated', (req) => {
141+
clearTimeout(timer);
142+
resolve(req.url());
143+
});
144+
});
145+
}
146+
147+
/* Subscriptions */
148+
149+
/**
150+
* @param {object} options
151+
*/
152+
async sendOnMediaControl(options = { pause: true }) {
153+
await this.simulateSubscriptionMessage('onMediaControl', options);
154+
}
155+
156+
/**
157+
* @param {object} options
158+
*/
159+
async sendOnSerpNotify(options = {}) {
160+
await this.simulateSubscriptionMessage('onSerpNotify', options);
161+
}
162+
163+
/**
164+
* @param {object} options
165+
*/
166+
async sendOnMuteAudio(options = { mute: true }) {
167+
await this.simulateSubscriptionMessage('onMuteAudio', options);
168+
}
169+
170+
/* Messaging assertions */
171+
113172
async didSendInitialHandshake() {
114173
const messages = await this.collector.waitForMessage('initialSetup');
115174
expect(messages).toMatchObject([
@@ -138,31 +197,14 @@ export class DuckPlayerNative {
138197
]);
139198
}
140199

141-
/**
142-
* Helper for creating an instance per platform
143-
* @param {import("@playwright/test").Page} page
144-
* @param {import("@playwright/test").TestInfo} testInfo
145-
*/
146-
static create(page, testInfo) {
147-
// Read the configuration object to determine which platform we're testing against
148-
const { platformInfo, build } = perPlatform(testInfo.project.use);
149-
return new DuckPlayerNative(page, build, platformInfo);
200+
/* Thumbnail Overlay assertions */
201+
202+
async didShowThumbnailOverlay() {
203+
await this.page.locator('ddg-video-thumbnail-overlay-mobile').waitFor({ state: 'visible', timeout: 1000 });
150204
}
151205

152-
/**
153-
* @return {Promise<string>}
154-
*/
155-
requestWillFail() {
156-
return new Promise((resolve, reject) => {
157-
// on windows it will be a failed request
158-
const timer = setTimeout(() => {
159-
reject(new Error('timed out'));
160-
}, 5000);
161-
this.page.on('framenavigated', (req) => {
162-
clearTimeout(timer);
163-
resolve(req.url());
164-
});
165-
});
206+
async didShowLogoInOverlay() {
207+
await this.page.locator('ddg-video-thumbnail-overlay-mobile .logo').waitFor({ state: 'visible', timeout: 1000 });
166208
}
167209
}
168210

injected/integration-test/test-pages/duckplayer-native/pages/player.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@
184184
featureSettings: settings.features,
185185
}
186186
}))
187-
188-
setTimeout(() => {
189-
document.dispatchEvent(new CustomEvent('initialSetup', { detail: {} }));
190-
})
191187
})();
192188
</script>
193189

injected/src/features.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const otherFeatures = /** @type {const} */ ([
3333
/** @typedef {baseFeatures[number]|otherFeatures[number]} FeatureName */
3434
/** @type {Record<string, FeatureName[]>} */
3535
export const platformSupport = {
36-
apple: ['webCompat', 'duckPlayerNative', ...baseFeatures],
37-
'apple-isolated': ['duckPlayerNative', 'brokerProtection', 'performanceMetrics', 'clickToLoad', 'messageBridge', 'favicon'],
36+
apple: ['webCompat', ...baseFeatures],
37+
'apple-isolated': ['duckPlayer', 'duckPlayerNative', 'brokerProtection', 'performanceMetrics', 'clickToLoad', 'messageBridge', 'favicon'],
3838
android: [...baseFeatures, 'webCompat', 'breakageReporting', 'duckPlayer', 'messageBridge'],
3939
'android-broker-protection': ['brokerProtection'],
4040
'android-autofill-password-import': ['autofillPasswordImport'],

injected/src/features/duck-player-native.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export class DuckPlayerNativeFeature extends ContentFeature {
2828
/**
2929
* @type {import("@duckduckgo/privacy-configuration/schema/features/duckplayer-native.js").DuckPlayerNativeSettings}
3030
*/
31-
// TODO: Why isn't this working?
32-
// const settings = this.getFeatureSetting('settings');
33-
const settings = args?.featureSettings?.duckPlayerNative?.settings || args?.featureSettings?.duckPlayerNative;
31+
const settings = this.getFeatureSetting('settings') || args?.featureSettings?.duckPlayerNative?.settings || args?.featureSettings?.duckPlayerNative; // TODO: Why doesn't it work with just getFeatureSettings?
3432
console.log('DUCK PLAYER NATIVE SELECTORS', settings?.selectors);
3533

3634
const locale = args?.locale || args?.language || 'en';

injected/src/features/duckplayer-native/custom-error/custom-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Logger } from '../util';
33
import { createPolicy, html } from '../../../dom-utils.js';
44
import { customElementsDefine, customElementsGet } from '../../../captured-globals.js';
55

6-
/** @typedef {import('../error-detection').YouTubeError} YouTubeError */
6+
/** @import {YouTubeError} from '../error-detection' */
77

88
/**
99
* The custom element that we use to present our UI elements

injected/src/features/duckplayer-native/error-detection.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Logger } from './util';
22

3-
/** @typedef {"age-restricted" | "sign-in-required" | "no-embed" | "unknown"} YouTubeError */
4-
5-
/** @typedef {(error: YouTubeError) => void} ErrorDetectionCallback */
6-
/** @typedef {import('./duckplayer-native').DuckPlayerNativeSettings['selectors']} DuckPlayerNativeSelectors */
3+
/**
4+
* @import {DuckPlayerNativeSettings} from './duckplayer-native'
5+
* @typedef {"age-restricted" | "sign-in-required" | "no-embed" | "unknown"} YouTubeError
6+
* @typedef {DuckPlayerNativeSettings['selectors']} DuckPlayerNativeSelectors
7+
* @typedef {(error: YouTubeError) => void} ErrorDetectionCallback
8+
*/
79

810
/**
911
* @typedef {object} ErrorDetectionSettings

injected/src/features/duckplayer-native/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as constants from './constants.js';
1111
*/
1212

1313
/**
14-
* @typedef {import("@duckduckgo/messaging").Messaging} Messaging
14+
* @import {Messaging} from '@duckduckgo/messaging'
1515
*
1616
* A wrapper for all communications.
1717
*

0 commit comments

Comments
 (0)