1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/markupview/test/browser_markupview_pagesize_01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* vim: set ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +// Tests that the markup view loads only as many nodes as specified by the 1.11 +// devtools.markup.pagesize preference. 1.12 + 1.13 +Services.prefs.setIntPref("devtools.markup.pagesize", 5); 1.14 + 1.15 +const TEST_URL = TEST_URL_ROOT + "doc_markup_pagesize_01.html"; 1.16 +const TEST_DATA = [{ 1.17 + desc: "Select the last item", 1.18 + selector: "#z", 1.19 + expected: "*more*vwxyz" 1.20 +}, { 1.21 + desc: "Select the first item", 1.22 + selector: "#a", 1.23 + expected: "abcde*more*" 1.24 +}, { 1.25 + desc: "Select the last item", 1.26 + selector: "#z", 1.27 + expected: "*more*vwxyz" 1.28 +}, { 1.29 + desc: "Select an already-visible item", 1.30 + selector: "#v", 1.31 + // Because "v" was already visible, we shouldn't have loaded 1.32 + // a different page. 1.33 + expected: "*more*vwxyz" 1.34 +}, { 1.35 + desc: "Verify childrenDirty reloads the page", 1.36 + selector: "#w", 1.37 + forceReload: true, 1.38 + // But now that we don't already have a loaded page, selecting 1.39 + // w should center around w. 1.40 + expected: "*more*uvwxy*more*" 1.41 +}]; 1.42 + 1.43 +let test = asyncTest(function*() { 1.44 + let {inspector} = yield addTab(TEST_URL).then(openInspector); 1.45 + 1.46 + info("Start iterating through the test data"); 1.47 + for (let step of TEST_DATA) { 1.48 + info("Start test: " + step.desc); 1.49 + 1.50 + if (step.forceReload) { 1.51 + forceReload(inspector); 1.52 + } 1.53 + info("Selecting the node that corresponds to " + step.selector); 1.54 + yield selectNode(step.selector, inspector); 1.55 + 1.56 + info("Checking that the right nodes are shwon"); 1.57 + assertChildren(step.expected, inspector); 1.58 + } 1.59 + 1.60 + info("Checking that clicking the more button loads everything"); 1.61 + clickShowMoreNodes(inspector); 1.62 + yield inspector.markup._waitForChildren(); 1.63 + assertChildren("abcdefghijklmnopqrstuvwxyz", inspector); 1.64 +}); 1.65 + 1.66 +function assertChildren(expected, inspector) { 1.67 + let container = getContainerForRawNode("body", inspector); 1.68 + let found = ""; 1.69 + for (let child of container.children.children) { 1.70 + if (child.classList.contains("more-nodes")) { 1.71 + found += "*more*"; 1.72 + } else { 1.73 + found += child.container.node.getAttribute("id"); 1.74 + } 1.75 + } 1.76 + is(found, expected, "Got the expected children."); 1.77 +} 1.78 + 1.79 +function forceReload(inspector) { 1.80 + let container = getContainerForRawNode("body", inspector); 1.81 + container.childrenDirty = true; 1.82 +} 1.83 + 1.84 +function clickShowMoreNodes(inspector) { 1.85 + let container = getContainerForRawNode("body", inspector); 1.86 + let button = container.elt.querySelector("button"); 1.87 + let win = button.ownerDocument.defaultView; 1.88 + EventUtils.sendMouseEvent({type: "click"}, button, win); 1.89 +}