Bug 1297362 - Part 3: Eliminate CPOWs from Netmonitor mochitests D-J r=ochameau

MozReview-Commit-ID: AOswFvfl2wW

--HG--
extra : rebase_source : b1e8e9836a4dd808be67dbccb67641005cf9cff0
This commit is contained in:
Jarda Snajdr 2016-08-24 15:55:56 +02:00
Родитель 0884210f36
Коммит 2b5233ff9f
14 изменённых файлов: 1158 добавлений и 1187 удалений

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

@ -1,13 +1,13 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// A test to ensure that the content in details pane is not duplicated.
var test = Task.async(function* () {
info("Initializing test");
let [tab, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
let panel = monitor.panelWin;
let { NetMonitorView, EVENTS } = panel;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
@ -45,7 +45,7 @@ var test = Task.async(function* () {
];
info("Adding a cookie for the \"Cookie\" tab test");
debuggee.document.cookie = "a=b; path=" + COOKIE_UNIQUE_PATH;
yield setDocCookie("a=b; path=" + COOKIE_UNIQUE_PATH);
info("Running tests");
for (let spec of TEST_CASES) {
@ -55,20 +55,29 @@ var test = Task.async(function* () {
// Remove the cookie. If an error occurs the path of the cookie ensures it
// doesn't mess with the other tests.
info("Removing the added cookie.");
debuggee.document.cookie = "a=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=" +
COOKIE_UNIQUE_PATH;
yield setDocCookie(
"a=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=" + COOKIE_UNIQUE_PATH);
yield teardown(monitor);
finish();
/**
* Set a content document cookie
*/
function setDocCookie(cookie) {
return ContentTask.spawn(tab.linkedBrowser, cookie, function* (cookieArg) {
content.document.cookie = cookieArg;
});
}
/**
* A helper that handles the execution of each case.
*/
function* runTestCase(spec) {
info("Running case: " + spec.desc);
debuggee.content.location = spec.pageURI;
let wait = waitForNetworkEvents(monitor, 1);
tab.linkedBrowser.loadURI(spec.pageURI);
yield wait;
yield waitForNetworkEvents(monitor, 1);
RequestsMenu.clear();
yield waitForFinalDetailTabUpdate(spec.tabIndex, spec.isPost, spec.requestURI);
@ -84,20 +93,23 @@ var test = Task.async(function* () {
* - waits for the final update to happen
*/
function* waitForFinalDetailTabUpdate(tabIndex, isPost, uri) {
let onNetworkEvent = waitFor(panel, EVENTS.NETWORK_EVENT);
let onDetailsPopulated = waitFor(panel, EVENTS.NETWORKDETAILSVIEW_POPULATED);
let onNetworkEvent = panel.once(EVENTS.NETWORK_EVENT);
let onDetailsPopulated = panel.once(EVENTS.NETWORKDETAILSVIEW_POPULATED);
let onRequestFinished = isPost ?
waitForNetworkEvents(monitor, 0, 1) : waitForNetworkEvents(monitor, 1);
waitForNetworkEvents(monitor, 0, 1) :
waitForNetworkEvents(monitor, 1);
info("Performing a request");
debuggee.performRequests(1, uri);
yield ContentTask.spawn(tab.linkedBrowser, uri, function* (url) {
content.wrappedJSObject.performRequests(1, url);
});
info("Waiting for NETWORK_EVENT");
yield onNetworkEvent;
if (!RequestsMenu.getItemAtIndex(0)) {
info("Waiting for the request to be added to the view");
yield monitor.panelWin.once(monitor.panelWin.EVENTS.REQUEST_ADDED);
yield monitor.panelWin.once(EVENTS.REQUEST_ADDED);
}
ok(true, "Received NETWORK_EVENT. Selecting the item.");
@ -146,7 +158,7 @@ var test = Task.async(function* () {
if (hasQueuedUpdates && hasRunningTabUpdate) {
info("Waiting for updates to be flushed.");
// _flushRequests calls .populate which emits the following event
yield waitFor(panel, EVENTS.NETWORKDETAILSVIEW_POPULATED);
yield panel.once(EVENTS.NETWORKDETAILSVIEW_POPULATED);
info("Requests flushed.");
}

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

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if filtering items in the network table works correctly.
*/
@ -26,8 +28,8 @@ const REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS = REQUESTS_WITH_MEDIA_AND_FLASH.conca
{ url: "sjs_content-type-test-server.sjs?fmt=ws" },
]);
function test() {
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [,, monitor] = yield initNetMonitor(FILTERING_URL);
function setFreetextFilter(value) {
// Set the text and manually call all callbacks synchronously to avoid the timeout
@ -39,12 +41,16 @@ function test() {
info("Starting test... ");
let { $, NetMonitorView } = aMonitor.panelWin;
let { $, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 9).then(() => {
let wait = waitForNetworkEvents(monitor, 9);
loadCommonFrameScript();
yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
yield wait;
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
isnot(RequestsMenu.selectedItem, null,
@ -55,143 +61,120 @@ function test() {
"The details pane should not be hidden after toggle button was pressed.");
// First test with single filters...
testFilterButtons(aMonitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1])
.then(() => {
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testFilterButtons(aMonitor, "html");
return testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
// Reset filters
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
testFilterButtons(aMonitor, "css");
return testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "css");
testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button"));
testFilterButtons(aMonitor, "js");
return testContents([0, 0, 1, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "js");
testContents([0, 0, 1, 0, 0, 0, 0, 0, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button"));
testFilterButtons(aMonitor, "xhr");
return testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
})
.then(() => {
testFilterButtons(monitor, "xhr");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button"));
testFilterButtons(aMonitor, "fonts");
return testContents([0, 0, 0, 1, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "fonts");
testContents([0, 0, 0, 1, 0, 0, 0, 0, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button"));
testFilterButtons(aMonitor, "images");
return testContents([0, 0, 0, 0, 1, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "images");
testContents([0, 0, 0, 0, 1, 0, 0, 0, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button"));
testFilterButtons(aMonitor, "media");
return testContents([0, 0, 0, 0, 0, 1, 1, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "media");
testContents([0, 0, 0, 0, 0, 1, 1, 0, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button"));
testFilterButtons(aMonitor, "flash");
return testContents([0, 0, 0, 0, 0, 0, 0, 1, 0]);
})
.then(() => {
testFilterButtons(monitor, "flash");
testContents([0, 0, 0, 0, 0, 0, 0, 1, 0]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-ws-button"));
testFilterButtons(aMonitor, "ws");
return testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
})
.then(() => {
testFilterButtons(monitor, "ws");
testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
testFilterButtons(aMonitor, "all");
return testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
})
.then(() => {
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
// Text in filter box that matches nothing should hide all.
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
setFreetextFilter("foobar");
return testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Text in filter box that matches should filter out everything else.
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
setFreetextFilter("sample");
return testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
// Text in filter box that matches should filter out everything else.
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
setFreetextFilter("SAMPLE");
return testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
// Test negative filtering (only show unmatched items)
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
setFreetextFilter("-sample");
return testContents([0, 0, 0, 1, 1, 1, 1, 1, 1]);
})
testContents([0, 0, 0, 1, 1, 1, 1, 1, 1]);
// ...then combine multiple filters together.
.then(() => {
// Enable filtering for html and css; should show request of both type.
setFreetextFilter("");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
testFilterButtonsCustom(aMonitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
return testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
// Html and css filter enabled and text filter should show just the html and css match.
// Should not show both the items that match the button plus the items that match the text.
setFreetextFilter("sample");
return testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
})
testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
// Html and css filter enabled and text filter should show just the html and css match.
// Should not show both the items matching the button plus the items matching the text.
setFreetextFilter("sample");
testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
.then(() => {
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button"));
setFreetextFilter("");
testFilterButtonsCustom(aMonitor, [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0]);
return testContents([1, 1, 0, 0, 0, 0, 0, 1, 0]);
})
.then(() => {
testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0]);
testContents([1, 1, 0, 0, 0, 0, 0, 1, 0]);
// Disable some filters. Only one left active.
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button"));
testFilterButtons(aMonitor, "html");
return testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
// Disable last active filter. Should toggle to all.
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testFilterButtons(aMonitor, "all");
return testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
})
.then(() => {
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
// Enable few filters and click on all. Only "all" should be checked.
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-ws-button"));
testFilterButtonsCustom(aMonitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 1]);
testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 1]);
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
testFilterButtons(aMonitor, "all");
return testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish);
});
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
function testContents(aVisibility) {
yield teardown(monitor);
function testContents(visibility) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after filtering.");
is(RequestsMenu.selectedIndex, 0,
@ -199,13 +182,13 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.items.length, aVisibility.length,
is(RequestsMenu.items.length, visibility.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisibility.filter(e => e).length,
is(RequestsMenu.visibleItems.length, visibility.filter(e => e).length,
"There should be a specific amount of visbile items in the requests menu.");
for (let i = 0; i < aVisibility.length; i++) {
is(RequestsMenu.getItemAtIndex(i).target.hidden, !aVisibility[i],
for (let i = 0; i < visibility.length; i++) {
is(RequestsMenu.getItemAtIndex(i).target.hidden, !visibility[i],
"The item at index " + i + " doesn't have the correct hidden state.");
}
@ -279,11 +262,5 @@ function test() {
status: 101,
statusText: "Switching Protocols",
});
return promise.resolve(null);
}
loadCommonFrameScript();
performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
});
}
});

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

@ -1,9 +1,12 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if filtering items in the network table works correctly with new requests.
*/
const BASIC_REQUESTS = [
{ url: "sjs_content-type-test-server.sjs?fmt=html&res=undefined" },
{ url: "sjs_content-type-test-server.sjs?fmt=css" },
@ -26,19 +29,23 @@ const REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS = REQUESTS_WITH_MEDIA_AND_FLASH.conca
{ url: "sjs_content-type-test-server.sjs?fmt=ws" },
]);
function test() {
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... ");
// It seems that this test may be slow on Ubuntu builds running on ec2.
requestLongerTimeout(2);
let { $, NetMonitorView } = aMonitor.panelWin;
let { $, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 9).then(() => {
let wait = waitForNetworkEvents(monitor, 9);
loadCommonFrameScript();
yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
yield wait;
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
isnot(RequestsMenu.selectedItem, null,
@ -48,47 +55,42 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should not be hidden after toggle button was pressed.");
testFilterButtons(aMonitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1])
.then(() => {
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
info("Testing html filtering.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testFilterButtons(aMonitor, "html");
return testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
info("Performing more requests.");
performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
return waitForNetworkEvents(aMonitor, 9);
})
.then(() => {
wait = waitForNetworkEvents(monitor, 9);
yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
yield wait;
info("Testing html filtering again.");
testFilterButtons(aMonitor, "html");
return testContents([1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
info("Performing more requests.");
performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
return waitForNetworkEvents(aMonitor, 9);
})
.then(() => {
wait = waitForNetworkEvents(monitor, 9);
yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
yield wait;
info("Testing html filtering again.");
testFilterButtons(aMonitor, "html");
return testContents([1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
info("Resetting filters.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button"));
testFilterButtons(aMonitor, "all");
return testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish);
});
testFilterButtons(monitor, "all");
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
function testContents(aVisibility) {
yield teardown(monitor);
function testContents(visibility) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after filtering.");
is(RequestsMenu.selectedIndex, 0,
@ -96,17 +98,17 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.items.length, aVisibility.length,
is(RequestsMenu.items.length, visibility.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisibility.filter(e => e).length,
is(RequestsMenu.visibleItems.length, visibility.filter(e => e).length,
"There should be a specific amount of visbile items in the requests menu.");
for (let i = 0; i < aVisibility.length; i++) {
is(RequestsMenu.getItemAtIndex(i).target.hidden, !aVisibility[i],
for (let i = 0; i < visibility.length; i++) {
is(RequestsMenu.getItemAtIndex(i).target.hidden, !visibility[i],
"The item at index " + i + " doesn't have the correct hidden state.");
}
for (let i = 0; i < aVisibility.length; i += 9) {
for (let i = 0; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=html", {
fuzzyUrl: true,
@ -116,7 +118,7 @@ function test() {
fullMimeType: "text/html; charset=utf-8"
});
}
for (let i = 1; i < aVisibility.length; i += 9) {
for (let i = 1; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=css", {
fuzzyUrl: true,
@ -126,7 +128,7 @@ function test() {
fullMimeType: "text/css; charset=utf-8"
});
}
for (let i = 2; i < aVisibility.length; i += 9) {
for (let i = 2; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=js", {
fuzzyUrl: true,
@ -136,7 +138,7 @@ function test() {
fullMimeType: "application/javascript; charset=utf-8"
});
}
for (let i = 3; i < aVisibility.length; i += 9) {
for (let i = 3; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=font", {
fuzzyUrl: true,
@ -146,7 +148,7 @@ function test() {
fullMimeType: "font/woff"
});
}
for (let i = 4; i < aVisibility.length; i += 9) {
for (let i = 4; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=image", {
fuzzyUrl: true,
@ -156,7 +158,7 @@ function test() {
fullMimeType: "image/png"
});
}
for (let i = 5; i < aVisibility.length; i += 9) {
for (let i = 5; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=audio", {
fuzzyUrl: true,
@ -166,7 +168,7 @@ function test() {
fullMimeType: "audio/ogg"
});
}
for (let i = 6; i < aVisibility.length; i += 9) {
for (let i = 6; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=video", {
fuzzyUrl: true,
@ -176,7 +178,7 @@ function test() {
fullMimeType: "video/webm"
});
}
for (let i = 7; i < aVisibility.length; i += 9) {
for (let i = 7; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=flash", {
fuzzyUrl: true,
@ -186,7 +188,7 @@ function test() {
fullMimeType: "application/x-shockwave-flash"
});
}
for (let i = 8; i < aVisibility.length; i += 9) {
for (let i = 8; i < visibility.length; i += 9) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
"GET", CONTENT_TYPE_SJS + "?fmt=ws", {
fuzzyUrl: true,
@ -194,11 +196,5 @@ function test() {
statusText: "Switching Protocols"
});
}
return promise.resolve(null);
}
loadCommonFrameScript();
performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
});
}
});

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

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if filtering items in the network table works correctly with new requests
* and while sorting is enabled.
@ -18,23 +20,30 @@ const REQUESTS_WITH_MEDIA = BASIC_REQUESTS.concat([
{ url: "sjs_content-type-test-server.sjs?fmt=video" },
]);
const REQUESTS_WITH_MEDIA_AND_FLASH = REQUESTS_WITH_MEDIA.concat([
{ url: "sjs_content-type-test-server.sjs?fmt=flash" },
]);
function test() {
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... ");
// It seems that this test may be slow on Ubuntu builds running on ec2.
requestLongerTimeout(2);
let { $, NetMonitorView } = aMonitor.panelWin;
let { $, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 7).then(() => {
// The test assumes that the first HTML request here has a longer response
// body than the other HTML requests performed later during the test.
let requests = Cu.cloneInto(REQUESTS_WITH_MEDIA, {});
let newres = "res=<p>" + new Array(10).join(Math.random(10)) + "</p>";
requests[0].url = requests[0].url.replace("res=undefined", newres);
loadCommonFrameScript();
let wait = waitForNetworkEvents(monitor, 7);
yield performRequestsInContent(requests);
yield wait;
EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
isnot(RequestsMenu.selectedItem, null,
@ -44,73 +53,66 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should not be hidden after toggle button was pressed.");
testFilterButtons(aMonitor, "all");
testContents([0, 1, 2, 3, 4, 5, 6], 7, 0)
.then(() => {
testFilterButtons(monitor, "all");
testContents([0, 1, 2, 3, 4, 5, 6], 7, 0);
info("Sorting by size, ascending.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
testFilterButtons(aMonitor, "all");
return testContents([6, 4, 5, 0, 1, 2, 3], 7, 6);
})
.then(() => {
testFilterButtons(monitor, "all");
testContents([6, 4, 5, 0, 1, 2, 3], 7, 6);
info("Testing html filtering.");
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testFilterButtons(aMonitor, "html");
return testContents([6, 4, 5, 0, 1, 2, 3], 1, 6);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([6, 4, 5, 0, 1, 2, 3], 1, 6);
info("Performing more requests.");
wait = waitForNetworkEvents(monitor, 7);
performRequestsInContent(REQUESTS_WITH_MEDIA);
return waitForNetworkEvents(aMonitor, 7);
})
.then(() => {
yield wait;
info("Testing html filtering again.");
resetSorting();
testFilterButtons(aMonitor, "html");
return testContents([8, 13, 9, 11, 10, 12, 0, 4, 1, 5, 2, 6, 3, 7], 2, 13);
})
.then(() => {
testFilterButtons(monitor, "html");
testContents([8, 13, 9, 11, 10, 12, 0, 4, 1, 5, 2, 6, 3, 7], 2, 13);
info("Performing more requests.");
performRequestsInContent(REQUESTS_WITH_MEDIA);
return waitForNetworkEvents(aMonitor, 7);
})
.then(() => {
yield waitForNetworkEvents(monitor, 7);
info("Testing html filtering again.");
resetSorting();
testFilterButtons(aMonitor, "html");
return testContents([12, 13, 20, 14, 16, 18, 15, 17, 19, 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11], 3, 20);
})
.then(() => {
return teardown(aMonitor);
})
.then(finish);
});
testFilterButtons(monitor, "html");
testContents([12, 13, 20, 14, 16, 18, 15, 17, 19, 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11],
3, 20);
yield teardown(monitor);
function resetSorting() {
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-waterfall-button"));
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-size-button"));
}
function testContents(aOrder, aVisible, aSelection) {
function testContents(order, visible, selection) {
isnot(RequestsMenu.selectedItem, null,
"There should still be a selected item after filtering.");
is(RequestsMenu.selectedIndex, aSelection,
is(RequestsMenu.selectedIndex, selection,
"The first item should be still selected after filtering.");
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.items.length, aOrder.length,
is(RequestsMenu.items.length, order.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisible,
is(RequestsMenu.visibleItems.length, visible,
"There should be a specific amount of visbile items in the requests menu.");
for (let i = 0; i < aOrder.length; i++) {
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 = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i]),
"GET", CONTENT_TYPE_SJS + "?fmt=html", {
fuzzyUrl: true,
status: 200,
@ -119,8 +121,8 @@ function test() {
fullMimeType: "text/html; charset=utf-8"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len]),
"GET", CONTENT_TYPE_SJS + "?fmt=css", {
fuzzyUrl: true,
status: 200,
@ -129,8 +131,8 @@ function test() {
fullMimeType: "text/css; charset=utf-8"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 2]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 2]),
"GET", CONTENT_TYPE_SJS + "?fmt=js", {
fuzzyUrl: true,
status: 200,
@ -139,8 +141,8 @@ function test() {
fullMimeType: "application/javascript; charset=utf-8"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 3]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 3]),
"GET", CONTENT_TYPE_SJS + "?fmt=font", {
fuzzyUrl: true,
status: 200,
@ -149,8 +151,8 @@ function test() {
fullMimeType: "font/woff"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 4]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 4]),
"GET", CONTENT_TYPE_SJS + "?fmt=image", {
fuzzyUrl: true,
status: 200,
@ -159,8 +161,8 @@ function test() {
fullMimeType: "image/png"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 5]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 5]),
"GET", CONTENT_TYPE_SJS + "?fmt=audio", {
fuzzyUrl: true,
status: 200,
@ -169,8 +171,8 @@ function test() {
fullMimeType: "audio/ogg"
});
}
for (let i = 0, len = aOrder.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 6]),
for (let i = 0, len = order.length / 7; i < len; i++) {
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(order[i + len * 6]),
"GET", CONTENT_TYPE_SJS + "?fmt=video", {
fuzzyUrl: true,
status: 200,
@ -179,19 +181,5 @@ function test() {
fullMimeType: "video/webm"
});
}
return promise.resolve(null);
}
// The test assumes that the first HTML request here has a longer response
// body than the other HTML requests performed later during the test.
let requests = Cu.cloneInto(REQUESTS_WITH_MEDIA, {});
let newres = "res=<p>" + new Array(10).join(Math.random(10)) + "</p>";
requests[0].url = requests[0].url.replace("res=undefined", newres);
loadCommonFrameScript();
performRequestsInContent(requests);
});
}
});

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

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if invalid filter types are sanitized when loaded from the preferences.
*/
@ -27,13 +29,13 @@ const REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS = REQUESTS_WITH_MEDIA_AND_FLASH.conca
{ url: "sjs_content-type-test-server.sjs?fmt=ws" },
]);
function test() {
add_task(function* () {
Services.prefs.setCharPref("devtools.netmonitor.filters", '["js", "bogus"]');
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
let [,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... ");
let { Prefs, NetMonitorView } = aMonitor.panelWin;
let { Prefs, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
@ -45,20 +47,17 @@ function test() {
is(Prefs.filters[1], "bogus",
"The second filter type is invalid, but loaded anyway.");
waitForNetworkEvents(aMonitor, 9).then(() => {
testFilterButtons(aMonitor, "js");
let wait = waitForNetworkEvents(monitor, 9);
loadCommonFrameScript();
yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
yield wait;
testFilterButtons(monitor, "js");
ok(true, "Only the correct filter type was taken into consideration.");
teardown(aMonitor).then(() => {
yield teardown(monitor);
let filters = Services.prefs.getCharPref("devtools.netmonitor.filters");
is(filters, '["js"]',
"The bogus filter type was ignored and removed from the preferences.");
finish();
});
});
loadCommonFrameScript();
performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
});
}
});

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

@ -1,84 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if the summary text displayed in the network requests menu footer
* is correct.
*/
function test() {
add_task(function* () {
requestLongerTimeout(2);
let { PluralForm } = Cu.import("resource://gre/modules/PluralForm.jsm", {});
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
let [tab,, monitor] = yield initNetMonitor(FILTERING_URL);
info("Starting test... ");
let { $, L10N, NetMonitorView } = aMonitor.panelWin;
let { $, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
testStatus();
waitForNetworkEvents(aMonitor, 8).then(() => {
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button"));
testStatus();
info("Performing more requests.");
aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }');
return waitForNetworkEvents(aMonitor, 8);
})
.then(() => {
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button"));
testStatus();
EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button"));
testStatus();
teardown(aMonitor).then(finish);
for (let i = 0; i < 2; i++) {
info(`Performing requests in batch #${i}`);
let wait = waitForNetworkEvents(monitor, 8);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests('{ "getMedia": true, "getFlash": true }');
});
yield wait;
testStatus();
let buttons = ["html", "css", "js", "xhr", "fonts", "images", "media", "flash"];
for (let button of buttons) {
let buttonEl = $(`#requests-menu-filter-${button}-button`);
EventUtils.sendMouseEvent({ type: "click" }, buttonEl);
testStatus();
}
}
yield teardown(monitor);
function testStatus() {
let summary = $("#requests-menu-network-summary-button");
@ -110,7 +71,4 @@ function test() {
.replace("#3", L10N.numberWithDecimals((totalMillis || 0) / 1000, 2))
, "The current summary text is incorrect.");
}
aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }');
});
}
});

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

@ -1,20 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if html responses show and properly populate a "Preview" tab.
*/
function test() {
initNetMonitor(CONTENT_TYPE_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(CONTENT_TYPE_URL);
info("Starting test... ");
let { $, document, EVENTS, NetMonitorView } = aMonitor.panelWin;
let { $, document, EVENTS, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 6).then(() => {
let wait = waitForNetworkEvents(monitor, 6);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
@ -33,7 +40,7 @@ function test() {
is($("#preview-tab").hidden, false,
"The preview tab should be visible now.");
waitFor(aMonitor.panelWin, EVENTS.RESPONSE_HTML_PREVIEW_DISPLAYED).then(() => {
yield monitor.panelWin.once(EVENTS.RESPONSE_HTML_PREVIEW_DISPLAYED);
let iframe = $("#response-preview");
ok(iframe,
"There should be a response preview iframe available.");
@ -51,10 +58,5 @@ function test() {
is($("#preview-tabpanel").hidden, false,
"The preview tabpanel is not hidden again for non html responses.");
teardown(aMonitor).then(finish);
});
});
aDebuggee.performRequests();
});
}
yield teardown(monitor);
});

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

@ -1,21 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if image responses show a thumbnail in the requests menu.
*/
function test() {
initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
info("Starting test... ");
let { $, $all, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } = aMonitor.panelWin;
let { $, $all, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } =
monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
promise.all([
waitForNetworkEvents(aMonitor, 7),
waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
]).then(() => {
let wait = waitForEvents();
yield performRequests();
yield wait;
info("Checking the image thumbnail when all items are shown.");
checkImageThumbnail();
@ -28,25 +31,33 @@ function test() {
checkImageThumbnail();
info("Reloading the debuggee and performing all requests again...");
reloadAndPerformRequests();
wait = waitForEvents();
yield reloadAndPerformRequests();
yield wait;
return promise.all([
waitForNetworkEvents(aMonitor, 7), // 6 + 1
waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
]);
}).then(() => {
info("Checking the image thumbnail after a reload.");
checkImageThumbnail();
teardown(aMonitor).then(finish);
});
yield teardown(monitor);
function reloadAndPerformRequests() {
NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED).then(() => {
aDebuggee.performRequests();
function waitForEvents() {
return promise.all([
waitForNetworkEvents(monitor, 7),
monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
]);
}
function performRequests() {
return ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
}
function* reloadAndPerformRequests() {
yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED);
yield performRequests();
}
function checkImageThumbnail() {
is($all(".requests-menu-icon[type=thumbnail]").length, 1,
"There should be only one image request with a thumbnail displayed.");
@ -55,7 +66,4 @@ function test() {
is($(".requests-menu-icon[type=thumbnail]").hidden, false,
"The image requests-menu-icon thumbnail should not be hidden.");
}
aDebuggee.performRequests();
});
}
});

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

@ -7,7 +7,7 @@
* Tests if image responses show a popup in the requests menu when hovered.
*/
add_task(function* test() {
let [, debuggee, monitor] = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
let [tab, , monitor] = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
info("Starting test... ");
let { $, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } =
@ -16,9 +16,9 @@ add_task(function* test() {
RequestsMenu.lazyUpdate = true;
let onEvents = waitForNetworkEvents(monitor, 7);
let onThumbnail = waitFor(monitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
let onThumbnail = monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
debuggee.performRequests();
yield performRequests();
yield onEvents;
yield onThumbnail;
@ -27,11 +27,11 @@ add_task(function* test() {
// 7 XHRs as before + 1 extra document reload
onEvents = waitForNetworkEvents(monitor, 8);
onThumbnail = waitFor(monitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
onThumbnail = monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
info("Reloading the debuggee and performing all requests again...");
yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED);
debuggee.performRequests();
yield performRequests();
yield onEvents;
yield onThumbnail;
@ -45,7 +45,12 @@ add_task(function* test() {
yield onHidden;
yield teardown(monitor);
finish();
function performRequests() {
return ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
}
/**
* Show a tooltip on the {requestItem} and verify that it was displayed

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

@ -1,49 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if very long JSON responses are handled correctly.
*/
function test() {
initNetMonitor(JSON_LONG_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(JSON_LONG_URL);
info("Starting test... ");
// This is receiving over 80 KB of json and will populate over 6000 items
// in a variables view instance. Debug builds are slow.
requestLongerTimeout(4);
let { document, L10N, NetMonitorView } = aMonitor.panelWin;
let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1).then(() => {
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
"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)),
size: L10N.getFormatStr("networkMenu.sizeKB",
L10N.numberWithDecimals(85975 / 1024, 2)),
time: true
});
aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED, () => {
testResponseTab();
teardown(aMonitor).then(finish);
});
let onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
testResponseTab();
yield teardown(monitor);
function testResponseTab() {
let tab = document.querySelectorAll("#details-pane tab")[3];
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
is(tab.getAttribute("selected"), "true",
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
@ -84,8 +93,4 @@ function test() {
is(jsonScope.querySelectorAll(values)[1].getAttribute("value"),
"\"Hello long string JSON!\"", "The second json property value was incorrect.");
}
});
aDebuggee.performRequests();
});
}
});

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

@ -1,20 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if malformed JSON responses are handled correctly.
*/
function test() {
initNetMonitor(JSON_MALFORMED_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(JSON_MALFORMED_URL);
info("Starting test... ");
let { document, Editor, NetMonitorView } = aMonitor.panelWin;
let { document, EVENTS, Editor, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1).then(() => {
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
"GET", CONTENT_TYPE_SJS + "?fmt=json-malformed", {
status: 200,
@ -23,17 +30,17 @@ function test() {
fullMimeType: "text/json; charset=utf-8"
});
let onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
let tab = document.querySelectorAll("#details-pane tab")[3];
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED).then(() => {
is(tab.getAttribute("selected"), "true",
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
@ -41,11 +48,13 @@ function test() {
"The response info header doesn't have the intended visibility.");
is(tabpanel.querySelector("#response-content-info-header")
.getAttribute("value"),
"SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data",
"SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data" +
" at line 1 column 40 of the JSON data",
"The response info header doesn't have the intended value attribute.");
is(tabpanel.querySelector("#response-content-info-header")
.getAttribute("tooltiptext"),
"SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data",
"SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data" +
" at line 1 column 40 of the JSON data",
"The response info header doesn't have the intended tooltiptext attribute.");
is(tabpanel.querySelector("#response-content-json-box")
@ -58,17 +67,11 @@ function test() {
.hasAttribute("hidden"), true,
"The response content image box doesn't have the intended visibility.");
NetMonitorView.editor("#response-content-textarea").then((aEditor) => {
is(aEditor.getText(), "{ \"greeting\": \"Hello malformed JSON!\" },",
let editor = yield NetMonitorView.editor("#response-content-textarea");
is(editor.getText(), "{ \"greeting\": \"Hello malformed JSON!\" },",
"The text shown in the source editor is incorrect.");
is(aEditor.getMode(), Editor.modes.js,
is(editor.getMode(), Editor.modes.js,
"The mode active in the source editor is incorrect.");
teardown(aMonitor).then(finish);
});
});
});
aDebuggee.performRequests();
});
}
yield teardown(monitor);
});

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

@ -1,20 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if JSON responses with unusal/custom MIME types are handled correctly.
*/
function test() {
initNetMonitor(JSON_CUSTOM_MIME_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(JSON_CUSTOM_MIME_URL);
info("Starting test... ");
let { document, L10N, NetMonitorView } = aMonitor.panelWin;
let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1).then(() => {
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
"GET", CONTENT_TYPE_SJS + "?fmt=json-custom-mime", {
status: 200,
@ -25,22 +32,22 @@ function test() {
time: true
});
let onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED)
.then(testResponseTab)
.then(() => teardown(aMonitor))
.then(finish);
testResponseTab();
yield teardown(monitor);
function testResponseTab() {
let tab = document.querySelectorAll("#details-pane tab")[3];
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
is(tab.getAttribute("selected"), "true",
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
@ -64,18 +71,18 @@ function test() {
"The empty notice should not be displayed in this tabpanel.");
let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[0]
.getAttribute("value"),
"greeting", "The first json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .value")[0]
.getAttribute("value"),
"\"Hello oddly-named JSON!\"", "The first json property value was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[1]
.getAttribute("value"),
"__proto__", "The second json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .value")[1]
.getAttribute("value"),
"Object", "The second json property value was incorrect.");
}
});
aDebuggee.performRequests();
});
}
});

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

@ -1,20 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if JSON responses with unusal/custom MIME types are handled correctly.
*/
function test() {
initNetMonitor(JSON_TEXT_MIME_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(JSON_TEXT_MIME_URL);
info("Starting test... ");
let { document, L10N, NetMonitorView } = aMonitor.panelWin;
let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1).then(() => {
let wait = waitForNetworkEvents(monitor, 1);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
"GET", CONTENT_TYPE_SJS + "?fmt=json-text-mime", {
status: 200,
@ -25,22 +32,22 @@ function test() {
time: true
});
let onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED)
.then(testResponseTab)
.then(() => teardown(aMonitor))
.then(finish);
testResponseTab();
yield teardown(monitor);
function testResponseTab() {
let tab = document.querySelectorAll("#details-pane tab")[3];
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
is(tab.getAttribute("selected"), "true",
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
@ -64,18 +71,18 @@ function test() {
"The empty notice should not be displayed in this tabpanel.");
let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[0]
.getAttribute("value"),
"greeting", "The first json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .value")[0]
.getAttribute("value"),
"\"Hello third-party JSON!\"", "The first json property value was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[1]
.getAttribute("value"),
"__proto__", "The second json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .value")[1]
.getAttribute("value"),
"Object", "The second json property value was incorrect.");
}
});
aDebuggee.performRequests();
});
}
});

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

@ -1,21 +1,28 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if JSONP responses are handled correctly.
*/
function test() {
initNetMonitor(JSONP_URL).then(([aTab, aDebuggee, aMonitor]) => {
add_task(function* () {
let [tab, , monitor] = yield initNetMonitor(JSONP_URL);
info("Starting test... ");
let { document, L10N, NetMonitorView } = aMonitor.panelWin;
let { document, EVENTS, L10N, NetMonitorView } = monitor.panelWin;
let { RequestsMenu, NetworkDetails } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
NetworkDetails._json.lazyEmpty = false;
waitForNetworkEvents(aMonitor, 2).then(() => {
let wait = waitForNetworkEvents(monitor, 2);
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests();
});
yield wait;
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
"GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", {
status: 200,
@ -35,31 +42,28 @@ function test() {
time: true
});
Task.spawn(function* () {
let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
let onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
EventUtils.sendMouseEvent({ type: "mousedown" },
document.getElementById("details-pane-toggle"));
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll("#details-pane tab")[3]);
yield onEvent;
yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
testResponseTab("$_0123Fun", "\"Hello JSONP!\"");
onEvent = monitor.panelWin.once(EVENTS.RESPONSE_BODY_DISPLAYED);
RequestsMenu.selectedIndex = 1;
yield onEvent;
yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
testResponseTab("$_4567Sad", "\"Hello weird JSONP!\"");
yield teardown(aMonitor);
finish();
});
yield teardown(monitor);
function testResponseTab(aFunction, aGreeting) {
let tab = document.querySelectorAll("#details-pane tab")[3];
function testResponseTab(func, greeting) {
let tabEl = document.querySelectorAll("#details-pane tab")[3];
let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
is(tab.getAttribute("selected"), "true",
is(tabEl.getAttribute("selected"), "true",
"The response tab in the network details pane should be selected.");
is(tabpanel.querySelector("#response-content-info-header")
@ -85,21 +89,21 @@ function test() {
let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
is(jsonScope.querySelector(".name").getAttribute("value"),
L10N.getFormatStr("jsonpScopeName", aFunction),
L10N.getFormatStr("jsonpScopeName", func),
"The json scope doesn't have the correct title.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[0]
.getAttribute("value"),
"greeting", "The first json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
aGreeting, "The first json property value was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[0]
.getAttribute("value"),
greeting, "The first json property value was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .name")[1]
.getAttribute("value"),
"__proto__", "The second json property name was incorrect.");
is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
is(jsonScope.querySelectorAll(".variables-view-property .value")[1]
.getAttribute("value"),
"Object", "The second json property value was incorrect.");
}
});
aDebuggee.performRequests();
});
}
});