widget/tests/test_input_events_on_deactive_window.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 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     4                  type="text/css"?>
     5 <window title="Testing composition, text and query content events"
     6   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <script type="application/javascript"
     9           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    10   <script type="application/javascript"
    11           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
    12   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
    14 <body  xmlns="http://www.w3.org/1999/xhtml">
    15 <div id="content" style="display: none">
    16 </div>
    17 <p id="display">
    18   <textarea id="textarea"></textarea>
    19 </p>
    20 <pre id="test">
    21 </pre>
    22 </body>
    24 <script class="testbody" type="application/javascript">
    25 <![CDATA[
    27 SimpleTest.waitForExplicitFinish();
    28 SimpleTest.waitForFocus(runTests, window);
    30 var fm = Components.classes["@mozilla.org/focus-manager;1"].
    31            getService(Components.interfaces.nsIFocusManager);
    32 var textarea = document.getElementById("textarea");
    33 var otherWindow;
    34 var timer;
    36 function runTests()
    37 {
    38   textarea.focus();
    39   is(fm.focusedElement, textarea, "we're deactive");
    40   if (fm.focusedElement != textarea) {
    41     SimpleTest.finish();
    42     return;
    43   }
    45   otherWindow =
    46     window.open("data:text/plain,this is an active window.", "_blank",
    47                 "chrome,width=100,height=100");
    48   ok(otherWindow, "failed to open other window");
    49   if (!otherWindow) {
    50     SimpleTest.finish();
    51     return;
    52   }
    54   SimpleTest.waitForFocus(startTests, otherWindow);
    55   otherWindow.focus();
    56 }
    58 function startTests()
    59 {
    60   clearTimeout(timer);
    61   isnot(fm.focusedWindow, window, "we're not deactive");
    62   if (fm.focusedWindow == window) {
    63     otherWindow.close();
    64     SimpleTest.finish();
    65     return;
    66   }
    68   var keydownHandled, keypressHandled, keyupHandled, compositionstartHandled,
    69       compositionendHandled, compositionupdateHandled, inputHandled;
    71   function clear()
    72   {
    73     keydownHandled = false;
    74     keypressHandled = false;
    75     keyupHandled = false;
    76     compositionstartHandled = false;
    77     compositionendHandled = false;
    78     compositionupdateHandled = false;
    79     inputHandled = false;
    80   }
    82   function onEvent(aEvent)
    83   {
    84     if (aEvent.type == "keydown") {
    85       keydownHandled = true;
    86     } else if (aEvent.type == "keypress") {
    87       keypressHandled = true;
    88     } else if (aEvent.type == "keyup") {
    89       keyupHandled = true;
    90     } else if (aEvent.type == "compositionstart") {
    91       compositionstartHandled = true;
    92     } else if (aEvent.type == "compositionend") {
    93       compositionendHandled = true;
    94     } else if (aEvent.type == "compositionupdate") {
    95       compositionupdateHandled = true;
    96     } else if (aEvent.type == "input") {
    97       inputHandled = true;
    98     } else {
    99       ok(false, "handled unknown event: " + aEvent.type);
   100     }
   101   }
   103   textarea.addEventListener("keydown", onEvent, false);
   104   textarea.addEventListener("keypress", onEvent, false);
   105   textarea.addEventListener("keyup", onEvent, false);
   106   textarea.addEventListener("compositionstart", onEvent, false);
   107   textarea.addEventListener("compositionend", onEvent, false);
   108   textarea.addEventListener("compositionupdate", onEvent, false);
   109   textarea.addEventListener("input", onEvent, false);
   111   startTestsInternal();
   113   function startTestsInternal()
   114   {
   115     // key events
   116     function checkKeyEvents(aKeydown, aKeypress, aKeyup, aInput, aDescription)
   117     {
   118       is(keydownHandled, aKeydown,
   119          "keydown event is (not) handled: " + aDescription);
   120       is(keypressHandled, aKeypress,
   121          "keypress event is (not) handled: " + aDescription);
   122       is(keyupHandled, aKeyup,
   123          "keyup event is (not) handled: " + aDescription);
   124       is(inputHandled, aInput,
   125          "input event is (not) handled: " + aDescription);
   126     }
   128     function checkCompositionEvents(aStart, aEnd, aUpdate, aInput, aDescription)
   129     {
   130       is(compositionstartHandled, aStart,
   131          "compositionstart event is (not) handled: " + aDescription);
   132       is(compositionendHandled, aEnd,
   133          "compositionend event is (not) handled: " + aDescription);
   134       is(compositionupdateHandled, aUpdate,
   135          "compositionupdate event is (not) handled: " + aDescription);
   136       is(inputHandled, aInput,
   137          "input event is (not) handled: " + aDescription);
   138     }
   140     clear();
   141     synthesizeKey("a", { type: "keydown" });
   142     checkKeyEvents(true, false, false, false, "a keydown");
   143     clear();
   144     synthesizeKey("a", { type: "keypress" });
   145     checkKeyEvents(false, true, false, true, "a keypress");
   146     is(textarea.value, "a", "textarea value isn't 'a'");
   147     clear();
   148     synthesizeKey("a", { type: "keyup" });
   149     checkKeyEvents(false, false, true, false, "a keyup");
   150     clear();
   151     synthesizeKey("VK_BACK_SPACE", {});
   152     checkKeyEvents(true, true, true, true, "VK_BACK_SPACE key events");
   153     is(textarea.value, "", "textarea value isn't empty");
   155     // IME events
   156     clear();
   157     // start composition
   158     synthesizeComposition({ type: "compositionstart" });
   159     checkCompositionEvents(true, false, false, false, "compositionstart");
   160     clear();
   161     // input first character
   162     synthesizeComposition({ type: "compositionupdate", data: "\u3089" });
   163     synthesizeText(
   164       { "composition":
   165         { "string": "\u3089",
   166           "clauses":
   167           [
   168             { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
   169           ]
   170         },
   171         "caret": { "start": 1, "length": 0 }
   172       });
   173     checkCompositionEvents(false, false, true, true, "composing");
   174     var queryText = synthesizeQueryTextContent(0, 100);
   175     ok(queryText, "query text event result is null");
   176     if (!queryText) {
   177       return;
   178     }
   179     ok(queryText.succeeded, "query text event failed");
   180     if (!queryText.succeeded) {
   181       return;
   182     }
   183     is(queryText.text, "\u3089", "composing text is incorrect");
   184     var querySelectedText = synthesizeQuerySelectedText();
   185     ok(querySelectedText, "query selected text event result is null");
   186     if (!querySelectedText) {
   187       return;
   188     }
   189     ok(querySelectedText.succeeded, "query selected text event failed");
   190     if (!querySelectedText.succeeded) {
   191       return;
   192     }
   193     is(querySelectedText.offset, 1,
   194        "query selected text event returns wrong offset");
   195     is(querySelectedText.text, "",
   196        "query selected text event returns wrong selected text");
   197     clear();
   198     // commit composition
   199     synthesizeText(
   200       { "composition":
   201         { "string": "\u3089",
   202           "clauses":
   203           [
   204             { "length": 0, "attr": 0 }
   205           ]
   206         },
   207         "caret": { "start": 1, "length": 0 }
   208       });
   209     checkCompositionEvents(false, false, false, false, "commit composition");
   210     queryText = synthesizeQueryTextContent(0, 100);
   211     ok(queryText, "query text event result is null after commit");
   212     if (!queryText) {
   213       return;
   214     }
   215     ok(queryText.succeeded, "query text event failed after commit");
   216     if (!queryText.succeeded) {
   217       return;
   218     }
   219     is(queryText.text, "\u3089", "composing text is incorrect after commit");
   220     querySelectedText = synthesizeQuerySelectedText();
   221     ok(querySelectedText,
   222        "query selected text event result is null after commit");
   223     if (!querySelectedText) {
   224       return;
   225     }
   226     ok(querySelectedText.succeeded,
   227        "query selected text event failed after commit");
   228     if (!querySelectedText.succeeded) {
   229       return;
   230     }
   231     is(querySelectedText.offset, 1,
   232        "query selected text event returns wrong offset after commit");
   233     is(querySelectedText.text, "",
   234        "query selected text event returns wrong selected text after commit");
   235     clear();
   236     // end composition
   237     synthesizeComposition({ type: "compositionend", data: "\u3089" });
   238     checkCompositionEvents(false, true, false, true, "compositionend");
   239   }
   241   textarea.removeEventListener("keydown", onEvent, false);
   242   textarea.removeEventListener("keypress", onEvent, false);
   243   textarea.removeEventListener("keyup", onEvent, false);
   244   textarea.removeEventListener("compositionstart", onEvent, false);
   245   textarea.removeEventListener("compositionupdate", onEvent, false);
   246   textarea.removeEventListener("compositionend", onEvent, false);
   247   textarea.removeEventListener("input", onEvent, false);
   249   otherWindow.close();
   251   SimpleTest.finish();
   252 }
   255 ]]>
   256 </script>
   257 </window>

mercurial