toolkit/content/tests/chrome/findbar_events_window.xul

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 <?xml version="1.0"?>
     3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     4    - License, v. 2.0. If a copy of the MPL was not distributed with this
     5    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     9 <window id="FindbarTest"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    11         width="600"
    12         height="600"
    13         onload="SimpleTest.executeSoon(startTest);"
    14         title="findbar events test">
    16   <script type="application/javascript"><![CDATA[
    17     const Ci = Components.interfaces;
    18     const Cc = Components.classes;
    19     const Cr = Components.results;
    21     var gFindBar = null;
    22     var gBrowser;
    24     var imports = ["SimpleTest", "ok"];
    25     for each (var name in imports) {
    26       window[name] = window.opener.wrappedJSObject[name];
    27     }
    29     function finish() {
    30       window.close();
    31       SimpleTest.finish();
    32     }
    34     function startTest() {
    35       gFindBar = document.getElementById("FindToolbar");
    36       gBrowser = document.getElementById("content");
    37       gBrowser.addEventListener("pageshow", onPageShow, false);
    38       gBrowser.loadURI('data:text/html,hello there');
    39     }
    41     var tests = [
    42       testFind,
    43       testFindAgain,
    44       testCaseSensitivity,
    45       testHighlight,
    46       finish
    47     ];
    49     // Iterates through the above tests and takes care of passing the done
    50     // callback for any async tests.
    51     function nextTest() {
    52       if (!tests.length) {
    53         return;
    54       }
    55       var func = tests.shift();
    56       if (!func.length) {
    57         // Test isn't async advance to the next test here.
    58         func();
    59         SimpleTest.executeSoon(nextTest);
    60       } else {
    61         func(nextTest);
    62       }
    63     }
    65     function onPageShow() {
    66       gFindBar.open();
    67       gFindBar.onFindCommand();
    68       nextTest();
    69     }
    71     function checkSelection(done) {
    72       SimpleTest.executeSoon(function() {
    73         var selected = gBrowser.contentWindow.getSelection();
    74         ok(selected == "", "No text is selected");
    76         var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
    77                                  .getInterface(Ci.nsISelectionDisplay)
    78                                  .QueryInterface(Ci.nsISelectionController);
    79         var selection = controller.getSelection(controller.SELECTION_FIND);
    80         ok(selection.rangeCount == 0, "No text is highlighted");
    81         done();
    82       });
    83     }
    85     function testFind(done) {
    86       var findTriggered = false;
    87       var query = "t";
    88       gFindBar.addEventListener("find", function(e) {
    89         eventTriggered = true;
    90         ok(e.detail.query === query, "find event query should match '" + query + "'");
    91         e.preventDefault();
    92         // Since we're preventing the default make sure nothing was selected.
    93         checkSelection(done);
    94       });
    96       // Put some text in the find box.
    97       var event = document.createEvent("KeyEvents");
    98       event.initKeyEvent("keypress", true, true, null, false, false,
    99                          false, false, 0, query.charCodeAt(0));
   100       gFindBar._findField.inputField.dispatchEvent(event);
   101       ok(eventTriggered, "find event should be triggered");
   102     }
   104     function testFindAgain(done) {
   105       var eventTriggered = false;
   106       gFindBar.addEventListener("findagain", function(e) {
   107         eventTriggered = true;
   108         e.preventDefault();
   109         // Since we're preventing the default make sure nothing was selected.
   110         checkSelection(done);
   111       });
   113       gFindBar.onFindAgainCommand();
   114       ok(eventTriggered, "findagain event should be triggered");
   115     }
   117     function testCaseSensitivity() {
   118       var eventTriggered = false;
   119       gFindBar.addEventListener("findcasesensitivitychange", function(e) {
   120         eventTriggered = true;
   121         ok(e.detail.caseSensitive, "find should be case sensitive");
   122       });
   124       var matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
   125       matchCaseCheckbox.click();
   126       ok(eventTriggered, "findcasesensitivitychange should be triggered");
   127     }
   129     function testHighlight(done) {
   130       // Update the find state so the highlight button is clickable.
   131       gFindBar.updateControlState(Ci.nsITypeAheadFind.FIND_FOUND, false);
   132       var eventTriggered = false;
   133       gFindBar.addEventListener("findhighlightallchange", function(e) {
   134         eventTriggered = true;
   135         ok(e.detail.highlightAll, "find event should have highlight all set");
   136         e.preventDefault();
   137         // Since we're preventing the default make sure nothing was highlighted.
   138         SimpleTest.executeSoon(function() {
   139           checkSelection(done);
   140         });
   141       });
   143       var highlightButton = gFindBar.getElement("highlight");
   144       if (!highlightButton.checked) {
   145         highlightButton.click();
   146       }
   147       ok(eventTriggered, "findhighlightallchange should be triggered");
   148     }
   149   ]]></script>
   151   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   152   <findbar id="FindToolbar" browserid="content"/>
   153 </window>

mercurial