toolkit/content/tests/widgets/test_popupreflows.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Popup Reflow Tests"
     6   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <panel id="testPanel"
     9          type="arrow"
    10          noautohide="true">
    11   </panel>
    13   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    15 <script>
    16 <![CDATA[
    17 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
    19 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    20 Cu.import("resource://gre/modules/Promise.jsm");
    22 let panel, anchor, arrow;
    24 // A reflow observer - it just remembers the stack trace of all sync reflows
    25 // done by the panel.
    26 let observer = {
    27   reflows: [],
    28   reflow: function (start, end) {
    29     this.reflows.push(new Error().stack);
    30   },
    32   reflowInterruptible: function (start, end) {
    33     // We're not interested in interruptible reflows.  Why, you ask?  Because
    34     // we've simply cargo-culted this test from browser_tabopen_reflows.js!
    35   },
    37   QueryInterface: XPCOMUtils.generateQI([Ci.nsIReflowObserver,
    38                                          Ci.nsISupportsWeakReference])
    39 };
    41 // A test utility that counts the reflows caused by a test function.  If the
    42 // count of reflows isn't what is expected, it causes a test failure and logs
    43 // the stack trace of all seen reflows.
    44 function countReflows(testfn, expected) {
    45   let deferred = Promise.defer();
    46   observer.reflows = [];
    47   let docShell = panel.ownerDocument.defaultView
    48                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    49                   .getInterface(Components.interfaces.nsIWebNavigation)
    50                   .QueryInterface(Components.interfaces.nsIDocShell);
    51   docShell.addWeakReflowObserver(observer);
    52   testfn().then(() => {
    53     docShell.removeWeakReflowObserver(observer);
    54     SimpleTest.is(observer.reflows.length, expected, "correct number of reflows");
    55     if (observer.reflows.length != expected) {
    56       SimpleTest.info("stack traces of reflows:\n" + observer.reflows.join("\n") + "\n");
    57     }
    58     deferred.resolve();
    59   });
    60   return deferred.promise
    61 }
    63 function openPopup() {
    64   let deferred = Promise.defer();
    65   panel.addEventListener("popupshown", function popupshown() {
    66     panel.removeEventListener("popupshown", popupshown);
    67     deferred.resolve();
    68   });
    69   panel.openPopup(anchor, "before_start");
    70   return deferred.promise
    71 }
    73 // ********************
    74 // The actual tests...
    75 // We only have one atm - simply open a popup.
    76 //
    77 function testSimplePanel() {
    78   return openPopup();
    79 }
    81 // ********************
    82 // The test harness...
    83 //
    84 SimpleTest.waitForExplicitFinish();
    86 addEventListener("load", function() {
    87   anchor = document.getElementById("anchor");
    88   panel = document.getElementById("testPanel");
    89   arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow");
    91   // Cancel the arrow panel slide-in transition (bug 767133) - we are only
    92   // testing reflows in the core panel implementation and not reflows that may
    93   // or may not be caused by transitioning....
    94   arrow.style.transition = "none";
    96   // and off we go...
    97   countReflows(testSimplePanel, 1).then(SimpleTest.finish);
    98 });
    99 ]]>
   100 </script>
   101 <body xmlns="http://www.w3.org/1999/xhtml">
   102   <p>The anchor --&gt; <span id="anchor">v</span> &lt;--</p>
   103 </body>
   104 </window>

mercurial