3 Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
10 NativeClient browser test runner
12 <script type=
"text/javascript" src=
"nacltest.js"></script>
13 <script type=
"text/javascript" src=
"nmf_test_list.js"></script>
17 <div id=
"scratch_space"></div>
19 <div id=
"load_warning">
20 Javascript has failed to load.
23 <script type=
"text/javascript">
25 function addTest(tester
, url
) {
26 tester
.addAsyncTest(url
, function(status
) {
27 var embed
= document
.createElement('embed');
31 embed
.type
= 'application/x-nacl';
34 // Webkit Bug Workaround
35 // THIS SHOULD BE REMOVED WHEN Webkit IS FIXED
36 // http://code.google.com/p/nativeclient/issues/detail?id=2428
37 // http://code.google.com/p/chromium/issues/detail?id=103588
38 ForcePluginLoadOnTimeout(embed
, tester
, 15000);
40 var div
= document
.createElement('div');
41 div
.appendChild(embed
);
43 var cleanup = function() {
44 document
.getElementById('scratch_space').removeChild(div
);
47 // This is the prefix prepended by NaCl's unofficial
48 // "dev://postmessage" feature.
49 var stdout_prefix
= 'DEBUG_POSTMESSAGE:';
51 // NaCl's "dev://postmessage" feature is unsynchronized, in the
52 // sense that the DEBUG_POSTMESSAGE messages can arrive after the
53 // test result event. As a workaround, we look for an
54 // "END_OF_LOG" string that the nexe prints.
55 var saw_end_of_log
= false;
56 var end_of_log_callbacks
= [];
58 var runEndOfLogCallbacks = function() {
59 if (!saw_end_of_log
) {
60 saw_end_of_log
= true;
61 for (var i
= 0; i
< end_of_log_callbacks
.length
; i
++) {
62 end_of_log_callbacks
[i
]();
64 end_of_log_callbacks
= [];
68 var callAtEndOfLog = function(func
) {
72 end_of_log_callbacks
.push(func
);
73 // If we do not see the end of the log soon, end the test
74 // anyway. This will happen if the nexe crashes or exits.
75 window
.setTimeout(status
.wrap(function() {
76 status
.log('Did not see the END_OF_LOG message after timeout; ' +
78 runEndOfLogCallbacks();
83 // Set up an event listener for success messages.
84 div
.addEventListener('message', status
.wrap(function(message_event
) {
85 if (message_event
.data
.substr(0, stdout_prefix
.length
) == stdout_prefix
) {
86 var msg
= message_event
.data
.substr(stdout_prefix
.length
);
87 if (msg
== '\nEND_OF_LOG\n') {
88 runEndOfLogCallbacks();
90 status
.log(msg
.replace(/\n/g, '\\n'));
93 callAtEndOfLog(function() {
94 status
.assertEqual(message_event
.data
, 'passed');
101 // Wait for the load event, which indicates successful loading.
102 div
.addEventListener('load', status
.wrap(function(e
) {
103 status
.log('Loaded ' + embed
.src
);
104 // Start tests in the module.
105 embed
.postMessage('run_tests');
108 var onError
= status
.wrap(function(e
) {
109 callAtEndOfLog(function() {
111 status
.fail(embed
.lastError
);
115 div
.addEventListener('error', onError
, true);
116 div
.addEventListener('crash', onError
, true);
118 // Insert div into the DOM. This starts the load of the nacl plugin, etc.
119 document
.getElementById('scratch_space').appendChild(div
);
123 // Remove the "failed to load" message.
124 document
.getElementById('load_warning').innerHTML
= '';
126 var tester
= new Tester();
127 for (var i
= 0; i
< G_NMF_TEST_LIST
.length
; i
++) {
128 addTest(tester
, G_NMF_TEST_LIST
[i
]);
131 var args
= getTestArguments({'parallel': '0'});
133 if (parseInt(args
['parallel'])) {
134 tester
.runParallel();