Bug 1400655 P2 Add a mochitest to verify the json viewer is shown for json intercepted by a service worker. r=jryans

This commit is contained in:
Ben Kelly 2017-10-25 17:32:04 -04:00
Родитель 61ffdf4130
Коммит a8b8c6f790
4 изменённых файлов: 81 добавлений и 0 удалений

Просмотреть файл

@ -7,11 +7,13 @@ support-files =
csp_json.json
csp_json.json^headers^
doc_frame_script.js
empty.html
head.js
invalid_json.json
invalid_json.json^headers^
manifest_json.json
manifest_json.json^headers^
passthrough-sw.js
simple_json.json
simple_json.json^headers^
valid_json.json
@ -47,3 +49,4 @@ support-files =
[browser_jsonview_slash.js]
[browser_jsonview_valid_json.js]
[browser_json_refresh.js]
[browser_jsonview_serviceworker.js]

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_JSON_URL = URL_ROOT + "valid_json.json";
const EMPTY_PAGE = URL_ROOT + "empty.html";
const SW_SCRIPT = URL_ROOT + "passthrough-sw.js";
add_task(async function() {
info("Test valid JSON with service worker started");
await SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
]});
let swTab = BrowserTestUtils.addTab(gBrowser, EMPTY_PAGE);
let browser = gBrowser.getBrowserForTab(swTab);
await BrowserTestUtils.browserLoaded(browser);
await ContentTask.spawn(browser, { script: SW_SCRIPT, scope: TEST_JSON_URL },
async opts => {
let reg = await content.navigator.serviceWorker.register(opts.script,
{ scope: opts.scope });
await new content.window.Promise(resolve => {
let worker = reg.installing;
if (worker.state === 'activated') {
return resolve();
}
worker.addEventListener('statechange', evt => {
if (worker.state === 'activated') {
resolve();
}
});
});
});
let tab = await addJsonViewTab(TEST_JSON_URL);
ok(tab.linkedBrowser.contentPrincipal.isNullPrincipal, "Should have null principal");
is(await countRows(), 3, "There must be three rows");
let objectCellCount = await getElementCount(
".jsonPanelBox .treeTable .objectCell");
is(objectCellCount, 1, "There must be one object cell");
let objectCellText = await getElementText(
".jsonPanelBox .treeTable .objectCell");
is(objectCellText, "", "The summary is hidden when object is expanded");
// Clicking the value does not collapse it (so that it can be selected and copied).
await clickJsonNode(".jsonPanelBox .treeTable .treeValueCell");
is(await countRows(), 3, "There must still be three rows");
// Clicking the label collapses the auto-expanded node.
await clickJsonNode(".jsonPanelBox .treeTable .treeLabel");
is(await countRows(), 1, "There must be one row");
await ContentTask.spawn(browser, { script: SW_SCRIPT, scope: TEST_JSON_URL },
async opts => {
let reg = await content.navigator.serviceWorker.getRegistration(opts.scope);
await reg.unregister();
});
await BrowserTestUtils.removeTab(swTab);
});
function countRows() {
return getElementCount(".jsonPanelBox .treeTable .treeRow");
}

Просмотреть файл

@ -0,0 +1 @@
<!doctype html>

Просмотреть файл

@ -0,0 +1,3 @@
addEventListener('fetch', evt => {
evt.respondWith(fetch(evt.request));
});