widget/tests/window_bug478536.xul

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <window title="Mozilla Bug 478536"
     4   width="600" height="600"
     5   onload="onload();"
     6   onunload="onunload();"
     7   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
    12 <body xmlns="http://www.w3.org/1999/xhtml" id="body">
    13 <style type="text/css">
    14   #view {
    15     overflow: auto;
    16     width: 100px;
    17     height: 100px;
    18     border: 1px solid;
    19     margin: 0;
    20   }
    21 </style>
    22 <pre id="view" onscroll="onScrollView(event);">
    23 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    24 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    25 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    26 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    27 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    28 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    29 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    30 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    31 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    32 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    33 </pre>
    34 </body>
    36 <script class="testbody" type="application/javascript">
    37 <![CDATA[
    39 function ok(aCondition, aMessage)
    40 {
    41   window.opener.wrappedJSObject.SimpleTest.ok(aCondition, aMessage);
    42 }
    44 function is(aLeft, aRight, aMessage)
    45 {
    46   window.opener.wrappedJSObject.SimpleTest.is(aLeft, aRight, aMessage);
    47 }
    49 function isnot(aLeft, aRight, aMessage)
    50 {
    51   window.opener.wrappedJSObject.SimpleTest.isnot(aLeft, aRight, aMessage);
    52 }
    54 var gBody = document.getElementById("body");
    55 var gView = document.getElementById("view");
    57 /**
    58  * Description:
    59  *
    60  *   First, lock the wheel scrolling target to "view" at first step.
    61  *   Next, scroll back to top most of the "view" at second step.
    62  *   Finally, scroll back again at third step.  This fails to scroll the "view",
    63  *   then, |onMouseScrollFailed| event should be fired.  And at that time, we
    64  *   can remove the "view".  So, in post processing of the event firere, the
    65  *   "view" should not be referred.
    66  *
    67  *   For suppressing random test failure, all tests will be retried if we handle
    68  *   unexpected timeout event.
    69  */
    71 var gTests = [
    72  { scrollToForward: true,  shouldScroll: true },
    73  { scrollToForward: false, shouldScroll: true },
    74  { scrollToForward: false, shouldScroll: false }
    75 ];
    76 var gCurrentTestIndex = -1;
    77 var gIgnoreScrollEvent = true;
    79 var gPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].
    80                getService(Components.interfaces.nsIPrefBranch);
    81 const kPrefSmoothScroll = "general.smoothScroll";
    82 const kPrefNameTimeout = "mousewheel.transaction.timeout";
    83 const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);
    85 gPrefSvc.setBoolPref(kPrefSmoothScroll, false);
    87 var gTimeout = kDefaultTimeout;
    89 gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed, false);
    90 gBody.addEventListener("MozMouseScrollTransactionTimeout",
    91                        onTransactionTimeout, false);
    93 function setTimeoutPrefs(aTimeout)
    94 {
    95   gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
    96   gTimeout = aTimeout;
    97 }
    99 function resetTimeoutPrefs()
   100 {
   101   if (gTimeout == kDefaultTimeout)
   102     return;
   103   setTimeoutPrefs(kDefaultTimeout);
   104 }
   106 function growUpTimeoutPrefs()
   107 {
   108   if (gTimeout != kDefaultTimeout)
   109     return;
   110   setTimeoutPrefs(5000);
   111 }
   113 function onload()
   114 {
   115   disableNonTestMouseEvents(true);
   116   setTimeout(runNextTest, 0);
   117 }
   119 function onunload()
   120 {
   121   resetTimeoutPrefs();
   122   disableNonTestMouseEvents(false);
   123   gPrefSvc.clearUserPref(kPrefSmoothScroll);
   124   window.opener.wrappedJSObject.SimpleTest.finish();
   125 }
   127 function finish()
   128 {
   129   window.close();
   130 }
   132 // testing code
   134 var gTimer;
   135 function clearTimer()
   136 {
   137   clearTimeout(gTimer);
   138   gTimer = 0;
   139 }
   141 function runNextTest()
   142 {
   143   clearTimer();
   144   if (++gCurrentTestIndex >= gTests.length) {
   145     ok(true, "didn't crash, succeeded");
   146     finish();
   147     return;
   148   }
   149   fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward);
   150 }
   152 var gRetryCount = 5;
   153 function retryAllTests()
   154 {
   155   clearTimer();
   156   if (--gRetryCount >= 0) {
   157     gView.scrollTop = 0;
   158     gView.scrollLeft = 0;
   159     gCurrentTestIndex = -1;
   160     growUpTimeoutPrefs();
   161     ok(true, "WARNING: retry current test-list...");
   162     gTimer = setTimeout(runNextTest, 0);
   163   } else {
   164     ok(false, "Failed by unexpected timeout");
   165     finish();
   166   }
   167 }
   169 function fireWheelScrollEvent(aForward)
   170 {
   171   gIgnoreScrollEvent = false;
   172   var event = { deltaY: aForward ? 4.0 : -4.0,
   173                 deltaMode: WheelEvent.DOM_DELTA_LINE };
   174   synthesizeWheel(gView, 5, 5, event, window);
   175 }
   177 function onScrollView(aEvent)
   178 {
   179   if (gIgnoreScrollEvent)
   180     return;
   181   gIgnoreScrollEvent = true;
   182   clearTimer();
   183   ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled");
   184   gTimer = setTimeout(runNextTest, 0);
   185 }
   187 function onMouseScrollFailed(aEvent)
   188 {
   189   clearTimer();
   190   gIgnoreScrollEvent = true;
   191   ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled");
   192   if (!gTests[gCurrentTestIndex].shouldScroll)
   193     gBody.removeChild(gView);
   194   runNextTest();
   195 }
   197 function onTransactionTimeout(aEvent)
   198 {
   199   if (!gTimer)
   200     return;
   201   gIgnoreScrollEvent = true;
   202   retryAllTests();
   203 }
   205 ]]>
   206 </script>
   208 </window>

mercurial