1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Helper routines for generating crash load tests.
6 // Depends on nacltest.js.
8 function createModule(id
, type
) {
9 return createNaClEmbed({
11 src
: 'ppapi_' + id
+ '.nmf',
19 function crashTest(pluginName
, testName
, pingToDetectCrash
) {
20 var mime
= 'application/x-nacl';
21 if (getTestArguments()['pnacl'] !== undefined) {
22 mime
= 'application/x-pnacl';
25 var plugin
= createModule(pluginName
, mime
);
26 document
.body
.appendChild(plugin
);
28 var tester
= new Tester();
29 tester
.addAsyncTest(testName
, function(test
) {
30 test
.expectEvent(plugin
, 'crash', function(e
) { test
.pass(); });
31 test
.expectEvent(plugin
, 'error', function(e
) { test
.fail(); });
32 plugin
.postMessage(testName
);
33 // In case the nexe does not crash right away, we will ping it
34 // until we detect that it's dead. DidChangeView and other events
35 // can do this too, but are less reliable.
36 if (pingToDetectCrash
) {
37 function PingBack(message
) {
38 test
.log(message
.data
);
39 plugin
.postMessage('Ping');
41 plugin
.addEventListener('message', PingBack
, false);
42 plugin
.postMessage("Ping");
45 tester
.waitFor(plugin
);