toolkit/content/tests/chrome/bug360437_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="360437Test"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    11         width="600"
    12         height="600"
    13         onload="onLoad();"
    14         title="360437 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     function ok(condition, message) {
    25       window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    26     }
    27     function finish() {
    28       window.close();
    29       window.opener.wrappedJSObject.SimpleTest.finish();
    30     }
    32     function onLoad() {
    33       var _delayedOnLoad = function() {
    34         gFindBar = document.getElementById("FindToolbar");
    35         gBrowser = document.getElementById("content");
    36         gBrowser.addEventListener("pageshow", onPageShow, false);
    37         gBrowser.loadURI("data:text/html,<form><input id='input' type='text' value='text inside an input element'></form>");
    38       }
    39       setTimeout(_delayedOnLoad, 1000);
    40     }
    42     function onPageShow() {
    43       testNormalFind();
    44     }
    46     function enterStringIntoFindField(aString) {
    47       for (var i=0; i < aString.length; i++) {
    48         var event = document.createEvent("KeyEvents");
    49         event.initKeyEvent("keypress", true, true, null, false, false,
    50                            false, false, 0, aString.charCodeAt(i));
    51         gFindBar._findField.inputField.dispatchEvent(event);
    52       }
    53     }
    55     function testNormalFind() {
    56       gFindBar.onFindCommand();
    58       // Make sure the findfield is correctly focused on open
    59       var searchStr = "text inside an input element";
    60       enterStringIntoFindField(searchStr);
    61       ok(document.commandDispatcher.focusedElement ==
    62          gFindBar._findField.inputField, "Find field isn't focused");
    64       // Make sure "find again" correctly transfers focus to the content element
    65       // when the find bar is closed.
    66       gFindBar.close();
    67       gFindBar.onFindAgainCommand(false);
    68       ok(document.commandDispatcher.focusedElement ==
    69          gBrowser.contentDocument.getElementById("input"),
    70              "Input Element isn't focused");
    72       // Make sure "find again" doesn't focus the content element if focus
    73       // isn't in the content document.
    74       var textbox = document.getElementById("textbox");
    75       textbox.focus();
    76       gFindBar.close();
    77       gFindBar.onFindAgainCommand(false);
    78       ok(textbox.hasAttribute("focused"),
    79          "Focus was stolen from a chrome element");
    80       finish();
    81     }
    82   ]]></script>
    83   <textbox id="textbox"/>
    84   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
    85   <findbar id="FindToolbar" browserid="content"/>
    86 </window>

mercurial