PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/js/jetpack/tests/test_jetpack_crash.xul

http://github.com/zpao/v8monkey
Unknown | 82 lines | 69 code | 13 blank | 0 comment | 0 complexity | 9d29b2f3d09c9946d5af4ad42962a03f MD5 | raw file
 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<window title="Jetpack Crash Test"
 7        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 8  <script type="application/javascript"
 9          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
10
11  <description id="remoteScript">
12  <![CDATA[
13  registerReceiver("testCTypes", function(name, libfile) {
14    var library = ctypes.open(libfile);
15    var zero = new ctypes.intptr_t(8);
16    _noteIntentionalCrash();
17    var badptr = ctypes.cast(zero, ctypes.PointerType(ctypes.int32_t));
18    sendMessage("testCTypes:response", badptr.contents); // should crash here!
19  });
20  ]]>
21  </description>
22
23  <script class="testbody" type="application/javascript">
24  <![CDATA[
25    Components.utils.import("resource://gre/modules/ctypes.jsm");
26    const libURL = "chrome://mochitests/content/chrome/libraries/" +
27      ctypes.libraryName("jsctypes-test");
28
29    SimpleTest.waitForExplicitFinish();
30
31    var jp = Components.classes["@mozilla.org/jetpack/service;1"].
32      getService(Components.interfaces.nsIJetpackService).
33      createJetpack();
34
35    jp.registerReceiver("core:exception", function(msgName, e) {
36      ok(false, "Received exception from remote code: " + uneval(e));
37    });
38
39    jp.registerReceiver("testCTypes:response", function(msgName, v) {
40      ok(false, "Should not have received testCTypes response!");
41      jp.destroy();
42      jp = null;
43      SimpleTest.finish();
44    });
45
46    jp.registerReceiver("core:process-error", function(msgName, e) {
47      ok(true, "Received process-error notification.");
48
49      if ('nsICrashReporter' in Components.interfaces)
50        ok(e.dumpID, "Process error has a dumpID");
51
52      jp.destroy();
53      jp = null;
54
55      SimpleTest.executeSoon(SimpleTest.finish);
56    });
57
58    var remoteScript = document.getElementById('remoteScript').textContent;
59    jp.evalScript(remoteScript);
60
61    var downloadObserver = {
62      onDownloadComplete: function(downloader, request, cx, status, file) {
63        Components.utils.reportError("download status: " + status);
64        try {
65          file.permission = 0700;
66        }
67        catch (e) {
68          Components.utils.reportError(e);
69        }
70        jp.sendMessage('testCTypes', file.path);
71      }
72    };
73    var downloader = Components.classes["@mozilla.org/network/downloader;1"].
74      createInstance(Components.interfaces.nsIDownloader);
75    downloader.init(downloadObserver, null);
76    var channel = Components.classes["@mozilla.org/network/io-service;1"].
77      getService(Components.interfaces.nsIIOService).
78      newChannel(libURL, null, null);
79    channel.asyncOpen(downloader, null);
80  ]]>
81  </script>
82</window>