Bug 1297362 - Part 5: Eliminate CPOWs from Netmonitor mochitests R-T r=ochameau

MozReview-Commit-ID: KPkb8wKWwmg

--HG--
extra : rebase_source : 32a4688a57bbe92eb80b4efbb448c355adf298a9
This commit is contained in:
Jarda Snajdr 2016-08-26 13:06:25 +02:00
parent 1d12dc8c7d
commit 28d6b9ecdd
30 changed files with 1632 additions and 1680 deletions

View File

@ -1,72 +1,70 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
var gPanelWin; "use strict";
var gPanelDoc;
/** /**
* Tests if showing raw headers works. * Tests if showing raw headers works.
*/ */
function test() { add_task(function* () {
initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(POST_DATA_URL);
info("Starting test... "); info("Starting test... ");
gPanelWin = aMonitor.panelWin; let { document, EVENTS, NetMonitorView } = monitor.panelWin;
gPanelDoc = gPanelWin.document; let { RequestsMenu } = NetMonitorView;
let { document, Editor, NetMonitorView } = gPanelWin; RequestsMenu.lazyUpdate = false;
let { RequestsMenu } = NetMonitorView;
let TAB_UPDATED = gPanelWin.EVENTS.TAB_UPDATED;
RequestsMenu.lazyUpdate = false; let wait = waitForNetworkEvents(monitor, 0, 2);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
waitForNetworkEvents(aMonitor, 0, 2).then(() => { content.wrappedJSObject.performRequests();
let origItem = RequestsMenu.getItemAtIndex(0);
RequestsMenu.selectedItem = origItem;
waitFor(aMonitor.panelWin, TAB_UPDATED).then(() => {
EventUtils.sendMouseEvent({ type: "click" }, document.getElementById("toggle-raw-headers"));
testShowRawHeaders(origItem.attachment);
EventUtils.sendMouseEvent({ type: "click" }, document.getElementById("toggle-raw-headers"));
testHideRawHeaders(document);
finishUp(aMonitor);
});
});
aDebuggee.performRequests();
}); });
} yield wait;
/* let origItem = RequestsMenu.getItemAtIndex(0);
* Tests that raw headers were displayed correctly
*/ let onTabEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
function testShowRawHeaders(aData) { RequestsMenu.selectedItem = origItem;
let requestHeaders = gPanelDoc.getElementById("raw-request-headers-textarea").value; yield onTabEvent;
for (let header of aData.requestHeaders.headers) {
ok(requestHeaders.indexOf(header.name + ": " + header.value) >= 0, "textarea contains request headers"); EventUtils.sendMouseEvent({ type: "click" },
document.getElementById("toggle-raw-headers"));
testShowRawHeaders(origItem.attachment);
EventUtils.sendMouseEvent({ type: "click" },
document.getElementById("toggle-raw-headers"));
testHideRawHeaders(document);
return teardown(monitor);
/*
* Tests that raw headers were displayed correctly
*/
function testShowRawHeaders(data) {
let requestHeaders = document.getElementById("raw-request-headers-textarea").value;
for (let header of data.requestHeaders.headers) {
ok(requestHeaders.indexOf(header.name + ": " + header.value) >= 0,
"textarea contains request headers");
}
let responseHeaders = document.getElementById("raw-response-headers-textarea").value;
for (let header of data.responseHeaders.headers) {
ok(responseHeaders.indexOf(header.name + ": " + header.value) >= 0,
"textarea contains response headers");
}
} }
let responseHeaders = gPanelDoc.getElementById("raw-response-headers-textarea").value;
for (let header of aData.responseHeaders.headers) { /*
ok(responseHeaders.indexOf(header.name + ": " + header.value) >= 0, "textarea contains response headers"); * Tests that raw headers textareas are hidden and empty
*/
function testHideRawHeaders() {
let rawHeadersHidden = document.getElementById("raw-headers").getAttribute("hidden");
let requestTextarea = document.getElementById("raw-request-headers-textarea");
let responseTextarea = document.getElementById("raw-response-headers-textarea");
ok(rawHeadersHidden, "raw headers textareas are hidden");
ok(requestTextarea.value == "", "raw request headers textarea is empty");
ok(responseTextarea.value == "", "raw response headers textarea is empty");
} }
} });
/*
* Tests that raw headers textareas are hidden and empty
*/
function testHideRawHeaders(document) {
let rawHeadersHidden = document.getElementById("raw-headers").getAttribute("hidden");
let requestTextarea = document.getElementById("raw-request-headers-textarea");
let responseTextare = document.getElementById("raw-response-headers-textarea");
ok(rawHeadersHidden, "raw headers textareas are hidden");
ok(requestTextarea.value == "", "raw request headers textarea is empty");
ok(responseTextare.value == "", "raw response headers textarea is empty");
}
function finishUp(aMonitor) {
gPanelWin = null;
gPanelDoc = null;
teardown(aMonitor).then(finish);
}

View File

@ -1,31 +1,25 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if the empty-requests reload button works. * Tests if the empty-requests reload button works.
*/ */
function test() { add_task(function* () {
let monitor, reqMenu; let [,, monitor] = yield initNetMonitor(SINGLE_GET_URL);
initNetMonitor(SINGLE_GET_URL).then(([aTab, aDebuggee, aMonitor]) => { info("Starting test... ");
info("Starting test... ");
monitor = aMonitor; let { document, NetMonitorView } = monitor.panelWin;
let { document, NetMonitorView } = aMonitor.panelWin; let { RequestsMenu } = NetMonitorView;
let { RequestsMenu } = NetMonitorView;
reqMenu = RequestsMenu;
let button = document.querySelector("#requests-menu-reload-notice-button"); let wait = waitForNetworkEvents(monitor, 2);
button.click(); let button = document.querySelector("#requests-menu-reload-notice-button");
}) button.click();
.then(() => { yield wait;
return waitForNetworkEvents(monitor, 2);
}) is(RequestsMenu.itemCount, 2, "The request menu should have two items after reloading");
.then(() => {
is(reqMenu.itemCount, 2, return teardown(monitor);
"The request menu should have two items after reloading"); });
})
.then(() => {
return teardown(monitor).then(finish);
});
}

View File

@ -1,45 +1,35 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if the empty-requests reload button works. * Tests if the empty-requests reload button works.
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(SINGLE_GET_URL); let [,, monitor] = yield initNetMonitor(SINGLE_GET_URL);
info("Starting test... "); info("Starting test... ");
let { document, EVENTS, NetworkEventsHandler } = monitor.panelWin; let { document, EVENTS } = monitor.panelWin;
let button = document.querySelector("#requests-menu-reload-notice-button"); let button = document.querySelector("#requests-menu-reload-notice-button");
button.click(); button.click();
let deferred = promise.defer(); let markers = [];
let markers = [];
monitor.panelWin.on(EVENTS.TIMELINE_EVENT, (_, marker) => { monitor.panelWin.on(EVENTS.TIMELINE_EVENT, (_, marker) => {
markers.push(marker); markers.push(marker);
}); });
yield waitForNetworkEvents(monitor, 2); yield waitForNetworkEvents(monitor, 2);
yield waitUntil(() => markers.length == 2); yield waitUntil(() => markers.length == 2);
ok(true, "Reloading finished"); ok(true, "Reloading finished");
is(markers[0].name, "document::DOMContentLoaded", is(markers[0].name, "document::DOMContentLoaded",
"The first received marker is correct."); "The first received marker is correct.");
is(markers[1].name, "document::Load", is(markers[1].name, "document::Load",
"The second received marker is correct."); "The second received marker is correct.");
teardown(monitor).then(finish); return teardown(monitor);
}); });
function waitUntil(predicate, interval = 10) {
if (predicate()) {
return Promise.resolve(true);
}
return new Promise(resolve => {
setTimeout(function () {
waitUntil(predicate).then(() => resolve(true));
}, interval);
});
}

View File

@ -1,60 +1,66 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Test if request and response body logging stays on after opening the console. * Test if request and response body logging stays on after opening the console.
*/ */
function test() { add_task(function* () {
initNetMonitor(JSON_LONG_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(JSON_LONG_URL);
info("Starting test... "); info("Starting test... ");
let { L10N, NetMonitorView } = aMonitor.panelWin; let { L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
function verifyRequest(aOffset) { // Perform first batch of requests.
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOffset), let wait = waitForNetworkEvents(monitor, 1);
"GET", CONTENT_TYPE_SJS + "?fmt=json-long", { yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
status: 200, content.wrappedJSObject.performRequests();
statusText: "OK",
type: "json",
fullMimeType: "text/json; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(85975 / 1024, 2)),
time: true
});
}
waitForNetworkEvents(aMonitor, 1).then(() => {
verifyRequest(0);
aMonitor._toolbox.once("webconsole-selected", () => {
aMonitor._toolbox.once("netmonitor-selected", () => {
waitForNetworkEvents(aMonitor, 1).then(() => {
waitForNetworkEvents(aMonitor, 1).then(() => {
verifyRequest(1);
teardown(aMonitor).then(finish);
});
// Perform another batch of requests.
aDebuggee.performRequests();
});
// Reload debugee.
aDebuggee.location.reload();
});
// Switch back to the netmonitor.
aMonitor._toolbox.selectTool("netmonitor");
});
// Switch to the webconsole.
aMonitor._toolbox.selectTool("webconsole");
});
// Perform first batch of requests.
aDebuggee.performRequests();
}); });
} yield wait;
verifyRequest(0);
// Switch to the webconsole.
let onWebConsole = monitor._toolbox.once("webconsole-selected");
monitor._toolbox.selectTool("webconsole");
yield onWebConsole;
// Switch back to the netmonitor.
let onNetMonitor = monitor._toolbox.once("netmonitor-selected");
monitor._toolbox.selectTool("netmonitor");
yield onNetMonitor;
// Reload debugee.
wait = waitForNetworkEvents(monitor, 1);
tab.linkedBrowser.reload();
yield wait;
// Perform another batch of requests.
wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequest(1);
return teardown(monitor);
function verifyRequest(offset) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(offset),
"GET", CONTENT_TYPE_SJS + "?fmt=json-long", {
status: 200,
statusText: "OK",
type: "json",
fullMimeType: "text/json; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB",
L10N.numberWithDecimals(85975 / 1024, 2)),
time: true
});
}
});

View File

@ -1,178 +1,162 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
var gPanelWin; "use strict";
var gPanelDoc;
const ADD_QUERY = "t1=t2";
const ADD_HEADER = "Test-header: true";
const ADD_POSTDATA = "t3=t4";
/** /**
* Tests if resending a request works. * Tests if resending a request works.
*/ */
function test() { const ADD_QUERY = "t1=t2";
initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => { const ADD_HEADER = "Test-header: true";
info("Starting test... "); const ADD_POSTDATA = "&t3=t4";
gPanelWin = aMonitor.panelWin; add_task(function* () {
gPanelDoc = gPanelWin.document; let [tab, , monitor] = yield initNetMonitor(POST_DATA_URL);
info("Starting test... ");
let { NetMonitorView } = gPanelWin; let { panelWin } = monitor;
let { RequestsMenu } = NetMonitorView; let { document, EVENTS, NetMonitorView } = panelWin;
let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; let { RequestsMenu } = NetMonitorView;
let CUSTOMREQUESTVIEW_POPULATED = aMonitor.panelWin.EVENTS.CUSTOMREQUESTVIEW_POPULATED;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 0, 2).then(() => { let wait = waitForNetworkEvents(monitor, 0, 2);
let origItem = RequestsMenu.getItemAtIndex(0); yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
RequestsMenu.selectedItem = origItem; content.wrappedJSObject.performRequests();
waitFor(aMonitor.panelWin, TAB_UPDATED).then(() => {
// add a new custom request cloned from selected request
RequestsMenu.cloneSelectedRequest();
return waitFor(aMonitor.panelWin, CUSTOMREQUESTVIEW_POPULATED);
}).then(() => {
testCustomForm(origItem.attachment);
let customItem = RequestsMenu.selectedItem;
testCustomItem(customItem, origItem);
// edit the custom request
editCustomForm(() => {
testCustomItemChanged(customItem, origItem);
waitForNetworkEvents(aMonitor, 0, 1).then(() => {
let sentItem = RequestsMenu.selectedItem;
testSentRequest(sentItem.attachment, origItem.attachment);
finishUp(aMonitor);
});
// send the new request
RequestsMenu.sendCustomRequest();
});
});
});
aDebuggee.performRequests();
}); });
} yield wait;
function testCustomItem(aItem, aOrigItem) { let origItem = RequestsMenu.getItemAtIndex(0);
let method = aItem.target.querySelector(".requests-menu-method").value;
let origMethod = aOrigItem.target.querySelector(".requests-menu-method").value;
is(method, origMethod, "menu item is showing the same method as original request");
let file = aItem.target.querySelector(".requests-menu-file").value; let onTabUpdated = panelWin.once(EVENTS.TAB_UPDATED);
let origFile = aOrigItem.target.querySelector(".requests-menu-file").value; RequestsMenu.selectedItem = origItem;
is(file, origFile, "menu item is showing the same file name as original request"); yield onTabUpdated;
let domain = aItem.target.querySelector(".requests-menu-domain").value; // add a new custom request cloned from selected request
let origDomain = aOrigItem.target.querySelector(".requests-menu-domain").value; let onPopulated = panelWin.once(EVENTS.CUSTOMREQUESTVIEW_POPULATED);
is(domain, origDomain, "menu item is showing the same domain as original request"); RequestsMenu.cloneSelectedRequest();
} yield onPopulated;
function testCustomItemChanged(aItem, aOrigItem) { testCustomForm(origItem.attachment);
let file = aItem.target.querySelector(".requests-menu-file").value;
let expectedFile = aOrigItem.target.querySelector(".requests-menu-file").value + "&" + ADD_QUERY;
is(file, expectedFile, "menu item is updated to reflect url entered in form"); let customItem = RequestsMenu.selectedItem;
} testCustomItem(customItem, origItem);
/* // edit the custom request
* Test that the New Request form was populated correctly yield editCustomForm();
*/ testCustomItemChanged(customItem, origItem);
function testCustomForm(aData) {
is(gPanelDoc.getElementById("custom-method-value").value, aData.method,
"new request form showing correct method");
is(gPanelDoc.getElementById("custom-url-value").value, aData.url, // send the new request
"new request form showing correct url"); wait = waitForNetworkEvents(monitor, 0, 1);
RequestsMenu.sendCustomRequest();
yield wait;
let query = gPanelDoc.getElementById("custom-query-value"); let sentItem = RequestsMenu.selectedItem;
is(query.value, "foo=bar\nbaz=42\ntype=urlencoded", testSentRequest(sentItem.attachment, origItem.attachment);
"new request form showing correct query string");
let headers = gPanelDoc.getElementById("custom-headers-value").value.split("\n"); return teardown(monitor);
for (let {name, value} of aData.requestHeaders.headers) {
ok(headers.indexOf(name + ": " + value) >= 0, "form contains header from request"); function testCustomItem(item, orig) {
let method = item.target.querySelector(".requests-menu-method").value;
let origMethod = orig.target.querySelector(".requests-menu-method").value;
is(method, origMethod, "menu item is showing the same method as original request");
let file = item.target.querySelector(".requests-menu-file").value;
let origFile = orig.target.querySelector(".requests-menu-file").value;
is(file, origFile, "menu item is showing the same file name as original request");
let domain = item.target.querySelector(".requests-menu-domain").value;
let origDomain = orig.target.querySelector(".requests-menu-domain").value;
is(domain, origDomain, "menu item is showing the same domain as original request");
} }
let postData = gPanelDoc.getElementById("custom-postdata-value"); function testCustomItemChanged(item, orig) {
is(postData.value, aData.requestPostData.postData.text, let file = item.target.querySelector(".requests-menu-file").value;
"new request form showing correct post data"); let expectedFile = orig.target.querySelector(".requests-menu-file").value +
} "&" + ADD_QUERY;
/* is(file, expectedFile, "menu item is updated to reflect url entered in form");
* Add some params and headers to the request form }
*/
function editCustomForm(callback) {
gPanelWin.focus();
let query = gPanelDoc.getElementById("custom-query-value"); /*
query.addEventListener("focus", function onFocus() { * Test that the New Request form was populated correctly
query.removeEventListener("focus", onFocus, false); */
function testCustomForm(data) {
is(document.getElementById("custom-method-value").value, data.method,
"new request form showing correct method");
is(document.getElementById("custom-url-value").value, data.url,
"new request form showing correct url");
let query = document.getElementById("custom-query-value");
is(query.value, "foo=bar\nbaz=42\ntype=urlencoded",
"new request form showing correct query string");
let headers = document.getElementById("custom-headers-value").value.split("\n");
for (let {name, value} of data.requestHeaders.headers) {
ok(headers.indexOf(name + ": " + value) >= 0, "form contains header from request");
}
let postData = document.getElementById("custom-postdata-value");
is(postData.value, data.requestPostData.postData.text,
"new request form showing correct post data");
}
/*
* Add some params and headers to the request form
*/
function* editCustomForm() {
panelWin.focus();
let query = document.getElementById("custom-query-value");
let queryFocus = once(query, "focus", false);
// Bug 1195825: Due to some unexplained dark-matter with promise,
// focus only works if delayed by one tick.
executeSoon(() => query.focus());
yield queryFocus;
// add params to url query string field // add params to url query string field
type(["VK_RETURN"]); type(["VK_RETURN"]);
type(ADD_QUERY); type(ADD_QUERY);
let headers = gPanelDoc.getElementById("custom-headers-value"); let headers = document.getElementById("custom-headers-value");
headers.addEventListener("focus", function onFocus() { let headersFocus = once(headers, "focus", false);
headers.removeEventListener("focus", onFocus, false);
// add a header
type(["VK_RETURN"]);
type(ADD_HEADER);
let postData = gPanelDoc.getElementById("custom-postdata-value");
postData.addEventListener("focus", function onFocus() {
postData.removeEventListener("focus", onFocus, false);
// add to POST data
type(ADD_POSTDATA);
callback();
}, false);
postData.focus();
}, false);
headers.focus(); headers.focus();
}, false); yield headersFocus;
// Bug 1195825: Due to some unexplained dark-matter with promise, // add a header
// focus only works if delayed by one tick. type(["VK_RETURN"]);
executeSoon(() => { type(ADD_HEADER);
query.focus();
});
}
/* let postData = document.getElementById("custom-postdata-value");
* Make sure newly created event matches expected request let postFocus = once(postData, "focus", false);
*/ postData.focus();
function testSentRequest(aData, aOrigData) { yield postFocus;
is(aData.method, aOrigData.method, "correct method in sent request");
is(aData.url, aOrigData.url + "&" + ADD_QUERY, "correct url in sent request");
let hasHeader = aData.requestHeaders.headers.some((header) => { // add to POST data
return (header.name + ": " + header.value) == ADD_HEADER; type(ADD_POSTDATA);
});
ok(hasHeader, "new header added to sent request");
is(aData.requestPostData.postData.text,
aOrigData.requestPostData.postData.text + ADD_POSTDATA,
"post data added to sent request");
}
function type(aString) {
for (let ch of aString) {
EventUtils.synthesizeKey(ch, {}, gPanelWin);
} }
}
function finishUp(aMonitor) { /*
gPanelWin = null; * Make sure newly created event matches expected request
gPanelDoc = null; */
function testSentRequest(data, origData) {
is(data.method, origData.method, "correct method in sent request");
is(data.url, origData.url + "&" + ADD_QUERY, "correct url in sent request");
teardown(aMonitor).then(finish); let { headers } = data.requestHeaders;
} let hasHeader = headers.some(h => `${h.name}: ${h.value}` == ADD_HEADER);
ok(hasHeader, "new header added to sent request");
is(data.requestPostData.postData.text,
origData.requestPostData.postData.text + ADD_POSTDATA,
"post data added to sent request");
}
function type(string) {
for (let ch of string) {
EventUtils.synthesizeKey(ch, {}, panelWin);
}
}
});

