summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/chrome/test_bug420499.xul
blob: fb20c417a0ca27587438dddb6353d897b5b1e565 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=420499
-->
<window title="Mozilla Bug 420499" onload="setTimeout(focusInput, 500);"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

  

    <menu id="menu" label="Menu">
      <menupopup id="file-popup">
        <!-- <textbox id="some-text" maxlength="10" value="some text"/> -->
        <menu label="submenu">
          <menupopup id="file-popup-inner">

            <menuitem label="Item1"/>
            <menuitem label="Item2"/>
            <textbox id="some-text" maxlength="10" value="some more text"/>
          </menupopup>
        </menu>
        <menuitem label="Item3"/>
        <menuitem label="Item4"/>
      </menupopup>
    </menu>

    <popupset>
      <popup id="contextmenu">
        <menuitem label="Cut"/>
        <menuitem label="Copy"/>
        <menuitem label="Paste"/>
      </popup>
      <tooltip id="tooltip" orient="vertical">
        <description value="This is a tooltip"/>
      </tooltip>
    </popupset>
  
  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml" bgcolor="white">
  
  <p id="par1">Paragraph 1</p>
  <p id="par2">Paragraph 2</p>
  <p id="par3">Paragraph 3</p>
  <p id="par4">Paragraph 4</p>
  <p id="par5">Paragraph 5</p>

  <input type="text" id="text-input" maxlength="10" value="some more text"/> <br />

  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420499"
     target="_blank">Mozilla Bug 420499</a>
  </body>

  <!-- test code goes here -->
  <script type="application/javascript"><![CDATA[
    
    /** Test for Bug 420499 **/
    SimpleTest.waitForExplicitFinish();

    function getSelectionController() {
      return document.docShell
        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
        .getInterface(Components.interfaces.nsISelectionDisplay)
        .QueryInterface(Components.interfaces.nsISelectionController);
    }

    function isCaretVisible() {
      window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
      var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                            .getInterface(Components.interfaces.nsIWebNavigation)
                            .QueryInterface(Components.interfaces.nsIDocShell);
      var selCon = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
        .getInterface(Components.interfaces.nsISelectionDisplay)
        .QueryInterface(Components.interfaces.nsISelectionController);
      return selCon.caretVisible;
    }
    
    function focusInput() {
      ok(!isCaretVisible(), "Caret shouldn't be visible");
      $("text-input").focus();
      ok(isCaretVisible(), "Caret should be visible when input focused");
      window.addEventListener("popupshown", popupMenuShownHandler, false);
      $("menu").open = true;
    }
    
    function popupMenuShownHandler() {
      window.removeEventListener("popupshown", popupMenuShownHandler, false);
      ok(!isCaretVisible(), "Caret shouldn't be visible when menu open");
      window.addEventListener("popuphidden", ensureParagraphFocused, false);
      $("menu").open = false;
    }
    
    function ensureParagraphFocused() {
      window.removeEventListener("popuphidden", ensureParagraphFocused, false);
      ok(isCaretVisible(), "Caret should have returned to previous focus");
      window.addEventListener("popupshown", popupMenuShownHandler2, false);
      $("contextmenu").openPopup($('text-input'), "topleft" , -1 , -1 , true, true);
    }

    function popupMenuShownHandler2() {
      window.removeEventListener("popupshown", popupMenuShownHandler2, false);
      ok(isCaretVisible(), "Caret should be visible when context menu open");
      window.addEventListener("popuphidden", ensureParagraphFocused2, false);
      document.getElementById("contextmenu").hidePopup();
    }

    function ensureParagraphFocused2() {
      window.removeEventListener("popuphidden", ensureParagraphFocused2, false);
      ok(isCaretVisible(), "Caret should still be visible");
      window.addEventListener("popupshown", tooltipShownHandler, false);
      $("tooltip").openPopup($('text-input'), "topleft" , -1 , -1 , false, true);
    }

    function tooltipShownHandler() {
      window.removeEventListener("popupshown", tooltipShownHandler, false);
      ok(isCaretVisible(), "Caret should be visible when tooltip is visible");
      window.addEventListener("popuphidden", ensureParagraphFocused3, false);
      document.getElementById("tooltip").hidePopup();
    }

    function ensureParagraphFocused3() {
      window.removeEventListener("popuphidden", ensureParagraphFocused2, false);
      ok(isCaretVisible(), "Caret should still be visible");
      SimpleTest.finish();
    }
  ]]></script>
</window>