1 // Copyright (c) 2012 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.
6 function moduleDidLoad() {
7 // The module is not hidden by default so we can easily see if the plugin
12 var currentTestEl = null;
14 function startCommand(testName) {
15 var testListEl = document.getElementById('tests');
16 var testEl = document.createElement('li');
17 var testRowEl = document.createElement('div');
18 var testNameEl = document.createElement('span');
19 var testResultEl = document.createElement('span');
20 testRowEl.classList.add('row');
21 testNameEl.classList.add('name');
22 testNameEl.textContent = testName;
23 testResultEl.classList.add('result');
24 testRowEl.appendChild(testNameEl);
25 testRowEl.appendChild(testResultEl);
26 testEl.appendChild(testRowEl);
27 testListEl.appendChild(testEl);
29 currentTestEl = testEl;
32 function failCommand(fileName, lineNumber, summary) {
33 var testMessageEl = document.createElement('pre');
34 testMessageEl.textContent += fileName + ':' + lineNumber + ': ' + summary;
35 currentTestEl.appendChild(testMessageEl);
38 function endCommand(testName, testResult) {
39 var testRowEl = currentTestEl.querySelector('.row');
40 var testResultEl = currentTestEl.querySelector('.result');
41 testRowEl.classList.add(testResult);
42 testResultEl.textContent = testResult;
45 function handleMessage(event) {
47 var firstColon = msg.indexOf(':');
48 var cmd = msg.substr(0, firstColon);
49 var cmdFunctionName = cmd + 'Command';
50 var cmdFunction = window[cmdFunctionName];
52 if (typeof(cmdFunction) !== 'function') {
53 console.log('Unknown command: ' + cmd);
54 console.log(' message: ' + msg);
58 var argCount = cmdFunction.length;
60 // Don't use split, because it will split all commas (for example any commas
61 // in the test failure summary).
62 var argList = msg.substr(firstColon + 1);
64 for (var i = 0; i < argCount - 1; ++i) {
66 var comma = argList.indexOf(',');
68 if (i !== argCount - 1) {
69 console.log('Bad arg count to command "' + cmd + '", expected ' +
71 console.log(' message: ' + msg);
76 arg = argList.substr(0, comma);
77 argList = argList.substr(comma + 1);
82 // Last argument is the rest of the message.
85 cmdFunction.apply(null, args);