Add copy of .ttf font with .eot extension for testing
[wine-gecko.git] / widget / tests / test_bug343416.xul
bloba6e0f7aa66ad4bfd33b58f06834ca9f67d8facdf
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;
103 idleTime = idleService.idleTime;
105 catch (ex)
108 ok (idleTime, "Getting the idle time should not fail " +
109 "in normal circumstances on any tier 1 platform.");
111 // Now we set up a timeout to sanity-test the idleTime after 5 seconds
112 setTimeout(testIdleTime, 5000);
113 var startTimeStamp = Date.now();
115 // Now we add the listener:
116 var newIdleSeconds = Math.floor(idleTime / 1000) + 6;
117 var addedObserver = false;
120 idleService.addIdleObserver(idleObserver, newIdleSeconds);
121 addedObserver = true;
123 catch (ex)
126 ok(addedObserver, "The nsIIdleService should allow us to add an observer.");
128 addedObserver = false;
131 idleService.addIdleObserver(idleObserver, newIdleSeconds);
132 addedObserver = true;
134 catch (ex)
137 ok(addedObserver, "The nsIIdleService should allow us to add the same observer again.");
139 var removedObserver = false;
142 idleService.removeIdleObserver(idleObserver, newIdleSeconds);
143 removedObserver = true;
145 catch (ex)
148 ok(removedObserver, "The nsIIdleService should allow us to remove the observer just once.");
150 function testIdleTime()
154 var newIdleTime = idleService.idleTime;
156 catch (ex)
158 ok(newIdleTime, "Getting the idle time should not fail " +
159 "in normal circumstances on any tier 1 platform.");
160 // Get the time difference, remove the approx. 5 seconds that we've waited,
161 // should be very close to 0 left.
162 var timeDiff = Math.abs((newIdleTime - idleTime) -
163 (Date.now() - startTimeStamp));
164 // 0.5 second leniency.
165 ok(timeDiff < 500, "The idle time should have increased by roughly the " +
166 "amount of time it took for the timeout to fire.");
167 finishedTimeoutOK = true;
170 // make sure we still exit when the listener and/or setTimeout don't fire:
171 var testBailout = setTimeout(finishThisTest, 12000);
172 var finishedTimeoutOK = false, finishedListenerOK = false;
173 function finishThisTest()
175 ok(finishedTimeoutOK, "We set a timeout and it should have fired by now.");
176 ok(finishedListenerOK, "We added a listener and it should have been called by now.");
177 if (!finishedListenerOK)
179 var removedListener = false;
182 idleService.removeIdleObserver(idleObserver, newIdleSeconds);
183 removedListener = true;
185 catch (ex)
188 ok(removedListener, "We added a listener and we should be able to remove it.");
190 // Done:
191 SimpleTest.finish();
195 </script>
197 </window>