browser/devtools/webconsole/test/browser_webconsole_bug_632817.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 // Tests that network log messages bring up the network panel.
michael@0 6
michael@0 7 const TEST_NETWORK_REQUEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-network-request.html";
michael@0 8
michael@0 9 const TEST_IMG = "http://example.com/browser/browser/devtools/webconsole/test/test-image.png";
michael@0 10
michael@0 11 const TEST_DATA_JSON_CONTENT =
michael@0 12 '{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
michael@0 13
michael@0 14 let lastRequest = null;
michael@0 15 let requestCallback = null;
michael@0 16
michael@0 17 function test()
michael@0 18 {
michael@0 19 const PREF = "devtools.webconsole.persistlog";
michael@0 20 let original = Services.prefs.getBoolPref("devtools.webconsole.filter.networkinfo");
michael@0 21 Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true);
michael@0 22 Services.prefs.setBoolPref(PREF, true);
michael@0 23 registerCleanupFunction(() => {
michael@0 24 Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", original);
michael@0 25 Services.prefs.clearUserPref(PREF);
michael@0 26 });
michael@0 27
michael@0 28 addTab("data:text/html;charset=utf-8,Web Console network logging tests");
michael@0 29
michael@0 30 browser.addEventListener("load", function onLoad() {
michael@0 31 browser.removeEventListener("load", onLoad, true);
michael@0 32
michael@0 33 openConsole(null, function(aHud) {
michael@0 34 hud = aHud;
michael@0 35
michael@0 36 HUDService.lastFinishedRequest.callback = function(aRequest) {
michael@0 37 lastRequest = aRequest;
michael@0 38 if (requestCallback) {
michael@0 39 requestCallback();
michael@0 40 }
michael@0 41 };
michael@0 42
michael@0 43 executeSoon(testPageLoad);
michael@0 44 });
michael@0 45 }, true);
michael@0 46 }
michael@0 47
michael@0 48 function testPageLoad()
michael@0 49 {
michael@0 50 requestCallback = function() {
michael@0 51 // Check if page load was logged correctly.
michael@0 52 ok(lastRequest, "Page load was logged");
michael@0 53 is(lastRequest.request.url, TEST_NETWORK_REQUEST_URI,
michael@0 54 "Logged network entry is page load");
michael@0 55 is(lastRequest.request.method, "GET", "Method is correct");
michael@0 56 lastRequest = null;
michael@0 57 requestCallback = null;
michael@0 58 executeSoon(testPageLoadBody);
michael@0 59 };
michael@0 60
michael@0 61 content.location = TEST_NETWORK_REQUEST_URI;
michael@0 62 }
michael@0 63
michael@0 64 function testPageLoadBody()
michael@0 65 {
michael@0 66 let loaded = false;
michael@0 67 let requestCallbackInvoked = false;
michael@0 68
michael@0 69 // Turn off logging of request bodies and check again.
michael@0 70 requestCallback = function() {
michael@0 71 ok(lastRequest, "Page load was logged again");
michael@0 72 lastRequest = null;
michael@0 73 requestCallback = null;
michael@0 74 requestCallbackInvoked = true;
michael@0 75
michael@0 76 if (loaded) {
michael@0 77 executeSoon(testXhrGet);
michael@0 78 }
michael@0 79 };
michael@0 80
michael@0 81 browser.addEventListener("load", function onLoad() {
michael@0 82 browser.removeEventListener("load", onLoad, true);
michael@0 83 loaded = true;
michael@0 84
michael@0 85 if (requestCallbackInvoked) {
michael@0 86 executeSoon(testXhrGet);
michael@0 87 }
michael@0 88 }, true);
michael@0 89
michael@0 90 content.location.reload();
michael@0 91 }
michael@0 92
michael@0 93 function testXhrGet()
michael@0 94 {
michael@0 95 requestCallback = function() {
michael@0 96 ok(lastRequest, "testXhrGet() was logged");
michael@0 97 is(lastRequest.request.method, "GET", "Method is correct");
michael@0 98 lastRequest = null;
michael@0 99 requestCallback = null;
michael@0 100 executeSoon(testXhrPost);
michael@0 101 };
michael@0 102
michael@0 103 // Start the XMLHttpRequest() GET test.
michael@0 104 content.wrappedJSObject.testXhrGet();
michael@0 105 }
michael@0 106
michael@0 107 function testXhrPost()
michael@0 108 {
michael@0 109 requestCallback = function() {
michael@0 110 ok(lastRequest, "testXhrPost() was logged");
michael@0 111 is(lastRequest.request.method, "POST", "Method is correct");
michael@0 112 lastRequest = null;
michael@0 113 requestCallback = null;
michael@0 114 executeSoon(testFormSubmission);
michael@0 115 };
michael@0 116
michael@0 117 // Start the XMLHttpRequest() POST test.
michael@0 118 content.wrappedJSObject.testXhrPost();
michael@0 119 }
michael@0 120
michael@0 121 function testFormSubmission()
michael@0 122 {
michael@0 123 // Start the form submission test. As the form is submitted, the page is
michael@0 124 // loaded again. Bind to the load event to catch when this is done.
michael@0 125 requestCallback = function() {
michael@0 126 ok(lastRequest, "testFormSubmission() was logged");
michael@0 127 is(lastRequest.request.method, "POST", "Method is correct");
michael@0 128
michael@0 129 // There should be 3 network requests pointing to the HTML file.
michael@0 130 waitForMessages({
michael@0 131 webconsole: hud,
michael@0 132 messages: [
michael@0 133 {
michael@0 134 text: "test-network-request.html",
michael@0 135 category: CATEGORY_NETWORK,
michael@0 136 severity: SEVERITY_LOG,
michael@0 137 count: 3,
michael@0 138 },
michael@0 139 {
michael@0 140 text: "test-data.json",
michael@0 141 category: CATEGORY_NETWORK,
michael@0 142 severity: SEVERITY_LOG,
michael@0 143 count: 2,
michael@0 144 },
michael@0 145 ],
michael@0 146 }).then(testLiveFilteringOnSearchStrings);
michael@0 147 };
michael@0 148
michael@0 149 let form = content.document.querySelector("form");
michael@0 150 ok(form, "we have the HTML form");
michael@0 151 form.submit();
michael@0 152 }
michael@0 153
michael@0 154 function testLiveFilteringOnSearchStrings() {
michael@0 155 setStringFilter("http");
michael@0 156 isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
michael@0 157 "search string is set to \"http\"");
michael@0 158
michael@0 159 setStringFilter("HTTP");
michael@0 160 isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
michael@0 161 "search string is set to \"HTTP\"");
michael@0 162
michael@0 163 setStringFilter("hxxp");
michael@0 164 is(countMessageNodes(), 0, "the log nodes are hidden when the search " +
michael@0 165 "string is set to \"hxxp\"");
michael@0 166
michael@0 167 setStringFilter("ht tp");
michael@0 168 isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
michael@0 169 "search string is set to \"ht tp\"");
michael@0 170
michael@0 171 setStringFilter("");
michael@0 172 isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
michael@0 173 "search string is removed");
michael@0 174
michael@0 175 setStringFilter("json");
michael@0 176 is(countMessageNodes(), 2, "the log nodes show only the nodes with \"json\"");
michael@0 177
michael@0 178 setStringFilter("'foo'");
michael@0 179 is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
michael@0 180 "the string 'foo'");
michael@0 181
michael@0 182 setStringFilter("foo\"bar'baz\"boo'");
michael@0 183 is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
michael@0 184 "the string \"foo\"bar'baz\"boo'\"");
michael@0 185
michael@0 186 HUDService.lastFinishedRequest.callback = null;
michael@0 187 lastRequest = null;
michael@0 188 requestCallback = null;
michael@0 189 finishTest();
michael@0 190 }
michael@0 191
michael@0 192 function countMessageNodes() {
michael@0 193 let messageNodes = hud.outputNode.querySelectorAll(".message");
michael@0 194 let displayedMessageNodes = 0;
michael@0 195 let view = hud.iframeWindow;
michael@0 196 for (let i = 0; i < messageNodes.length; i++) {
michael@0 197 let computedStyle = view.getComputedStyle(messageNodes[i], null);
michael@0 198 if (computedStyle.display !== "none")
michael@0 199 displayedMessageNodes++;
michael@0 200 }
michael@0 201
michael@0 202 return displayedMessageNodes;
michael@0 203 }
michael@0 204
michael@0 205 function setStringFilter(aValue)
michael@0 206 {
michael@0 207 hud.ui.filterBox.value = aValue;
michael@0 208 hud.ui.adjustVisibilityOnSearchStringChange();
michael@0 209 }

mercurial