browser/devtools/markupview/test/browser_markupview_pagesize_01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 // Tests that the markup view loads only as many nodes as specified by the
michael@0 8 // devtools.markup.pagesize preference.
michael@0 9
michael@0 10 Services.prefs.setIntPref("devtools.markup.pagesize", 5);
michael@0 11
michael@0 12 const TEST_URL = TEST_URL_ROOT + "doc_markup_pagesize_01.html";
michael@0 13 const TEST_DATA = [{
michael@0 14 desc: "Select the last item",
michael@0 15 selector: "#z",
michael@0 16 expected: "*more*vwxyz"
michael@0 17 }, {
michael@0 18 desc: "Select the first item",
michael@0 19 selector: "#a",
michael@0 20 expected: "abcde*more*"
michael@0 21 }, {
michael@0 22 desc: "Select the last item",
michael@0 23 selector: "#z",
michael@0 24 expected: "*more*vwxyz"
michael@0 25 }, {
michael@0 26 desc: "Select an already-visible item",
michael@0 27 selector: "#v",
michael@0 28 // Because "v" was already visible, we shouldn't have loaded
michael@0 29 // a different page.
michael@0 30 expected: "*more*vwxyz"
michael@0 31 }, {
michael@0 32 desc: "Verify childrenDirty reloads the page",
michael@0 33 selector: "#w",
michael@0 34 forceReload: true,
michael@0 35 // But now that we don't already have a loaded page, selecting
michael@0 36 // w should center around w.
michael@0 37 expected: "*more*uvwxy*more*"
michael@0 38 }];
michael@0 39
michael@0 40 let test = asyncTest(function*() {
michael@0 41 let {inspector} = yield addTab(TEST_URL).then(openInspector);
michael@0 42
michael@0 43 info("Start iterating through the test data");
michael@0 44 for (let step of TEST_DATA) {
michael@0 45 info("Start test: " + step.desc);
michael@0 46
michael@0 47 if (step.forceReload) {
michael@0 48 forceReload(inspector);
michael@0 49 }
michael@0 50 info("Selecting the node that corresponds to " + step.selector);
michael@0 51 yield selectNode(step.selector, inspector);
michael@0 52
michael@0 53 info("Checking that the right nodes are shwon");
michael@0 54 assertChildren(step.expected, inspector);
michael@0 55 }
michael@0 56
michael@0 57 info("Checking that clicking the more button loads everything");
michael@0 58 clickShowMoreNodes(inspector);
michael@0 59 yield inspector.markup._waitForChildren();
michael@0 60 assertChildren("abcdefghijklmnopqrstuvwxyz", inspector);
michael@0 61 });
michael@0 62
michael@0 63 function assertChildren(expected, inspector) {
michael@0 64 let container = getContainerForRawNode("body", inspector);
michael@0 65 let found = "";
michael@0 66 for (let child of container.children.children) {
michael@0 67 if (child.classList.contains("more-nodes")) {
michael@0 68 found += "*more*";
michael@0 69 } else {
michael@0 70 found += child.container.node.getAttribute("id");
michael@0 71 }
michael@0 72 }
michael@0 73 is(found, expected, "Got the expected children.");
michael@0 74 }
michael@0 75
michael@0 76 function forceReload(inspector) {
michael@0 77 let container = getContainerForRawNode("body", inspector);
michael@0 78 container.childrenDirty = true;
michael@0 79 }
michael@0 80
michael@0 81 function clickShowMoreNodes(inspector) {
michael@0 82 let container = getContainerForRawNode("body", inspector);
michael@0 83 let button = container.elt.querySelector("button");
michael@0 84 let win = button.ownerDocument.defaultView;
michael@0 85 EventUtils.sendMouseEvent({type: "click"}, button, win);
michael@0 86 }

mercurial