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.
http://creativecommons.org/publicdomain/zero/1.0/ */
var gPanelWin;
var gPanelDoc;
"use strict";
/**
* Tests if showing raw headers works.
*/
function test() {
initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(POST_DATA_URL);
info("Starting test... ");
gPanelWin = aMonitor.panelWin;
gPanelDoc = gPanelWin.document;
let { document, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let { document, Editor, NetMonitorView } = gPanelWin;
let { RequestsMenu } = NetMonitorView;
let TAB_UPDATED = gPanelWin.EVENTS.TAB_UPDATED;
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 0, 2).then(() => {
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();
let wait = waitForNetworkEvents(monitor, 0, 2);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
}
yield wait;
/*
* Tests that raw headers were displayed correctly
*/
function testShowRawHeaders(aData) {
let requestHeaders = gPanelDoc.getElementById("raw-request-headers-textarea").value;
for (let header of aData.requestHeaders.headers) {
ok(requestHeaders.indexOf(header.name + ": " + header.value) >= 0, "textarea contains request headers");
let origItem = RequestsMenu.getItemAtIndex(0);
let onTabEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
RequestsMenu.selectedItem = origItem;
yield onTabEvent;
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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if the empty-requests reload button works.
*/
function test() {
let monitor, reqMenu;
initNetMonitor(SINGLE_GET_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [,, monitor] = yield initNetMonitor(SINGLE_GET_URL);
info("Starting test... ");
monitor = aMonitor;
let { document, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
reqMenu = RequestsMenu;
let { document, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let button = document.querySelector("#requests-menu-reload-notice-button");
button.click();
})
.then(() => {
return waitForNetworkEvents(monitor, 2);
})
.then(() => {
is(reqMenu.itemCount, 2,
"The request menu should have two items after reloading");
})
.then(() => {
return teardown(monitor).then(finish);
});
}
let wait = waitForNetworkEvents(monitor, 2);
let button = document.querySelector("#requests-menu-reload-notice-button");
button.click();
yield wait;
is(RequestsMenu.itemCount, 2, "The request menu should have two items after reloading");
return teardown(monitor);
});

View File

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

View File

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

View File

@ -8,15 +8,18 @@
*/
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 { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
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.");
RequestsMenu.selectedIndex = 0;
@ -39,7 +42,7 @@ add_task(function* () {
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

View File

@ -8,17 +8,14 @@
*/
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 { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
info("Requesting a resource over HTTPS.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH + "?request_2");
yield waitForNetworkEvents(monitor, 1);
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH + "?request_1");
yield waitForNetworkEvents(monitor, 1);
yield performRequestAndWait("https://example.com" + CORS_SJS_PATH + "?request_2");
yield performRequestAndWait("https://example.com" + CORS_SJS_PATH + "?request_1");
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.");
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() {
let item = RequestsMenu.items[0];
@ -49,5 +54,4 @@ add_task(function* () {
is(NetworkDetails.widget.selectedPanel, $("#security-tabpanel"),
"Security tab is selected.");
}
});

View File

@ -9,13 +9,16 @@
*/
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 { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
debuggee.performRequests(1, HTTPS_REDIRECT_SJS);
yield waitForNetworkEvents(monitor, 2);
let wait = 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.");

View File

@ -16,7 +16,7 @@ add_task(function* () {
"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 { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
@ -37,7 +37,7 @@ add_task(function* () {
ok(classes.contains(expectedClass), "Icon contained the correct class name.");
}
yield teardown(monitor);
return teardown(monitor);
/**
* 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.
*/
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
// those only emit 9/13 events of a successful request.
let done = waitForSecurityBrokenNetworkEvent();
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
// 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...
done = waitForNetworkEvents(monitor, 1);
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;
done = waitForNetworkEvents(monitor, 1);
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;
done = waitForSecurityBrokenNetworkEvent(true);
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;
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
// STARTED_RECEIVING_RESPONSE event does not fire.
if (networkError) {
awaitedEvents.splice(4, 1);
awaitedEvents = awaitedEvents.filter(e => e !== "STARTED_RECEIVING_RESPONSE");
}
let promises = awaitedEvents.map((event) => {

View File

@ -9,15 +9,23 @@
*/
add_task(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
info("Performing requests.");
debuggee.performRequests(1, "https://example.com" + CORS_SJS_PATH);
debuggee.performRequests(1, "http://example.com" + CORS_SJS_PATH);
yield waitForNetworkEvents(monitor, 2);
let wait = waitForNetworkEvents(monitor, 2);
const REQUEST_URLS = [
"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.");
RequestsMenu.selectedIndex = 0;
@ -34,5 +42,5 @@ add_task(function* () {
is(NetworkDetails.widget.selectedIndex, 0,
"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 { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
@ -44,11 +44,13 @@ add_task(function* () {
waitForSecurityBrokenNetworkEvent() :
waitForNetworkEvents(monitor, 1);
let tab = $("#security-tab");
let tabEl = $("#security-tab");
let tabpanel = $("#security-tabpanel");
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.");
yield onNewItem;
@ -58,7 +60,7 @@ add_task(function* () {
is(RequestsMenu.selectedItem.attachment.securityState, undefined,
"Security state has not yet arrived.");
is(tab.hidden, !testcase.visibleOnNewEvent,
is(tabEl.hidden, !testcase.visibleOnNewEvent,
"Security tab is " +
(testcase.visibleOnNewEvent ? "visible" : "hidden") +
" after new request was added to the menu.");
@ -70,7 +72,7 @@ add_task(function* () {
ok(RequestsMenu.selectedItem.attachment.securityState,
"Security state arrived.");
is(tab.hidden, !testcase.visibleOnSecurityInfo,
is(tabEl.hidden, !testcase.visibleOnSecurityInfo,
"Security tab is " +
(testcase.visibleOnSecurityInfo ? "visible" : "hidden") +
" after security information arrived.");
@ -79,7 +81,8 @@ add_task(function* () {
info("Waiting for request to complete.");
yield onComplete;
is(tab.hidden, !testcase.visibleOnceComplete,
is(tabEl.hidden, !testcase.visibleOnceComplete,
"Security tab is " +
(testcase.visibleOnceComplete ? "visible" : "hidden") +
" after request has been completed.");
@ -90,7 +93,7 @@ add_task(function* () {
RequestsMenu.clear();
}
yield teardown(monitor);
return teardown(monitor);
/**
* 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* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let { $, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
@ -27,8 +27,11 @@ add_task(function* () {
info("Testing site with " + test.desc);
info("Performing request to " + test.uri);
debuggee.performRequests(1, test.uri);
yield waitForNetworkEvents(monitor, 1);
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, test.uri, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
yield wait;
info("Selecting the request.");
RequestsMenu.selectedIndex = 0;
@ -47,9 +50,7 @@ add_task(function* () {
is(cipher.hidden, !test.warnCipher, "Cipher suite warning is hidden.");
RequestsMenu.clear();
}
yield teardown(monitor);
return teardown(monitor);
});

View File

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

View File

@ -1,27 +1,31 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if beacons are handled correctly.
*/
var test = Task.async(function* () {
let [, debuggee, monitor] = yield initNetMonitor(SEND_BEACON_URL);
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(SEND_BEACON_URL);
let { RequestsMenu } = monitor.panelWin.NetMonitorView;
RequestsMenu.lazyUpdate = false;
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.");
let request = RequestsMenu.getItemAtIndex(0);
is(request.attachment.method, "POST", "The method is correct.");
ok(request.attachment.url.endsWith("beacon_request"), "The URL is correct.");
is(request.attachment.status, "404", "The status is correct.");
yield teardown(monitor);
finish();
return teardown(monitor);
});

View File

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

View File

@ -1,24 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if requests render correct information in the menu UI.
*/
function test() {
initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => {
initNetMonitor(SIMPLE_SJS).then(([tab, , monitor]) => {
info("Starting test... ");
let { L10N, NetMonitorView } = aMonitor.panelWin;
let { L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1)
.then(() => teardown(aMonitor))
waitForNetworkEvents(monitor, 1)
.then(() => teardown(monitor))
.then(finish);
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
monitor.panelWin.once(monitor.panelWin.EVENTS.NETWORK_EVENT, () => {
is(RequestsMenu.selectedItem, null,
"There shouldn't be any selected item in the requests menu.");
is(RequestsMenu.itemCount, 1,
@ -27,7 +29,6 @@ function test() {
"The details pane should still be hidden after the first request.");
let requestItem = RequestsMenu.getItemAtIndex(0);
let target = requestItem.target;
is(typeof requestItem.value, "string",
"The attached request id is incorrect.");
@ -83,7 +84,7 @@ function test() {
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);
ok(requestItem.attachment.requestHeaders,
@ -98,7 +99,7 @@ function test() {
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);
ok(requestItem.attachment.requestCookies,
@ -109,11 +110,11 @@ function test() {
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.");
});
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
let requestItem = RequestsMenu.getItemAtIndex(0);
ok(requestItem.attachment.responseHeaders,
@ -126,7 +127,7 @@ function test() {
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);
ok(requestItem.attachment.responseCookies,
@ -137,7 +138,7 @@ function test() {
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);
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);
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);
ok(requestItem.attachment.responseContent,
"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.");
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.");
is(requestItem.attachment.responseContent.content.size, 12,
is(requestItem.attachment.responseContent.content.size,
12,
"The responseContent attachment has an incorrect |content.size| property.");
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);
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);
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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if requests render correct information in the details UI.
*/
function test() {
initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(SIMPLE_SJS);
info("Starting test... ");
let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED;
RequestsMenu.lazyUpdate = false;
let { document, EVENTS, L10N, Editor, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
Task.spawn(function* () {
yield waitForNetworkEvents(aMonitor, 1);
is(RequestsMenu.selectedItem, null,
"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.");
let wait = waitForNetworkEvents(monitor, 1);
tab.linkedBrowser.reload();
yield wait;
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
is(RequestsMenu.selectedItem, null,
"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,
"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.");
let onTabUpdated = monitor.panelWin.once(EVENTS.TAB_UPDATED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
yield onTabUpdated;
yield waitFor(aMonitor.panelWin, TAB_UPDATED);
testHeadersTab();
yield testCookiesTab();
testParamsTab();
yield testResponseTab();
testTimingsTab();
yield teardown(aMonitor);
finish();
});
isnot(RequestsMenu.selectedItem, null,
"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.");
function testHeadersTab() {
let tab = document.querySelectorAll("#details-pane tab")[0];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
testHeadersTab();
yield testCookiesTab();
testParamsTab();
yield testResponseTab();
testTimingsTab();
return teardown(monitor);
is(tab.getAttribute("selected"), "true",
"The headers tab in the network details pane should be selected.");
function testHeadersTab() {
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"),
SIMPLE_SJS, "The url summary value is incorrect.");
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(tabEl.getAttribute("selected"), "true",
"The headers tab in the network details pane should be selected.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"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.");
is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"),
SIMPLE_SJS, "The url summary value is incorrect.");
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-empty-notice").length, 0,
"The empty notice should not be displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"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];
let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
"The empty notice should not be displayed in this tabpanel.");
is(responseScope.querySelector(".name").getAttribute("value"),
L10N.getStr("responseHeaders") + " (" +
L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(330 / 1024, 3)) + ")",
"The response headers scope doesn't have the correct title.");
let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
ok(requestScope.querySelector(".name").getAttribute("value").includes(
L10N.getStr("requestHeaders") + " (0"),
"The request headers scope doesn't have the correct title.");
// Can't test for full request headers title because the size may
// vary across platforms ("User-Agent" header differs). We're pretty
// sure it's smaller than 1 MB though, so it starts with a 0.
is(responseScope.querySelector(".name").getAttribute("value"),
L10N.getStr("responseHeaders") + " (" +
L10N.getFormatStr("networkMenu.sizeKB",
L10N.numberWithDecimals(330 / 1024, 3)) + ")",
"The response headers scope doesn't have the correct title.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
"Cache-Control", "The first response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
"\"no-cache, no-store, must-revalidate\"", "The first response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
"Connection", "The second response header name was incorrect.");
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.");
ok(requestScope.querySelector(".name").getAttribute("value").includes(
L10N.getStr("requestHeaders") + " (0"),
"The request headers scope doesn't have the correct title.");
// Can't test for full request headers title because the size may
// vary across platforms ("User-Agent" header differs). We're pretty
// sure it's smaller than 1 MB though, so it starts with a 0.
is(requestScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
"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.");
}
is(responseScope.querySelectorAll(".variables-view-variable .name")[0]
.getAttribute("value"),
"Cache-Control", "The first response header name was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .value")[0]
.getAttribute("value"),
"\"no-cache, no-store, must-revalidate\"",
"The first response header value was incorrect.");
is(responseScope.querySelectorAll(".variables-view-variable .name")[1]
.getAttribute("value"),
"Connection", "The second response header name was incorrect.");
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.");
function testCookiesTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[1]);
is(requestScope.querySelectorAll(".variables-view-variable .name")[0]
.getAttribute("value"),
"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* () {
yield waitFor(aMonitor.panelWin, TAB_UPDATED);
function* testCookiesTab() {
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 tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
let tabEl = document.querySelectorAll("#details-pane tab")[1];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
is(tab.getAttribute("selected"), "true",
"The cookies tab in the network details pane should be selected.");
is(tabEl.getAttribute("selected"), "true",
"The cookies tab in the network details pane should be selected.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"There should be 2 cookie scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 6,
"There should be 6 cookie values displayed in this tabpanel.");
});
}
is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
"There should be 2 cookie scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 6,
"There should be 6 cookie values displayed in this tabpanel.");
}
function testParamsTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[2]);
function testParamsTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[2]);
let tab = document.querySelectorAll("#details-pane tab")[2];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
let tabEl = document.querySelectorAll("#details-pane tab")[2];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
is(tab.getAttribute("selected"), "true",
"The params tab in the network details pane should be selected.");
is(tabEl.getAttribute("selected"), "true",
"The params tab in the network details pane should be selected.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
"There should be no param scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
"There should be no param values displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
"The empty notice should be displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
"There should be no param scopes displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
"There should be no param values displayed in this tabpanel.");
is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
"The empty notice should be displayed in this tabpanel.");
is(tabpanel.querySelector("#request-params-box")
.hasAttribute("hidden"), false,
"The request params box should not be hidden.");
is(tabpanel.querySelector("#request-post-data-textarea-box")
.hasAttribute("hidden"), true,
"The request post data textarea box should be hidden.");
}
is(tabpanel.querySelector("#request-params-box")
.hasAttribute("hidden"), false,
"The request params box should not be hidden.");
is(tabpanel.querySelector("#request-post-data-textarea-box")
.hasAttribute("hidden"), true,
"The request post data textarea box should be hidden.");
}
function testResponseTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
function* testResponseTab() {
let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
return Task.spawn(function* () {
yield waitFor(aMonitor.panelWin, TAB_UPDATED);
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
let tab = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tab.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
.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")
.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.");
let editor = yield NetMonitorView.editor("#response-content-textarea");
is(editor.getText(), "Hello world!",
"The text shown in the source editor is incorrect.");
is(editor.getMode(), Editor.modes.text,
"The mode active in the source editor is incorrect.");
}
let aEditor = yield NetMonitorView.editor("#response-content-textarea");
is(aEditor.getText(), "Hello world!",
"The text shown in the source editor is incorrect.");
is(aEditor.getMode(), Editor.modes.text,
"The mode active in the source editor is incorrect.");
});
}
function testTimingsTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[4]);
function testTimingsTab() {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[4]);
let tabEl = document.querySelectorAll("#details-pane tab")[4];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4];
let tab = document.querySelectorAll("#details-pane tab")[4];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4];
is(tabEl.getAttribute("selected"), "true",
"The timings tab in the network details pane should be selected.");
is(tab.getAttribute("selected"), "true",
"The timings tab in the network details pane should be selected.");
ok(tabpanel.querySelector("#timings-summary-blocked .requests-menu-timings-total")
.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")
.getAttribute("value").match(/[0-9]+/),
"The blocked timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The dns timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The dns timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The connect timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The connect timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The send timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The send timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The wait timing info does not appear to be correct.");
ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total")
.getAttribute("value").match(/[0-9]+/),
"The wait 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();
});
}
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.");
}
});

View File

@ -11,69 +11,62 @@
* 3) Empty user message visibility
* 4) Number of requests displayed
*/
function test() {
initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(SIMPLE_URL);
info("Starting test... ");
let { document, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let { document, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
is(document.querySelector("#details-pane-toggle")
.hasAttribute("disabled"), true,
"The pane toggle button should be disabled when the frontend is opened.");
is(document.querySelector("#requests-menu-empty-notice")
.hasAttribute("hidden"), false,
"An empty notice should be displayed when the frontend is opened.");
is(RequestsMenu.itemCount, 0,
"The requests menu should be empty when the frontend is opened.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should be hidden when the frontend is opened.");
is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), true,
"The pane toggle button should be disabled when the frontend is opened.");
is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), false,
"An empty notice should be displayed when the frontend is opened.");
is(RequestsMenu.itemCount, 0,
"The requests menu should be empty when the frontend is opened.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should be hidden when the frontend is opened.");
waitForNetworkEvents(aMonitor, 1).then(() => {
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.");
yield reloadAndWait();
waitForNetworkEvents(aMonitor, 1).then(() => {
is(document.querySelector("#details-pane-toggle")
.hasAttribute("disabled"), false,
"The pane toggle button should be still be enabled after a reload.");
is(document.querySelector("#requests-menu-empty-notice")
.hasAttribute("hidden"), true,
"The empty notice should be still hidden after a reload.");
is(RequestsMenu.itemCount, 1,
"The requests menu should not be empty after a reload.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after a reload.");
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.");
RequestsMenu.clear();
yield reloadAndWait();
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.");
is(document.querySelector("#details-pane-toggle").hasAttribute("disabled"), false,
"The pane toggle button should be still be enabled after a reload.");
is(document.querySelector("#requests-menu-empty-notice").hasAttribute("hidden"), true,
"The empty notice should be still hidden after a reload.");
is(RequestsMenu.itemCount, 1,
"The requests menu should not be empty after a reload.");
is(NetMonitorView.detailsPaneHidden, true,
"The details pane should still be hidden after a reload.");
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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if the sorting mechanism works correctly.
*/
function test() {
initNetMonitor(STATUS_CODES_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(STATUS_CODES_URL);
info("Starting test... ");
let { $all, L10N, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let { $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => {
testContents([0, 1, 2, 3, 4])
.then(() => {
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();
let wait = waitForNetworkEvents(monitor, 5);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if sorting columns in the network table works correctly.
*/
function test() {
initNetMonitor(SORTING_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [,, monitor] = yield initNetMonitor(SORTING_URL);
info("Starting test... ");
// It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2);
// It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2);
let { $, $all, L10N, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let { $, $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
// Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later.
loadCommonFrameScript();
let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1"
}, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5"
}, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2"
}, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4"
}, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3"
}];
// Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later.
loadCommonFrameScript();
let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1"
}, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5"
}, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2"
}, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4"
}, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3"
}];
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => {
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
let wait = waitForNetworkEvents(monitor, 5);
yield performRequestsInContent(requests);
yield wait;
isnot(RequestsMenu.selectedItem, null,
"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.");
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
testHeaders();
testContents([0, 2, 4, 3, 1])
.then(() => {
info("Testing status sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
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);
});
isnot(RequestsMenu.selectedItem, null,
"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.");
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");
testHeaders();
testContents([0, 2, 4, 3, 1]);
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.");
}
info("Testing status sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
testContents([0, 1, 2, 3, 4]);
info("Testing status sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
testContents([4, 3, 2, 1, 0]);
info("Testing status sort, ascending. Checking sort loops correctly.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
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]) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after sorting.");
is(RequestsMenu.selectedIndex, a,
"The first item should be still selected after sorting.");
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after sorting.");
function testContents([a, b, c, d, e]) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after sorting.");
is(RequestsMenu.selectedIndex, a,
"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, 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.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.");
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),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
"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);
}
performRequestsInContent(requests).then(null, e => {
ok(false, e);
});
});
}
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
"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
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
"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

@ -1,220 +1,207 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if sorting columns in the network table works correctly with new requests.
*/
function test() {
initNetMonitor(SORTING_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [,, monitor] = yield initNetMonitor(SORTING_URL);
info("Starting test... ");
// It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2);
// It seems that this test may be slow on debug builds. This could be because
// of the heavy dom manipulation associated with sorting.
requestLongerTimeout(2);
let { $, $all, L10N, NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
let { $, $all, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
// Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later.
loadCommonFrameScript();
let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1"
}, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5"
}, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2"
}, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4"
}, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3"
}];
// Loading the frame script and preparing the xhr request URLs so we can
// generate some requests later.
loadCommonFrameScript();
let requests = [{
url: "sjs_sorting-test-server.sjs?index=1&" + Math.random(),
method: "GET1"
}, {
url: "sjs_sorting-test-server.sjs?index=5&" + Math.random(),
method: "GET5"
}, {
url: "sjs_sorting-test-server.sjs?index=2&" + Math.random(),
method: "GET2"
}, {
url: "sjs_sorting-test-server.sjs?index=4&" + Math.random(),
method: "GET4"
}, {
url: "sjs_sorting-test-server.sjs?index=3&" + Math.random(),
method: "GET3"
}];
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 5).then(() => {
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
let wait = waitForNetworkEvents(monitor, 5);
yield performRequestsInContent(requests);
yield wait;
isnot(RequestsMenu.selectedItem, null,
"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.");
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
testHeaders();
testContents([0, 2, 4, 3, 1], 0)
.then(() => {
info("Testing status sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
return testContents([0, 1, 2, 3, 4], 0);
})
.then(() => {
info("Performing more requests.");
performRequestsInContent(requests);
return waitForNetworkEvents(aMonitor, 5);
})
.then(() => {
info("Testing status sort again, ascending.");
testHeaders("status", "ascending");
return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0);
})
.then(() => {
info("Testing status sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
return testContents([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 9);
})
.then(() => {
info("Performing more requests.");
performRequestsInContent(requests);
return waitForNetworkEvents(aMonitor, 5);
})
.then(() => {
info("Testing status sort again, descending.");
testHeaders("status", "descending");
return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
})
.then(() => {
info("Testing status sort yet again, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 0);
})
.then(() => {
info("Testing status sort yet again, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish, e => {
ok(false, e);
isnot(RequestsMenu.selectedItem, null,
"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();
testContents([0, 2, 4, 3, 1], 0);
info("Testing status sort, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
testContents([0, 1, 2, 3, 4], 0);
info("Performing more requests.");
wait = waitForNetworkEvents(monitor, 5);
yield performRequestsInContent(requests);
yield wait;
info("Testing status sort again, ascending.");
testHeaders("status", "ascending");
testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0);
info("Testing status sort, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
testContents([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 9);
info("Performing more requests.");
wait = waitForNetworkEvents(monitor, 5);
yield performRequestsInContent(requests);
yield wait;
info("Testing status sort again, descending.");
testHeaders("status", "descending");
testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
info("Testing status sort yet again, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "ascending");
testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 0);
info("Testing status sort yet again, descending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
testHeaders("status", "descending");
testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
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(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.");
}
}
}
function testContents(aOrder, aSelection) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after sorting.");
is(RequestsMenu.selectedIndex, aSelection,
"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, aOrder.length,
"There should be a specific number of items in the requests menu.");
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++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[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
});
}
performRequestsInContent(requests).then(null, e => console.error(e));
});
}
for (let i = 0, len = order.length / 5; i < len; i++) {
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.");
let onChartDisplayed = Promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
panel.once(EVENTS.PRIMED_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");
NetMonitorView.toggleFrontendMode();
@ -51,25 +51,13 @@ add_task(function* () {
is($("#empty-cache-chart").childNodes.length, 1,
"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.");
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.");
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* () {
let [, debuggee, monitor] = yield initNetMonitor(STATISTICS_URL);
let [tab, , monitor] = yield initNetMonitor(STATISTICS_URL);
info("Starting test... ");
let panel = monitor.panelWin;
@ -18,8 +18,8 @@ add_task(function* () {
"The initial frontend mode is correct.");
let onChartDisplayed = Promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
panel.once(EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
panel.once(EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]);
info("Displaying statistics view");
@ -29,9 +29,9 @@ add_task(function* () {
"The frontend mode is currently in the statistics view.");
info("Reloading page");
let onWillNavigate = waitFor(panel, EVENTS.TARGET_WILL_NAVIGATE);
let onDidNavigate = waitFor(panel, EVENTS.TARGET_DID_NAVIGATE);
debuggee.location.reload();
let onWillNavigate = panel.once(EVENTS.TARGET_WILL_NAVIGATE);
let onDidNavigate = panel.once(EVENTS.TARGET_DID_NAVIGATE);
tab.linkedBrowser.reload();
yield onWillNavigate;
is(NetMonitorView.currentFrontendMode, "network-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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if the correct filtering predicates are used when filtering from
* the performance analysis view.
*/
function test() {
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
add_task(function* () {
let [,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... ");
let panel = aMonitor.panelWin;
let { $, EVENTS, NetMonitorView } = panel;
let panel = monitor.panelWin;
let { $, EVENTS, NetMonitorView } = panel;
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-js-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-ws-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-other-button"));
testFilterButtonsCustom(aMonitor, [0, 1, 1, 1, 0, 0, 0, 0, 0, 1]);
ok(true, "The correct filtering predicates are used before entering perf. analysis mode.");
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-js-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-ws-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-other-button"));
testFilterButtonsCustom(monitor, [0, 1, 1, 1, 0, 0, 0, 0, 0, 1]);
info("The correct filtering predicates are used before entering perf. analysis mode.");
promise.all([
waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]).then(() => {
EventUtils.sendMouseEvent({ type: "click" }, $(".pie-chart-slice"));
testFilterButtons(aMonitor, "html");
ok(true, "The correct filtering predicate is used when exiting perf. analysis mode.");
let onEvents = promise.all([
panel.once(EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
panel.once(EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
]);
NetMonitorView.toggleFrontendMode();
yield onEvents;
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.
*/
var test = Task.async(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(STATUS_CODES_URL);
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(STATUS_CODES_URL);
info("Starting test... ");
let { document, L10N, NetMonitorView } = monitor.panelWin;
let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
let requestItems = [];
@ -20,7 +20,8 @@ var test = Task.async(function* () {
NetworkDetails._params.lazyEmpty = false;
const REQUEST_DATA = [
{ // request #0
{
// request #0
method: "GET",
uri: STATUS_CODES_SJS + "?sts=100",
details: {
@ -32,7 +33,8 @@ var test = Task.async(function* () {
time: true
}
},
{ // request #1
{
// request #1
method: "GET",
uri: STATUS_CODES_SJS + "?sts=200",
details: {
@ -44,7 +46,8 @@ var test = Task.async(function* () {
time: true
}
},
{ // request #2
{
// request #2
method: "GET",
uri: STATUS_CODES_SJS + "?sts=300",
details: {
@ -56,7 +59,8 @@ var test = Task.async(function* () {
time: true
}
},
{ // request #3
{
// request #3
method: "GET",
uri: STATUS_CODES_SJS + "?sts=400",
details: {
@ -68,7 +72,8 @@ var test = Task.async(function* () {
time: true
}
},
{ // request #4
{
// request #4
method: "GET",
uri: STATUS_CODES_SJS + "?sts=500",
details: {
@ -82,15 +87,18 @@ var test = Task.async(function* () {
}
];
debuggee.performRequests();
yield waitForNetworkEvents(monitor, 5);
let wait = waitForNetworkEvents(monitor, 5);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
info("Performing tests");
yield verifyRequests();
yield testTab(0, testSummary);
yield testTab(2, testParams);
yield teardown(monitor);
finish();
return teardown(monitor);
/**
* 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
* all requests to the given test function.
*
* @param Number tab
* @param Number tabIdx
* The index of NetworkDetails tab to activate.
* @param Function testFn(requestItem)
* 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
* NetworkMonitor.
*/
function* testTab(tab, testFn) {
info("Testing tab #" + tab);
function* testTab(tabIdx, testFn) {
info("Testing tab #" + tabIdx);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[tab]);
document.querySelectorAll("#details-pane tab")[tabIdx]);
let counter = 0;
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);
info("Tab updated. Performing checks");
@ -142,7 +150,6 @@ var test = Task.async(function* () {
* A function that tests "Summary" contains correct information.
*/
function* testSummary(data) {
let tab = document.querySelectorAll("#details-pane tab")[0];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
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.
*/
function* testParams(data) {
let tab = document.querySelectorAll("#details-pane tab")[2];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
let statusParamValue = data.uri.split("=").pop();
let statusParamShownValue = "\"" + statusParamValue + "\"";
@ -178,9 +184,11 @@ var test = Task.async(function* () {
L10N.getStr("paramsQueryString"),
"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.");
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.");
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.
*/
function chooseRequest(index) {
let onTabUpdated = monitor.panelWin.once(EVENTS.TAB_UPDATED);
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.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if reponses from streaming content types (MPEG-DASH, HLS) are
* displayed as XML or plain text
*/
function test() {
Task.spawn(function* () {
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
info("Starting test... ");
let { panelWin } = monitor;
let { document, Editor, NetMonitorView } = panelWin;
let { RequestsMenu } = NetMonitorView;
info("Starting test... ");
let { panelWin } = monitor;
let { document, Editor, NetMonitorView } = panelWin;
let { RequestsMenu } = NetMonitorView;
const REQUESTS = [
[ "hls-m3u8", /^#EXTM3U/, Editor.modes.text ],
[ "mpeg-dash", /^<\?xml/, Editor.modes.html ]
];
const REQUESTS = [
[ "hls-m3u8", /^#EXTM3U/, Editor.modes.text ],
[ "mpeg-dash", /^<\?xml/, Editor.modes.html ]
];
RequestsMenu.lazyUpdate = false;
RequestsMenu.lazyUpdate = false;
REQUESTS.forEach(([ fmt ]) => {
debuggee.performRequests(1, CONTENT_TYPE_SJS + "?fmt=" + fmt);
let wait = waitForNetworkEvents(monitor, REQUESTS.length);
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),
"GET", CONTENT_TYPE_SJS + "?fmt=" + fmt, {
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();
REQUESTS.forEach(([ fmt ], i) => {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=" + fmt, {
status: 200,
statusText: "OK"
});
});
function testEditorContent(editor, [ fmt, textRe, mode ]) {
ok(editor.getText().match(textRe),
"The text shown in the source editor for " + fmt + " is incorrect.");
is(editor.getMode(), mode,
"The mode active in the source editor for " + fmt + " is incorrect.");
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");
// 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);
let [, , monitor] = yield initNetMonitor(SIMPLE_URL);
const {ACTIVITY_TYPE, NetMonitorController, NetMonitorView} =
monitor.panelWin;
const {ACTIVITY_TYPE, EVENTS, NetMonitorController, NetMonitorView} = monitor.panelWin;
info("Starting test... (actuallyThrottle = " + actuallyThrottle + ")");
@ -42,12 +41,10 @@ function* throttleTest(actuallyThrottle) {
});
yield deferred.promise;
let eventPromise =
monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS);
yield NetMonitorController
.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
let eventPromise = monitor.panelWin.once(EVENTS.RECEIVED_EVENT_TIMINGS);
yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
yield eventPromise;
let requestItem = NetMonitorView.RequestsMenu.getItemAtIndex(0);
const reportedOneSecond = requestItem.attachment.eventTimings.timings.receive > 1000;
if (actuallyThrottle) {

View File

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