summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_popupremoving_frame.xul
blob: dec73c7f70f679b3875bf8ad4888eb638d8a81e1 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Popup Unload Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<!--
  This test checks that popup elements are removed when the document is changed.
  -->

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      

<iframe id="frame" width="300" height="150" src="frame_popupremoving_frame.xul"/>

<script class="testbody" type="application/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

var gMenus = [];

function popupsOpened()
{
  var framedoc = $("frame").contentDocument;
  framedoc.addEventListener("DOMAttrModified", modified, false);

  // this is the order in which the menus should be hidden (reverse of the
  // order they were opened in). The second menu is removed during the
  // mutation listener, so gets the event afterwards.
  gMenus.push(framedoc.getElementById("nestedmenu4"));
  gMenus.push(framedoc.getElementById("nestedmenu2"));
  gMenus.push(framedoc.getElementById("nestedmenu3"));
  gMenus.push(framedoc.getElementById("nestedmenu1"));
  gMenus.push(framedoc.getElementById("separatemenu4"));
  gMenus.push(framedoc.getElementById("separatemenu2"));
  gMenus.push(framedoc.getElementById("separatemenu3"));
  gMenus.push(framedoc.getElementById("separatemenu1"));

  framedoc.location = "about:blank";
}

function modified(event)
{
  if (event.attrName != "open")
    return;

  var framedoc = $("frame").contentDocument;

  var tohide = null;
  if (event.target.id == "separatemenu3")
    tohide = framedoc.getElementById("separatemenu2");
  else if (event.target.id == "nestedmenu3")
    tohide = framedoc.getElementById("nestedmenu2");

  if (tohide) {
    tohide.hidden = true;
    // force a layout flush
    $("frame").contentDocument.documentElement.boxObject.width;
  }

  is(event.target, gMenus.shift(), event.target.id + " hidden");
  if (gMenus.length == 0)
    SimpleTest.finish();
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>