View File

@ -8,15 +8,18 @@
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
info("Performing a secure request."); info("Performing a secure request.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH); const REQUESTS_URL = "https://example.com" + CORS_SJS_PATH;
let wait = waitForNetworkEvents(monitor, 1);
yield waitForNetworkEvents(monitor, 1); yield ContentTask.spawn(tab.linkedBrowser, REQUESTS_URL, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
yield wait;
info("Selecting the request."); info("Selecting the request.");
RequestsMenu.selectedIndex = 0; RequestsMenu.selectedIndex = 0;

View File

@ -8,15 +8,18 @@
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
info("Requesting a resource that has a certificate problem."); info("Requesting a resource that has a certificate problem.");
debuggee.performRequests(1, "https://nocert.example.com");
yield waitForSecurityBrokenNetworkEvent(); let wait = waitForSecurityBrokenNetworkEvent();
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests(1, "https://nocert.example.com");
});
yield wait;
info("Selecting the request."); info("Selecting the request.");
RequestsMenu.selectedIndex = 0; RequestsMenu.selectedIndex = 0;
@ -39,7 +42,7 @@ add_task(function* () {
isnot(errormsg.value, "", "Error message is not empty."); isnot(errormsg.value, "", "Error message is not empty.");
yield teardown(monitor); return teardown(monitor);
/** /**
* Returns a promise that's resolved once a request with security issues is * Returns a promise that's resolved once a request with security issues is

View File

@ -8,17 +8,14 @@
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
info("Requesting a resource over HTTPS."); info("Requesting a resource over HTTPS.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH + "?request_2"); yield performRequestAndWait("https://example.com" + CORS_SJS_PATH + "?request_2");
yield waitForNetworkEvents(monitor, 1); yield performRequestAndWait("https://example.com" + CORS_SJS_PATH + "?request_1");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH + "?request_1");
yield waitForNetworkEvents(monitor, 1);
is(RequestsMenu.itemCount, 2, "Two events event logged."); is(RequestsMenu.itemCount, 2, "Two events event logged.");
@ -34,7 +31,15 @@ add_task(function* () {
info("Testing that security icon can be clicked after the items were sorted."); info("Testing that security icon can be clicked after the items were sorted.");
yield clickAndTestSecurityIcon(); yield clickAndTestSecurityIcon();
yield teardown(monitor); return teardown(monitor);
function* performRequestAndWait(url) {
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, { url }, function* (args) {
content.wrappedJSObject.performRequests(1, args.url);
});
return wait;
}
function* clickAndTestSecurityIcon() { function* clickAndTestSecurityIcon() {
let item = RequestsMenu.items[0]; let item = RequestsMenu.items[0];
@ -49,5 +54,4 @@ add_task(function* () {
is(NetworkDetails.widget.selectedPanel, $("#security-tabpanel"), is(NetworkDetails.widget.selectedPanel, $("#security-tabpanel"),
"Security tab is selected."); "Security tab is selected.");
} }
}); });

View File

@ -9,13 +9,16 @@
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, NetMonitorView } = monitor.panelWin; let { $, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
debuggee.performRequests(1, HTTPS_REDIRECT_SJS); let wait = waitForNetworkEvents(monitor, 2);
yield waitForNetworkEvents(monitor, 2); yield ContentTask.spawn(tab.linkedBrowser, HTTPS_REDIRECT_SJS, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
yield wait;
is(RequestsMenu.itemCount, 2, "There were two requests due to redirect."); is(RequestsMenu.itemCount, 2, "There were two requests due to redirect.");

View File

@ -16,7 +16,7 @@ add_task(function* () {
"localhost": "security-state-local", "localhost": "security-state-local",
}; };
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
@ -37,7 +37,7 @@ add_task(function* () {
ok(classes.contains(expectedClass), "Icon contained the correct class name."); ok(classes.contains(expectedClass), "Icon contained the correct class name.");
} }
yield teardown(monitor); return teardown(monitor);
/** /**
* A helper that performs requests to * A helper that performs requests to
@ -48,12 +48,18 @@ add_task(function* () {
* and waits until NetworkMonitor has handled all packets sent by the server. * and waits until NetworkMonitor has handled all packets sent by the server.
*/ */
function* performRequests() { function* performRequests() {
function executeRequests(count, url) {
return ContentTask.spawn(tab.linkedBrowser, {count, url}, function* (args) {
content.wrappedJSObject.performRequests(args.count, args.url);
});
}
// waitForNetworkEvents does not work for requests with security errors as // waitForNetworkEvents does not work for requests with security errors as
// those only emit 9/13 events of a successful request. // those only emit 9/13 events of a successful request.
let done = waitForSecurityBrokenNetworkEvent(); let done = waitForSecurityBrokenNetworkEvent();
info("Requesting a resource that has a certificate problem."); info("Requesting a resource that has a certificate problem.");
debuggee.performRequests(1, "https://nocert.example.com"); yield executeRequests(1, "https://nocert.example.com");
// Wait for the request to complete before firing another request. Otherwise // Wait for the request to complete before firing another request. Otherwise
// the request with security issues interfere with waitForNetworkEvents. // the request with security issues interfere with waitForNetworkEvents.
@ -64,17 +70,17 @@ add_task(function* () {
// occasionally hangs waiting for event timings that don't seem to appear... // occasionally hangs waiting for event timings that don't seem to appear...
done = waitForNetworkEvents(monitor, 1); done = waitForNetworkEvents(monitor, 1);
info("Requesting a resource over HTTP."); info("Requesting a resource over HTTP.");
debuggee.performRequests(1, "http://test1.example.com" + CORS_SJS_PATH); yield executeRequests(1, "http://test1.example.com" + CORS_SJS_PATH);
yield done; yield done;
done = waitForNetworkEvents(monitor, 1); done = waitForNetworkEvents(monitor, 1);
info("Requesting a resource over HTTPS."); info("Requesting a resource over HTTPS.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH); yield executeRequests(1, "https://example.com" + CORS_SJS_PATH);
yield done; yield done;
done = waitForSecurityBrokenNetworkEvent(true); done = waitForSecurityBrokenNetworkEvent(true);
info("Requesting a resource over HTTP to localhost."); info("Requesting a resource over HTTP to localhost.");
debuggee.performRequests(1, "http://localhost" + CORS_SJS_PATH); yield executeRequests(1, "http://localhost" + CORS_SJS_PATH);
yield done; yield done;
const expectedCount = Object.keys(EXPECTED_SECURITY_STATES).length; const expectedCount = Object.keys(EXPECTED_SECURITY_STATES).length;
@ -101,7 +107,7 @@ add_task(function* () {
// If the reason for breakage is a network error, then the // If the reason for breakage is a network error, then the
// STARTED_RECEIVING_RESPONSE event does not fire. // STARTED_RECEIVING_RESPONSE event does not fire.
if (networkError) { if (networkError) {
awaitedEvents.splice(4, 1); awaitedEvents = awaitedEvents.filter(e => e !== "STARTED_RECEIVING_RESPONSE");
} }
let promises = awaitedEvents.map((event) => { let promises = awaitedEvents.map((event) => {

View File

@ -9,15 +9,23 @@
*/ */
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
info("Performing requests."); info("Performing requests.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH); let wait = waitForNetworkEvents(monitor, 2);
debuggee.performRequests(1, "http://example.com" + CORS_SJS_PATH); const REQUEST_URLS = [
yield waitForNetworkEvents(monitor, 2); "https://example.com" + CORS_SJS_PATH,
"http://example.com" + CORS_SJS_PATH,
];
yield ContentTask.spawn(tab.linkedBrowser, REQUEST_URLS, function* (urls) {
for (let url of urls) {
content.wrappedJSObject.performRequests(1, url);
}
});
yield wait;
info("Selecting secure request."); info("Selecting secure request.");
RequestsMenu.selectedIndex = 0; RequestsMenu.selectedIndex = 0;
@ -34,5 +42,5 @@ add_task(function* () {
is(NetworkDetails.widget.selectedIndex, 0, is(NetworkDetails.widget.selectedIndex, 0,
"Selected tab was reset when selected security tab was hidden."); "Selected tab was reset when selected security tab was hidden.");
yield teardown(monitor); return teardown(monitor);
}); });

View File

@ -31,7 +31,7 @@ add_task(function* () {
} }
]; ];
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
@ -44,11 +44,13 @@ add_task(function* () {
waitForSecurityBrokenNetworkEvent() : waitForSecurityBrokenNetworkEvent() :
waitForNetworkEvents(monitor, 1); waitForNetworkEvents(monitor, 1);
let tab = $("#security-tab"); let tabEl = $("#security-tab");
let tabpanel = $("#security-tabpanel"); let tabpanel = $("#security-tabpanel");
info("Performing a request to " + testcase.uri); info("Performing a request to " + testcase.uri);
debuggee.performRequests(1, testcase.uri); yield ContentTask.spawn(tab.linkedBrowser, testcase.uri, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
info("Waiting for new network event."); info("Waiting for new network event.");
yield onNewItem; yield onNewItem;
@ -58,7 +60,7 @@ add_task(function* () {
is(RequestsMenu.selectedItem.attachment.securityState, undefined, is(RequestsMenu.selectedItem.attachment.securityState, undefined,
"Security state has not yet arrived."); "Security state has not yet arrived.");
is(tab.hidden, !testcase.visibleOnNewEvent, is(tabEl.hidden, !testcase.visibleOnNewEvent,
"Security tab is " + "Security tab is " +
(testcase.visibleOnNewEvent ? "visible" : "hidden") + (testcase.visibleOnNewEvent ? "visible" : "hidden") +
" after new request was added to the menu."); " after new request was added to the menu.");
@ -70,7 +72,7 @@ add_task(function* () {
ok(RequestsMenu.selectedItem.attachment.securityState, ok(RequestsMenu.selectedItem.attachment.securityState,
"Security state arrived."); "Security state arrived.");
is(tab.hidden, !testcase.visibleOnSecurityInfo, is(tabEl.hidden, !testcase.visibleOnSecurityInfo,
"Security tab is " + "Security tab is " +
(testcase.visibleOnSecurityInfo ? "visible" : "hidden") + (testcase.visibleOnSecurityInfo ? "visible" : "hidden") +
" after security information arrived."); " after security information arrived.");
@ -79,7 +81,8 @@ add_task(function* () {
info("Waiting for request to complete."); info("Waiting for request to complete.");
yield onComplete; yield onComplete;
is(tab.hidden, !testcase.visibleOnceComplete,
is(tabEl.hidden, !testcase.visibleOnceComplete,
"Security tab is " + "Security tab is " +
(testcase.visibleOnceComplete ? "visible" : "hidden") + (testcase.visibleOnceComplete ? "visible" : "hidden") +
" after request has been completed."); " after request has been completed.");
@ -90,7 +93,7 @@ add_task(function* () {
RequestsMenu.clear(); RequestsMenu.clear();
} }
yield teardown(monitor); return teardown(monitor);
/** /**
* Returns a promise that's resolved once a request with security issues is * Returns a promise that's resolved once a request with security issues is

View File

@ -16,7 +16,7 @@ const TEST_CASES = [
]; ];
add_task(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL); let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin; let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
@ -27,8 +27,11 @@ add_task(function* () {
info("Testing site with " + test.desc); info("Testing site with " + test.desc);
info("Performing request to " + test.uri); info("Performing request to " + test.uri);
debuggee.performRequests(1, test.uri); let wait = waitForNetworkEvents(monitor, 1);
yield waitForNetworkEvents(monitor, 1); yield ContentTask.spawn(tab.linkedBrowser, test.uri, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
yield wait;
info("Selecting the request."); info("Selecting the request.");
RequestsMenu.selectedIndex = 0; RequestsMenu.selectedIndex = 0;
@ -47,9 +50,7 @@ add_task(function* () {
is(cipher.hidden, !test.warnCipher, "Cipher suite warning is hidden."); is(cipher.hidden, !test.warnCipher, "Cipher suite warning is hidden.");
RequestsMenu.clear(); RequestsMenu.clear();
} }
yield teardown(monitor); return teardown(monitor);
}); });

View File

@ -1,31 +1,34 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if beacons from other tabs are properly ignored. * Tests if beacons from other tabs are properly ignored.
*/ */
var test = Task.async(function* () { add_task(function* () {
let [, debuggee, monitor] = yield initNetMonitor(SIMPLE_URL); let [tab, , monitor] = yield initNetMonitor(SIMPLE_URL);
let { RequestsMenu } = monitor.panelWin.NetMonitorView; let { RequestsMenu } = monitor.panelWin.NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
let tab = yield addTab(SEND_BEACON_URL); let beaconTab = yield addTab(SEND_BEACON_URL);
let beaconDebuggee = tab.linkedBrowser.contentWindow.wrappedJSObject;
info("Beacon tab added successfully."); info("Beacon tab added successfully.");
is(RequestsMenu.itemCount, 0, "The requests menu should be empty."); is(RequestsMenu.itemCount, 0, "The requests menu should be empty.");
beaconDebuggee.performRequest(); let wait = waitForNetworkEvents(monitor, 1);
debuggee.location.reload(); yield ContentTask.spawn(beaconTab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequest();
});
tab.linkedBrowser.reload();
yield wait;
yield waitForNetworkEvents(monitor, 1);
is(RequestsMenu.itemCount, 1, "Only the reload should be recorded."); is(RequestsMenu.itemCount, 1, "Only the reload should be recorded.");
let request = RequestsMenu.getItemAtIndex(0); let request = RequestsMenu.getItemAtIndex(0);
is(request.attachment.method, "GET", "The method is correct."); is(request.attachment.method, "GET", "The method is correct.");
is(request.attachment.status, "200", "The status is correct."); is(request.attachment.status, "200", "The status is correct.");
yield teardown(monitor); yield removeTab(beaconTab);
removeTab(tab); return teardown(monitor);
finish();
}); });

View File

@ -1,27 +1,31 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if beacons are handled correctly. * Tests if beacons are handled correctly.
*/ */
var test = Task.async(function* () { add_task(function* () {
let [, debuggee, monitor] = yield initNetMonitor(SEND_BEACON_URL); let [tab, , monitor] = yield initNetMonitor(SEND_BEACON_URL);
let { RequestsMenu } = monitor.panelWin.NetMonitorView; let { RequestsMenu } = monitor.panelWin.NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
is(RequestsMenu.itemCount, 0, "The requests menu should be empty."); is(RequestsMenu.itemCount, 0, "The requests menu should be empty.");
debuggee.performRequest(); let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequest();
});
yield wait;
yield waitForNetworkEvents(monitor, 1);
is(RequestsMenu.itemCount, 1, "The beacon should be recorded."); is(RequestsMenu.itemCount, 1, "The beacon should be recorded.");
let request = RequestsMenu.getItemAtIndex(0); let request = RequestsMenu.getItemAtIndex(0);
is(request.attachment.method, "POST", "The method is correct."); is(request.attachment.method, "POST", "The method is correct.");
ok(request.attachment.url.endsWith("beacon_request"), "The URL is correct."); ok(request.attachment.url.endsWith("beacon_request"), "The URL is correct.");
is(request.attachment.status, "404", "The status is correct."); is(request.attachment.status, "404", "The status is correct.");
yield teardown(monitor); return teardown(monitor);
finish();
}); });

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Simple check if the network monitor starts up and shuts down properly. * Simple check if the network monitor starts up and shuts down properly.
*/ */
@ -11,66 +13,64 @@ function test() {
let gInfo = info; let gInfo = info;
let gOk = ok; let gOk = ok;
initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { initNetMonitor(SIMPLE_URL).then(([tab, , monitor]) => {
info("Starting test... "); info("Starting test... ");
is(aTab.linkedBrowser.contentWindow.wrappedJSObject.location, SIMPLE_URL, is(tab.linkedBrowser.currentURI.spec, SIMPLE_URL,
"The current tab's location is the correct one."); "The current tab's location is the correct one.");
is(aDebuggee.location, SIMPLE_URL,
"The current debuggee's location is the correct one.");
function checkIfInitialized(aTag) { function checkIfInitialized(tag) {
info("Checking if initialization is ok (" + aTag + ")."); info(`Checking if initialization is ok (${tag}).`);
ok(aMonitor._view, ok(monitor._view,
"The network monitor view object exists (" + aTag + ")."); `The network monitor view object exists (${tag}).`);
ok(aMonitor._controller, ok(monitor._controller,
"The network monitor controller object exists (" + aTag + ")."); `The network monitor controller object exists (${tag}).`);
ok(aMonitor._controller._startup, ok(monitor._controller._startup,
"The network monitor controller object exists and is initialized (" + aTag + ")."); `The network monitor controller object exists and is initialized (${tag}).`);
ok(aMonitor.isReady, ok(monitor.isReady,
"The network monitor panel appears to be ready (" + aTag + ")."); `The network monitor panel appears to be ready (${tag}).`);
ok(aMonitor._controller.tabClient, ok(monitor._controller.tabClient,
"There should be a tabClient available at this point (" + aTag + ")."); `There should be a tabClient available at this point (${tag}).`);
ok(aMonitor._controller.webConsoleClient, ok(monitor._controller.webConsoleClient,
"There should be a webConsoleClient available at this point (" + aTag + ")."); `There should be a webConsoleClient available at this point (${tag}).`);
ok(aMonitor._controller.timelineFront, ok(monitor._controller.timelineFront,
"There should be a timelineFront available at this point (" + aTag + ")."); `There should be a timelineFront available at this point (${tag}).`);
} }
function checkIfDestroyed(aTag) { function checkIfDestroyed(tag) {
gInfo("Checking if destruction is ok."); gInfo("Checking if destruction is ok.");
gOk(aMonitor._view, gOk(monitor._view,
"The network monitor view object still exists (" + aTag + ")."); `The network monitor view object still exists (${tag}).`);
gOk(aMonitor._controller, gOk(monitor._controller,
"The network monitor controller object still exists (" + aTag + ")."); `The network monitor controller object still exists (${tag}).`);
gOk(aMonitor._controller._shutdown, gOk(monitor._controller._shutdown,
"The network monitor controller object still exists and is destroyed (" + aTag + ")."); `The network monitor controller object still exists and is destroyed (${tag}).`);
gOk(!aMonitor._controller.tabClient, gOk(!monitor._controller.tabClient,
"There shouldn't be a tabClient available after destruction (" + aTag + ")."); `There shouldn't be a tabClient available after destruction (${tag}).`);
gOk(!aMonitor._controller.webConsoleClient, gOk(!monitor._controller.webConsoleClient,
"There shouldn't be a webConsoleClient available after destruction (" + aTag + ")."); `There shouldn't be a webConsoleClient available after destruction (${tag}).`);
gOk(!aMonitor._controller.timelineFront, gOk(!monitor._controller.timelineFront,
"There shouldn't be a timelineFront available after destruction (" + aTag + ")."); `There shouldn't be a timelineFront available after destruction (${tag}).`);
} }
executeSoon(() => { executeSoon(() => {
checkIfInitialized(1); checkIfInitialized(1);
aMonitor._controller.startupNetMonitor() monitor._controller.startupNetMonitor()
.then(() => { .then(() => {
info("Starting up again shouldn't do anything special."); info("Starting up again shouldn't do anything special.");
checkIfInitialized(2); checkIfInitialized(2);
return aMonitor._controller.connect(); return monitor._controller.connect();
}) })
.then(() => { .then(() => {
info("Connecting again shouldn't do anything special."); info("Connecting again shouldn't do anything special.");
checkIfInitialized(3); checkIfInitialized(3);
return teardown(aMonitor); return teardown(monitor);
}) })
.then(finish); .then(finish);
}); });
@ -78,11 +78,11 @@ function test() {
registerCleanupFunction(() => { registerCleanupFunction(() => {
checkIfDestroyed(1); checkIfDestroyed(1);
aMonitor._controller.shutdownNetMonitor() monitor._controller.shutdownNetMonitor()
.then(() => { .then(() => {
gInfo("Shutting down again shouldn't do anything special."); gInfo("Shutting down again shouldn't do anything special.");
checkIfDestroyed(2); checkIfDestroyed(2);
return aMonitor._controller.disconnect(); return monitor._controller.disconnect();
}) })
.then(() => { .then(() => {
gInfo("Disconnecting again shouldn't do anything special."); gInfo("Disconnecting again shouldn't do anything special.");

View File

@ -1,24 +1,26 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if requests render correct information in the menu UI. * Tests if requests render correct information in the menu UI.
*/ */
function test() { function test() {
initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { initNetMonitor(SIMPLE_SJS).then(([tab, , monitor]) => {
info("Starting test... "); info("Starting test... ");
let { L10N, NetMonitorView } = aMonitor.panelWin; let { L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1) waitForNetworkEvents(monitor, 1)
.then(() => teardown(aMonitor)) .then(() => teardown(monitor))
.then(finish); .then(finish);
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.NETWORK_EVENT, () => {
is(RequestsMenu.selectedItem, null, is(RequestsMenu.selectedItem, null,
"There shouldn't be any selected item in the requests menu."); "There shouldn't be any selected item in the requests menu.");
is(RequestsMenu.itemCount, 1, is(RequestsMenu.itemCount, 1,
@ -27,7 +29,6 @@ function test() {
"The details pane should still be hidden after the first request."); "The details pane should still be hidden after the first request.");
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
let target = requestItem.target;
is(typeof requestItem.value, "string", is(typeof requestItem.value, "string",
"The attached request id is incorrect."); "The attached request id is incorrect.");
@ -83,7 +84,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.requestHeaders, ok(requestItem.attachment.requestHeaders,
@ -98,7 +99,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.requestCookies, ok(requestItem.attachment.requestCookies,
@ -109,11 +110,11 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
ok(false, "Trap listener: this request doesn't have any post data."); ok(false, "Trap listener: this request doesn't have any post data.");
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.responseHeaders, ok(requestItem.attachment.responseHeaders,
@ -126,7 +127,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.responseCookies, ok(requestItem.attachment.responseCookies,
@ -137,7 +138,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
is(requestItem.attachment.httpVersion, "HTTP/1.1", is(requestItem.attachment.httpVersion, "HTTP/1.1",
@ -155,7 +156,7 @@ function test() {
}); });
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
is(requestItem.attachment.transferredSize, "12", is(requestItem.attachment.transferredSize, "12",
@ -173,16 +174,19 @@ function test() {
}); });
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.responseContent, ok(requestItem.attachment.responseContent,
"There should be a responseContent attachment available."); "There should be a responseContent attachment available.");
is(requestItem.attachment.responseContent.content.mimeType, "text/plain; charset=utf-8", is(requestItem.attachment.responseContent.content.mimeType,
"text/plain; charset=utf-8",
"The responseContent attachment has an incorrect |content.mimeType| property."); "The responseContent attachment has an incorrect |content.mimeType| property.");
is(requestItem.attachment.responseContent.content.text, "Hello world!", is(requestItem.attachment.responseContent.content.text,
"Hello world!",
"The responseContent attachment has an incorrect |content.text| property."); "The responseContent attachment has an incorrect |content.text| property.");
is(requestItem.attachment.responseContent.content.size, 12, is(requestItem.attachment.responseContent.content.size,
12,
"The responseContent attachment has an incorrect |content.size| property."); "The responseContent attachment has an incorrect |content.size| property.");
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
@ -193,7 +197,7 @@ function test() {
}); });
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
is(typeof requestItem.attachment.totalTime, "number", is(typeof requestItem.attachment.totalTime, "number",
@ -211,7 +215,7 @@ function test() {
}); });
}); });
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => { monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => {
let requestItem = RequestsMenu.getItemAtIndex(0); let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.eventTimings, ok(requestItem.attachment.eventTimings,
@ -236,6 +240,6 @@ function test() {
}); });
}); });
aDebuggee.location.reload(); tab.linkedBrowser.reload();
}); });
} }

View File

@ -1,244 +1,259 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if requests render correct information in the details UI. * Tests if requests render correct information in the details UI.
*/ */
function test() { add_task(function* () {
initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(SIMPLE_SJS);
info("Starting test... "); info("Starting test... ");
let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin; let { document, EVENTS, L10N, Editor, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
Task.spawn(function* () { let wait = waitForNetworkEvents(monitor, 1);
yield waitForNetworkEvents(aMonitor, 1); tab.linkedBrowser.reload();
is(RequestsMenu.selectedItem, null, yield wait;
"There shouldn't be any selected item in the requests menu.");
is(RequestsMenu.itemCount, 1,
"The requests menu should not be empty after the first request.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after the first request.");
EventUtils.sendMouseEvent({ type: "mousedown" }, is(RequestsMenu.selectedItem, null,
document.getElementById("details-pane-toggle")); "There shouldn't be any selected item in the requests menu.");
is(RequestsMenu.itemCount, 1,
"The requests menu should not be empty after the first request.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after the first request.");
isnot(RequestsMenu.selectedItem, null, let onTabUpdated = monitor.panelWin.once(EVENTS.TAB_UPDATED);
"There should be a selected item in the requests menu."); EventUtils.sendMouseEvent({ type: "mousedown" },
is(RequestsMenu.selectedIndex, 0, document.getElementById("details-pane-toggle"));
"The first item should be selected in the requests menu."); yield onTabUpdated;
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should not be hidden after toggle button was pressed.");
yield waitFor(aMonitor.panelWin, TAB_UPDATED); isnot(RequestsMenu.selectedItem, null,
testHeadersTab(); "There should be a selected item in the requests menu.");
yield testCookiesTab(); is(RequestsMenu.selectedIndex, 0,
testParamsTab(); "The first item should be selected in the requests menu.");
yield testResponseTab(); is(NetMonitorView.detailsPaneHidden, false,
testTimingsTab(); "The details pane should not be hidden after toggle button was pressed.");
yield teardown(aMonitor);
finish();
});
function testHeadersTab() { testHeadersTab();
let tab = document.querySelectorAll("#details-pane tab")[0]; yield testCookiesTab();
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0]; testParamsTab();
yield testResponseTab();
testTimingsTab();
return teardown(monitor);
is(tab.getAttribute("selected"), "true", function testHeadersTab() {
"The headers tab in the network details pane should be selected."); let tabEl = document.querySelectorAll("#details-pane tab")[0];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"), is(tabEl.getAttribute("selected"), "true",
SIMPLE_SJS, "The url summary value is incorrect."); "The headers tab in the network details pane should be selected.");
is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("tooltiptext"),
SIMPLE_SJS, "The url summary tooltiptext is incorrect.");
is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"),
"GET", "The method summary value is incorrect.");
is(tabpanel.querySelector("#headers-summary-address-value").getAttribute("value"),
"127.0.0.1:8888", "The remote address summary value is incorrect.");
is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
"200", "The status summary code is incorrect.");
is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
"200 Och Aye", "The status summary value is incorrect.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"),
"There should be 2 header scopes displayed in this tabpanel."); SIMPLE_SJS, "The url summary value is incorrect.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 19, is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("tooltiptext"),
"There should be 19 header values displayed in this tabpanel."); SIMPLE_SJS, "The url summary tooltiptext is incorrect.");
is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"),
"GET", "The method summary value is incorrect.");
is(tabpanel.querySelector("#headers-summary-address-value").getAttribute("value"),
"127.0.0.1:8888", "The remote address summary value is incorrect.");
is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
"200", "The status summary code is incorrect.");
is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
"200 Och Aye", "The status summary value is incorrect.");
is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"The empty notice should not be displayed in this tabpanel."); "There should be 2 header scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 19,
"There should be 19 header values displayed in this tabpanel.");
let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; "The empty notice should not be displayed in this tabpanel.");
is(responseScope.querySelector(".name").getAttribute("value"), let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
L10N.getStr("responseHeaders") + " (" + let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(330 / 1024, 3)) + ")",
"The response headers scope doesn't have the correct title.");
ok(requestScope.querySelector(".name").getAttribute("value").includes( is(responseScope.querySelector(".name").getAttribute("value"),
L10N.getStr("requestHeaders") + " (0"), L10N.getStr("responseHeaders") + " (" +
"The request headers scope doesn't have the correct title."); L10N.getFormatStr("networkMenu.sizeKB",
// Can't test for full request headers title because the size may L10N.numberWithDecimals(330 / 1024, 3)) + ")",
// vary across platforms ("User-Agent" header differs). We're pretty "The response headers scope doesn't have the correct title.");
// sure it's smaller than 1 MB though, so it starts with a 0.
is(responseScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), ok(requestScope.querySelector(".name").getAttribute("value").includes(
"Cache-Control", "The first response header name was incorrect."); L10N.getStr("requestHeaders") + " (0"),
is(responseScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), "The request headers scope doesn't have the correct title.");
"\"no-cache, no-store, must-revalidate\"", "The first response header value was incorrect."); // Can't test for full request headers title because the size may
is(responseScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), // vary across platforms ("User-Agent" header differs). We're pretty
"Connection", "The second response header name was incorrect."); // sure it's smaller than 1 MB though, so it starts with a 0.
is(responseScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
"\"close\"", "The second response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"),
"Content-Length", "The third response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"),
"\"12\"", "The third response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[3].getAttribute("value"),
"Content-Type", "The fourth response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[3].getAttribute("value"),
"\"text/plain; charset=utf-8\"", "The fourth response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[9].getAttribute("value"),
"foo-bar", "The last response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[9].getAttribute("value"),
"\"baz\"", "The last response header value was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), is(responseScope.querySelectorAll(".variables-view-variable .name")[0]
"Host", "The first request header name was incorrect."); .getAttribute("value"),
is(requestScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), "Cache-Control", "The first response header name was incorrect.");
"\"example.com\"", "The first request header value was incorrect."); is(responseScope.querySelectorAll(".variables-view-variable .value")[0]
is(requestScope.querySelectorAll(".variables-view-variable .name")[6].getAttribute("value"), .getAttribute("value"),
"Connection", "The ante-penultimate request header name was incorrect."); "\"no-cache, no-store, must-revalidate\"",
is(requestScope.querySelectorAll(".variables-view-variable .value")[6].getAttribute("value"), "The first response header value was incorrect.");
"\"keep-alive\"", "The ante-penultimate request header value was incorrect."); is(responseScope.querySelectorAll(".variables-view-variable .name")[1]
is(requestScope.querySelectorAll(".variables-view-variable .name")[7].getAttribute("value"), .getAttribute("value"),
"Pragma", "The penultimate request header name was incorrect."); "Connection", "The second response header name was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .value")[7].getAttribute("value"), is(responseScope.querySelectorAll(".variables-view-variable .value")[1]
"\"no-cache\"", "The penultimate request header value was incorrect."); .getAttribute("value"),
is(requestScope.querySelectorAll(".variables-view-variable .name")[8].getAttribute("value"), "\"close\"", "The second response header value was incorrect.");
"Cache-Control", "The last request header name was incorrect."); is(responseScope.querySelectorAll(".variables-view-variable .name")[2]
is(requestScope.querySelectorAll(".variables-view-variable .value")[8].getAttribute("value"), .getAttribute("value"),
"\"no-cache\"", "The last request header value was incorrect."); "Content-Length", "The third response header name was incorrect.");
} is(responseScope.querySelectorAll(".variables-view-variable .value")[2]
.getAttribute("value"),
"\"12\"", "The third response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[3]
.getAttribute("value"),
"Content-Type", "The fourth response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[3]
.getAttribute("value"),
"\"text/plain; charset=utf-8\"", "The fourth response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[9]
.getAttribute("value"),
"foo-bar", "The last response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[9]
.getAttribute("value"),
"\"baz\"", "The last response header value was incorrect.");
function testCookiesTab() { is(requestScope.querySelectorAll(".variables-view-variable .name")[0]
EventUtils.sendMouseEvent({ type: "mousedown" }, .getAttribute("value"),
document.querySelectorAll("#details-pane tab")[1]); "Host", "The first request header name was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .value")[0]
.getAttribute("value"),
"\"example.com\"", "The first request header value was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .name")[6]
.getAttribute("value"),
"Connection", "The ante-penultimate request header name was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .value")[6]
.getAttribute("value"),
"\"keep-alive\"", "The ante-penultimate request header value was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .name")[7]
.getAttribute("value"),
"Pragma", "The penultimate request header name was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .value")[7]
.getAttribute("value"),
"\"no-cache\"", "The penultimate request header value was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .name")[8]
.getAttribute("value"),
"Cache-Control", "The last request header name was incorrect.");
is(requestScope.querySelectorAll(".variables-view-variable .value")[8]
.getAttribute("value"),
"\"no-cache\"", "The last request header value was incorrect.");
}
return Task.spawn(function* () { function* testCookiesTab() {
yield waitFor(aMonitor.panelWin, TAB_UPDATED); let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[1]);
yield onEvent;
let tab = document.querySelectorAll("#details-pane tab")[1]; let tabEl = document.querySelectorAll("#details-pane tab")[1];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1]; let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
is(tab.getAttribute("selected"), "true", is(tabEl.getAttribute("selected"), "true",
"The cookies tab in the network details pane should be selected."); "The cookies tab in the network details pane should be selected.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"There should be 2 cookie scopes displayed in this tabpanel."); "There should be 2 cookie scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 6, is(tabpanel.querySelectorAll(".variable-or-property").length, 6,
"There should be 6 cookie values displayed in this tabpanel."); "There should be 6 cookie values displayed in this tabpanel.");
}); }
}
function testParamsTab() { function testParamsTab() {
EventUtils.sendMouseEvent({ type: "mousedown" }, EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[2]); document.querySelectorAll("#details-pane tab")[2]);
let tab = document.querySelectorAll("#details-pane tab")[2]; let tabEl = document.querySelectorAll("#details-pane tab")[2];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
is(tab.getAttribute("selected"), "true", is(tabEl.getAttribute("selected"), "true",
"The params tab in the network details pane should be selected."); "The params tab in the network details pane should be selected.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 0, is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
"There should be no param scopes displayed in this tabpanel."); "There should be no param scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 0, is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
"There should be no param values displayed in this tabpanel."); "There should be no param values displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1, is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
"The empty notice should be displayed in this tabpanel."); "The empty notice should be displayed in this tabpanel.");
is(tabpanel.querySelector("#request-params-box") is(tabpanel.querySelector("#request-params-box")
.hasAttribute("hidden"), false, .hasAttribute("hidden"), false,
"The request params box should not be hidden."); "The request params box should not be hidden.");
is(tabpanel.querySelector("#request-post-data-textarea-box") is(tabpanel.querySelector("#request-post-data-textarea-box")
.hasAttribute("hidden"), true, .hasAttribute("hidden"), true,
"The request post data textarea box should be hidden."); "The request post data textarea box should be hidden.");
} }
function testResponseTab() { function* testResponseTab() {
EventUtils.sendMouseEvent({ type: "mousedown" }, let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
document.querySelectorAll("#details-pane tab")[3]); EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
return Task.spawn(function* () { let tabEl = document.querySelectorAll("#details-pane tab")[3];
yield waitFor(aMonitor.panelWin, TAB_UPDATED); let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
let tab = document.querySelectorAll("#details-pane tab")[3]; is(tabEl.getAttribute("selected"), "true",
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; "The response tab in the network details pane should be selected.");
is(tab.getAttribute("selected"), "true", is(tabpanel.querySelector("#response-content-info-header")
"The response tab in the network details pane should be selected."); .hasAttribute("hidden"), true,
"The response info header should be hidden.");
is(tabpanel.querySelector("#response-content-json-box")
.hasAttribute("hidden"), true,
"The response content json box should be hidden.");
is(tabpanel.querySelector("#response-content-textarea-box")
.hasAttribute("hidden"), false,
"The response content textarea box should not be hidden.");
is(tabpanel.querySelector("#response-content-image-box")
.hasAttribute("hidden"), true,
"The response content image box should be hidden.");
is(tabpanel.querySelector("#response-content-info-header") let editor = yield NetMonitorView.editor("#response-content-textarea");
.hasAttribute("hidden"), true, is(editor.getText(), "Hello world!",
"The response info header should be hidden."); "The text shown in the source editor is incorrect.");
is(tabpanel.querySelector("#response-content-json-box") is(editor.getMode(), Editor.modes.text,
.hasAttribute("hidden"), true, "The mode active in the source editor is incorrect.");
"The response content json box should be hidden."); }
is(tabpanel.querySelector("#response-content-textarea-box")
.hasAttribute("hidden"), false,
"The response content textarea box should not be hidden.");
is(tabpanel.querySelector("#response-content-image-box")
.hasAttribute("hidden"), true,
"The response content image box should be hidden.");
let aEditor = yield NetMonitorView.editor("#response-content-textarea"); function testTimingsTab() {
is(aEditor.getText(), "Hello world!", EventUtils.sendMouseEvent({ type: "mousedown" },
"The text shown in the source editor is incorrect."); document.querySelectorAll("#details-pane tab")[4]);
is(aEditor.getMode(), Editor.modes.text,
"The mode active in the source editor is incorrect.");
});
}
function testTimingsTab() { let tabEl = document.querySelectorAll("#details-pane tab")[4];
EventUtils.sendMouseEvent({ type: "mousedown" }, let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4];
document.querySelectorAll("#details-pane tab")[4]);
let tab = document.querySelectorAll("#details-pane tab")[4]; is(tabEl.getAttribute("selected"), "true",
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4]; "The timings tab in the network details pane should be selected.");
is(tab.getAttribute("selected"), "true", ok(tabpanel.querySelector("#timings-summary-blocked .requests-menu-timings-total")
"The timings tab in the network details pane should be selected."); .getAttribute("value").match(/[0-9]+/),
"The blocked timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-blocked .requests-menu-timings-total") ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/), .getAttribute("value").match(/[0-9]+/),
"The blocked timing info does not appear to be correct."); "The dns timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total") ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/), .getAttribute("value").match(/[0-9]+/),
"The dns timing info does not appear to be correct."); "The connect timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total") ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/), .getAttribute("value").match(/[0-9]+/),
"The connect timing info does not appear to be correct."); "The send timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total") ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/), .getAttribute("value").match(/[0-9]+/),
"The send timing info does not appear to be correct."); "The wait timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total") ok(tabpanel.querySelector("#timings-summary-receive .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/), .getAttribute("value").match(/[0-9]+/),
"The wait timing info does not appear to be correct."); "The receive timing info does not appear to be correct.");
}
ok(tabpanel.querySelector("#timings-summary-receive .requests-menu-timings-total") });
.getAttribute("value").match(/[0-9]+/),
"The receive timing info does not appear to be correct.");
}
aDebuggee.location.reload();
});
}

