Bug 839103 - part 4 - add test for StyleSheet{Added,Removed} events; r=bz
authorNathan Froyd <froydnj@mozilla.com>
Wed, 27 Mar 2013 15:48:04 -0400
changeset 127497 c0e889e95154b5ab5c8a5cf93e3e8e845d5fa224
parent 127496 90c602d8475a013f2c331876bf5913fbd2710881
child 127498 3bb88ea0881ecacced9548bbb88807e6c0b798a0
push id25820
push usernfroyd@mozilla.com
push dateWed, 03 Apr 2013 17:24:48 +0000
treeherdermozilla-inbound@c0e889e95154 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs839103
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 839103 - part 4 - add test for StyleSheet{Added,Removed} events; r=bz
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug839103.js
browser/base/content/test/bug839103.css
browser/base/content/test/test_bug839103.html
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -155,16 +155,17 @@ endif
                  browser_bug767836_perwindowpb.js \
                  browser_bug771331.js \
                  browser_bug783614.js \
                  browser_bug797677.js \
                  browser_bug816527.js \
                  browser_bug817947.js \
                  browser_bug822367.js \
                  browser_bug832435.js \
+                 browser_bug839103.js \
                  browser_canonizeURL.js \
                  browser_customize.js \
                  browser_findbarClose.js \
                  browser_homeDrop.js \
                  browser_keywordBookmarklets.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
                  browser_customize_popupNotification.js \
@@ -204,16 +205,18 @@ endif
                  browser_tabMatchesInAwesomebar_perwindowpb.js \
                  browser_tab_drag_drop_perwindow.js \
                  bug564387.html \
                  bug564387_video1.ogv \
                  bug564387_video1.ogv^headers^ \
                  bug792517.html \
                  bug792517-2.html \
                  bug792517.sjs \
+                 test_bug839103.html \
+                 bug839103.css \
                  browser_scope.js \
                  browser_selectTabAtIndex.js \
                  browser_tab_dragdrop.js \
                  browser_tab_dragdrop2.js \
                  browser_tab_dragdrop2_frame1.xul \
                  browser_tabfocus.js \
                  browser_tabs_isActive.js \
                  browser_tabs_owner.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug839103.js
@@ -0,0 +1,85 @@
+const gTestRoot = getRootDirectory(gTestPath);
+const gStyleSheet = "bug839103.css";
+
+var gTab = 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.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.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
+  doc.addEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
+  doc.defaultView.addEventListener("StyleSheetAdded", unexpectedContentEvent, false);
+  doc.defaultView.addEventListener("StyleSheetRemoved", 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);
+  doc.body.appendChild(link);
+}
+
+function dynamicStylesheetAdded(evt) {
+  gBrowser.removeEventListener("StyleSheetAdded", dynamicStylesheetAdded, true);
+  ok(true, "received dynamic style sheet event");
+  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");
+
+  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.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");
+  executeSoon(concludeTest);
+}
+
+function concludeTest() {
+  let doc = gBrowser.contentDocument;
+  doc.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
+  doc.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
+  doc.defaultView.removeEventListener("StyleSheetAdded", unexpectedContentEvent, false);
+  doc.defaultView.removeEventListener("StyleSheetRemoved", unexpectedContentEvent, false);
+  gBrowser.removeCurrentTab();
+  gLinkElement = null;
+  gTab = null;
+  finish();
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/bug839103.css
@@ -0,0 +1,1 @@
+* {}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/test_bug839103.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Document for Bug 839103</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+</body>
+</html>