From a2d35e9cf53f324d8153cb56982074e1af5fb177 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 28 Apr 2023 01:20:46 +0200 Subject: [PATCH] test: re-enable extensions test with http server (#38129) --- spec/extensions-spec.ts | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/spec/extensions-spec.ts b/spec/extensions-spec.ts index 05adbc2e368d..5e4db3b3d29f 100644 --- a/spec/extensions-spec.ts +++ b/spec/extensions-spec.ts @@ -590,17 +590,32 @@ describe('chrome extensions', () => { }); }); - // FIXME(nornagon): real extensions don't load on file: urls, so this - // test needs to be updated to serve its content over http. - xdescribe('supports "all_frames" option', () => { + describe('supports "all_frames" option', () => { const contentScript = path.resolve(fixtures, 'extensions/content-script'); + const contentPath = path.join(contentScript, 'frame-with-frame.html'); // Computed style values const COLOR_RED = 'rgb(255, 0, 0)'; const COLOR_BLUE = 'rgb(0, 0, 255)'; const COLOR_TRANSPARENT = 'rgba(0, 0, 0, 0)'; - before(() => { + let server: http.Server; + let port: number; + before(async () => { + server = http.createServer((_, res) => { + fs.readFile(contentPath, (error, content) => { + if (error) { + res.writeHead(500); + res.end(`Failed to load ${contentPath} : ${error.code}`); + } else { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(content, 'utf-8'); + } + }); + }); + + ({ port, url } = await listen(server)); + session.defaultSession.loadExtension(contentScript); }); @@ -627,7 +642,8 @@ describe('chrome extensions', () => { it('applies matching rules in subframes', async () => { const detailsPromise = emittedNTimes(w.webContents, 'did-frame-finish-load', 2); - w.loadFile(path.join(contentScript, 'frame-with-frame.html')); + + w.loadURL(`http://127.0.0.1:${port}`); const frameEvents = await detailsPromise; await Promise.all( frameEvents.map(async frameEvent => { @@ -644,12 +660,9 @@ describe('chrome extensions', () => { } })()` ); + expect(result.enabledColor).to.equal(COLOR_RED); - if (isMainFrame) { - expect(result.disabledColor).to.equal(COLOR_BLUE); - } else { - expect(result.disabledColor).to.equal(COLOR_TRANSPARENT); // null color - } + expect(result.disabledColor).to.equal(isMainFrame ? COLOR_BLUE : COLOR_TRANSPARENT); }) ); });