summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_webconsole_bug_653531_highlighter_console_helper.js
blob: 217d481e25d51178d6452a7b2d3e912cd838ea03 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -*- 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 the $0 console helper works as intended.

"use strict";

var inspector, h1, outputNode;

function createDocument() {
  let doc = content.document;
  let div = doc.createElement("div");
  h1 = doc.createElement("h1");
  let p1 = doc.createElement("p");
  let p2 = doc.createElement("p");
  let div2 = doc.createElement("div");
  let p3 = doc.createElement("p");
  doc.title = "Inspector Tree Selection Test";
  h1.textContent = "Inspector Tree Selection Test";
  p1.textContent = "This is some example text";
  p2.textContent = "Lorem ipsum dolor sit amet, consectetur adipisicing " +
    "elit, sed do eiusmod tempor incididunt ut labore et dolore magna " +
    "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
    "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
    "dolor in reprehenderit in voluptate velit esse cillum dolore eu " +
    "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
    "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
  p3.textContent = "Lorem ipsum dolor sit amet, consectetur adipisicing " +
    "elit, sed do eiusmod tempor incididunt ut labore et dolore magna " +
    "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
    "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
    "dolor in reprehenderit in voluptate velit esse cillum dolore eu " +
    "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
    "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
  div.appendChild(h1);
  div.appendChild(p1);
  div.appendChild(p2);
  div2.appendChild(p3);
  doc.body.appendChild(div);
  doc.body.appendChild(div2);
  setupHighlighterTests();
}

function setupHighlighterTests() {
  ok(h1, "we have the header node");
  openInspector().then(runSelectionTests);
}

var runSelectionTests = Task.async(function* (aInspector) {
  inspector = aInspector;

  let onPickerStarted = inspector.toolbox.once("picker-started");
  inspector.toolbox.highlighterUtils.startPicker();
  yield onPickerStarted;

  info("Picker mode started, now clicking on H1 to select that node");
  h1.scrollIntoView();
  let onPickerStopped = inspector.toolbox.once("picker-stopped");
  let onInspectorUpdated = inspector.once("inspector-updated");
  EventUtils.synthesizeMouseAtCenter(h1, {}, content);
  yield onPickerStopped;
  yield onInspectorUpdated;

  info("Picker mode stopped, H1 selected, now switching to the console");
  let hud = yield openConsole(gBrowser.selectedTab);

  performWebConsoleTests(hud);
});

function performWebConsoleTests(hud) {
  let jsterm = hud.jsterm;
  outputNode = hud.outputNode;

  jsterm.clearOutput();
  jsterm.execute("$0", onNodeOutput);

  function onNodeOutput(node) {
    isnot(node.textContent.indexOf("<h1>"), -1, "correct output for $0");

    jsterm.clearOutput();
    jsterm.execute("$0.textContent = 'bug653531'", onNodeUpdate);
  }

  function onNodeUpdate(node) {
    isnot(node.textContent.indexOf("bug653531"), -1,
          "correct output for $0.textContent");
    is(inspector.selection.node.textContent, "bug653531",
       "node successfully updated");

    inspector = h1 = outputNode = null;
    gBrowser.removeCurrentTab();
    finishTest();
  }
}

function test() {
  waitForExplicitFinish();

  gBrowser.selectedTab = gBrowser.addTab();
  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    waitForFocus(createDocument, content);
  }, true);

  BrowserTestUtils.loadURI(gBrowser.selectedBrowser,
    "data:text/html;charset=utf-8,test for highlighter helper in web console");
}