summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js
blob: b66d5afff2700830eef76e061875a7bdeea0a7f6 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URI = "data:text/html;charset=utf8,Test that the web console " +
                 "displays requests that have been recorded in the " +
                 "netmonitor, even if the console hadn't opened yet.";

const TEST_FILE = "test-network-request.html";
const TEST_PATH = "http://example.com/browser/devtools/client/webconsole/" +
                  "test/" + TEST_FILE;

const NET_PREF = "devtools.webconsole.filter.networkinfo";
Services.prefs.setBoolPref(NET_PREF, true);
registerCleanupFunction(() => {
  Services.prefs.clearUserPref(NET_PREF);
});

add_task(function* () {
  let { tab, browser } = yield loadTab(TEST_URI);

  let target = TargetFactory.forTab(tab);
  let toolbox = yield gDevTools.showToolbox(target, "netmonitor");
  info("Network panel is open.");

  yield loadDocument(browser);
  info("Document loaded.");

  // Test that the request appears in the network panel.
  testNetmonitor(toolbox);

  // Test that the request appears in the console.
  let hud = yield openConsole();
  info("Web console is open");

  yield waitForMessages({
    webconsole: hud,
    messages: [
      {
        name: "network message",
        text: TEST_FILE,
        category: CATEGORY_NETWORK,
        severity: SEVERITY_LOG
      }
    ]
  });
});

function loadDocument(browser) {
  let deferred = promise.defer();

  browser.addEventListener("load", function onLoad() {
    browser.removeEventListener("load", onLoad, true);
    deferred.resolve();
  }, true);
  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_PATH);

  return deferred.promise;
}

function testNetmonitor(toolbox) {
  let monitor = toolbox.getCurrentPanel();
  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
  RequestsMenu.lazyUpdate = false;
  is(RequestsMenu.itemCount, 1, "Network request appears in the network panel");

  let item = RequestsMenu.getItemAtIndex(0);
  is(item.attachment.method, "GET", "The attached method is correct.");
  is(item.attachment.url, TEST_PATH, "The attached url is correct.");
}