View File

@ -11,69 +11,62 @@
* 3) Empty user message visibility * 3) Empty user message visibility
* 4) Number of requests displayed * 4) Number of requests displayed
*/ */
function test() { add_task(function* () {
initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(SIMPLE_URL);
info("Starting test... "); info("Starting test... ");
let { document, NetMonitorView } = aMonitor.panelWin; let { document, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
is(document.querySelector("#details-pane-toggle") is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), true,
.hasAttribute("disabled"), true, "The pane toggle button should be disabled when the frontend is opened.");
"The pane toggle button should be disabled when the frontend is opened."); is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), false,
is(document.querySelector("#requests-menu-empty-notice") "An empty notice should be displayed when the frontend is opened.");
.hasAttribute("hidden"), false, is(RequestsMenu.itemCount, 0,
"An empty notice should be displayed when the frontend is opened."); "The requests menu should be empty when the frontend is opened.");
is(RequestsMenu.itemCount, 0, is(NetMonitorView.detailsPaneHidden, true,
"The requests menu should be empty when the frontend is opened."); "The details pane should be hidden when the frontend is opened.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should be hidden when the frontend is opened.");
waitForNetworkEvents(aMonitor, 1).then(() => { yield reloadAndWait();
is(document.querySelector("#details-pane-toggle")
.hasAttribute("disabled"), false,
"The pane toggle button should be enabled after the first request.");
is(document.querySelector("#requests-menu-empty-notice")
.hasAttribute("hidden"), true,
"The empty notice should be hidden after the first request.");
is(RequestsMenu.itemCount, 1,
"The requests menu should not be empty after the first request.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after the first request.");
waitForNetworkEvents(aMonitor, 1).then(() => { is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), false,
is(document.querySelector("#details-pane-toggle") "The pane toggle button should be enabled after the first request.");
.hasAttribute("disabled"), false, is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), true,
"The pane toggle button should be still be enabled after a reload."); "The empty notice should be hidden after the first request.");
is(document.querySelector("#requests-menu-empty-notice") is(RequestsMenu.itemCount, 1,
.hasAttribute("hidden"), true, "The requests menu should not be empty after the first request.");
"The empty notice should be still hidden after a reload."); is(NetMonitorView.detailsPaneHidden, true,
is(RequestsMenu.itemCount, 1, "The details pane should still be hidden after the first request.");
"The requests menu should not be empty after a reload.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after a reload.");
RequestsMenu.clear(); yield reloadAndWait();
is(document.querySelector("#details-pane-toggle") is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), false,
.hasAttribute("disabled"), true, "The pane toggle button should be still be enabled after a reload.");
"The pane toggle button should be disabled when after clear."); is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), true,
is(document.querySelector("#requests-menu-empty-notice") "The empty notice should be still hidden after a reload.");
.hasAttribute("hidden"), false, is(RequestsMenu.itemCount, 1,
"An empty notice should be displayed again after clear."); "The requests menu should not be empty after a reload.");
is(RequestsMenu.itemCount, 0, is(NetMonitorView.detailsPaneHidden, true,
"The requests menu should be empty after clear."); "The details pane should still be hidden after a reload.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should be hidden after clear.");
teardown(aMonitor).then(finish); RequestsMenu.clear();
});
aDebuggee.location.reload(); is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), true,
}); "The pane toggle button should be disabled when after clear.");
is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), false,
"An empty notice should be displayed again after clear.");
is(RequestsMenu.itemCount, 0,
"The requests menu should be empty after clear.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should be hidden after clear.");
aDebuggee.location.reload(); return teardown(monitor);
});
} function* reloadAndWait() {
let wait = waitForNetworkEvents(monitor, 1);
tab.linkedBrowser.reload();
return wait;
}
});

