1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_599725_response_headers.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* ***** BEGIN LICENSE BLOCK ***** 1.6 + * Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.8 + * 1.9 + * Contributor(s): 1.10 + * Mihai Șucan <mihai.sucan@gmail.com> 1.11 + * 1.12 + * ***** END LICENSE BLOCK ***** */ 1.13 + 1.14 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-599725-response-headers.sjs"; 1.15 + 1.16 +let loads = 0; 1.17 +function performTest(aRequest, aConsole) 1.18 +{ 1.19 + loads++; 1.20 + ok(aRequest, "page load was logged"); 1.21 + if (loads != 2) { 1.22 + return; 1.23 + } 1.24 + 1.25 + let headers = null; 1.26 + 1.27 + function readHeader(aName) 1.28 + { 1.29 + for (let header of headers) { 1.30 + if (header.name == aName) { 1.31 + return header.value; 1.32 + } 1.33 + } 1.34 + return null; 1.35 + } 1.36 + 1.37 + aConsole.webConsoleClient.getResponseHeaders(aRequest.actor, 1.38 + function (aResponse) { 1.39 + headers = aResponse.headers; 1.40 + ok(headers, "we have the response headers for reload"); 1.41 + 1.42 + let contentType = readHeader("Content-Type"); 1.43 + let contentLength = readHeader("Content-Length"); 1.44 + 1.45 + ok(!contentType, "we do not have the Content-Type header"); 1.46 + isnot(contentLength, 60, "Content-Length != 60"); 1.47 + 1.48 + if (contentType || contentLength == 60) { 1.49 + console.debug("lastFinishedRequest", lastFinishedRequest, 1.50 + "request", lastFinishedRequest.request, 1.51 + "response", lastFinishedRequest.response, 1.52 + "updates", lastFinishedRequest.updates, 1.53 + "response headers", headers); 1.54 + } 1.55 + 1.56 + executeSoon(finishTest); 1.57 + }); 1.58 + 1.59 + HUDService.lastFinishedRequest.callback = null; 1.60 +} 1.61 + 1.62 +function test() 1.63 +{ 1.64 + addTab("data:text/plain;charset=utf8,hello world"); 1.65 + 1.66 + browser.addEventListener("load", function onLoad() { 1.67 + browser.removeEventListener("load", onLoad, true); 1.68 + openConsole(null, () => { 1.69 + HUDService.lastFinishedRequest.callback = performTest; 1.70 + 1.71 + browser.addEventListener("load", function onReload() { 1.72 + browser.removeEventListener("load", onReload, true); 1.73 + executeSoon(() => content.location.reload()); 1.74 + }, true); 1.75 + 1.76 + executeSoon(() => content.location = TEST_URI); 1.77 + }); 1.78 + }, true); 1.79 +}