Bug 1223726 - Update tests; r=ochameau
☠☠ backed out by 48400efc4958 ☠ ☠
authorJan Odvarko <odvarko@gmail.com>
Mon, 12 Mar 2018 08:10:40 +0100
changeset 407588 41da2897f549475c85639df00e984b987df8ef66
parent 407587 fa0a1e88a238faf3a74535f78c172a9f548c016f
child 407589 1a09e6c3c0a3c0109c32e49b164c7170fc3cfbe5
push id60962
push userjodvarko@mozilla.com
push dateMon, 12 Mar 2018 11:00:44 +0000
treeherderautoland@1a09e6c3c0a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1223726
milestone60.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 1223726 - Update tests; r=ochameau MozReview-Commit-ID: 3iokswH0ybw
devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js
--- a/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js
+++ b/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js
@@ -5,40 +5,22 @@
 
 /**
  * Basic tests for exporting Network panel content into HAR format.
  */
 add_task(async function () {
   // Disable tcp fast open, because it is setting a response header indicator
   // (bug 1352274). TCP Fast Open is not present on all platforms therefore the
   // number of response headers will vary depending on the platform.
-  Services.prefs.setBoolPref("network.tcp.tcp_fastopen_enable", false);
+  await pushPref("network.tcp.tcp_fastopen_enable", false);
   let { tab, monitor } = await initNetMonitor(SIMPLE_URL);
 
-  info("Starting test... ");
-
-  let { connector, store, windowRequire } = monitor.panelWin;
-  let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
-  let RequestListContextMenu = windowRequire(
-    "devtools/client/netmonitor/src/widgets/RequestListContextMenu");
-  let { getSortedRequests } = windowRequire(
-    "devtools/client/netmonitor/src/selectors/index");
-
-  store.dispatch(Actions.batchEnable(false));
+  info("Starting test...");
 
-  let wait = waitForNetworkEvents(monitor, 1);
-  tab.linkedBrowser.reload();
-  await wait;
-
-  let contextMenu = new RequestListContextMenu({ connector });
-
-  await contextMenu.copyAllAsHar(getSortedRequests(store.getState()));
-
-  let jsonString = SpecialPowers.getClipboardData("text/unicode");
-  let har = JSON.parse(jsonString);
+  let har = await reloadAndCopyAllAsHar(tab, monitor);
 
   // Check out HAR log
   isnot(har.log, null, "The HAR log must exist");
   is(har.log.creator.name, "Firefox", "The creator field must be set");
   is(har.log.browser.name, "Firefox", "The browser field must be set");
   is(har.log.pages.length, 1, "There must be one page");
   is(har.log.entries.length, 1, "There must be one request");
 
@@ -55,10 +37,49 @@ add_task(async function () {
   is(entry.response.statusText, "OK", "Check response status text");
   is(entry.response.headers.length, 6, "Check number of response headers");
   is(entry.response.content.mimeType, // eslint-disable-line
     "text/html", "Check response content type"); // eslint-disable-line
   isnot(entry.response.content.text, undefined, // eslint-disable-line
     "Check response body");
   isnot(entry.timings, undefined, "Check timings");
 
+  // Test response body limit (non zero).
+  await pushPref("devtools.netmonitor.responseBodyLimit", 10);
+  har = await reloadAndCopyAllAsHar(tab, monitor);
+  entry = har.log.entries[0];
+  is(entry.response.content.text.length, 10, // eslint-disable-line
+    "Response body must be truncated");
+
+  // Test response body limit (zero).
+  await pushPref("devtools.netmonitor.responseBodyLimit", 0);
+  har = await reloadAndCopyAllAsHar(tab, monitor);
+  entry = har.log.entries[0];
+  is(entry.response.content.text.length, 465, // eslint-disable-line
+    "Response body must not be truncated");
+
   return teardown(monitor);
 });
+
+/**
+ * Reload the page and copy all as HAR.
+ */
+async function reloadAndCopyAllAsHar(tab, monitor) {
+  let { connector, store, windowRequire } = monitor.panelWin;
+  let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  let RequestListContextMenu = windowRequire(
+    "devtools/client/netmonitor/src/widgets/RequestListContextMenu");
+  let { getSortedRequests } = windowRequire(
+    "devtools/client/netmonitor/src/selectors/index");
+
+  store.dispatch(Actions.batchEnable(false));
+
+  let wait = waitForNetworkEvents(monitor, 1);
+  tab.linkedBrowser.reload();
+  await wait;
+
+  let contextMenu = new RequestListContextMenu({ connector });
+
+  await contextMenu.copyAllAsHar(getSortedRequests(store.getState()));
+
+  let jsonString = SpecialPowers.getClipboardData("text/unicode");
+  return JSON.parse(jsonString);
+}