View File

@ -1,255 +1,228 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Test if the sorting mechanism works correctly. * Test if the sorting mechanism works correctly.
*/ */
function test() { add_task(function* () {
initNetMonitor(STATUS_CODES_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(STATUS_CODES_URL);
info("Starting test... "); info("Starting test... ");
let { $all, L10N, NetMonitorView } = aMonitor.panelWin; let { $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => { let wait = waitForNetworkEvents(monitor, 5);
testContents([0, 1, 2, 3, 4]) yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
.then(() => { content.wrappedJSObject.performRequests();
info("Testing swap(0, 0)");
RequestsMenu.swapItemsAtIndices(0, 0);
RequestsMenu.refreshZebra();
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing swap(0, 1)");
RequestsMenu.swapItemsAtIndices(0, 1);
RequestsMenu.refreshZebra();
return testContents([1, 0, 2, 3, 4]);
})
.then(() => {
info("Testing swap(0, 2)");
RequestsMenu.swapItemsAtIndices(0, 2);
RequestsMenu.refreshZebra();
return testContents([1, 2, 0, 3, 4]);
})
.then(() => {
info("Testing swap(0, 3)");
RequestsMenu.swapItemsAtIndices(0, 3);
RequestsMenu.refreshZebra();
return testContents([1, 2, 3, 0, 4]);
})
.then(() => {
info("Testing swap(0, 4)");
RequestsMenu.swapItemsAtIndices(0, 4);
RequestsMenu.refreshZebra();
return testContents([1, 2, 3, 4, 0]);
})
.then(() => {
info("Testing swap(1, 0)");
RequestsMenu.swapItemsAtIndices(1, 0);
RequestsMenu.refreshZebra();
return testContents([0, 2, 3, 4, 1]);
})
.then(() => {
info("Testing swap(1, 1)");
RequestsMenu.swapItemsAtIndices(1, 1);
RequestsMenu.refreshZebra();
return testContents([0, 2, 3, 4, 1]);
})
.then(() => {
info("Testing swap(1, 2)");
RequestsMenu.swapItemsAtIndices(1, 2);
RequestsMenu.refreshZebra();
return testContents([0, 1, 3, 4, 2]);
})
.then(() => {
info("Testing swap(1, 3)");
RequestsMenu.swapItemsAtIndices(1, 3);
RequestsMenu.refreshZebra();
return testContents([0, 3, 1, 4, 2]);
})
.then(() => {
info("Testing swap(1, 4)");
RequestsMenu.swapItemsAtIndices(1, 4);
RequestsMenu.refreshZebra();
return testContents([0, 3, 4, 1, 2]);
})
.then(() => {
info("Testing swap(2, 0)");
RequestsMenu.swapItemsAtIndices(2, 0);
RequestsMenu.refreshZebra();
return testContents([2, 3, 4, 1, 0]);
})
.then(() => {
info("Testing swap(2, 1)");
RequestsMenu.swapItemsAtIndices(2, 1);
RequestsMenu.refreshZebra();
return testContents([1, 3, 4, 2, 0]);
})
.then(() => {
info("Testing swap(2, 2)");
RequestsMenu.swapItemsAtIndices(2, 2);
RequestsMenu.refreshZebra();
return testContents([1, 3, 4, 2, 0]);
})
.then(() => {
info("Testing swap(2, 3)");
RequestsMenu.swapItemsAtIndices(2, 3);
RequestsMenu.refreshZebra();
return testContents([1, 2, 4, 3, 0]);
})
.then(() => {
info("Testing swap(2, 4)");
RequestsMenu.swapItemsAtIndices(2, 4);
RequestsMenu.refreshZebra();
return testContents([1, 4, 2, 3, 0]);
})
.then(() => {
info("Testing swap(3, 0)");
RequestsMenu.swapItemsAtIndices(3, 0);
RequestsMenu.refreshZebra();
return testContents([1, 4, 2, 0, 3]);
})
.then(() => {
info("Testing swap(3, 1)");
RequestsMenu.swapItemsAtIndices(3, 1);
RequestsMenu.refreshZebra();
return testContents([3, 4, 2, 0, 1]);
})
.then(() => {
info("Testing swap(3, 2)");
RequestsMenu.swapItemsAtIndices(3, 2);
RequestsMenu.refreshZebra();
return testContents([2, 4, 3, 0, 1]);
})
.then(() => {
info("Testing swap(3, 3)");
RequestsMenu.swapItemsAtIndices(3, 3);
RequestsMenu.refreshZebra();
return testContents([2, 4, 3, 0, 1]);
})
.then(() => {
info("Testing swap(3, 4)");
RequestsMenu.swapItemsAtIndices(3, 4);
RequestsMenu.refreshZebra();
return testContents([2, 3, 4, 0, 1]);
})
.then(() => {
info("Testing swap(4, 0)");
RequestsMenu.swapItemsAtIndices(4, 0);
RequestsMenu.refreshZebra();
return testContents([2, 3, 0, 4, 1]);
})
.then(() => {
info("Testing swap(4, 1)");
RequestsMenu.swapItemsAtIndices(4, 1);
RequestsMenu.refreshZebra();
return testContents([2, 3, 0, 1, 4]);
})
.then(() => {
info("Testing swap(4, 2)");
RequestsMenu.swapItemsAtIndices(4, 2);
RequestsMenu.refreshZebra();
return testContents([4, 3, 0, 1, 2]);
})
.then(() => {
info("Testing swap(4, 3)");
RequestsMenu.swapItemsAtIndices(4, 3);
RequestsMenu.refreshZebra();
return testContents([3, 4, 0, 1, 2]);
})
.then(() => {
info("Testing swap(4, 4)");
RequestsMenu.swapItemsAtIndices(4, 4);
RequestsMenu.refreshZebra();
return testContents([3, 4, 0, 1, 2]);
})
.then(() => {
info("Clearing sort.");
RequestsMenu.sortBy();
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish);
});
function testContents([a, b, c, d, e]) {
is(RequestsMenu.items.length, 5,
"There should be a total of 5 items in the requests menu.");
is(RequestsMenu.visibleItems.length, 5,
"There should be a total of 5 visbile items in the requests menu.");
is($all(".side-menu-widget-item").length, 5,
"The visible items in the requests menu are, in fact, visible!");
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0],
"The requests menu items aren't ordered correctly. First item is misplaced.");
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1],
"The requests menu items aren't ordered correctly. Second item is misplaced.");
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2],
"The requests menu items aren't ordered correctly. Third item is misplaced.");
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3],
"The requests menu items aren't ordered correctly. Fourth item is misplaced.");
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4],
"The requests menu items aren't ordered correctly. Fifth item is misplaced.");
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),
"GET", STATUS_CODES_SJS + "?sts=100", {
status: 101,
statusText: "Switching Protocols",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getStr("networkMenu.sizeUnavailable"),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
"GET", STATUS_CODES_SJS + "?sts=200", {
status: 202,
statusText: "Created",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
"GET", STATUS_CODES_SJS + "?sts=300", {
status: 303,
statusText: "See Other",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
"GET", STATUS_CODES_SJS + "?sts=400", {
status: 404,
statusText: "Not Found",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
"GET", STATUS_CODES_SJS + "?sts=500", {
status: 501,
statusText: "Not Implemented",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
return promise.resolve(null);
}
aDebuggee.performRequests();
}); });
} yield wait;
testContents([0, 1, 2, 3, 4]);
info("Testing swap(0, 0)");
RequestsMenu.swapItemsAtIndices(0, 0);
RequestsMenu.refreshZebra();
testContents([0, 1, 2, 3, 4]);
info("Testing swap(0, 1)");
RequestsMenu.swapItemsAtIndices(0, 1);
RequestsMenu.refreshZebra();
testContents([1, 0, 2, 3, 4]);
info("Testing swap(0, 2)");
RequestsMenu.swapItemsAtIndices(0, 2);
RequestsMenu.refreshZebra();
testContents([1, 2, 0, 3, 4]);
info("Testing swap(0, 3)");
RequestsMenu.swapItemsAtIndices(0, 3);
RequestsMenu.refreshZebra();
testContents([1, 2, 3, 0, 4]);
info("Testing swap(0, 4)");
RequestsMenu.swapItemsAtIndices(0, 4);
RequestsMenu.refreshZebra();
testContents([1, 2, 3, 4, 0]);
info("Testing swap(1, 0)");
RequestsMenu.swapItemsAtIndices(1, 0);
RequestsMenu.refreshZebra();
testContents([0, 2, 3, 4, 1]);
info("Testing swap(1, 1)");
RequestsMenu.swapItemsAtIndices(1, 1);
RequestsMenu.refreshZebra();
testContents([0, 2, 3, 4, 1]);
info("Testing swap(1, 2)");
RequestsMenu.swapItemsAtIndices(1, 2);
RequestsMenu.refreshZebra();
testContents([0, 1, 3, 4, 2]);
info("Testing swap(1, 3)");
RequestsMenu.swapItemsAtIndices(1, 3);
RequestsMenu.refreshZebra();
testContents([0, 3, 1, 4, 2]);
info("Testing swap(1, 4)");
RequestsMenu.swapItemsAtIndices(1, 4);
RequestsMenu.refreshZebra();
testContents([0, 3, 4, 1, 2]);
info("Testing swap(2, 0)");
RequestsMenu.swapItemsAtIndices(2, 0);
RequestsMenu.refreshZebra();
testContents([2, 3, 4, 1, 0]);
info("Testing swap(2, 1)");
RequestsMenu.swapItemsAtIndices(2, 1);
RequestsMenu.refreshZebra();
testContents([1, 3, 4, 2, 0]);
info("Testing swap(2, 2)");
RequestsMenu.swapItemsAtIndices(2, 2);
RequestsMenu.refreshZebra();
testContents([1, 3, 4, 2, 0]);
info("Testing swap(2, 3)");
RequestsMenu.swapItemsAtIndices(2, 3);
RequestsMenu.refreshZebra();
testContents([1, 2, 4, 3, 0]);
info("Testing swap(2, 4)");
RequestsMenu.swapItemsAtIndices(2, 4);
RequestsMenu.refreshZebra();
testContents([1, 4, 2, 3, 0]);
info("Testing swap(3, 0)");
RequestsMenu.swapItemsAtIndices(3, 0);
RequestsMenu.refreshZebra();
testContents([1, 4, 2, 0, 3]);
info("Testing swap(3, 1)");
RequestsMenu.swapItemsAtIndices(3, 1);
RequestsMenu.refreshZebra();
testContents([3, 4, 2, 0, 1]);
info("Testing swap(3, 2)");
RequestsMenu.swapItemsAtIndices(3, 2);
RequestsMenu.refreshZebra();
testContents([2, 4, 3, 0, 1]);
info("Testing swap(3, 3)");
RequestsMenu.swapItemsAtIndices(3, 3);
RequestsMenu.refreshZebra();
testContents([2, 4, 3, 0, 1]);
info("Testing swap(3, 4)");
RequestsMenu.swapItemsAtIndices(3, 4);
RequestsMenu.refreshZebra();
testContents([2, 3, 4, 0, 1]);
info("Testing swap(4, 0)");
RequestsMenu.swapItemsAtIndices(4, 0);
RequestsMenu.refreshZebra();
testContents([2, 3, 0, 4, 1]);
info("Testing swap(4, 1)");
RequestsMenu.swapItemsAtIndices(4, 1);
RequestsMenu.refreshZebra();
testContents([2, 3, 0, 1, 4]);
info("Testing swap(4, 2)");
RequestsMenu.swapItemsAtIndices(4, 2);
RequestsMenu.refreshZebra();
testContents([4, 3, 0, 1, 2]);
info("Testing swap(4, 3)");
RequestsMenu.swapItemsAtIndices(4, 3);
RequestsMenu.refreshZebra();
testContents([3, 4, 0, 1, 2]);
info("Testing swap(4, 4)");
RequestsMenu.swapItemsAtIndices(4, 4);
RequestsMenu.refreshZebra();
testContents([3, 4, 0, 1, 2]);
info("Clearing sort.");
RequestsMenu.sortBy();
testContents([0, 1, 2, 3, 4]);
return teardown(monitor);
function testContents([a, b, c, d, e]) {
is(RequestsMenu.items.length, 5,
"There should be a total of 5 items in the requests menu.");
is(RequestsMenu.visibleItems.length, 5,
"There should be a total of 5 visbile items in the requests menu.");
is($all(".side-menu-widget-item").length, 5,
"The visible items in the requests menu are, in fact, visible!");
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0],
"The requests menu items aren't ordered correctly. First item is misplaced.");
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1],
"The requests menu items aren't ordered correctly. Second item is misplaced.");
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2],
"The requests menu items aren't ordered correctly. Third item is misplaced.");
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3],
"The requests menu items aren't ordered correctly. Fourth item is misplaced.");
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4],
"The requests menu items aren't ordered correctly. Fifth item is misplaced.");
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),
"GET", STATUS_CODES_SJS + "?sts=100", {
status: 101,
statusText: "Switching Protocols",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getStr("networkMenu.sizeUnavailable"),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
"GET", STATUS_CODES_SJS + "?sts=200", {
status: 202,
statusText: "Created",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
"GET", STATUS_CODES_SJS + "?sts=300", {
status: 303,
statusText: "See Other",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
"GET", STATUS_CODES_SJS + "?sts=400", {
status: 404,
statusText: "Not Found",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
"GET", STATUS_CODES_SJS + "?sts=500", {
status: 501,
statusText: "Not Implemented",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 22),
time: true
});
}
});

