summaryrefslogtreecommitdiffstats
path: root/dom/base/test/chrome/test_bug814638.xul
blob: f507099c9809f5a440b7289fc32ab839e7ca3ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=814638
-->
<window title="Mozilla Bug 814638"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=814638"
     target="_blank" id="link">Mozilla Bug 814638</a>
  </body>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[
  /** Test for Bug 814638 **/

  SimpleTest.waitForExplicitFinish();

  function startTest() {
    let hostURL = "chrome://mochitests/content/chrome/dom/base/test/chrome/host_bug814638.xul";
    let host1 = window.open(hostURL, "_blank", "chrome");
    let host2 = window.open(hostURL, "_blank", "chrome");

    let isHost1Loaded = isHost2Loaded = false
    host1.onload = function() {
      isHost1Loaded = true;
      if (isHost2Loaded) swapFrames();
    }
    host2.onload = function() {
      isHost2Loaded = true;
      if (isHost1Loaded) swapFrames();
    }

    function swapFrames() {
      let iframe1 = host1.document.querySelector("iframe");
      let iframe2 = host2.document.querySelector("iframe");
      iframe2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
      iframe2.swapFrameLoaders(iframe1);
      setTimeout(function() {
        iframe2.contentWindow.receivedKeyEvent = receivedKeyEvent;
        let innerIframe2 = iframe2.contentDocument.querySelector("iframe");
        let e = innerIframe2.contentDocument.createEvent("KeyboardEvent");
        e.initKeyEvent("keypress", true, true, null, true, false, false, false, 0, "t".charCodeAt(0));
        innerIframe2.contentDocument.documentElement.dispatchEvent(e);
        host1.close();
        host2.close();
      }, 0);
    }
  }

  function receivedKeyEvent() {
    ok(true, "Received key event");
    SimpleTest.finish();
  }

  addLoadEvent(startTest);
  ]]>
  </script>
</window>