browser/devtools/webconsole/test/browser_webconsole_bug_632817.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_632817.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +// Tests that network log messages bring up the network panel.
     1.9 +
    1.10 +const TEST_NETWORK_REQUEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-network-request.html";
    1.11 +
    1.12 +const TEST_IMG = "http://example.com/browser/browser/devtools/webconsole/test/test-image.png";
    1.13 +
    1.14 +const TEST_DATA_JSON_CONTENT =
    1.15 +  '{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
    1.16 +
    1.17 +let lastRequest = null;
    1.18 +let requestCallback = null;
    1.19 +
    1.20 +function test()
    1.21 +{
    1.22 +  const PREF = "devtools.webconsole.persistlog";
    1.23 +  let original = Services.prefs.getBoolPref("devtools.webconsole.filter.networkinfo");
    1.24 +  Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true);
    1.25 +  Services.prefs.setBoolPref(PREF, true);
    1.26 +  registerCleanupFunction(() => {
    1.27 +    Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", original);
    1.28 +    Services.prefs.clearUserPref(PREF);
    1.29 +  });
    1.30 +
    1.31 +  addTab("data:text/html;charset=utf-8,Web Console network logging tests");
    1.32 +
    1.33 +  browser.addEventListener("load", function onLoad() {
    1.34 +    browser.removeEventListener("load", onLoad, true);
    1.35 +
    1.36 +    openConsole(null, function(aHud) {
    1.37 +      hud = aHud;
    1.38 +
    1.39 +      HUDService.lastFinishedRequest.callback = function(aRequest) {
    1.40 +        lastRequest = aRequest;
    1.41 +        if (requestCallback) {
    1.42 +          requestCallback();
    1.43 +        }
    1.44 +      };
    1.45 +
    1.46 +      executeSoon(testPageLoad);
    1.47 +    });
    1.48 +  }, true);
    1.49 +}
    1.50 +
    1.51 +function testPageLoad()
    1.52 +{
    1.53 +  requestCallback = function() {
    1.54 +    // Check if page load was logged correctly.
    1.55 +    ok(lastRequest, "Page load was logged");
    1.56 +    is(lastRequest.request.url, TEST_NETWORK_REQUEST_URI,
    1.57 +      "Logged network entry is page load");
    1.58 +    is(lastRequest.request.method, "GET", "Method is correct");
    1.59 +    lastRequest = null;
    1.60 +    requestCallback = null;
    1.61 +    executeSoon(testPageLoadBody);
    1.62 +  };
    1.63 +
    1.64 +  content.location = TEST_NETWORK_REQUEST_URI;
    1.65 +}
    1.66 +
    1.67 +function testPageLoadBody()
    1.68 +{
    1.69 +  let loaded = false;
    1.70 +  let requestCallbackInvoked = false;
    1.71 +
    1.72 +  // Turn off logging of request bodies and check again.
    1.73 +  requestCallback = function() {
    1.74 +    ok(lastRequest, "Page load was logged again");
    1.75 +    lastRequest = null;
    1.76 +    requestCallback = null;
    1.77 +    requestCallbackInvoked = true;
    1.78 +
    1.79 +    if (loaded) {
    1.80 +      executeSoon(testXhrGet);
    1.81 +    }
    1.82 +  };
    1.83 +
    1.84 +  browser.addEventListener("load", function onLoad() {
    1.85 +    browser.removeEventListener("load", onLoad, true);
    1.86 +    loaded = true;
    1.87 +
    1.88 +    if (requestCallbackInvoked) {
    1.89 +      executeSoon(testXhrGet);
    1.90 +    }
    1.91 +  }, true);
    1.92 +
    1.93 +  content.location.reload();
    1.94 +}
    1.95 +
    1.96 +function testXhrGet()
    1.97 +{
    1.98 +  requestCallback = function() {
    1.99 +    ok(lastRequest, "testXhrGet() was logged");
   1.100 +    is(lastRequest.request.method, "GET", "Method is correct");
   1.101 +    lastRequest = null;
   1.102 +    requestCallback = null;
   1.103 +    executeSoon(testXhrPost);
   1.104 +  };
   1.105 +
   1.106 +  // Start the XMLHttpRequest() GET test.
   1.107 +  content.wrappedJSObject.testXhrGet();
   1.108 +}
   1.109 +
   1.110 +function testXhrPost()
   1.111 +{
   1.112 +  requestCallback = function() {
   1.113 +    ok(lastRequest, "testXhrPost() was logged");
   1.114 +    is(lastRequest.request.method, "POST", "Method is correct");
   1.115 +    lastRequest = null;
   1.116 +    requestCallback = null;
   1.117 +    executeSoon(testFormSubmission);
   1.118 +  };
   1.119 +
   1.120 +  // Start the XMLHttpRequest() POST test.
   1.121 +  content.wrappedJSObject.testXhrPost();
   1.122 +}
   1.123 +
   1.124 +function testFormSubmission()
   1.125 +{
   1.126 +  // Start the form submission test. As the form is submitted, the page is
   1.127 +  // loaded again. Bind to the load event to catch when this is done.
   1.128 +  requestCallback = function() {
   1.129 +    ok(lastRequest, "testFormSubmission() was logged");
   1.130 +    is(lastRequest.request.method, "POST", "Method is correct");
   1.131 +
   1.132 +    // There should be 3 network requests pointing to the HTML file.
   1.133 +    waitForMessages({
   1.134 +      webconsole: hud,
   1.135 +      messages: [
   1.136 +        {
   1.137 +          text: "test-network-request.html",
   1.138 +          category: CATEGORY_NETWORK,
   1.139 +          severity: SEVERITY_LOG,
   1.140 +          count: 3,
   1.141 +        },
   1.142 +        {
   1.143 +          text: "test-data.json",
   1.144 +          category: CATEGORY_NETWORK,
   1.145 +          severity: SEVERITY_LOG,
   1.146 +          count: 2,
   1.147 +        },
   1.148 +      ],
   1.149 +    }).then(testLiveFilteringOnSearchStrings);
   1.150 +  };
   1.151 +
   1.152 +  let form = content.document.querySelector("form");
   1.153 +  ok(form, "we have the HTML form");
   1.154 +  form.submit();
   1.155 +}
   1.156 +
   1.157 +function testLiveFilteringOnSearchStrings() {
   1.158 +  setStringFilter("http");
   1.159 +  isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
   1.160 +    "search string is set to \"http\"");
   1.161 +
   1.162 +  setStringFilter("HTTP");
   1.163 +  isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
   1.164 +    "search string is set to \"HTTP\"");
   1.165 +
   1.166 +  setStringFilter("hxxp");
   1.167 +  is(countMessageNodes(), 0, "the log nodes are hidden when the search " +
   1.168 +    "string is set to \"hxxp\"");
   1.169 +
   1.170 +  setStringFilter("ht tp");
   1.171 +  isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
   1.172 +    "search string is set to \"ht tp\"");
   1.173 +
   1.174 +  setStringFilter("");
   1.175 +  isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
   1.176 +    "search string is removed");
   1.177 +
   1.178 +  setStringFilter("json");
   1.179 +  is(countMessageNodes(), 2, "the log nodes show only the nodes with \"json\"");
   1.180 +
   1.181 +  setStringFilter("'foo'");
   1.182 +  is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
   1.183 +    "the string 'foo'");
   1.184 +
   1.185 +  setStringFilter("foo\"bar'baz\"boo'");
   1.186 +  is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
   1.187 +    "the string \"foo\"bar'baz\"boo'\"");
   1.188 +
   1.189 +  HUDService.lastFinishedRequest.callback = null;
   1.190 +  lastRequest = null;
   1.191 +  requestCallback = null;
   1.192 +  finishTest();
   1.193 +}
   1.194 +
   1.195 +function countMessageNodes() {
   1.196 +  let messageNodes = hud.outputNode.querySelectorAll(".message");
   1.197 +  let displayedMessageNodes = 0;
   1.198 +  let view = hud.iframeWindow;
   1.199 +  for (let i = 0; i < messageNodes.length; i++) {
   1.200 +    let computedStyle = view.getComputedStyle(messageNodes[i], null);
   1.201 +    if (computedStyle.display !== "none")
   1.202 +      displayedMessageNodes++;
   1.203 +  }
   1.204 +
   1.205 +  return displayedMessageNodes;
   1.206 +}
   1.207 +
   1.208 +function setStringFilter(aValue)
   1.209 +{
   1.210 +  hud.ui.filterBox.value = aValue;
   1.211 +  hud.ui.adjustVisibilityOnSearchStringChange();
   1.212 +}

mercurial