View File

@ -1,296 +1,270 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Test if sorting columns in the network table works correctly. * Test if sorting columns in the network table works correctly.
*/ */
function test() { add_task(function* () {
initNetMonitor(SORTING_URL).then(([aTab, aDebuggee, aMonitor]) => { let [,, monitor] = yield initNetMonitor(SORTING_URL);
info("Starting test... "); info("Starting test... ");
// It seems that this test may be slow on debug builds. This could be because // It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting. // of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2); requestLongerTimeout(2);
let { $, $all, L10N, NetMonitorView } = aMonitor.panelWin; let { $, $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
// Loading the frame script and preparing the xhr request URLs so we can // Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later. // generate some requests later.
loadCommonFrameScript(); loadCommonFrameScript();
let requests = [{ let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1" method: "GET1"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5" method: "GET5"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2" method: "GET2"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4" method: "GET4"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3" method: "GET3"
}]; }];
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => { let wait = waitForNetworkEvents(monitor, 5);
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle")); yield performRequestsInContent(requests);
yield wait;
isnot(RequestsMenu.selectedItem, null, EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
"There should be a selected item in the requests menu.");
is(RequestsMenu.selectedIndex, 0,
"The first item should be selected in the requests menu.");
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should not be hidden after toggle button was pressed.");
testHeaders(); isnot(RequestsMenu.selectedItem, null,
testContents([0, 2, 4, 3, 1]) "There should be a selected item in the requests menu.");
.then(() => { is(RequestsMenu.selectedIndex, 0,
info("Testing status sort, ascending."); "The first item should be selected in the requests menu.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button")); is(NetMonitorView.detailsPaneHidden, false,
testHeaders("status", "ascending"); "The details pane should not be hidden after toggle button was pressed.");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing status sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing status sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing method sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing method sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing method sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing file sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing file sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing file sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing type sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing type sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing type sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing transferred sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing transferred sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing transferred sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing size sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing size sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "descending");
return testContents([4, 3, 2, 1, 0]);
})
.then(() => {
info("Testing size sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "ascending");
return testContents([0, 1, 2, 3, 4]);
})
.then(() => {
info("Testing waterfall sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "ascending");
return testContents([0, 2, 4, 3, 1]);
})
.then(() => {
info("Testing waterfall sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "descending");
return testContents([4, 2, 0, 1, 3]);
})
.then(() => {
info("Testing waterfall sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "ascending");
return testContents([0, 2, 4, 3, 1]);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish);
});
function testHeaders(aSortType, aDirection) { testHeaders();
let doc = aMonitor.panelWin.document; testContents([0, 2, 4, 3, 1]);
let target = doc.querySelector("#requests-menu-" + aSortType + "-button");
let headers = doc.querySelectorAll(".requests-menu-header-button");
for (let header of headers) { info("Testing status sort, ascending.");
if (header != target) { EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
is(header.hasAttribute("sorted"), false, testHeaders("status", "ascending");
"The " + header.id + " header should not have a 'sorted' attribute."); testContents([0, 1, 2, 3, 4]);
is(header.hasAttribute("tooltiptext"), false,
"The " + header.id + " header should not have a 'tooltiptext' attribute."); info("Testing status sort, descending.");
} else { EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
is(header.getAttribute("sorted"), aDirection, testHeaders("status", "descending");
"The " + header.id + " header has an incorrect 'sorted' attribute."); testContents([4, 3, 2, 1, 0]);
is(header.getAttribute("tooltiptext"), aDirection == "ascending"
? L10N.getStr("networkMenu.sortedAsc") info("Testing status sort, ascending. Checking sort loops correctly.");
: L10N.getStr("networkMenu.sortedDesc"), EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
"The " + header.id + " has an incorrect 'tooltiptext' attribute."); testHeaders("status", "ascending");
} testContents([0, 1, 2, 3, 4]);
info("Testing method sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing method sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing method sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-method-button"));
testHeaders("method", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing file sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing file sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing file sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-file-button"));
testHeaders("file", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing type sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing type sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing type sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-type-button"));
testHeaders("type", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing transferred sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing transferred sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing transferred sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-transferred-button"));
testHeaders("transferred", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing size sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing size sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing size sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testHeaders("size", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing waterfall sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "ascending");
testContents([0, 2, 4, 3, 1]);
info("Testing waterfall sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "descending");
testContents([4, 2, 0, 1, 3]);
info("Testing waterfall sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
testHeaders("waterfall", "ascending");
testContents([0, 2, 4, 3, 1]);
return teardown(monitor);
function testHeaders(sortType, direction) {
let doc = monitor.panelWin.document;
let target = doc.querySelector("#requests-menu-" + sortType + "-button");
let headers = doc.querySelectorAll(".requests-menu-header-button");
for (let header of headers) {
if (header != target) {
is(header.hasAttribute("sorted"), false,
"The " + header.id + " header should not have a 'sorted' attribute.");
is(header.hasAttribute("tooltiptext"), false,
"The " + header.id + " header should not have a 'tooltiptext' attribute.");
} else {
is(header.getAttribute("sorted"), direction,
"The " + header.id + " header has an incorrect 'sorted' attribute.");
is(header.getAttribute("tooltiptext"), direction == "ascending"
? L10N.getStr("networkMenu.sortedAsc")
: L10N.getStr("networkMenu.sortedDesc"),
"The " + header.id + " has an incorrect 'tooltiptext' attribute.");
} }
} }
}
function testContents([a, b, c, d, e]) { function testContents([a, b, c, d, e]) {
isnot(RequestsMenu.selectedItem, null, isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after sorting."); "There should still be a selected item after sorting.");
is(RequestsMenu.selectedIndex, a, is(RequestsMenu.selectedIndex, a,
"The first item should be still selected after sorting."); "The first item should be still selected after sorting.");
is(NetMonitorView.detailsPaneHidden, false, is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after sorting."); "The details pane should still be visible after sorting.");
is(RequestsMenu.items.length, 5, is(RequestsMenu.items.length, 5,
"There should be a total of 5 items in the requests menu."); "There should be a total of 5 items in the requests menu.");
is(RequestsMenu.visibleItems.length, 5, is(RequestsMenu.visibleItems.length, 5,
"There should be a total of 5 visbile items in the requests menu."); "There should be a total of 5 visbile items in the requests menu.");
is($all(".side-menu-widget-item").length, 5, is($all(".side-menu-widget-item").length, 5,
"The visible items in the requests menu are, in fact, visible!"); "The visible items in the requests menu are, in fact, visible!");
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0], is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0],
"The requests menu items aren't ordered correctly. First item is misplaced."); "The requests menu items aren't ordered correctly. First item is misplaced.");
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1], is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1],
"The requests menu items aren't ordered correctly. Second item is misplaced."); "The requests menu items aren't ordered correctly. Second item is misplaced.");
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2], is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2],
"The requests menu items aren't ordered correctly. Third item is misplaced."); "The requests menu items aren't ordered correctly. Third item is misplaced.");
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3], is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3],
"The requests menu items aren't ordered correctly. Fourth item is misplaced."); "The requests menu items aren't ordered correctly. Fourth item is misplaced.");
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4], is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4],
"The requests menu items aren't ordered correctly. Fifth item is misplaced."); "The requests menu items aren't ordered correctly. Fifth item is misplaced.");
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a), verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),
"GET1", SORTING_SJS + "?index=1", { "GET1", SORTING_SJS + "?index=1", {
fuzzyUrl: true, fuzzyUrl: true,
status: 101, status: 101,
statusText: "Meh", statusText: "Meh",
type: "1", type: "1",
fullMimeType: "text/1", fullMimeType: "text/1",
transferred: L10N.getStr("networkMenu.sizeUnavailable"), transferred: L10N.getStr("networkMenu.sizeUnavailable"),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0), size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true time: true
}); });
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b), verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
"GET2", SORTING_SJS + "?index=2", { "GET2", SORTING_SJS + "?index=2", {
fuzzyUrl: true, fuzzyUrl: true,
status: 200, status: 200,
statusText: "Meh", statusText: "Meh",
type: "2", type: "2",
fullMimeType: "text/2", fullMimeType: "text/2",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19), transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19), size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
time: true time: true
}); });
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c), verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
"GET3", SORTING_SJS + "?index=3", { "GET3", SORTING_SJS + "?index=3", {
fuzzyUrl: true, fuzzyUrl: true,
status: 300, status: 300,
statusText: "Meh", statusText: "Meh",
type: "3", type: "3",
fullMimeType: "text/3", fullMimeType: "text/3",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29), transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29), size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
time: true time: true
}); });
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d), verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
"GET4", SORTING_SJS + "?index=4", { "GET4", SORTING_SJS + "?index=4", {
fuzzyUrl: true, fuzzyUrl: true,
status: 400, status: 400,
statusText: "Meh", statusText: "Meh",
type: "4", type: "4",
fullMimeType: "text/4", fullMimeType: "text/4",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39), transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39), size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
time: true time: true
}); });
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e), verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
"GET5", SORTING_SJS + "?index=5", { "GET5", SORTING_SJS + "?index=5", {
fuzzyUrl: true, fuzzyUrl: true,
status: 500, status: 500,
statusText: "Meh", statusText: "Meh",
type: "5", type: "5",
fullMimeType: "text/5", fullMimeType: "text/5",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49), transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49), size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
time: true time: true
}); });
}
return promise.resolve(null); });
}
performRequestsInContent(requests).then(null, e => {
ok(false, e);
});
});
}

