File: browser_bug839103.js

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (159 lines) | stat: -rw-r--r-- 7,687 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const gTestRoot = getRootDirectory(gTestPath);
const gStyleSheet = "bug839103.css";

var gTab = null;
var needsInitialApplicableStateEvent = false;
var needsInitialApplicableStateEventFor = null;

function test() {
  waitForExplicitFinish();
  gBrowser.addEventListener("StyleSheetAdded", initialStylesheetAdded, true);
  gTab = gBrowser.selectedTab = gBrowser.addTab(gTestRoot + "test_bug839103.html");
  gTab.linkedBrowser.addEventListener("load", tabLoad, true);
}

function initialStylesheetAdded(evt) {
  gBrowser.removeEventListener("StyleSheetAdded", initialStylesheetAdded, true);
  ok(true, "received initial style sheet event");
  is(evt.type, "StyleSheetAdded", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.documentSheet, "style sheet is a document sheet");
}

function tabLoad(evt) {
  gTab.linkedBrowser.removeEventListener(evt.type, tabLoad, true);
  executeSoon(continueTest);
}

var gLinkElement = null;

function unexpectedContentEvent(evt) {
  ok(false, "Received a " + evt.type + " event on content");
}

// We've seen the original stylesheet in the document.
// Now add a stylesheet on the fly and make sure we see it.
function continueTest() {
  info("continuing test");

  let doc = gBrowser.contentDocument;
  doc.styleSheetChangeEventsEnabled = true;
  doc.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
  doc.addEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
  doc.addEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
  doc.defaultView.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
  doc.defaultView.addEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
  doc.defaultView.addEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
  let link = doc.createElement('link');
  link.setAttribute('rel', 'stylesheet');
  link.setAttribute('type', 'text/css');
  link.setAttribute('href', gTestRoot + gStyleSheet);
  gLinkElement = link;

  gBrowser.addEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
  gBrowser.addEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChanged, true);
  doc.body.appendChild(link);
}

function dynamicStylesheetAdded(evt) {
  gBrowser.removeEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
  ok(true, "received dynamic style sheet event");
  is(evt.type, "StyleSheetAdded", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.documentSheet, "style sheet is a document sheet");
}

function dynamicStylesheetApplicableStateChanged(evt) {
  gBrowser.removeEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChanged, true);
  ok(true, "received dynamic style sheet applicable state change event");
  is(evt.type, "StyleSheetApplicableStateChanged", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  is(evt.stylesheet, gLinkElement.sheet, "evt.stylesheet has the right value");
  is(evt.applicable, true, "evt.applicable has the right value");

  gBrowser.addEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChangedToFalse, true);
  gLinkElement.disabled = true;
}

function dynamicStylesheetApplicableStateChangedToFalse(evt) {
  gBrowser.removeEventListener("StyleSheetApplicableStateChanged", dynamicStylesheetApplicableStateChangedToFalse, true);
  is(evt.type, "StyleSheetApplicableStateChanged", "evt.type has expected value");
  ok(true, "received dynamic style sheet applicable state change event after media=\"\" changed");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  is(evt.stylesheet, gLinkElement.sheet, "evt.stylesheet has the right value");
  is(evt.applicable, false, "evt.applicable has the right value");

  gBrowser.addEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
  gBrowser.contentDocument.body.removeChild(gLinkElement);
}

function dynamicStylesheetRemoved(evt) {
  gBrowser.removeEventListener("StyleSheetRemoved", dynamicStylesheetRemoved, true);
  ok(true, "received dynamic style sheet removal");
  is(evt.type, "StyleSheetRemoved", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.stylesheet.href.contains(gStyleSheet), "evt.stylesheet is the removed stylesheet");

  gBrowser.addEventListener("StyleRuleAdded", styleRuleAdded, true);
  gBrowser.contentDocument.querySelector("style").sheet.insertRule("*{color:black}", 0);
}

function styleRuleAdded(evt) {
  gBrowser.removeEventListener("StyleRuleAdded", styleRuleAdded, true);
  ok(true, "received style rule added event");
  is(evt.type, "StyleRuleAdded", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.rule, "evt.rule is defined");
  is(evt.rule.cssText, "* { color: black; }", "evt.rule.cssText has expected value");

  gBrowser.addEventListener("StyleRuleChanged", styleRuleChanged, true);
  evt.rule.style.cssText = "color:green";
}

function styleRuleChanged(evt) {
  gBrowser.removeEventListener("StyleRuleChanged", styleRuleChanged, true);
  ok(true, "received style rule changed event");
  is(evt.type, "StyleRuleChanged", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.rule, "evt.rule is defined");
  is(evt.rule.cssText, "* { color: green; }", "evt.rule.cssText has expected value");

  gBrowser.addEventListener("StyleRuleRemoved", styleRuleRemoved, true);
  evt.stylesheet.deleteRule(0);
}

function styleRuleRemoved(evt) {
  gBrowser.removeEventListener("StyleRuleRemoved", styleRuleRemoved, true);
  ok(true, "received style rule removed event");
  is(evt.type, "StyleRuleRemoved", "evt.type has expected value");
  is(evt.target, gBrowser.contentDocument, "event targets correct document");
  ok(evt.stylesheet, "evt.stylesheet is defined");
  ok(evt.stylesheet.toString().contains("CSSStyleSheet"), "evt.stylesheet is a stylesheet");
  ok(evt.rule, "evt.rule is defined");

  executeSoon(concludeTest);
}

function concludeTest() {
  let doc = gBrowser.contentDocument;
  doc.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
  doc.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
  doc.removeEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
  doc.defaultView.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
  doc.defaultView.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
  doc.defaultView.removeEventListener("StyleSheetApplicableStateChanged", unexpectedContentEvent, false);
  gBrowser.removeCurrentTab();
  gLinkElement = null;
  gTab = null;
  finish();
}