Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | <!-- |
michael@0 | 5 | XUL Widget Test for panels |
michael@0 | 6 | --> |
michael@0 | 7 | <window title="Titlebar" width="200" height="200" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 11 | <script type="application/javascript" |
michael@0 | 12 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
michael@0 | 13 | |
michael@0 | 14 | <tree id="tree" seltype="single" width="100" height="100"> |
michael@0 | 15 | <treecols> |
michael@0 | 16 | <treecol flex="1"/> |
michael@0 | 17 | <treecol flex="1"/> |
michael@0 | 18 | </treecols> |
michael@0 | 19 | <treechildren id="treechildren"> |
michael@0 | 20 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 21 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 22 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 23 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 24 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 25 | <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
michael@0 | 26 | </treechildren> |
michael@0 | 27 | </tree> |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | <!-- test results are displayed in the html:body --> |
michael@0 | 31 | <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
michael@0 | 32 | |
michael@0 | 33 | <!-- test code goes here --> |
michael@0 | 34 | <script type="application/javascript"><![CDATA[ |
michael@0 | 35 | |
michael@0 | 36 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 37 | |
michael@0 | 38 | var currentTest = null; |
michael@0 | 39 | |
michael@0 | 40 | var i = 0; |
michael@0 | 41 | var my_debug = false; |
michael@0 | 42 | function test_panels() |
michael@0 | 43 | { |
michael@0 | 44 | checkTreeCoords(); |
michael@0 | 45 | |
michael@0 | 46 | addEventListener("popupshown", popupShown, false); |
michael@0 | 47 | addEventListener("popuphidden", nextTest, false); |
michael@0 | 48 | return nextTest(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function nextTest() |
michael@0 | 52 | { |
michael@0 | 53 | ok(true,"popuphidden " + i) |
michael@0 | 54 | if (i == tests.length) { |
michael@0 | 55 | return i; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | currentTest = tests[i]; |
michael@0 | 59 | var panel = createPanel(currentTest.attrs); |
michael@0 | 60 | currentTest.test(panel); |
michael@0 | 61 | return i; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | var waitSteps = 0; |
michael@0 | 65 | function popupShown(event) |
michael@0 | 66 | { |
michael@0 | 67 | var panel = event.target; |
michael@0 | 68 | if (waitSteps > 0 && navigator.platform.indexOf("Linux") >= 0 && |
michael@0 | 69 | panel.boxObject.screenY == 210) { |
michael@0 | 70 | waitSteps--; |
michael@0 | 71 | setTimeout(popupShown, 10, event); |
michael@0 | 72 | return; |
michael@0 | 73 | } |
michael@0 | 74 | ++i; |
michael@0 | 75 | |
michael@0 | 76 | currentTest.result(currentTest.testname + " ", panel); |
michael@0 | 77 | panel.hidePopup(); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function createPanel(attrs) |
michael@0 | 81 | { |
michael@0 | 82 | var panel = document.createElement("panel"); |
michael@0 | 83 | for (var a in attrs) { |
michael@0 | 84 | panel.setAttribute(a, attrs[a]); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | var button = document.createElement("button"); |
michael@0 | 88 | panel.appendChild(button); |
michael@0 | 89 | button.label = "OK"; |
michael@0 | 90 | button.width = 120; |
michael@0 | 91 | button.height = 40; |
michael@0 | 92 | button.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;"); |
michael@0 | 93 | panel.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;"); |
michael@0 | 94 | return document.documentElement.appendChild(panel); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | function checkTreeCoords() |
michael@0 | 98 | { |
michael@0 | 99 | var tree = $("tree"); |
michael@0 | 100 | var treechildren = $("treechildren"); |
michael@0 | 101 | tree.currentIndex = 0; |
michael@0 | 102 | tree.treeBoxObject.scrollToRow(0); |
michael@0 | 103 | synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { }); |
michael@0 | 104 | |
michael@0 | 105 | tree.treeBoxObject.scrollToRow(2); |
michael@0 | 106 | synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { }); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | var tests = [ |
michael@0 | 110 | { |
michael@0 | 111 | testname: "normal panel", |
michael@0 | 112 | attrs: { }, |
michael@0 | 113 | test: function(panel) { |
michael@0 | 114 | panel.openPopupAtScreen(200, 210); |
michael@0 | 115 | }, |
michael@0 | 116 | result: function(testname, panel) { |
michael@0 | 117 | if (my_debug) alert(testname); |
michael@0 | 118 | var panelrect = panel.getBoundingClientRect(); |
michael@0 | 119 | } |
michael@0 | 120 | }, |
michael@0 | 121 | { |
michael@0 | 122 | // only noautohide panels support titlebars, so one shouldn't be shown here |
michael@0 | 123 | testname: "autohide panel with titlebar", |
michael@0 | 124 | attrs: { titlebar: "normal" }, |
michael@0 | 125 | test: function(panel) { |
michael@0 | 126 | panel.openPopupAtScreen(200, 210); |
michael@0 | 127 | }, |
michael@0 | 128 | result: function(testname, panel) { |
michael@0 | 129 | if (my_debug) alert(testname); |
michael@0 | 130 | var panelrect = panel.getBoundingClientRect(); |
michael@0 | 131 | } |
michael@0 | 132 | }, |
michael@0 | 133 | { |
michael@0 | 134 | testname: "noautohide panel with titlebar", |
michael@0 | 135 | attrs: { noautohide: true, titlebar: "normal" }, |
michael@0 | 136 | test: function(panel) { |
michael@0 | 137 | waitSteps = 25; |
michael@0 | 138 | panel.openPopupAtScreen(200, 210); |
michael@0 | 139 | }, |
michael@0 | 140 | result: function(testname, panel) { |
michael@0 | 141 | if (my_debug) alert(testname); |
michael@0 | 142 | var panelrect = panel.getBoundingClientRect(); |
michael@0 | 143 | |
michael@0 | 144 | var gotMouseEvent = false; |
michael@0 | 145 | function mouseMoved(event) |
michael@0 | 146 | { |
michael@0 | 147 | gotMouseEvent = true; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | panel.addEventListener("mousemove", mouseMoved, true); |
michael@0 | 151 | synthesizeMouse(panel, 10, 10, { type: "mousemove" }); |
michael@0 | 152 | panel.removeEventListener("mousemove", mouseMoved, true); |
michael@0 | 153 | |
michael@0 | 154 | var tree = $("tree"); |
michael@0 | 155 | tree.currentIndex = 0; |
michael@0 | 156 | panel.appendChild(tree); |
michael@0 | 157 | checkTreeCoords(); |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | ]; |
michael@0 | 161 | |
michael@0 | 162 | SimpleTest.waitForFocus(test_panels); |
michael@0 | 163 | |
michael@0 | 164 | ]]> |
michael@0 | 165 | </script> |
michael@0 | 166 | |
michael@0 | 167 | </window> |