summaryrefslogtreecommitdiff
path: root/browser/devtools/webconsole/test/browser_webconsole_bug_599725_response_headers.js
blob: a913f5e0ca1dd4ffa979ca70fdf37245b1a0afe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 *
 * Contributor(s):
 *  Mihai Șucan <mihai.sucan@gmail.com>
 *
 * ***** END LICENSE BLOCK ***** */

const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-599725-response-headers.sjs";

let loads = 0;
function performTest(aRequest, aConsole)
{
  loads++;
  ok(aRequest, "page load was logged");
  if (loads != 2) {
    return;
  }

  let headers = null;

  function readHeader(aName)
  {
    for (let header of headers) {
      if (header.name == aName) {
        return header.value;
      }
    }
    return null;
  }

  aConsole.webConsoleClient.getResponseHeaders(aRequest.actor,
    function (aResponse) {
      headers = aResponse.headers;
      ok(headers, "we have the response headers for reload");

      let contentType = readHeader("Content-Type");
      let contentLength = readHeader("Content-Length");

      ok(!contentType, "we do not have the Content-Type header");
      isnot(contentLength, 60, "Content-Length != 60");

      if (contentType || contentLength == 60) {
        console.debug("lastFinishedRequest", lastFinishedRequest,
                      "request", lastFinishedRequest.request,
                      "response", lastFinishedRequest.response,
                      "updates", lastFinishedRequest.updates,
                      "response headers", headers);
      }

      executeSoon(finishTest);
    });

  HUDService.lastFinishedRequestCallback = null;
}

function test()
{
  addTab("data:text/plain;charset=utf8,hello world");

  browser.addEventListener("load", function onLoad() {
    browser.removeEventListener("load", onLoad, true);
    openConsole(null, () => {
      HUDService.lastFinishedRequestCallback = performTest;

      browser.addEventListener("load", function onReload() {
        browser.removeEventListener("load", onReload, true);
        executeSoon(() => content.location.reload());
      }, true);

      executeSoon(() => content.location = TEST_URI);
    });
  }, true);
}