Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Test that locking the pseudoclass displays correctly in the ruleview |
michael@0 | 5 | |
michael@0 | 6 | let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); |
michael@0 | 7 | const PSEUDO = ":hover"; |
michael@0 | 8 | const TEST_URL = 'data:text/html,' + |
michael@0 | 9 | '<head>' + |
michael@0 | 10 | ' <style>div {color:red;} div:hover {color:blue;}</style>' + |
michael@0 | 11 | '</head>' + |
michael@0 | 12 | '<body>' + |
michael@0 | 13 | ' <div id="parent-div">' + |
michael@0 | 14 | ' <div id="div-1">test div</div>' + |
michael@0 | 15 | ' <div id="div-2">test div2</div>' + |
michael@0 | 16 | ' </div>' + |
michael@0 | 17 | '</body>'; |
michael@0 | 18 | |
michael@0 | 19 | waitForExplicitFinish(); |
michael@0 | 20 | |
michael@0 | 21 | function test() { |
michael@0 | 22 | ignoreAllUncaughtExceptions(); |
michael@0 | 23 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 24 | gBrowser.selectedBrowser.addEventListener("load", function() { |
michael@0 | 25 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 26 | waitForFocus(startTests, content); |
michael@0 | 27 | }, true); |
michael@0 | 28 | |
michael@0 | 29 | content.location = TEST_URL; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | let startTests = Task.async(function*() { |
michael@0 | 33 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 34 | yield selectNode("#div-1", inspector); |
michael@0 | 35 | |
michael@0 | 36 | yield performTests(inspector, view); |
michael@0 | 37 | |
michael@0 | 38 | yield finishUp(toolbox); |
michael@0 | 39 | finish(); |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | function* performTests(inspector, ruleview) { |
michael@0 | 43 | yield togglePseudoClass(inspector); |
michael@0 | 44 | yield testAdded(inspector, ruleview); |
michael@0 | 45 | |
michael@0 | 46 | yield togglePseudoClass(inspector); |
michael@0 | 47 | yield testRemoved(); |
michael@0 | 48 | yield testRemovedFromUI(inspector, ruleview); |
michael@0 | 49 | |
michael@0 | 50 | yield togglePseudoClass(inspector); |
michael@0 | 51 | yield testNavigate(inspector, ruleview); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function* togglePseudoClass(inspector) { |
michael@0 | 55 | info("Toggle the pseudoclass, wait for the pseudoclass event and wait for the refresh of the rule view"); |
michael@0 | 56 | |
michael@0 | 57 | let onPseudo = inspector.selection.once("pseudoclass"); |
michael@0 | 58 | let onRefresh = inspector.once("rule-view-refreshed"); |
michael@0 | 59 | inspector.togglePseudoClass(PSEUDO); |
michael@0 | 60 | |
michael@0 | 61 | yield onPseudo; |
michael@0 | 62 | yield onRefresh; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function* testNavigate(inspector, ruleview) { |
michael@0 | 66 | yield selectNode("#parent-div", inspector); |
michael@0 | 67 | |
michael@0 | 68 | info("Make sure the pseudoclass is still on after navigating to a parent"); |
michael@0 | 69 | is(DOMUtils.hasPseudoClassLock(getNode("#div-1"), PSEUDO), true, |
michael@0 | 70 | "pseudo-class lock is still applied after inspecting ancestor"); |
michael@0 | 71 | |
michael@0 | 72 | let onPseudo = inspector.selection.once("pseudoclass"); |
michael@0 | 73 | yield selectNode("#div-2", inspector); |
michael@0 | 74 | yield onPseudo; |
michael@0 | 75 | |
michael@0 | 76 | info("Make sure the pseudoclass is removed after navigating to a non-hierarchy node"); |
michael@0 | 77 | is(DOMUtils.hasPseudoClassLock(getNode("#div-1"), PSEUDO), false, |
michael@0 | 78 | "pseudo-class lock is removed after inspecting sibling node"); |
michael@0 | 79 | |
michael@0 | 80 | yield selectNode("#div-1", inspector); |
michael@0 | 81 | yield togglePseudoClass(inspector); |
michael@0 | 82 | yield inspector.once("computed-view-refreshed"); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function showPickerOn(node, inspector) { |
michael@0 | 86 | let highlighter = inspector.toolbox.highlighter; |
michael@0 | 87 | return highlighter.showBoxModel(getNodeFront(node)); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function* testAdded(inspector, ruleview) { |
michael@0 | 91 | info("Make sure the pseudoclass lock is applied to #div-1 and its ancestors"); |
michael@0 | 92 | let node = getNode("#div-1"); |
michael@0 | 93 | do { |
michael@0 | 94 | is(DOMUtils.hasPseudoClassLock(node, PSEUDO), true, |
michael@0 | 95 | "pseudo-class lock has been applied"); |
michael@0 | 96 | node = node.parentNode; |
michael@0 | 97 | } while (node.parentNode) |
michael@0 | 98 | |
michael@0 | 99 | info("Check that the ruleview contains the pseudo-class rule"); |
michael@0 | 100 | let rules = ruleview.element.querySelectorAll(".ruleview-rule.theme-separator"); |
michael@0 | 101 | is(rules.length, 3, "rule view is showing 3 rules for pseudo-class locked div"); |
michael@0 | 102 | is(rules[1]._ruleEditor.rule.selectorText, "div:hover", "rule view is showing " + PSEUDO + " rule"); |
michael@0 | 103 | |
michael@0 | 104 | info("Show the highlighter on #div-1"); |
michael@0 | 105 | yield showPickerOn(getNode("#div-1"), inspector); |
michael@0 | 106 | |
michael@0 | 107 | info("Check that the infobar selector contains the pseudo-class"); |
michael@0 | 108 | let pseudoClassesBox = getHighlighter().querySelector(".highlighter-nodeinfobar-pseudo-classes"); |
michael@0 | 109 | is(pseudoClassesBox.textContent, PSEUDO, "pseudo-class in infobar selector"); |
michael@0 | 110 | yield inspector.toolbox.highlighter.hideBoxModel(); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function* testRemoved() { |
michael@0 | 114 | info("Make sure the pseudoclass lock is removed from #div-1 and its ancestors"); |
michael@0 | 115 | let node = getNode("#div-1"); |
michael@0 | 116 | do { |
michael@0 | 117 | is(DOMUtils.hasPseudoClassLock(node, PSEUDO), false, |
michael@0 | 118 | "pseudo-class lock has been removed"); |
michael@0 | 119 | node = node.parentNode; |
michael@0 | 120 | } while (node.parentNode) |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | function* testRemovedFromUI(inspector, ruleview) { |
michael@0 | 124 | info("Check that the ruleview no longer contains the pseudo-class rule"); |
michael@0 | 125 | let rules = ruleview.element.querySelectorAll(".ruleview-rule.theme-separator"); |
michael@0 | 126 | is(rules.length, 2, "rule view is showing 2 rules after removing lock"); |
michael@0 | 127 | |
michael@0 | 128 | yield showPickerOn(getNode("#div-1"), inspector); |
michael@0 | 129 | |
michael@0 | 130 | let pseudoClassesBox = getHighlighter().querySelector(".highlighter-nodeinfobar-pseudo-classes"); |
michael@0 | 131 | is(pseudoClassesBox.textContent, "", "pseudo-class removed from infobar selector"); |
michael@0 | 132 | yield inspector.toolbox.highlighter.hideBoxModel(); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function* finishUp(toolbox) { |
michael@0 | 136 | let onDestroy = gDevTools.once("toolbox-destroyed"); |
michael@0 | 137 | toolbox.destroy(); |
michael@0 | 138 | yield onDestroy; |
michael@0 | 139 | |
michael@0 | 140 | yield testRemoved(getNode("#div-1")); |
michael@0 | 141 | gBrowser.removeCurrentTab(); |
michael@0 | 142 | } |