Skip to content

Commit 5e651c4

Browse files
author
Shane Osbourne
committed
run tests on apple platform
1 parent dbbc71c commit 5e651c4

File tree

4 files changed

+84
-34
lines changed

4 files changed

+84
-34
lines changed

packages/special-pages/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build.dev": "NODE_ENV=development node index.mjs",
1010
"test": "playwright test",
1111
"test.windows": "npm run test -- --project duckplayer-windows",
12+
"test.apple": "npm run test -- --project duckplayer-apple",
1213
"test.headed": "npm run test -- --headed",
1314
"test.ui": "npm run test -- --ui",
1415
"pretest": "npm run build.dev",

packages/special-pages/pages/duckplayer/src/js/index.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,10 @@ const Setting = {
529529
* Initializes the setting checkbox:
530530
* 1. Listens for (user) changes on the actual checkbox
531531
* 2. Listens for to clicks on the checkbox text
532+
* @param {object} opts
533+
* @param {string} opts.settingsUrl
532534
*/
533-
init: () => {
535+
init: (opts) => {
534536
const checkbox = Setting.checkbox()
535537

536538
checkbox.addEventListener('change', () => {
@@ -540,7 +542,7 @@ const Setting = {
540542
const settingsIcon = Setting.settingsIcon()
541543

542544
// windows settings - we will need to alter for other platforms.
543-
settingsIcon.setAttribute('href', 'duck://settings/duckplayer')
545+
settingsIcon.setAttribute('href', opts.settingsUrl)
544546
}
545547
}
546548

@@ -758,18 +760,41 @@ const MouseMove = {
758760
* Initializes all parts of the page on load.
759761
*/
760762
document.addEventListener('DOMContentLoaded', () => {
761-
Setting.init()
763+
Setting.init({
764+
settingsUrl: settingsUrl(import.meta.platform)
765+
})
762766
Comms.init({
763767
platform: import.meta.platform,
764768
env: import.meta.env
765769
})
766770
VideoPlayer.init()
767771
Tooltip.init()
768772
PlayOnYouTube.init({
769-
// todo(Shane): platform specific
770-
base: 'duck://player/openInYoutube'
773+
base: baseUrl(import.meta.platform)
771774
})
772775
MouseMove.init()
773776
})
774777

778+
/**
779+
* @param {ImportMeta['platform']} platform
780+
*/
781+
function baseUrl (platform) {
782+
switch (platform) {
783+
// this is different on Windows to allow the native side to intercept the navigation more easily
784+
case 'windows': return 'duck://player/openInYoutube'
785+
default: return 'https://www.youtube.com/watch'
786+
}
787+
}
788+
789+
/**
790+
* @param {ImportMeta['platform']} platform
791+
*/
792+
function settingsUrl (platform) {
793+
switch (platform) {
794+
// this is different on Windows to allow the native side to intercept the navigation more easily
795+
case 'windows': return 'duck://settings/duckplayer'
796+
default: return 'about:preferences/duckplayer'
797+
}
798+
}
799+
775800
initStorage()

packages/special-pages/playwright.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export default defineConfig({
66
name: 'duckplayer-windows',
77
testMatch: 'duckplayer.spec.js',
88
use: { platform: 'windows' }
9+
},
10+
{
11+
name: 'duckplayer-apple',
12+
testMatch: 'duckplayer.spec.js',
13+
use: { platform: 'apple' }
914
}
1015
// Coming in a future PR
1116
// {

packages/special-pages/tests/page-objects/duck-player.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,10 @@ export class DuckPlayerPage {
3737
*/
3838
async openPage (urlParams) {
3939
const url = 'https://www.youtube-nocookie.com' + '?' + urlParams.toString()
40-
41-
switch (this.platform.name) {
42-
case 'windows': {
43-
await this.mocks.install()
44-
await this.installYoutubeMocks()
45-
// construct the final url
46-
await this.page.goto(url)
47-
break
48-
}
49-
default:
50-
throw new Error('unreachable')
51-
}
40+
await this.mocks.install()
41+
await this.installYoutubeMocks()
42+
// construct the final url
43+
await this.page.goto(url)
5244
}
5345

5446
/**
@@ -175,29 +167,55 @@ export class DuckPlayerPage {
175167
}
176168

177169
async opensSettingsInNewTab () {
178-
// duck:// scheme will fail, but we can assert that it was tried and grab the URL
179-
const failure = new Promise(resolve => {
180-
this.page.context().on('requestfailed', f => {
181-
resolve(f.url())
182-
})
170+
const newTab = new Promise(resolve => {
171+
// on pages with about:preferences it will launch a new tab
172+
this.page.context().on('page', resolve)
173+
174+
// on windows it will be a failed request
175+
this.page.context().on('requestfailed', resolve)
183176
})
184177

185-
await this.page.locator('.open-settings').click()
178+
const expected = {
179+
windows: 'duck://settings/duckplayer',
180+
apple: 'about:preferences/duckplayer'
181+
}[this.platform.name]
182+
183+
const openSettings = this.page.locator('.open-settings')
184+
expect(await openSettings.getAttribute('href')).toEqual(expected)
185+
expect(await openSettings.getAttribute('target')).toEqual('_blank')
186186

187-
// this is for windows, we'll need to support more
188-
expect(await failure).toEqual('duck://settings/duckplayer')
187+
// click to ensure a new tab opens
188+
await openSettings.click()
189+
190+
// ensure a new tab was opened (eg: that nothing in our JS stopped the regular click)
191+
await newTab
189192
}
190193

191194
async opensInYoutube () {
192-
// duck:// scheme will fail, but we can assert that it was tried and grab the URL
193-
const failure = new Promise(resolve => {
194-
this.page.context().on('requestfailed', f => {
195-
resolve(f.url())
195+
switch (this.platform.name) {
196+
// Windows uses a special URL handler to exit duck player
197+
case 'windows': {
198+
const failure = new Promise(resolve => {
199+
this.page.context().on('requestfailed', f => {
200+
resolve(f.url())
201+
})
196202
})
197-
})
198-
await this.page.getByRole('link', { name: 'Watch on YouTube' }).click()
199-
// todo(Shane): platform specific
200-
expect(await failure).toEqual('duck://player/openInYoutube?v=VIDEO_ID')
203+
await this.page.getByRole('link', { name: 'Watch on YouTube' }).click()
204+
expect(await failure).toEqual('duck://player/openInYoutube?v=VIDEO_ID')
205+
break
206+
}
207+
// the default is just a regular link
208+
default: {
209+
const nextNavigation = new Promise(resolve => {
210+
this.page.context().on('request', f => {
211+
resolve(f.url())
212+
})
213+
})
214+
await this.page.getByRole('link', { name: 'Watch on YouTube' }).click()
215+
expect(await nextNavigation).toEqual('https://www.youtube.com/watch?v=VIDEO_ID')
216+
break
217+
}
218+
}
201219
}
202220

203221
/**
@@ -270,7 +288,8 @@ export class DuckPlayerPage {
270288
*/
271289
get basePath () {
272290
return {
273-
windows: '../../build/windows/pages/duckplayer'
291+
windows: '../../build/windows/pages/duckplayer',
292+
apple: '../../Sources/ContentScopeScripts/dist/pages/duckplayer'
274293
}[this.platform.name]
275294
}
276295

0 commit comments

Comments
 (0)