Bug 574821 - Fix for incorrect maximized window non-client margins and remove excess...
[mozilla-central.git] / widget / tests / test_bug343416.xul
blobfad6589b9de87d84b93c457dc4032ab4217b75a5
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
4 type="text/css"?>
5 <!--
6 https://bugzilla.mozilla.org/show_bug.cgi?id=343416
7 -->
8 <window title="Mozilla Bug 343416"
9 xmlns:html="http://www.w3.org/1999/xhtml"
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
12 <title>Test for Bug 343416</title>
13 <script type="application/javascript"
14 src="chrome://mochikit/content/MochiKit/packed.js"></script>
15 <script type="application/javascript"
16 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
18 <body xmlns="http://www.w3.org/1999/xhtml">
19 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=343416">Mozilla Bug 343416</a>
20 <p id="display"></p>
21 <div id="content" style="display: none">
23 </div>
24 <pre id="test">
25 </pre>
26 </body>
28 <script class="testbody" type="application/javascript">
29 <![CDATA[
31 /** Test for Bug 343416 **/
32 SimpleTest.waitForExplicitFinish();
34 // Observer:
35 var idleObserver =
37 QueryInterface: function _qi(iid)
39 if (iid.equals(Components.interfaces.nsISupports) ||
40 iid.equals(Components.interfaces.nsIObserver))
42 return this;
44 throw Components.results.NS_ERROR_NO_INTERFACE;
46 observe: function _observe(subject, topic, data)
48 if (topic != "idle")
49 return;
51 var diff = Math.abs(data - newIdleSeconds * 1000);
53 // ok (diff < 5000, "The idle time should have increased by roughly 6 seconds, " +
54 // "as that's when we told this listener to fire.");
55 // if (diff >= 5000)
56 // alert(data + " " + newIdleSeconds);
58 // Attempt to get to the nsIIdleService
59 var subjectOK = false;
60 try {
61 var idleService = subject.QueryInterface(nsIIdleService);
62 subjectOK = true;
64 catch (ex)
66 ok(subjectOK, "The subject of the notification should be the " +
67 "nsIIdleService.");
69 // Attempt to remove ourselves.
70 var removedObserver = false;
71 try {
72 idleService.removeIdleObserver(this, newIdleSeconds);
73 removedObserver = true;
75 catch (ex)
77 ok(removedObserver, "We should be able to remove our observer here.");
78 finishedListenerOK = true;
79 if (finishedTimeoutOK)
81 clearTimeout(testBailout);
82 finishThisTest();
88 const nsIIdleService = Components.interfaces.nsIIdleService;
89 const nsIISCID = "@mozilla.org/widget/idleservice;1";
90 var idleService = null;
91 try
93 idleService = Components.classes[nsIISCID].getService(nsIIdleService);
95 catch (ex)
98 ok(idleService, "nsIIdleService should exist and be implemented on all tier 1 platforms.");
100 var idleTime = null;
101 var gotIdleTime = false;
104 idleTime = idleService.idleTime;
105 gotIdleTime = true;
107 catch (ex)
110 ok (gotIdleTime, "Getting the idle time should not fail " +
111 "in normal circumstances on any tier 1 platform.");
113 // Now we set up a timeout to sanity-test the idleTime after 5 seconds
114 setTimeout(testIdleTime, 5000);
115 var startTimeStamp = Date.now();
117 // Now we add the listener:
118 var newIdleSeconds = Math.floor(idleTime / 1000) + 6;
119 var addedObserver = false;
122 idleService.addIdleObserver(idleObserver, newIdleSeconds);
123 addedObserver = true;
125 catch (ex)
128 ok(addedObserver, "The nsIIdleService should allow us to add an observer.");
130 addedObserver = false;
133 idleService.addIdleObserver(idleObserver, newIdleSeconds);
134 addedObserver = true;
136 catch (ex)
139 ok(addedObserver, "The nsIIdleService should allow us to add the same observer again.");
141 var removedObserver = false;
144 idleService.removeIdleObserver(idleObserver, newIdleSeconds);
145 removedObserver = true;
147 catch (ex)
150 ok(removedObserver, "The nsIIdleService should allow us to remove the observer just once.");
152 function testIdleTime()
154 var gotIdleTime = false
157 var newIdleTime = idleService.idleTime;
158 gotIdleTime = true
160 catch (ex)
162 ok(gotIdleTime, "Getting the idle time should not fail " +
163 "in normal circumstances on any tier 1 platform.");
164 // Get the time difference, remove the approx. 5 seconds that we've waited,
165 // should be very close to 0 left.
166 var timeDiff = Math.abs((newIdleTime - idleTime) -
167 (Date.now() - startTimeStamp));
169 var timePassed = Date.now() - startTimeStamp;
170 var idleTimeDiff = newIdleTime - idleTime;
171 // 1 second leniency.
172 ok(timeDiff < 1000, "The idle time should have increased by roughly the " +
173 "amount of time it took for the timeout to fire. " +
174 "You didn't touch the mouse or keyboard during the" +
175 "test did you?");
176 finishedTimeoutOK = true;
179 // make sure we still exit when the listener and/or setTimeout don't fire:
180 var testBailout = setTimeout(finishThisTest, 12000);
181 var finishedTimeoutOK = false, finishedListenerOK = false;
182 function finishThisTest()
184 ok(finishedTimeoutOK, "We set a timeout and it should have fired by now.");
185 ok(finishedListenerOK, "We added a listener and it should have been called by now.");
186 if (!finishedListenerOK)
188 var removedListener = false;
191 idleService.removeIdleObserver(idleObserver, newIdleSeconds);
192 removedListener = true;
194 catch (ex)
197 ok(removedListener, "We added a listener and we should be able to remove it.");
199 // Done:
200 SimpleTest.finish();
204 </script>
206 </window>