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
|
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<window title="DOM Worker Threads Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="test();">
<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 type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js"/>
<script type="application/javascript">
<![CDATA[
Components.utils.import("resource://gre/modules/ctypes.jsm");
CTYPES_TEST_LIB = ctypes.libraryName("jsctypes-test");
CTYPES_UNICODE_LIB = ctypes.libraryName("jsctyp\u00E8s-t\u00EB\u00DFt");
/*
* input: string of the url where we are running from
* return: nsILocalFile
*/
function getCurrentDir(path) {
var rootDir = getRootDirectory(window.location.href);
var jar = getJar(rootDir);
if (jar) {
return extractJarToTmp(jar);
} else {
return getLocalDir(path);
}
}
function getLocalDir(path) {
let dir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("CurWorkD", Components.interfaces.nsILocalFile);
path = location.pathname;
path = path.slice("content/".length,
-1 * "/test_ctypes.xul".length);
let components = path.split("/");
for (let part in components) {
dir.append(components[part]);
}
return dir;
}
function setupLibs(path) {
let libFile = path.clone();
libFile.append(CTYPES_TEST_LIB);
ok(libFile.exists(), "ctypes test library doesn't exist!?");
libFile.copyTo(null, CTYPES_UNICODE_LIB);
}
function cleanupLibs(path) {
let unicodeFile = path.clone();
unicodeFile.append(CTYPES_UNICODE_LIB);
ok(unicodeFile.exists(), "ctypes unicode test library doesn't exist!?");
unicodeFile.remove(false);
}
function test()
{
SimpleTest.waitForExplicitFinish();
var dir = getCurrentDir(location.path);
ok(dir.exists() && dir.isDirectory(), "Chrome test dir doesn't exist?!");
setupLibs(dir);
var worker = new ChromeWorker("ctypes_worker.js");
worker.onmessage = function(event) {
is(event.data, "Done!", "Wrong message!");
cleanupLibs(dir);
SimpleTest.finish();
}
worker.onerror = function(event) {
if (event.message == "uncaught exception: 7.5 million years for that?" ||
event.message == "uncaught exception: Just following orders, sir!") {
// We throw those on purpose in the worker, so ignore them.
return true;
}
ok(false, "Worker had an error: " + event.message);
worker.terminate();
cleanupLibs(dir);
SimpleTest.finish();
}
worker.postMessage({dir: dir.path, os: Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS});
}
]]>
</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>
<label id="test-result"/>
</window>
|