View File

@ -1,220 +1,207 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Test if sorting columns in the network table works correctly with new requests. * Test if sorting columns in the network table works correctly with new requests.
*/ */
function test() { add_task(function* () {
initNetMonitor(SORTING_URL).then(([aTab, aDebuggee, aMonitor]) => { let [,, monitor] = yield initNetMonitor(SORTING_URL);
info("Starting test... "); info("Starting test... ");
// It seems that this test may be slow on debug builds. This could be because // It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting. // of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2); requestLongerTimeout(2);
let { $, $all, L10N, NetMonitorView } = aMonitor.panelWin; let { $, $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
// Loading the frame script and preparing the xhr request URLs so we can // Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later. // generate some requests later.
loadCommonFrameScript(); loadCommonFrameScript();
let requests = [{ let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1" method: "GET1"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5" method: "GET5"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2" method: "GET2"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4" method: "GET4"
}, { }, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(), url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3" method: "GET3"
}]; }];
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => { let wait = waitForNetworkEvents(monitor, 5);
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle")); yield performRequestsInContent(requests);
yield wait;
isnot(RequestsMenu.selectedItem, null, EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
"There should be a selected item in the requests menu.");
is(RequestsMenu.selectedIndex, 0,
"The first item should be selected in the requests menu.");
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should not be hidden after toggle button was pressed.");
testHeaders(); isnot(RequestsMenu.selectedItem, null,
testContents([0, 2, 4, 3, 1], 0) "There should be a selected item in the requests menu.");
.then(() => { is(RequestsMenu.selectedIndex, 0,
info("Testing status sort, ascending."); "The first item should be selected in the requests menu.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button")); is(NetMonitorView.detailsPaneHidden, false,
testHeaders("status", "ascending"); "The details pane should not be hidden after toggle button was pressed.");
return testContents([0, 1, 2, 3, 4], 0);
}) testHeaders();
.then(() => { testContents([0, 2, 4, 3, 1], 0);
info("Performing more requests.");
performRequestsInContent(requests); info("Testing status sort, ascending.");
return waitForNetworkEvents(aMonitor, 5); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
}) testHeaders("status", "ascending");
.then(() => { testContents([0, 1, 2, 3, 4], 0);
info("Testing status sort again, ascending.");
testHeaders("status", "ascending"); info("Performing more requests.");
return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0); wait = waitForNetworkEvents(monitor, 5);
}) yield performRequestsInContent(requests);
.then(() => { yield wait;
info("Testing status sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button")); info("Testing status sort again, ascending.");
testHeaders("status", "descending"); testHeaders("status", "ascending");
return testContents([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 9); testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0);
})
.then(() => { info("Testing status sort, descending.");
info("Performing more requests."); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
performRequestsInContent(requests); testHeaders("status", "descending");
return waitForNetworkEvents(aMonitor, 5); testContents([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 9);
})
.then(() => { info("Performing more requests.");
info("Testing status sort again, descending."); wait = waitForNetworkEvents(monitor, 5);
testHeaders("status", "descending"); yield performRequestsInContent(requests);
return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14); yield wait;
})
.then(() => { info("Testing status sort again, descending.");
info("Testing status sort yet again, ascending."); testHeaders("status", "descending");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button")); testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
testHeaders("status", "ascending");
return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 0); info("Testing status sort yet again, ascending.");
}) EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
.then(() => { testHeaders("status", "ascending");
info("Testing status sort yet again, descending."); testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 0);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending"); info("Testing status sort yet again, descending.");
return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
}) testHeaders("status", "descending");
.then(() => { testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
return teardown(aMonitor);
}) return teardown(monitor);
.then(finish, e => {
ok(false, e); function testHeaders(sortType, direction) {
let doc = monitor.panelWin.document;
let target = doc.querySelector("#requests-menu-" + sortType + "-button");
let headers = doc.querySelectorAll(".requests-menu-header-button");
for (let header of headers) {
if (header != target) {
is(header.hasAttribute("sorted"), false,
"The " + header.id + " header should not have a 'sorted' attribute.");
is(header.hasAttribute("tooltiptext"), false,
"The " + header.id + " header should not have a 'tooltiptext' attribute.");
} else {
is(header.getAttribute("sorted"), direction,
"The " + header.id + " header has an incorrect 'sorted' attribute.");
is(header.getAttribute("tooltiptext"), direction == "ascending"
? L10N.getStr("networkMenu.sortedAsc")
: L10N.getStr("networkMenu.sortedDesc"),
"The " + header.id + " has an incorrect 'tooltiptext' attribute.");
}
}
}
function testContents(order, selection) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after sorting.");
is(RequestsMenu.selectedIndex, selection,
"The first item should be still selected after sorting.");
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after sorting.");
is(RequestsMenu.items.length, order.length,
"There should be a specific number of items in the requests menu.");
is(RequestsMenu.visibleItems.length, order.length,
"There should be a specific number of visbile items in the requests menu.");
is($all(".side-menu-widget-item").length, order.length,
"The visible items in the requests menu are, in fact, visible!");
for (let i = 0; i < order.length; i++) {
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.items[i],
"The requests menu items aren't ordered correctly. Misplaced item " + i + ".");
}
for (let i = 0, len = order.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i]),
"GET1", SORTING_SJS + "?index=1", {
fuzzyUrl: true,
status: 101,
statusText: "Meh",
type: "1",
fullMimeType: "text/1",
transferred: L10N.getStr("networkMenu.sizeUnavailable"),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
}); });
}, e => {
ok(false, e);
});
function testHeaders(aSortType, aDirection) {
let doc = aMonitor.panelWin.document;
let target = doc.querySelector("#requests-menu-" + aSortType + "-button");
let headers = doc.querySelectorAll(".requests-menu-header-button");
for (let header of headers) {
if (header != target) {
is(header.hasAttribute("sorted"), false,
"The " + header.id + " header should not have a 'sorted' attribute.");
is(header.hasAttribute("tooltiptext"), false,
"The " + header.id + " header should not have a 'tooltiptext' attribute.");
} else {
is(header.getAttribute("sorted"), aDirection,
"The " + header.id + " header has an incorrect 'sorted' attribute.");
is(header.getAttribute("tooltiptext"), aDirection == "ascending"
? L10N.getStr("networkMenu.sortedAsc")
: L10N.getStr("networkMenu.sortedDesc"),
"The " + header.id + " has an incorrect 'tooltiptext' attribute.");
}
}
} }
for (let i = 0, len = order.length / 5; i < len; i++) {
function testContents(aOrder, aSelection) { verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len]),
isnot(RequestsMenu.selectedItem, null, "GET2", SORTING_SJS + "?index=2", {
"There should still be a selected item after sorting."); fuzzyUrl: true,
is(RequestsMenu.selectedIndex, aSelection, status: 200,
"The first item should be still selected after sorting."); statusText: "Meh",
is(NetMonitorView.detailsPaneHidden, false, type: "2",
"The details pane should still be visible after sorting."); fullMimeType: "text/2",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
is(RequestsMenu.items.length, aOrder.length, size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
"There should be a specific number of items in the requests menu."); time: true
is(RequestsMenu.visibleItems.length, aOrder.length, });
"There should be a specific number of visbile items in the requests menu.");
is($all(".side-menu-widget-item").length, aOrder.length,
"The visible items in the requests menu are, in fact, visible!");
for (let i = 0; i < aOrder.length; i++) {
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.items[i],
"The requests menu items aren't ordered correctly. Misplaced item " + i + ".");
}
for (let i = 0, len = aOrder.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i]),
"GET1", SORTING_SJS + "?index=1", {
fuzzyUrl: true,
status: 101,
statusText: "Meh",
type: "1",
fullMimeType: "text/1",
transferred: L10N.getStr("networkMenu.sizeUnavailable"),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 0),
time: true
});
}
for (let i = 0, len = aOrder.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len]),
"GET2", SORTING_SJS + "?index=2", {
fuzzyUrl: true,
status: 200,
statusText: "Meh",
type: "2",
fullMimeType: "text/2",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 19),
time: true
});
}
for (let i = 0, len = aOrder.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 2]),
"GET3", SORTING_SJS + "?index=3", {
fuzzyUrl: true,
status: 300,
statusText: "Meh",
type: "3",
fullMimeType: "text/3",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
time: true
});
}
for (let i = 0, len = aOrder.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 3]),
"GET4", SORTING_SJS + "?index=4", {
fuzzyUrl: true,
status: 400,
statusText: "Meh",
type: "4",
fullMimeType: "text/4",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
time: true
});
}
for (let i = 0, len = aOrder.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 4]),
"GET5", SORTING_SJS + "?index=5", {
fuzzyUrl: true,
status: 500,
statusText: "Meh",
type: "5",
fullMimeType: "text/5",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
time: true
});
}
return promise.resolve(null);
} }
for (let i = 0, len = order.length / 5; i < len; i++) {
performRequestsInContent(requests).then(null, e => console.error(e)); verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 2]),
}); "GET3", SORTING_SJS + "?index=3", {
} fuzzyUrl: true,
status: 300,
statusText: "Meh",
type: "3",
fullMimeType: "text/3",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
time: true
});
}
for (let i = 0, len = order.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 3]),
"GET4", SORTING_SJS + "?index=4", {
fuzzyUrl: true,
status: 400,
statusText: "Meh",
type: "4",
fullMimeType: "text/4",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 39),
time: true
});
}
for (let i = 0, len = order.length / 5; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 4]),
"GET5", SORTING_SJS + "?index=5", {
fuzzyUrl: true,
status: 500,
statusText: "Meh",
type: "5",
fullMimeType: "text/5",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 49),
time: true
});
}
}
});

