browser/base/content/test/general/browser_bug839103.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 const gTestRoot = getRootDirectory(gTestPath);
michael@0 2 const gStyleSheet = "bug839103.css";
michael@0 3
michael@0 4 var gTab = null;
michael@0 5 var needsInitialApplicableStateEvent = false;
michael@0 6 var needsInitialApplicableStateEventFor = null;
michael@0 7
michael@0 8 function test() {
michael@0 9 waitForExplicitFinish();
michael@0 10 gBrowser.addEventListener("StyleSheetAdded", initialStylesheetAdded, true);
michael@0 11 gTab = gBrowser.selectedTab = gBrowser.addTab(gTestRoot + "test_bug839103.html");
michael@0 12 gTab.linkedBrowser.addEventListener("load", tabLoad, true);
michael@0 13 }
michael@0 14
michael@0 15 function initialStylesheetAdded(evt) {
michael@0 16 gBrowser.removeEventListener("StyleSheetAdded", initialStylesheetAdded, true);
michael@0 17 ok(true, "received initial style sheet event");
michael@0 18 is(evt.type, "StyleSheetAdded", "evt.type has expected value");
michael@0 19 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 20 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 21 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 22 ok(evt.documentSheet, "style sheet is a document sheet");
michael@0 23 }
michael@0 24
michael@0 25 function tabLoad(evt) {
michael@0 26 gTab.linkedBrowser.removeEventListener(evt.type, tabLoad, true);
michael@0 27 executeSoon(continueTest);
michael@0 28 }
michael@0 29
michael@0 30 var gLinkElement = null;
michael@0 31
michael@0 32 function unexpectedContentEvent(evt) {
michael@0 33 ok(false, "Received a " + evt.type + " event on content");
michael@0 34 }
michael@0 35
michael@0 36 // We've seen the original stylesheet in the document.
michael@0 37 // Now add a stylesheet on the fly and make sure we see it.
michael@0 38 function continueTest() {
michael@0 39 info("continuing test");
michael@0 40
michael@0 41 let doc = gBrowser.contentDocument;
michael@0 42 doc.styleSheetChangeEventsEnabled = true;
michael@0 43 doc.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
michael@0 44 doc.addEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
michael@0 45 doc.addEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
michael@0 46 doc.defaultView.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
michael@0 47 doc.defaultView.addEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
michael@0 48 doc.defaultView.addEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
michael@0 49 let link = doc.createElement('link');
michael@0 50 link.setAttribute('rel', 'stylesheet');
michael@0 51 link.setAttribute('type', 'text/css');
michael@0 52 link.setAttribute('href', gTestRoot + gStyleSheet);
michael@0 53 gLinkElement = link;
michael@0 54
michael@0 55 gBrowser.addEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
michael@0 56 gBrowser.addEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChanged, true);
michael@0 57 doc.body.appendChild(link);
michael@0 58 }
michael@0 59
michael@0 60 function dynamicStylesheetAdded(evt) {
michael@0 61 gBrowser.removeEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
michael@0 62 ok(true, "received dynamic style sheet event");
michael@0 63 is(evt.type, "StyleSheetAdded", "evt.type has expected value");
michael@0 64 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 65 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 66 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 67 ok(evt.documentSheet, "style sheet is a document sheet");
michael@0 68 }
michael@0 69
michael@0 70 function dynamicStylesheetApplicableStateChanged(evt) {
michael@0 71 gBrowser.removeEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChanged, true);
michael@0 72 ok(true, "received dynamic style sheet applicable state change event");
michael@0 73 is(evt.type, "StyleSheetApplicableStateChanged", "evt.type has expected value");
michael@0 74 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 75 is(evt.stylesheet, gLinkElement.sheet, "evt.stylesheet has the right value");
michael@0 76 is(evt.applicable, true, "evt.applicable has the right value");
michael@0 77
michael@0 78 gBrowser.addEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChangedToFalse, true);
michael@0 79 gLinkElement.disabled = true;
michael@0 80 }
michael@0 81
michael@0 82 function dynamicStylesheetApplicableStateChangedToFalse(evt) {
michael@0 83 gBrowser.removeEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChangedToFalse, true);
michael@0 84 is(evt.type, "StyleSheetApplicableStateChanged", "evt.type has expected value");
michael@0 85 ok(true, "received dynamic style sheet applicable state change event after media=\"\" changed");
michael@0 86 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 87 is(evt.stylesheet, gLinkElement.sheet, "evt.stylesheet has the right value");
michael@0 88 is(evt.applicable, false, "evt.applicable has the right value");
michael@0 89
michael@0 90 gBrowser.addEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
michael@0 91 gBrowser.contentDocument.body.removeChild(gLinkElement);
michael@0 92 }
michael@0 93
michael@0 94 function dynamicStylesheetRemoved(evt) {
michael@0 95 gBrowser.removeEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
michael@0 96 ok(true, "received dynamic style sheet removal");
michael@0 97 is(evt.type, "StyleSheetRemoved", "evt.type has expected value");
michael@0 98 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 99 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 100 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 101 ok(evt.stylesheet.href.contains(gStyleSheet), "evt.stylesheet is the removed stylesheet");
michael@0 102
michael@0 103 gBrowser.addEventListener("StyleRuleAdded", styleRuleAdded, true);
michael@0 104 gBrowser.contentDocument.querySelector("style").sheet.insertRule("*{color:black}", 0);
michael@0 105 }
michael@0 106
michael@0 107 function styleRuleAdded(evt) {
michael@0 108 gBrowser.removeEventListener("StyleRuleAdded", styleRuleAdded, true);
michael@0 109 ok(true, "received style rule added event");
michael@0 110 is(evt.type, "StyleRuleAdded", "evt.type has expected value");
michael@0 111 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 112 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 113 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 114 ok(evt.rule, "evt.rule is defined");
michael@0 115 is(evt.rule.cssText, "* { color: black; }", "evt.rule.cssText has expected value");
michael@0 116
michael@0 117 gBrowser.addEventListener("StyleRuleChanged", styleRuleChanged, true);
michael@0 118 evt.rule.style.cssText = "color:green";
michael@0 119 }
michael@0 120
michael@0 121 function styleRuleChanged(evt) {
michael@0 122 gBrowser.removeEventListener("StyleRuleChanged", styleRuleChanged, true);
michael@0 123 ok(true, "received style rule changed event");
michael@0 124 is(evt.type, "StyleRuleChanged", "evt.type has expected value");
michael@0 125 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 126 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 127 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 128 ok(evt.rule, "evt.rule is defined");
michael@0 129 is(evt.rule.cssText, "* { color: green; }", "evt.rule.cssText has expected value");
michael@0 130
michael@0 131 gBrowser.addEventListener("StyleRuleRemoved", styleRuleRemoved, true);
michael@0 132 evt.stylesheet.deleteRule(0);
michael@0 133 }
michael@0 134
michael@0 135 function styleRuleRemoved(evt) {
michael@0 136 gBrowser.removeEventListener("StyleRuleRemoved", styleRuleRemoved, true);
michael@0 137 ok(true, "received style rule removed event");
michael@0 138 is(evt.type, "StyleRuleRemoved", "evt.type has expected value");
michael@0 139 is(evt.target, gBrowser.contentDocument, "event targets correct document");
michael@0 140 ok(evt.stylesheet, "evt.stylesheet is defined");
michael@0 141 ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
michael@0 142 ok(evt.rule, "evt.rule is defined");
michael@0 143
michael@0 144 executeSoon(concludeTest);
michael@0 145 }
michael@0 146
michael@0 147 function concludeTest() {
michael@0 148 let doc = gBrowser.contentDocument;
michael@0 149 doc.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
michael@0 150 doc.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
michael@0 151 doc.removeEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
michael@0 152 doc.defaultView.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
michael@0 153 doc.defaultView.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
michael@0 154 doc.defaultView.removeEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
michael@0 155 gBrowser.removeCurrentTab();
michael@0 156 gLinkElement = null;
michael@0 157 gTab = null;
michael@0 158 finish();
michael@0 159 }

mercurial