Bug 862341 Part 5: Tests. r=vporof
authorPanos Astithas <past@mozilla.com>
Wed, 06 May 2015 09:24:57 +0300
changeset 242943 2bda9fb3b5d66a32ba9ed090caa2113a7d9de48e
parent 242942 6db74fd5b4474861726f4673bc233d8b1c19ec2c
child 242944 067e21985d8dbd9f5bda06898806bae5542d69e0
push id28714
push userkwierso@gmail.com
push dateFri, 08 May 2015 17:29:48 +0000
treeherdermozilla-central@5e8adf0e7f2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs862341
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 862341 Part 5: Tests. r=vporof
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js
browser/devtools/webconsole/test/browser_webconsole_netlogging.js
browser/devtools/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -380,8 +380,10 @@ skip-if = e10s # Bug 1042253 - webconsol
 [browser_webconsole_console_trace_duplicates.js]
 [browser_webconsole_cd_iframe.js]
 [browser_webconsole_autocomplete_crossdomain_iframe.js]
 [browser_webconsole_console_custom_styles.js]
 [browser_webconsole_console_api_stackframe.js]
 [browser_webconsole_column_numbers.js]
 [browser_console_open_or_focus.js]
 [browser_webconsole_bug_922212_console_dirxml.js]
+[browser_webconsole_shows_reqs_in_netmonitor.js]
+[browser_netmonitor_shows_reqs_in_webconsole.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js
@@ -0,0 +1,71 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const TEST_URI = "data:text/html;charset=utf8,Test that the netmonitor " +
+                 "displays requests that have been recorded in the " +
+                 "web console, even if the netmonitor hadn't opened yet.";
+
+const TEST_FILE = "test-network-request.html";
+const TEST_PATH = "http://example.com/browser/browser/devtools/webconsole/test/" +
+                 TEST_FILE;
+
+const NET_PREF = "devtools.webconsole.filter.networkinfo";
+Services.prefs.setBoolPref(NET_PREF, true);
+registerCleanupFunction(() => {
+  Services.prefs.clearUserPref(NET_PREF);
+});
+
+add_task(function* () {
+  let { tab, browser } = yield loadTab(TEST_URI);
+
+  // Test that the request appears in the console.
+  let hud = yield openConsole();
+  info("Web console is open");
+
+  yield loadDocument(browser);
+  info("Document loaded.");
+
+  yield waitForMessages({
+    webconsole: hud,
+    messages: [
+      {
+        name: "network message",
+        text: TEST_FILE,
+        category: CATEGORY_NETWORK,
+        severity: SEVERITY_LOG
+      }
+    ]
+  });
+
+  // Test that the request appears in the network panel.
+  let target = TargetFactory.forTab(tab);
+  let toolbox = yield gDevTools.showToolbox(target, "netmonitor");
+  info("Network panel is open.");
+
+  testNetmonitor(toolbox);
+});
+
+
+function loadDocument(browser) {
+  let deferred = promise.defer();
+
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    deferred.resolve();
+  }, true);
+  content.location = TEST_PATH;
+
+  return deferred.promise;
+}
+
+function testNetmonitor(toolbox) {
+  let monitor = toolbox.getCurrentPanel();
+  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
+  is(RequestsMenu.itemCount, 1, "Network request appears in the network panel");
+
+  let item = RequestsMenu.getItemAtIndex(0);
+  is(item.attachment.method, "GET", "The attached method is correct.");
+  is(item.attachment.url, TEST_PATH, "The attached url is correct.");
+}
--- a/browser/devtools/webconsole/test/browser_webconsole_netlogging.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_netlogging.js
@@ -68,17 +68,18 @@ function testPageLoad()
     ok(lastRequest, "Page load was logged");
 
     is(lastRequest.request.url, TEST_NETWORK_REQUEST_URI,
       "Logged network entry is page load");
     is(lastRequest.request.method, "GET", "Method is correct");
     ok(!lastRequest.request.postData.text, "No request body was stored");
     ok(lastRequest.discardRequestBody, "Request body was discarded");
     ok(!lastRequest.response.content.text, "No response body was stored");
-    ok(lastRequest.discardResponseBody, "Response body was discarded");
+    ok(lastRequest.discardResponseBody || lastRequest.fromCache,
+       "Response body was discarded or response came from the cache");
 
     lastRequest = null;
     requestCallback = null;
     executeSoon(testPageLoadBody);
   };
 
   content.location = TEST_NETWORK_REQUEST_URI;
 }
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js
@@ -0,0 +1,71 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const TEST_URI = "data:text/html;charset=utf8,Test that the web console " +
+                 "displays requests that have been recorded in the " +
+                 "netmonitor, even if the console hadn't opened yet.";
+
+const TEST_FILE = "test-network-request.html";
+const TEST_PATH = "http://example.com/browser/browser/devtools/webconsole/test/" +
+                 TEST_FILE;
+
+const NET_PREF = "devtools.webconsole.filter.networkinfo";
+Services.prefs.setBoolPref(NET_PREF, true);
+registerCleanupFunction(() => {
+  Services.prefs.clearUserPref(NET_PREF);
+});
+
+add_task(function* () {
+  let { tab, browser } = yield loadTab(TEST_URI);
+
+  let target = TargetFactory.forTab(tab);
+  let toolbox = yield gDevTools.showToolbox(target, "netmonitor");
+  info("Network panel is open.");
+
+  yield loadDocument(browser);
+  info("Document loaded.");
+
+  // Test that the request appears in the network panel.
+  testNetmonitor(toolbox);
+
+  // Test that the request appears in the console.
+  let hud = yield openConsole();
+  info("Web console is open");
+
+  yield waitForMessages({
+    webconsole: hud,
+    messages: [
+      {
+        name: "network message",
+        text: TEST_FILE,
+        category: CATEGORY_NETWORK,
+        severity: SEVERITY_LOG
+      }
+    ]
+  });
+});
+
+
+function loadDocument(browser) {
+  let deferred = promise.defer();
+
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    deferred.resolve();
+  }, true);
+  content.location = TEST_PATH;
+
+  return deferred.promise;
+}
+
+function testNetmonitor(toolbox) {
+  let monitor = toolbox.getCurrentPanel();
+  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
+  is(RequestsMenu.itemCount, 1, "Network request appears in the network panel");
+
+  let item = RequestsMenu.getItemAtIndex(0);
+  is(item.attachment.method, "GET", "The attached method is correct.");
+  is(item.attachment.url, TEST_PATH, "The attached url is correct.");
+}