View File

@ -22,10 +22,10 @@ add_task(function* () {
"There should be no empty cache chart created yet."); "There should be no empty cache chart created yet.");
let onChartDisplayed = Promise.all([ let onChartDisplayed = Promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED), panel.once(EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED) panel.once(EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]); ]);
let onPlaceholderDisplayed = waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED); let onPlaceholderDisplayed = panel.once(EVENTS.PLACEHOLDER_CHARTS_DISPLAYED);
info("Displaying statistics view"); info("Displaying statistics view");
NetMonitorView.toggleFrontendMode(); NetMonitorView.toggleFrontendMode();
@ -51,25 +51,13 @@ add_task(function* () {
is($("#empty-cache-chart").childNodes.length, 1, is($("#empty-cache-chart").childNodes.length, 1,
"There should be a real empty cache chart created now."); "There should be a real empty cache chart created now.");
yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2); yield waitUntil(
() => $all(".pie-chart-container:not([placeholder=true])").length == 2);
ok(true, "Two real pie charts appear to be rendered correctly."); ok(true, "Two real pie charts appear to be rendered correctly.");
yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2); yield waitUntil(
() => $all(".table-chart-container:not([placeholder=true])").length == 2);
ok(true, "Two real table charts appear to be rendered correctly."); ok(true, "Two real table charts appear to be rendered correctly.");
yield teardown(monitor); yield teardown(monitor);
}); });
function waitForTick() {
let deferred = promise.defer();
executeSoon(deferred.resolve);
return deferred.promise;
}
function until(predicate) {
return Task.spawn(function* () {
while (!predicate()) {
yield waitForTick();
}
});
}

View File

@ -9,7 +9,7 @@
*/ */
add_task(function* () { add_task(function* () {
let [, debuggee, monitor] = yield initNetMonitor(STATISTICS_URL); let [tab, , monitor] = yield initNetMonitor(STATISTICS_URL);
info("Starting test... "); info("Starting test... ");
let panel = monitor.panelWin; let panel = monitor.panelWin;
@ -18,8 +18,8 @@ add_task(function* () {
"The initial frontend mode is correct."); "The initial frontend mode is correct.");
let onChartDisplayed = Promise.all([ let onChartDisplayed = Promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED), panel.once(EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED) panel.once(EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]); ]);
info("Displaying statistics view"); info("Displaying statistics view");
@ -29,9 +29,9 @@ add_task(function* () {
"The frontend mode is currently in the statistics view."); "The frontend mode is currently in the statistics view.");
info("Reloading page"); info("Reloading page");
let onWillNavigate = waitFor(panel, EVENTS.TARGET_WILL_NAVIGATE); let onWillNavigate = panel.once(EVENTS.TARGET_WILL_NAVIGATE);
let onDidNavigate = waitFor(panel, EVENTS.TARGET_DID_NAVIGATE); let onDidNavigate = panel.once(EVENTS.TARGET_DID_NAVIGATE);
debuggee.location.reload(); tab.linkedBrowser.reload();
yield onWillNavigate; yield onWillNavigate;
is(NetMonitorView.currentFrontendMode, "network-inspector-view", is(NetMonitorView.currentFrontendMode, "network-inspector-view",
"The frontend mode switched back to the inspector view."); "The frontend mode switched back to the inspector view.");

View File

@ -1,37 +1,38 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Test if the correct filtering predicates are used when filtering from * Test if the correct filtering predicates are used when filtering from
* the performance analysis view. * the performance analysis view.
*/ */
function test() { add_task(function* () {
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => { let [,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... "); info("Starting test... ");
let panel = aMonitor.panelWin; let panel = monitor.panelWin;
let { $, EVENTS, NetMonitorView } = panel; let { $, EVENTS, NetMonitorView } = panel;
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button")); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button")); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button")); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-ws-button")); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-ws-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-other-button")); EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-other-button"));
testFilterButtonsCustom(aMonitor, [0, 1, 1, 1, 0, 0, 0, 0, 0, 1]); testFilterButtonsCustom(monitor, [0, 1, 1, 1, 0, 0, 0, 0, 0, 1]);
ok(true, "The correct filtering predicates are used before entering perf. analysis mode."); info("The correct filtering predicates are used before entering perf. analysis mode.");
promise.all([ let onEvents = promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED), panel.once(EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED) panel.once(EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]).then(() => { ]);
EventUtils.sendMouseEvent({ type: "click" }, $(".pie-chart-slice")); NetMonitorView.toggleFrontendMode();
testFilterButtons(aMonitor, "html"); yield onEvents;
ok(true, "The correct filtering predicate is used when exiting perf. analysis mode.");
teardown(aMonitor).then(finish); EventUtils.sendMouseEvent({ type: "click" }, $(".pie-chart-slice"));
}); testFilterButtons(monitor, "html");
info("The correct filtering predicate is used when exiting perf. analysis mode.");
NetMonitorView.toggleFrontendMode(); yield teardown(monitor);
}); });
}

View File

