summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_webconsole_netlogging_reset_filter.js
blob: 265bc7c0022ee8ba3b9a2d042ffec1b4de175158 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* -*- 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/ */

// Tests that network log messages bring up the network panel and select the
// right request even if it was previously filtered off.

"use strict";

const TEST_FILE_URI =
  "http://example.com/browser/devtools/client/webconsole/test/" +
  "test-network.html";
const TEST_URI = "data:text/html;charset=utf8,<p>test file URI";

var hud;

add_task(function* () {
  let Actions = require("devtools/client/netmonitor/actions/index");

  let requests = [];
  let { browser } = yield loadTab(TEST_URI);

  yield pushPrefEnv();
  hud = yield openConsole();
  hud.jsterm.clearOutput();

  HUDService.lastFinishedRequest.callback = request => requests.push(request);

  let loaded = loadBrowser(browser);
  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_FILE_URI);
  yield loaded;

  yield testMessages();
  let htmlRequest = requests.find(e => e.request.url.endsWith("html"));
  ok(htmlRequest, "htmlRequest was a html");

  yield hud.ui.openNetworkPanel(htmlRequest.actor);
  let toolbox = gDevTools.getToolbox(hud.target);
  is(toolbox.currentToolId, "netmonitor", "Network panel was opened");

  let panel = toolbox.getCurrentPanel();
  let selected = panel.panelWin.NetMonitorView.RequestsMenu.selectedItem;
  is(selected.attachment.method, htmlRequest.request.method,
     "The correct request is selected");
  is(selected.attachment.url, htmlRequest.request.url,
     "The correct request is definitely selected");

  // Filter out the HTML request.
  panel.panelWin.gStore.dispatch(Actions.toggleFilterType("js"));

  yield toolbox.selectTool("webconsole");
  is(toolbox.currentToolId, "webconsole", "Web console was selected");
  yield hud.ui.openNetworkPanel(htmlRequest.actor);

  panel.panelWin.NetMonitorView.RequestsMenu.selectedItem;
  is(selected.attachment.method, htmlRequest.request.method,
     "The correct request is selected");
  is(selected.attachment.url, htmlRequest.request.url,
     "The correct request is definitely selected");

  // All tests are done. Shutdown.
  HUDService.lastFinishedRequest.callback = null;
  htmlRequest = browser = requests = hud = null;
});

function testMessages() {
  return waitForMessages({
    webconsole: hud,
    messages: [{
      text: "running network console logging tests",
      category: CATEGORY_WEBDEV,
      severity: SEVERITY_LOG,
    },
    {
      text: "test-network.html",
      category: CATEGORY_NETWORK,
      severity: SEVERITY_LOG,
    },
    {
      text: "testscript.js",
      category: CATEGORY_NETWORK,
      severity: SEVERITY_LOG,
    }],
  });
}

function pushPrefEnv() {
  let deferred = promise.defer();
  let options = {
    set: [["devtools.webconsole.filter.networkinfo", true]]
  };
  SpecialPowers.pushPrefEnv(options, deferred.resolve);
  return deferred.promise;
}