From 5129866099978db91dc5018a1835c6493d6c49a8 Mon Sep 17 00:00:00 2001 From: erwin mombay Date: Wed, 8 Jan 2025 09:56:28 -0800 Subject: [PATCH] append a `base` element to force the baseURI of the FakeWindow (#40218) --- .../0.1/test/test-affiliate-link-resolver.js | 3 +-- .../0.1/test/test-e2e/test-amp-story-player.js | 3 +-- extensions/amp-video/0.1/test/test-flexible-bitrate.js | 3 +-- testing/fake-dom.js | 8 ++++++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/extensions/amp-skimlinks/0.1/test/test-affiliate-link-resolver.js b/extensions/amp-skimlinks/0.1/test/test-affiliate-link-resolver.js index 12d81ef80e54..7a261598b1d8 100644 --- a/extensions/amp-skimlinks/0.1/test/test-affiliate-link-resolver.js +++ b/extensions/amp-skimlinks/0.1/test/test-affiliate-link-resolver.js @@ -396,8 +396,7 @@ describes.fakeWin( expect(resolver.getAnchorDomain_(anchor)).to.equal('test.com'); }); - // TODO(#40214): fix flaky test. - it.skip('removes // protocol', () => { + it('removes // protocol', () => { const anchor = helpers.createAnchor('//test.com/'); expect(resolver.getAnchorDomain_(anchor)).to.equal('test.com'); }); diff --git a/extensions/amp-story-player/0.1/test/test-e2e/test-amp-story-player.js b/extensions/amp-story-player/0.1/test/test-e2e/test-amp-story-player.js index 874e0aaf5560..e3ca2f483253 100644 --- a/extensions/amp-story-player/0.1/test/test-e2e/test-amp-story-player.js +++ b/extensions/amp-story-player/0.1/test/test-e2e/test-amp-story-player.js @@ -22,8 +22,7 @@ describes.endtoend( await expect(player); }); - // TODO(#40214): fix flaky test. - it.skip('loads and displays first story on page load when player is visible in viewport', async () => { + it('loads and displays first story on page load when player is visible in viewport', async () => { const shadowHost = await controller.findElement( 'div.i-amphtml-story-player-shadow-root-intermediary' ); diff --git a/extensions/amp-video/0.1/test/test-flexible-bitrate.js b/extensions/amp-video/0.1/test/test-flexible-bitrate.js index 40cfcf32c007..6137f90ebb73 100644 --- a/extensions/amp-video/0.1/test/test-flexible-bitrate.js +++ b/extensions/amp-video/0.1/test/test-flexible-bitrate.js @@ -47,8 +47,7 @@ describes.fakeWin('amp-video flexible-bitrate', {}, (env) => { expect(currentBitrates(v0)[0]).to.equal(1000); }); - // TODO(#40214): fix flaky test. - it.skip('should observe lower bandwidth on next sort', () => { + it('should observe lower bandwidth on next sort', () => { const m = getManager('4g'); const v0 = getVideo([4000, 1000, 3000, 2000]); v0.id = 'v0'; diff --git a/testing/fake-dom.js b/testing/fake-dom.js index 044e59282b19..6e9bce717894 100644 --- a/testing/fake-dom.js +++ b/testing/fake-dom.js @@ -71,6 +71,14 @@ export class FakeWindow { // Document. /** @const {!HTMLDocument} */ this.document = self.document.implementation.createHTMLDocument(''); + // NOTE: There was a change between chrome 119 and 120 where the above + // self.document.implementation.createHTMLDocument no longer inherits + // the baseURI of self.document. We explicitly set and force it thru + // a `` element. + const base = this.document.createElement('base'); + base.href = self.document.baseURI; + this.document.head.appendChild(base); + Object.defineProperty(this.document, 'defaultView', { get: () => this, });