1 // Copyright (c) 2013 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.
4 // Called by the common.js module.
5 function moduleDidLoad() {
6 // The module is not hidden by default so we can easily see if the plugin
11 var currentTestEl
= null;
13 function startCommand(testName
) {
14 var testListEl
= document
.getElementById('tests');
15 var testEl
= document
.createElement('li');
16 var testRowEl
= document
.createElement('div');
17 var testNameEl
= document
.createElement('span');
18 var testResultEl
= document
.createElement('span');
19 testRowEl
.classList
.add('row');
20 testNameEl
.classList
.add('name');
21 testNameEl
.textContent
= testName
;
22 testResultEl
.classList
.add('result');
23 testRowEl
.appendChild(testNameEl
);
24 testRowEl
.appendChild(testResultEl
);
25 testEl
.appendChild(testRowEl
);
26 testListEl
.appendChild(testEl
);
28 currentTestEl
= testEl
;
31 function failCommand(fileName
, lineNumber
, summary
) {
32 var testMessageEl
= document
.createElement('pre');
33 testMessageEl
.textContent
+= fileName
+ ':' + lineNumber
+ ': ' + summary
;
34 currentTestEl
.appendChild(testMessageEl
);
37 function endCommand(testName
, testResult
) {
38 var testRowEl
= currentTestEl
.querySelector('.row');
39 var testResultEl
= currentTestEl
.querySelector('.result');
40 testRowEl
.classList
.add(testResult
);
41 testResultEl
.textContent
= testResult
;
44 function handleMessage(event
) {
46 var firstColon
= msg
.indexOf(':');
47 var cmd
= msg
.substr(0, firstColon
);
49 if (cmd
== 'testend') {
50 event
.srcElement
.postMessage({'testend' : ''});
54 var cmdFunctionName
= cmd
+ 'Command';
55 var cmdFunction
= window
[cmdFunctionName
];
56 if (typeof(cmdFunction
) !== 'function') {
57 console
.log('Unknown command: ' + cmd
);
58 console
.log(' message: ' + msg
);
62 var argCount
= cmdFunction
.length
;
64 // Don't use split, because it will split all commas (for example any commas
65 // in the test failure summary).
66 var argList
= msg
.substr(firstColon
+ 1);
68 for (var i
= 0; i
< argCount
- 1; ++i
) {
70 var comma
= argList
.indexOf(',');
72 if (i
!== argCount
- 1) {
73 console
.log('Bad arg count to command "' + cmd
+ '", expected ' +
75 console
.log(' message: ' + msg
);
80 arg
= argList
.substr(0, comma
);
81 argList
= argList
.substr(comma
+ 1);
86 // Last argument is the rest of the message.
89 cmdFunction
.apply(null, args
);