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.

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

mercurial