summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_pagesize_01.js
blob: a9ba9fc050f56461b335bd101e03018c329f398a (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
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the markup view loads only as many nodes as specified by the
// devtools.markup.pagesize preference.

Services.prefs.setIntPref("devtools.markup.pagesize", 5);

const TEST_URL = URL_ROOT + "doc_markup_pagesize_01.html";
const TEST_DATA = [{
  desc: "Select the last item",
  selector: "#z",
  expected: "*more*vwxyz"
}, {
  desc: "Select the first item",
  selector: "#a",
  expected: "abcde*more*"
}, {
  desc: "Select the last item",
  selector: "#z",
  expected: "*more*vwxyz"
}, {
  desc: "Select an already-visible item",
  selector: "#v",
  // Because "v" was already visible, we shouldn't have loaded
  // a different page.
  expected: "*more*vwxyz"
}, {
  desc: "Verify childrenDirty reloads the page",
  selector: "#w",
  forceReload: true,
  // But now that we don't already have a loaded page, selecting
  // w should center around w.
  expected: "*more*uvwxy*more*"
}];

add_task(function* () {
  let {inspector} = yield openInspectorForURL(TEST_URL);

  info("Start iterating through the test data");
  for (let step of TEST_DATA) {
    info("Start test: " + step.desc);

    if (step.forceReload) {
      yield forceReload(inspector);
    }
    info("Selecting the node that corresponds to " + step.selector);
    yield selectNode(step.selector, inspector);

    info("Checking that the right nodes are shwon");
    yield assertChildren(step.expected, inspector);
  }

  info("Checking that clicking the more button loads everything");
  yield clickShowMoreNodes(inspector);
  yield inspector.markup._waitForChildren();
  yield assertChildren("abcdefghijklmnopqrstuvwxyz", inspector);
});

function* assertChildren(expected, inspector) {
  let container = yield getContainerForSelector("body", inspector);
  let found = "";
  for (let child of container.children.children) {
    if (child.classList.contains("more-nodes")) {
      found += "*more*";
    } else {
      found += child.container.node.getAttribute("id");
    }
  }
  is(found, expected, "Got the expected children.");
}

function* forceReload(inspector) {
  let container = yield getContainerForSelector("body", inspector);
  container.childrenDirty = true;
}

function* clickShowMoreNodes(inspector) {
  let container = yield getContainerForSelector("body", inspector);
  let button = container.elt.querySelector("button");
  let win = button.ownerDocument.defaultView;
  EventUtils.sendMouseEvent({type: "click"}, button, win);
}