@ -7,12 +7,12 @@
* Tests if requests display the correct status code and text in the UI. * Tests if requests display the correct status code and text in the UI.
*/ */
var test = Task.async(function* () { add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(STATUS_CODES_URL); let [tab, , monitor] = yield initNetMonitor(STATUS_CODES_URL);
info("Starting test... "); info("Starting test... ");
let { document, L10N, NetMonitorView } = monitor.panelWin; let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView; let { RequestsMenu, NetworkDetails } = NetMonitorView;
let requestItems = []; let requestItems = [];
@ -20,7 +20,8 @@ var test = Task.async(function* () {
NetworkDetails._params.lazyEmpty = false; NetworkDetails._params.lazyEmpty = false;
const REQUEST_DATA = [ const REQUEST_DATA = [
{ // request #0 {
// request #0
method: "GET", method: "GET",
uri: STATUS_CODES_SJS + "?sts=100", uri: STATUS_CODES_SJS + "?sts=100",
details: { details: {
@ -32,7 +33,8 @@ var test = Task.async(function* () {
time: true time: true
} }
}, },
{ // request #1 {
// request #1
method: "GET", method: "GET",
uri: STATUS_CODES_SJS + "?sts=200", uri: STATUS_CODES_SJS + "?sts=200",
details: { details: {
@ -44,7 +46,8 @@ var test = Task.async(function* () {
time: true time: true
} }
}, },
{ // request #2 {
// request #2
method: "GET", method: "GET",
uri: STATUS_CODES_SJS + "?sts=300", uri: STATUS_CODES_SJS + "?sts=300",
details: { details: {
@ -56,7 +59,8 @@ var test = Task.async(function* () {
time: true time: true
} }
}, },
{ // request #3 {
// request #3
method: "GET", method: "GET",
uri: STATUS_CODES_SJS + "?sts=400", uri: STATUS_CODES_SJS + "?sts=400",
details: { details: {
@ -68,7 +72,8 @@ var test = Task.async(function* () {
time: true time: true
} }
}, },
{ // request #4 {
// request #4
method: "GET", method: "GET",
uri: STATUS_CODES_SJS + "?sts=500", uri: STATUS_CODES_SJS + "?sts=500",
details: { details: {
@ -82,15 +87,18 @@ var test = Task.async(function* () {
} }
]; ];
debuggee.performRequests(); let wait = waitForNetworkEvents(monitor, 5);
yield waitForNetworkEvents(monitor, 5); yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
info("Performing tests"); info("Performing tests");
yield verifyRequests(); yield verifyRequests();
yield testTab(0, testSummary); yield testTab(0, testSummary);
yield testTab(2, testParams); yield testTab(2, testParams);
yield teardown(monitor); return teardown(monitor);
finish();
/** /**
* A helper that verifies all requests show the correct information and caches * A helper that verifies all requests show the correct information and caches
@ -114,21 +122,21 @@ var test = Task.async(function* () {
* A helper that opens a given tab of request details pane, selects and passes * A helper that opens a given tab of request details pane, selects and passes
* all requests to the given test function. * all requests to the given test function.
* *
* @param Number tab * @param Number tabIdx
* The index of NetworkDetails tab to activate. * The index of NetworkDetails tab to activate.
* @param Function testFn(requestItem) * @param Function testFn(requestItem)
* A function that should perform all necessary tests. It's called once * A function that should perform all necessary tests. It's called once
* for every item of REQUEST_DATA with that item being selected in the * for every item of REQUEST_DATA with that item being selected in the
* NetworkMonitor. * NetworkMonitor.
*/ */
function* testTab(tab, testFn) { function* testTab(tabIdx, testFn) {
info("Testing tab #" + tab); info("Testing tab #" + tabIdx);
EventUtils.sendMouseEvent({ type: "mousedown" }, EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[tab]); document.querySelectorAll("#details-pane tab")[tabIdx]);
let counter = 0; let counter = 0;
for (let item of REQUEST_DATA) { for (let item of REQUEST_DATA) {
info("Waiting tab #" + tab + " to update with request #" + counter); info("Waiting tab #" + tabIdx + " to update with request #" + counter);
yield chooseRequest(counter); yield chooseRequest(counter);
info("Tab updated. Performing checks"); info("Tab updated. Performing checks");
@ -142,7 +150,6 @@ var test = Task.async(function* () {
* A function that tests "Summary" contains correct information. * A function that tests "Summary" contains correct information.
*/ */
function* testSummary(data) { function* testSummary(data) {
let tab = document.querySelectorAll("#details-pane tab")[0];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0]; let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
let { method, uri, details: { status, statusText } } = data; let { method, uri, details: { status, statusText } } = data;
@ -160,7 +167,6 @@ var test = Task.async(function* () {
* A function that tests "Params" tab contains correct information. * A function that tests "Params" tab contains correct information.
*/ */
function* testParams(data) { function* testParams(data) {
let tab = document.querySelectorAll("#details-pane tab")[2];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
let statusParamValue = data.uri.split("=").pop(); let statusParamValue = data.uri.split("=").pop();
let statusParamShownValue = "\"" + statusParamValue + "\""; let statusParamShownValue = "\"" + statusParamValue + "\"";
@ -178,9 +184,11 @@ var test = Task.async(function* () {
L10N.getStr("paramsQueryString"), L10N.getStr("paramsQueryString"),
"The params scope doesn't have the correct title."); "The params scope doesn't have the correct title.");
is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), is(paramsScope.querySelectorAll(".variables-view-variable .name")[0]
.getAttribute("value"),
"sts", "The param name was incorrect."); "sts", "The param name was incorrect.");
is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), is(paramsScope.querySelectorAll(".variables-view-variable .value")[0]
.getAttribute("value"),
statusParamShownValue, "The param value was incorrect."); statusParamShownValue, "The param value was incorrect.");
is(tabpanel.querySelector("#request-params-box") is(tabpanel.querySelector("#request-params-box")
@ -196,7 +204,8 @@ var test = Task.async(function* () {
* when NetworkDetails has been populated with the data of the given request. * when NetworkDetails has been populated with the data of the given request.
*/ */
function chooseRequest(index) { function chooseRequest(index) {
let onTabUpdated = monitor.panelWin.once(EVENTS.TAB_UPDATED);
EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[index].target); EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[index].target);
return waitFor(monitor.panelWin, monitor.panelWin.EVENTS.TAB_UPDATED); return onTabUpdated;
} }
}); });

View File

@ -1,65 +1,69 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if reponses from streaming content types (MPEG-DASH, HLS) are * Tests if reponses from streaming content types (MPEG-DASH, HLS) are
* displayed as XML or plain text * displayed as XML or plain text
*/ */
function test() { add_task(function* () {
Task.spawn(function* () { let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
info("Starting test... "); info("Starting test... ");
let { panelWin } = monitor; let { panelWin } = monitor;
let { document, Editor, NetMonitorView } = panelWin; let { document, Editor, NetMonitorView } = panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
const REQUESTS = [ const REQUESTS = [
[ "hls-m3u8", /^#EXTM3U/, Editor.modes.text ], [ "hls-m3u8", /^#EXTM3U/, Editor.modes.text ],
[ "mpeg-dash", /^<\?xml/, Editor.modes.html ] [ "mpeg-dash", /^<\?xml/, Editor.modes.html ]
]; ];
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
REQUESTS.forEach(([ fmt ]) => { let wait = waitForNetworkEvents(monitor, REQUESTS.length);
debuggee.performRequests(1, CONTENT_TYPE_SJS + "?fmt=" + fmt); for (let [fmt] of REQUESTS) {
let url = CONTENT_TYPE_SJS + "?fmt=" + fmt;
yield ContentTask.spawn(tab.linkedBrowser, { url }, function* (args) {
content.wrappedJSObject.performRequests(1, args.url);
}); });
}
yield wait;
yield waitForNetworkEvents(monitor, REQUESTS.length); REQUESTS.forEach(([ fmt ], i) => {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
REQUESTS.forEach(([ fmt ], i) => { "GET", CONTENT_TYPE_SJS + "?fmt=" + fmt, {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i), status: 200,
"GET", CONTENT_TYPE_SJS + "?fmt=" + fmt, { statusText: "OK"
status: 200, });
statusText: "OK"
});
});
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
let editor = yield NetMonitorView.editor("#response-content-textarea");
testEditorContent(editor, REQUESTS[0]); // the hls-m3u8 part
RequestsMenu.selectedIndex = 1;
yield panelWin.once(panelWin.EVENTS.TAB_UPDATED);
yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
testEditorContent(editor, REQUESTS[1]); // the mpeg-dash part
yield teardown(monitor);
finish();
}); });
function testEditorContent(editor, [ fmt, textRe, mode ]) { EventUtils.sendMouseEvent({ type: "mousedown" },
ok(editor.getText().match(textRe), document.getElementById("details-pane-toggle"));
"The text shown in the source editor for " + fmt + " is incorrect."); EventUtils.sendMouseEvent({ type: "mousedown" },
is(editor.getMode(), mode, document.querySelectorAll("#details-pane tab")[3]);
"The mode active in the source editor for " + fmt + " is incorrect.");
yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
let editor = yield NetMonitorView.editor("#response-content-textarea");
// the hls-m3u8 part
testEditorContent(editor, REQUESTS[0]);
RequestsMenu.selectedIndex = 1;
yield panelWin.once(panelWin.EVENTS.TAB_UPDATED);
yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
// the mpeg-dash part
testEditorContent(editor, REQUESTS[1]);
return teardown(monitor);
function testEditorContent(e, [ fmt, textRe, mode ]) {
ok(e.getText().match(textRe),
"The text shown in the source editor for " + fmt + " is correct.");
is(e.getMode(), mode,
"The mode active in the source editor for " + fmt + " is correct.");
} }
} });

View File

@ -14,8 +14,7 @@ function* throttleTest(actuallyThrottle) {
requestLongerTimeout(2); requestLongerTimeout(2);
let [, , monitor] = yield initNetMonitor(SIMPLE_URL); let [, , monitor] = yield initNetMonitor(SIMPLE_URL);
const {ACTIVITY_TYPE, NetMonitorController, NetMonitorView} = const {ACTIVITY_TYPE, EVENTS, NetMonitorController, NetMonitorView} = monitor.panelWin;
monitor.panelWin;
info("Starting test... (actuallyThrottle = " + actuallyThrottle + ")"); info("Starting test... (actuallyThrottle = " + actuallyThrottle + ")");
@ -42,12 +41,10 @@ function* throttleTest(actuallyThrottle) {
}); });
yield deferred.promise; yield deferred.promise;
let eventPromise = let eventPromise = monitor.panelWin.once(EVENTS.RECEIVED_EVENT_TIMINGS);
monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS); yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
yield NetMonitorController
.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
yield eventPromise; yield eventPromise;
let requestItem = NetMonitorView.RequestsMenu.getItemAtIndex(0); let requestItem = NetMonitorView.RequestsMenu.getItemAtIndex(0);
const reportedOneSecond = requestItem.attachment.eventTimings.timings.receive > 1000; const reportedOneSecond = requestItem.attachment.eventTimings.timings.receive > 1000;
if (actuallyThrottle) { if (actuallyThrottle) {

View File

@ -1,146 +1,140 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if timeline correctly displays interval divisions. * Tests if timeline correctly displays interval divisions.
*/ */
function test() { add_task(function* () {
initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(SIMPLE_URL);
info("Starting test... "); info("Starting test... ");
let { document, L10N, NetMonitorView, NetMonitorController } = aMonitor.panelWin; let { $, $all, L10N, NetMonitorView, NetMonitorController } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
// Disable transferred size column support for this test. // Disable transferred size column support for this test.
// Without this, the waterfall only has enough room for one division, which // Without this, the waterfall only has enough room for one division, which
// would remove most of the value of this test. // would remove most of the value of this test.
document.querySelector("#requests-menu-transferred-header-box").hidden = true; $("#requests-menu-transferred-header-box").hidden = true;
document.querySelector("#requests-menu-item-template .requests-menu-transferred").hidden = true; $("#requests-menu-item-template .requests-menu-transferred").hidden = true;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
ok(document.querySelector("#requests-menu-waterfall-label"), ok($("#requests-menu-waterfall-label"),
"An timeline label should be displayed when the frontend is opened."); "An timeline label should be displayed when the frontend is opened.");
ok(document.querySelectorAll(".requests-menu-timings-division").length == 0, ok($all(".requests-menu-timings-division").length == 0,
"No tick labels should be displayed when the frontend is opened."); "No tick labels should be displayed when the frontend is opened.");
ok(!RequestsMenu._canvas, ok(!RequestsMenu._canvas, "No canvas should be created when the frontend is opened.");
"No canvas should be created when the frontend is opened."); ok(!RequestsMenu._ctx, "No 2d context should be created when the frontend is opened.");
ok(!RequestsMenu._ctx,
"No 2d context should be created when the frontend is opened.");
waitForNetworkEvents(aMonitor, 1).then(() => { let wait = waitForNetworkEvents(monitor, 1);
// Make sure the DOMContentLoaded and load markers don't interfere with tab.linkedBrowser.reload();
// this test by removing them and redrawing the waterfall (bug 1224088). yield wait;
NetMonitorController.NetworkEventsHandler.clearMarkers();
RequestsMenu._flushWaterfallViews(true);
ok(!document.querySelector("#requests-menu-waterfall-label"), // Make sure the DOMContentLoaded and load markers don't interfere with
"The timeline label should be hidden after the first request."); // this test by removing them and redrawing the waterfall (bug 1224088).
ok(document.querySelectorAll(".requests-menu-timings-division").length >= 3, NetMonitorController.NetworkEventsHandler.clearMarkers();
"There should be at least 3 tick labels in the network requests header."); RequestsMenu._flushWaterfallViews(true);
is(document.querySelectorAll(".requests-menu-timings-division")[0] ok(!$("#requests-menu-waterfall-label"),
.getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 0), "The timeline label should be hidden after the first request.");
"The first tick label has an incorrect value"); ok($all(".requests-menu-timings-division").length >= 3,
is(document.querySelectorAll(".requests-menu-timings-division")[1] "There should be at least 3 tick labels in the network requests header.");
.getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 80),
"The second tick label has an incorrect value");
is(document.querySelectorAll(".requests-menu-timings-division")[2]
.getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 160),
"The third tick label has an incorrect value");
is(document.querySelectorAll(".requests-menu-timings-division")[0] is($all(".requests-menu-timings-division")[0].getAttribute("value"),
.style.transform, "translateX(0px)", L10N.getFormatStr("networkMenu.millisecond", 0),
"The first tick label has an incorrect translation"); "The first tick label has an incorrect value");
is(document.querySelectorAll(".requests-menu-timings-division")[1] is($all(".requests-menu-timings-division")[1].getAttribute("value"),
.style.transform, "translateX(80px)", L10N.getFormatStr("networkMenu.millisecond", 80),
"The second tick label has an incorrect translation"); "The second tick label has an incorrect value");
is(document.querySelectorAll(".requests-menu-timings-division")[2] is($all(".requests-menu-timings-division")[2].getAttribute("value"),
.style.transform, "translateX(160px)", L10N.getFormatStr("networkMenu.millisecond", 160),
"The third tick label has an incorrect translation"); "The third tick label has an incorrect value");
ok(RequestsMenu._canvas, is($all(".requests-menu-timings-division")[0].style.transform, "translateX(0px)",
"A canvas should be created after the first request."); "The first tick label has an incorrect translation");
ok(RequestsMenu._ctx, is($all(".requests-menu-timings-division")[1].style.transform, "translateX(80px)",
"A 2d context should be created after the first request."); "The second tick label has an incorrect translation");
is($all(".requests-menu-timings-division")[2].style.transform, "translateX(160px)",
"The third tick label has an incorrect translation");
let imageData = RequestsMenu._ctx.getImageData(0, 0, 161, 1); ok(RequestsMenu._canvas, "A canvas should be created after the first request.");
ok(imageData, "The image data should have been created."); ok(RequestsMenu._ctx, "A 2d context should be created after the first request.");
let data = imageData.data; let imageData = RequestsMenu._ctx.getImageData(0, 0, 161, 1);
ok(data, "The image data should contain a pixel array."); ok(imageData, "The image data should have been created.");
ok(hasPixelAt(0), "The tick at 0 is should not be empty."); let data = imageData.data;
ok(!hasPixelAt(1), "The tick at 1 is should be empty."); ok(data, "The image data should contain a pixel array.");
ok(!hasPixelAt(19), "The tick at 19 is should be empty.");
ok(hasPixelAt(20), "The tick at 20 is should not be empty.");
ok(!hasPixelAt(21), "The tick at 21 is should be empty.");
ok(!hasPixelAt(39), "The tick at 39 is should be empty.");
ok(hasPixelAt(40), "The tick at 40 is should not be empty.");
ok(!hasPixelAt(41), "The tick at 41 is should be empty.");
ok(!hasPixelAt(59), "The tick at 59 is should be empty.");
ok(hasPixelAt(60), "The tick at 60 is should not be empty.");
ok(!hasPixelAt(61), "The tick at 61 is should be empty.");
ok(!hasPixelAt(79), "The tick at 79 is should be empty.");
ok(hasPixelAt(80), "The tick at 80 is should not be empty.");
ok(!hasPixelAt(81), "The tick at 81 is should be empty.");
ok(!hasPixelAt(159), "The tick at 159 is should be empty.");
ok(hasPixelAt(160), "The tick at 160 is should not be empty.");
ok(!hasPixelAt(161), "The tick at 161 is should be empty.");
ok(isPixelBrighterAtThan(0, 20), ok(hasPixelAt(0), "The tick at 0 is should not be empty.");
"The tick at 0 should be brighter than the one at 20"); ok(!hasPixelAt(1), "The tick at 1 is should be empty.");
ok(isPixelBrighterAtThan(40, 20), ok(!hasPixelAt(19), "The tick at 19 is should be empty.");
"The tick at 40 should be brighter than the one at 20"); ok(hasPixelAt(20), "The tick at 20 is should not be empty.");
ok(isPixelBrighterAtThan(40, 60), ok(!hasPixelAt(21), "The tick at 21 is should be empty.");
"The tick at 40 should be brighter than the one at 60"); ok(!hasPixelAt(39), "The tick at 39 is should be empty.");
ok(isPixelBrighterAtThan(80, 60), ok(hasPixelAt(40), "The tick at 40 is should not be empty.");
"The tick at 80 should be brighter than the one at 60"); ok(!hasPixelAt(41), "The tick at 41 is should be empty.");
ok(!hasPixelAt(59), "The tick at 59 is should be empty.");
ok(hasPixelAt(60), "The tick at 60 is should not be empty.");
ok(!hasPixelAt(61), "The tick at 61 is should be empty.");
ok(!hasPixelAt(79), "The tick at 79 is should be empty.");
ok(hasPixelAt(80), "The tick at 80 is should not be empty.");
ok(!hasPixelAt(81), "The tick at 81 is should be empty.");
ok(!hasPixelAt(159), "The tick at 159 is should be empty.");
ok(hasPixelAt(160), "The tick at 160 is should not be empty.");
ok(!hasPixelAt(161), "The tick at 161 is should be empty.");
ok(isPixelBrighterAtThan(80, 100), ok(isPixelBrighterAtThan(0, 20),
"The tick at 80 should be brighter than the one at 100"); "The tick at 0 should be brighter than the one at 20");
ok(isPixelBrighterAtThan(120, 100), ok(isPixelBrighterAtThan(40, 20),
"The tick at 120 should be brighter than the one at 100"); "The tick at 40 should be brighter than the one at 20");
ok(isPixelBrighterAtThan(120, 140), ok(isPixelBrighterAtThan(40, 60),
"The tick at 120 should be brighter than the one at 140"); "The tick at 40 should be brighter than the one at 60");
ok(isPixelBrighterAtThan(160, 140), ok(isPixelBrighterAtThan(80, 60),
"The tick at 160 should be brighter than the one at 140"); "The tick at 80 should be brighter than the one at 60");
ok(isPixelEquallyBright(20, 60), ok(isPixelBrighterAtThan(80, 100),
"The tick at 20 should be equally bright to the one at 60"); "The tick at 80 should be brighter than the one at 100");
ok(isPixelEquallyBright(100, 140), ok(isPixelBrighterAtThan(120, 100),
"The tick at 100 should be equally bright to the one at 140"); "The tick at 120 should be brighter than the one at 100");
ok(isPixelBrighterAtThan(120, 140),
"The tick at 120 should be brighter than the one at 140");
ok(isPixelBrighterAtThan(160, 140),
"The tick at 160 should be brighter than the one at 140");
ok(isPixelEquallyBright(40, 120), ok(isPixelEquallyBright(20, 60),
"The tick at 40 should be equally bright to the one at 120"); "The tick at 20 should be equally bright to the one at 60");
ok(isPixelEquallyBright(100, 140),
"The tick at 100 should be equally bright to the one at 140");
ok(isPixelEquallyBright(0, 80), ok(isPixelEquallyBright(40, 120),
"The tick at 80 should be equally bright to the one at 160"); "The tick at 40 should be equally bright to the one at 120");
ok(isPixelEquallyBright(80, 160),
"The tick at 80 should be equally bright to the one at 160");
function hasPixelAt(x) { ok(isPixelEquallyBright(0, 80),
let i = (x | 0) * 4; "The tick at 80 should be equally bright to the one at 160");
return data[i] && data[i + 1] && data[i + 2] && data[i + 3]; ok(isPixelEquallyBright(80, 160),
} "The tick at 80 should be equally bright to the one at 160");
function isPixelBrighterAtThan(x1, x2) { function hasPixelAt(x) {
let i = (x1 | 0) * 4; let i = (x | 0) * 4;
let j = (x2 | 0) * 4; return data[i] && data[i + 1] && data[i + 2] && data[i + 3];
return data[i + 3] > data [j + 3]; }
}
function isPixelEquallyBright(x1, x2) { function isPixelBrighterAtThan(x1, x2) {
let i = (x1 | 0) * 4; let i = (x1 | 0) * 4;
let j = (x2 | 0) * 4; let j = (x2 | 0) * 4;
return data[i + 3] == data [j + 3]; return data[i + 3] > data [j + 3];
} }
teardown(aMonitor).then(finish); function isPixelEquallyBright(x1, x2) {
}); let i = (x1 | 0) * 4;
let j = (x2 | 0) * 4;
return data[i + 3] == data [j + 3];
}
aDebuggee.location.reload(); return teardown(monitor);
}); });
}

View File

@ -1,58 +1,61 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/** /**
* Tests if timing intervals are divided againts seconds when appropriate. * Tests if timing intervals are divided againts seconds when appropriate.
*/ */
function test() { add_task(function* () {
initNetMonitor(CUSTOM_GET_URL).then(([aTab, aDebuggee, aMonitor]) => { let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
info("Starting test... "); info("Starting test... ");
let { $all, NetMonitorView } = aMonitor.panelWin; let { $all, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView; let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false; RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 2).then(() => { let wait = waitForNetworkEvents(monitor, 2);
let millisecondDivs = $all(".requests-menu-timings-division[division-scale=millisecond]"); // Timeout needed for having enough divisions on the time scale.
let secondDivs = $all(".requests-menu-timings-division[division-scale=second]"); yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
let minuteDivs = $all(".requests-menu-timings-division[division-scale=minute]"); content.wrappedJSObject.performRequests(2, null, 3000);
info("Number of millisecond divisions: " + millisecondDivs.length);
info("Number of second divisions: " + secondDivs.length);
info("Number of minute divisions: " + minuteDivs.length);
for (let div of millisecondDivs) {
info("Millisecond division: " + div.getAttribute("value"));
}
for (let div of secondDivs) {
info("Second division: " + div.getAttribute("value"));
}
for (let div of minuteDivs) {
info("Minute division: " + div.getAttribute("value"));
}
is(RequestsMenu.itemCount, 2,
"There should be only two requests made.");
let firstRequest = RequestsMenu.getItemAtIndex(0);
let lastRequest = RequestsMenu.getItemAtIndex(1);
info("First request happened at: " +
firstRequest.attachment.responseHeaders.headers.find(e => e.name == "Date").value);
info("Last request happened at: " +
lastRequest.attachment.responseHeaders.headers.find(e => e.name == "Date").value);
ok(secondDivs.length,
"There should be at least one division on the seconds time scale.");
ok(secondDivs[0].getAttribute("value").match(/\d+\.\d{2}\s\w+/),
"The division on the seconds time scale looks legit.");
teardown(aMonitor).then(finish);
});
// Timeout needed for having enough divisions on the time scale.
aDebuggee.performRequests(2, null, 3000);
}); });
} yield wait;
let milDivs = $all(".requests-menu-timings-division[division-scale=millisecond]");
let secDivs = $all(".requests-menu-timings-division[division-scale=second]");
let minDivs = $all(".requests-menu-timings-division[division-scale=minute]");
info("Number of millisecond divisions: " + milDivs.length);
info("Number of second divisions: " + secDivs.length);
info("Number of minute divisions: " + minDivs.length);
for (let div of milDivs) {
info("Millisecond division: " + div.getAttribute("value"));
}
for (let div of secDivs) {
info("Second division: " + div.getAttribute("value"));
}
for (let div of minDivs) {
info("Minute division: " + div.getAttribute("value"));
}
is(RequestsMenu.itemCount, 2,
"There should be only two requests made.");
let firstRequest = RequestsMenu.getItemAtIndex(0);
let lastRequest = RequestsMenu.getItemAtIndex(1);
info("First request happened at: " +
firstRequest.attachment.responseHeaders.headers.find(e => e.name == "Date").value);
info("Last request happened at: " +
lastRequest.attachment.responseHeaders.headers.find(e => e.name == "Date").value);
ok(secDivs.length,
"There should be at least one division on the seconds time scale.");
ok(secDivs[0].getAttribute("value").match(/\d+\.\d{2}\s\w+/),
"The division on the seconds time scale looks legit.");
return teardown(monitor);
});