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 | /* vim: set ft=javascript 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 | // Test that changing the current element's attributes refreshes the rule-view |
michael@0 | 8 | |
michael@0 | 9 | let test = asyncTest(function*() { |
michael@0 | 10 | yield addTab("data:text/html;charset=utf-8,browser_ruleview_refresh-on-attribute-change.js"); |
michael@0 | 11 | |
michael@0 | 12 | info("Preparing the test document and node"); |
michael@0 | 13 | let style = '' + |
michael@0 | 14 | '#testid {' + |
michael@0 | 15 | ' background-color: blue;' + |
michael@0 | 16 | '} ' + |
michael@0 | 17 | '.testclass {' + |
michael@0 | 18 | ' background-color: green;' + |
michael@0 | 19 | '}'; |
michael@0 | 20 | let styleNode = addStyle(content.document, style); |
michael@0 | 21 | content.document.body.innerHTML = '<div id="testid" class="testclass">Styled Node</div>'; |
michael@0 | 22 | let testElement = getNode("#testid"); |
michael@0 | 23 | let elementStyle = 'margin-top: 1px; padding-top: 5px;' |
michael@0 | 24 | testElement.setAttribute("style", elementStyle); |
michael@0 | 25 | |
michael@0 | 26 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 27 | yield selectNode(testElement, inspector); |
michael@0 | 28 | |
michael@0 | 29 | info("Checking that the rule-view has the element, #testid and .testclass selectors"); |
michael@0 | 30 | checkRuleViewContent(view, ["element", "#testid", ".testclass"]); |
michael@0 | 31 | |
michael@0 | 32 | info("Changing the node's ID attribute and waiting for the rule-view refresh"); |
michael@0 | 33 | let ruleViewRefreshed = inspector.once("rule-view-refreshed"); |
michael@0 | 34 | testElement.setAttribute("id", "differentid"); |
michael@0 | 35 | yield ruleViewRefreshed; |
michael@0 | 36 | |
michael@0 | 37 | info("Checking that the rule-view doesn't have the #testid selector anymore"); |
michael@0 | 38 | checkRuleViewContent(view, ["element", ".testclass"]); |
michael@0 | 39 | |
michael@0 | 40 | info("Reverting the ID attribute change"); |
michael@0 | 41 | let ruleViewRefreshed = inspector.once("rule-view-refreshed"); |
michael@0 | 42 | testElement.setAttribute("id", "testid"); |
michael@0 | 43 | yield ruleViewRefreshed; |
michael@0 | 44 | |
michael@0 | 45 | info("Checking that the rule-view has all the selectors again"); |
michael@0 | 46 | checkRuleViewContent(view, ["element", "#testid", ".testclass"]); |
michael@0 | 47 | }); |
michael@0 | 48 | |
michael@0 | 49 | function checkRuleViewContent(view, expectedSelectors) { |
michael@0 | 50 | let selectors = view.doc.querySelectorAll(".ruleview-selector"); |
michael@0 | 51 | |
michael@0 | 52 | is(selectors.length, expectedSelectors.length, |
michael@0 | 53 | expectedSelectors.length + " selectors are displayed"); |
michael@0 | 54 | |
michael@0 | 55 | for (let i = 0; i < expectedSelectors.length; i ++) { |
michael@0 | 56 | is(selectors[i].textContent.indexOf(expectedSelectors[i]), 0, |
michael@0 | 57 | "Selector " + (i + 1) + " is " + expectedSelectors[i]); |
michael@0 | 58 | } |
michael@0 | 59 | } |