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 the display of overridden declarations in 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_override.js"); |
michael@0 | 11 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 12 | |
michael@0 | 13 | yield simpleOverride(inspector, view); |
michael@0 | 14 | yield partialOverride(inspector, view); |
michael@0 | 15 | yield importantOverride(inspector, view); |
michael@0 | 16 | yield disableOverride(inspector, view); |
michael@0 | 17 | }); |
michael@0 | 18 | |
michael@0 | 19 | function* createTestContent(inspector, style) { |
michael@0 | 20 | let onMutated = inspector.once("markupmutation"); |
michael@0 | 21 | let styleNode = addStyle(content.document, style); |
michael@0 | 22 | content.document.body.innerHTML = '<div id="testid" class="testclass">Styled Node</div>'; |
michael@0 | 23 | yield onMutated; |
michael@0 | 24 | yield selectNode("#testid", inspector); |
michael@0 | 25 | return styleNode; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function* simpleOverride(inspector, view) { |
michael@0 | 29 | let styleNode = yield createTestContent(inspector, '' + |
michael@0 | 30 | '#testid {' + |
michael@0 | 31 | ' background-color: blue;' + |
michael@0 | 32 | '} ' + |
michael@0 | 33 | '.testclass {' + |
michael@0 | 34 | ' background-color: green;' + |
michael@0 | 35 | '}'); |
michael@0 | 36 | |
michael@0 | 37 | let elementStyle = view._elementStyle; |
michael@0 | 38 | |
michael@0 | 39 | let idRule = elementStyle.rules[1]; |
michael@0 | 40 | let idProp = idRule.textProps[0]; |
michael@0 | 41 | is(idProp.name, "background-color", "First ID prop should be background-color"); |
michael@0 | 42 | ok(!idProp.overridden, "ID prop should not be overridden."); |
michael@0 | 43 | |
michael@0 | 44 | let classRule = elementStyle.rules[2]; |
michael@0 | 45 | let classProp = classRule.textProps[0]; |
michael@0 | 46 | is(classProp.name, "background-color", "First class prop should be background-color"); |
michael@0 | 47 | ok(classProp.overridden, "Class property should be overridden."); |
michael@0 | 48 | |
michael@0 | 49 | // Override background-color by changing the element style. |
michael@0 | 50 | let elementRule = elementStyle.rules[0]; |
michael@0 | 51 | elementRule.createProperty("background-color", "purple", ""); |
michael@0 | 52 | yield elementRule._applyingModifications; |
michael@0 | 53 | |
michael@0 | 54 | let elementProp = elementRule.textProps[0]; |
michael@0 | 55 | is(classProp.name, "background-color", "First element prop should now be background-color"); |
michael@0 | 56 | ok(!elementProp.overridden, "Element style property should not be overridden"); |
michael@0 | 57 | ok(idProp.overridden, "ID property should be overridden"); |
michael@0 | 58 | ok(classProp.overridden, "Class property should be overridden"); |
michael@0 | 59 | |
michael@0 | 60 | styleNode.remove(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function* partialOverride(inspector, view) { |
michael@0 | 64 | let styleNode = yield createTestContent(inspector, '' + |
michael@0 | 65 | // Margin shorthand property... |
michael@0 | 66 | '.testclass {' + |
michael@0 | 67 | ' margin: 2px;' + |
michael@0 | 68 | '}' + |
michael@0 | 69 | // ... will be partially overridden. |
michael@0 | 70 | '#testid {' + |
michael@0 | 71 | ' margin-left: 1px;' + |
michael@0 | 72 | '}'); |
michael@0 | 73 | |
michael@0 | 74 | let elementStyle = view._elementStyle; |
michael@0 | 75 | |
michael@0 | 76 | let classRule = elementStyle.rules[2]; |
michael@0 | 77 | let classProp = classRule.textProps[0]; |
michael@0 | 78 | ok(!classProp.overridden, |
michael@0 | 79 | "Class prop shouldn't be overridden, some props are still being used."); |
michael@0 | 80 | |
michael@0 | 81 | for (let computed of classProp.computed) { |
michael@0 | 82 | if (computed.name.indexOf("margin-left") == 0) { |
michael@0 | 83 | ok(computed.overridden, "margin-left props should be overridden."); |
michael@0 | 84 | } else { |
michael@0 | 85 | ok(!computed.overridden, "Non-margin-left props should not be overridden."); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | styleNode.remove(); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function* importantOverride(inspector, view) { |
michael@0 | 93 | let styleNode = yield createTestContent(inspector, '' + |
michael@0 | 94 | // Margin shorthand property... |
michael@0 | 95 | '.testclass {' + |
michael@0 | 96 | ' background-color: green !important;' + |
michael@0 | 97 | '}' + |
michael@0 | 98 | // ... will be partially overridden. |
michael@0 | 99 | '#testid {' + |
michael@0 | 100 | ' background-color: blue;' + |
michael@0 | 101 | '}'); |
michael@0 | 102 | |
michael@0 | 103 | let elementStyle = view._elementStyle; |
michael@0 | 104 | |
michael@0 | 105 | let idRule = elementStyle.rules[1]; |
michael@0 | 106 | let idProp = idRule.textProps[0]; |
michael@0 | 107 | ok(idProp.overridden, "Not-important rule should be overridden."); |
michael@0 | 108 | |
michael@0 | 109 | let classRule = elementStyle.rules[2]; |
michael@0 | 110 | let classProp = classRule.textProps[0]; |
michael@0 | 111 | ok(!classProp.overridden, "Important rule should not be overridden."); |
michael@0 | 112 | |
michael@0 | 113 | styleNode.remove(); |
michael@0 | 114 | |
michael@0 | 115 | let elementRule = elementStyle.rules[0]; |
michael@0 | 116 | let elementProp = elementRule.createProperty("background-color", "purple", "important"); |
michael@0 | 117 | yield elementRule._applyingModifications; |
michael@0 | 118 | |
michael@0 | 119 | ok(classProp.overridden, "New important prop should override class property."); |
michael@0 | 120 | ok(!elementProp.overridden, "New important prop should not be overriden."); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | function* disableOverride(inspector, view) { |
michael@0 | 124 | let styleNode = yield createTestContent(inspector, '' + |
michael@0 | 125 | '#testid {' + |
michael@0 | 126 | ' background-color: blue;' + |
michael@0 | 127 | '}' + |
michael@0 | 128 | '.testclass {' + |
michael@0 | 129 | ' background-color: green;' + |
michael@0 | 130 | '}'); |
michael@0 | 131 | |
michael@0 | 132 | let elementStyle = view._elementStyle; |
michael@0 | 133 | |
michael@0 | 134 | let idRule = elementStyle.rules[1]; |
michael@0 | 135 | let idProp = idRule.textProps[0]; |
michael@0 | 136 | |
michael@0 | 137 | idProp.setEnabled(false); |
michael@0 | 138 | yield idRule._applyingModifications; |
michael@0 | 139 | |
michael@0 | 140 | let classRule = elementStyle.rules[2]; |
michael@0 | 141 | let classProp = classRule.textProps[0]; |
michael@0 | 142 | ok(!classProp.overridden, "Class prop should not be overridden after id prop was disabled."); |
michael@0 | 143 | |
michael@0 | 144 | styleNode.remove(); |
michael@0 | 145 | yield inspector.once("inspector-updated"); |
michael@0 | 146 | } |