1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview This file contains small testing framework along with the
* test suite for the frontend. These tests are a part of the continues build
* and are executed by the devtools_sanity_unittest.cc as a part of the
* Interactive UI Test suite.
*/
if (window.domAutomationController) {
var ___interactiveUiTestsMode = true;
/**
* Test suite for interactive UI tests.
* @constructor
*/
TestSuite = function() {
this.controlTaken_ = false;
this.timerId_ = -1;
};
/**
* Reports test failure.
* @param {string} message Failure description.
*/
TestSuite.prototype.fail = function(message) {
if (this.controlTaken_) {
this.reportFailure_(message);
} else {
throw message;
}
};
/**
* Equals assertion tests that expected == actual.
* @param {Object} expected Expected object.
* @param {Object} actual Actual object.
* @param {string} opt_message User message to print if the test fails.
*/
TestSuite.prototype.assertEquals = function(expected, actual, opt_message) {
if (expected != actual) {
var message = 'Expected: "' + expected + '", but was "' + actual + '"';
if (opt_message) {
message = opt_message + '(' + message + ')';
}
this.fail(message);
}
};
/**
* True assertion tests that value == true.
* @param {Object} value Actual object.
* @param {string} opt_message User message to print if the test fails.
*/
TestSuite.prototype.assertTrue = function(value, opt_message) {
this.assertEquals(true, value, opt_message);
};
/**
* Contains assertion tests that string contains substring.
* @param {string} string Outer.
* @param {string} substring Inner.
*/
TestSuite.prototype.assertContains = function(string, substring) {
if (string.indexOf(substring) == -1) {
this.fail('Expected to: "' + string + '" to contain "' + substring + '"');
}
};
/**
* Takes control over execution.
*/
TestSuite.prototype.takeControl = function() {
this.controlTaken_ = true;
// Set up guard timer.
var self = this;
this.timerId_ = setTimeout(function() {
self.reportFailure_('Timeout exceeded: 20 sec');
}, 20000);
};
/**
* Releases control over execution.
*/
TestSuite.prototype.releaseControl = function() {
if (this.timerId_ != -1) {
clearTimeout(this.timerId_);
this.timerId_ = -1;
}
this.reportOk_();
};
/**
* Async tests use this one to report that they are completed.
*/
TestSuite.prototype.reportOk_ = function() {
window.domAutomationController.send('[OK]');
};
/**
* Async tests use this one to report failures.
*/
TestSuite.prototype.reportFailure_ = function(error) {
if (this.timerId_ != -1) {
clearTimeout(this.timerId_);
this.timerId_ = -1;
}
window.domAutomationController.send('[FAILED] ' + error);
};
/**
* Runs all global functions starting with 'test' as unit tests.
*/
TestSuite.prototype.runTest = function(testName) {
try {
this[testName]();
if (!this.controlTaken_) {
this.reportOk_();
}
} catch (e) {
this.reportFailure_(e);
}
};
/**
* @param {string} panelName Name of the panel to show.
*/
TestSuite.prototype.showPanel = function(panelName) {
// Open Scripts panel.
var toolbar = document.getElementById('toolbar');
var button = toolbar.getElementsByClassName(panelName)[0];
button.click();
this.assertEquals(WebInspector.panels[panelName],
WebInspector.currentPanel);
};
/**
* Overrides the method with specified name until it's called first time.
* @param {Object} receiver An object whose method to override.
* @param {string} methodName Name of the method to override.
* @param {Function} override A function that should be called right after the
* overriden method returns.
* @param {boolean} opt_sticky Whether restore original method after first run
* or not.
*/
TestSuite.prototype.addSniffer = function(receiver, methodName, override,
opt_sticky) {
var orig = receiver[methodName];
if (typeof orig != 'function') {
this.fail('Cannot find method to override: ' + methodName);
}
var test = this;
receiver[methodName] = function(var_args) {
try {
var result = orig.apply(this, arguments);
} finally {
if (!opt_sticky) {
receiver[methodName] = orig;
}
}
// In case of exception the override won't be called.
try {
override.apply(this, arguments);
} catch (e) {
test.fail('Exception in overriden method "' + methodName + '": ' + e);
}
return result;
};
};
// UI Tests
/**
* Tests that the real injected host is present in the context.
*/
TestSuite.prototype.testHostIsPresent = function() {
this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub);
};
/**
* Tests elements tree has an 'HTML' root.
*/
TestSuite.prototype.testElementsTreeRoot = function() {
var doc = WebInspector.domAgent.document;
this.assertEquals('HTML', doc.documentElement.nodeName);
this.assertTrue(doc.documentElement.hasChildNodes());
};
/**
* Tests that main resource is present in the system and that it is
* the only resource.
*/
TestSuite.prototype.testMainResource = function() {
var tokens = [];
var resources = WebInspector.resources;
for (var id in resources) {
tokens.push(resources[id].lastPathComponent);
}
this.assertEquals('simple_page.html', tokens.join(','));
};
/**
* Tests that resources tab is enabled when corresponding item is selected.
*/
TestSuite.prototype.testEnableResourcesTab = function() {
this.showPanel('resources');
var test = this;
this.addSniffer(WebInspector, 'addResource',
function(identifier, payload) {
test.assertEquals('simple_page.html', payload.lastPathComponent);
WebInspector.panels.resources.refresh();
WebInspector.resources[identifier]._resourcesTreeElement.select();
test.releaseControl();
});
// Following call should lead to reload that we capture in the
// addResource override.
WebInspector.panels.resources._enableResourceTracking();
// We now have some time to report results to controller.
this.takeControl();
};
/**
* Tests resource headers.
*/
TestSuite.prototype.testResourceHeaders = function() {
this.showPanel('resources');
var test = this;
var requestOk = false;
var responseOk = false;
var timingOk = false;
this.addSniffer(WebInspector, 'addResource',
function(identifier, payload) {
var resource = this.resources[identifier];
if (resource.mainResource) {
// We are only interested in secondary resources in this test.
return;
}
var requestHeaders = JSON.stringify(resource.requestHeaders);
test.assertContains(requestHeaders, 'Accept');
requestOk = true;
}, true);
this.addSniffer(WebInspector, 'updateResource',
function(identifier, payload) {
var resource = this.resources[identifier];
if (resource.mainResource) {
// We are only interested in secondary resources in this test.
return;
}
if (payload.didResponseChange) {
var responseHeaders = JSON.stringify(resource.responseHeaders);
test.assertContains(responseHeaders, 'Content-type');
test.assertContains(responseHeaders, 'Content-Length');
test.assertTrue(typeof resource.responseReceivedTime != 'undefnied');
responseOk = true;
}
if (payload.didTimingChange) {
test.assertTrue(typeof resource.startTime != 'undefnied');
timingOk = true;
}
if (payload.didCompletionChange) {
test.assertTrue(requestOk);
test.assertTrue(responseOk);
test.assertTrue(timingOk);
test.assertTrue(typeof resource.endTime != 'undefnied');
test.releaseControl();
}
}, true);
WebInspector.panels.resources._enableResourceTracking();
this.takeControl();
};
/**
* Test that profiler works.
*/
TestSuite.prototype.testProfilerTab = function() {
this.showPanel('profiles');
var test = this;
this.addSniffer(WebInspector, 'addProfile',
function(profile) {
var panel = WebInspector.panels.profiles;
panel.showProfile(profile);
var node = panel.visibleView.profileDataGridTree.children[0];
// Iterate over displayed functions and search for a function
// that is called 'fib' or 'eternal_fib'. If found, it will mean
// that we actually have profiled page's code.
while (node) {
if (node.functionName.indexOf('fib') != -1) {
test.releaseControl();
}
node = node.traverseNextNode(true, null, true);
}
test.fail();
});
var ticksCount = 0;
var tickRecord = '\nt,';
this.addSniffer(RemoteDebuggerAgent, 'DidGetNextLogLines',
function(log) {
var pos = 0;
while ((pos = log.indexOf(tickRecord, pos)) != -1) {
pos += tickRecord.length;
ticksCount++;
}
if (ticksCount > 100) {
InspectorController.stopProfiling();
}
}, true);
InspectorController.startProfiling();
this.takeControl();
};
/**
* Tests that scripts tab can be open and populated with inspected scripts.
*/
TestSuite.prototype.testShowScriptsTab = function() {
var parsedDebuggerTestPageHtml = false;
// Intercept parsedScriptSource calls to check that all expected scripts are
// added to the debugger.
var test = this;
var receivedConsoleApiSource = false;
this.addSniffer(WebInspector, 'parsedScriptSource',
function(sourceID, sourceURL, source, startingLine) {
if (sourceURL == undefined) {
if (receivedConsoleApiSource) {
test.fail('Unexpected script without URL');
} else {
receivedConsoleApiSource = true;
}
} else if (sourceURL.search(/debugger_test_page.html$/) != -1) {
if (parsedDebuggerTestPageHtml) {
test.fail('Unexpected parse event: ' + sourceURL);
}
parsedDebuggerTestPageHtml = true;
} else {
test.fail('Unexpected script URL: ' + sourceURL);
}
if (!WebInspector.panels.scripts.visibleView) {
test.fail('No visible script view: ' + sourceURL);
}
// There should be two scripts: one for the main page and another
// one which is source of console API(see
// InjectedScript._ensureCommandLineAPIInstalled).
if (parsedDebuggerTestPageHtml && receivedConsoleApiSource) {
test.releaseControl();
}
}, true /* sticky */);
this.showPanel('scripts');
// Wait until all scripts are added to the debugger.
this.takeControl();
};
/**
* Tests that scripts are not duplicaed on Scripts tab switch.
*/
TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function() {
var test = this;
// There should be two scripts: one for the main page and another
// one which is source of console API(see
// InjectedScript._ensureCommandLineAPIInstalled).
var expectedScriptsCount = 2;
var parsedScripts = [];
function switchToElementsTab() {
test.showPanel('elements');
setTimeout(switchToScriptsTab, 0);
}
function switchToScriptsTab() {
test.showPanel('scripts');
setTimeout(checkScriptsPanel, 0);
}
function checkScriptsPanel() {
test.assertTrue(!!WebInspector.panels.scripts.visibleView,
'No visible script view.');
var select = WebInspector.panels.scripts.filesSelectElement;
test.assertEquals(expectedScriptsCount, select.options.length,
'Unexpected options count');
test.releaseControl();
}
this.addSniffer(WebInspector, 'parsedScriptSource',
function(sourceID, sourceURL, source, startingLine) {
test.assertTrue(
parsedScripts.indexOf(sourceURL) == -1,
'Duplicated script: ' + sourceURL);
test.assertTrue(
parsedScripts.length < expectedScriptsCount,
'Too many scripts: ' + sourceURL);
parsedScripts.push(sourceURL);
if (parsedScripts.length == expectedScriptsCount) {
setTimeout(switchToElementsTab, 0);
}
}, true /* sticky */);
this.showPanel('scripts');
// Wait until all scripts are added to the debugger.
this.takeControl();
};
/**
* Tests that a breakpoint can be set.
*/
TestSuite.prototype.testSetBreakpoint = function() {
var parsedDebuggerTestPageHtml = false;
var parsedDebuggerTestJs = false;
this.showPanel('scripts');
var scriptUrl = null;
var breakpointLine = 12;
var test = this;
this.addSniffer(devtools.DebuggerAgent.prototype, 'handleScriptsResponse_',
function(msg) {
var scriptSelect = document.getElementById('scripts-files');
var options = scriptSelect.options;
// There should be console API source (see
// InjectedScript._ensureCommandLineAPIInstalled) and the page script.
test.assertEquals(2, options.length, 'Unexpected number of scripts(' +
test.optionsToString_(options) + ')');
test.showMainPageScriptSource_(
'debugger_test_page.html',
function(view, url) {
view._addBreakpoint(breakpointLine);
// Force v8 execution.
RemoteToolsAgent.ExecuteVoidJavaScript();
test.waitForSetBreakpointResponse_(url, breakpointLine,
function() {
test.releaseControl();
});
});
});
this.takeControl();
};
/**
* Serializes options collection to string.
* @param {HTMLOptionsCollection} options
* @return {string}
*/
TestSuite.prototype.optionsToString_ = function(options) {
var names = [];
for (var i = 0; i < options.length; i++) {
names.push('"' + options[i].text + '"');
}
return names.join(',');
};
/**
* Ensures that main HTML resource is selected in Scripts panel and that its
* source frame is setup. Invokes the callback when the condition is satisfied.
* @param {HTMLOptionsCollection} options
* @param {function(WebInspector.SourceView,string)} callback
*/
TestSuite.prototype.showMainPageScriptSource_ = function(scriptName, callback) {
var test = this;
var scriptSelect = document.getElementById('scripts-files');
var options = scriptSelect.options;
// There should be console API source (see
// InjectedScript._ensureCommandLineAPIInstalled) and the page script.
test.assertEquals(2, options.length,
'Unexpected number of scripts(' + test.optionsToString_(options) + ')');
// Select page's script if it's not current option.
if (options[scriptSelect.selectedIndex].text !== scriptName) {
var pageScriptIndex = -1;
for (var i = 0; i < options.length; i++) {
if (options[i].text === scriptName) {
pageScriptIndex = i;
break;
}
}
test.assertTrue(-1 !== pageScriptIndex,
'Script with url ' + scriptName + ' not found among ' +
test.optionsToString_(options));
// Current panel is 'Scripts'.
WebInspector.currentPanel._showScriptOrResource(scriptResource);
test.assertEquals(pageScriptIndex, scriptSelect.selectedIndex,
'Unexpected selected option index.');
}
var scriptResource = options[scriptSelect.selectedIndex].representedObject;
test.assertTrue(scriptResource instanceof WebInspector.Resource,
'Unexpected resource class.');
test.assertTrue(!!scriptResource.url, 'Resource URL is null.');
test.assertTrue(
scriptResource.url.search(scriptName + '$') != -1,
'Main HTML resource should be selected.');
var scriptsPanel = WebInspector.panels.scripts;
var view = scriptsPanel.visibleView;
test.assertTrue(view instanceof WebInspector.SourceView);
if (!view.sourceFrame._isContentLoaded()) {
test.addSniffer(view, '_sourceFrameSetupFinished', function(event) {
callback(view, scriptResource.url);
});
} else {
callback(view, scriptResource.url);
}
};
/*
* Evaluates the code in the console as if user typed it manually and invokes
* the callback when the result message is received and added to the console.
* @param {string} code
* @param {function(string)} callback
*/
TestSuite.prototype.evaluateInConsole_ = function(code, callback) {
WebInspector.console.visible = true;
WebInspector.console.prompt.text = code;
WebInspector.console.promptElement.handleKeyEvent(
new TestSuite.KeyEvent('Enter'));
this.addSniffer(WebInspector.ConsoleView.prototype, 'addMessage',
function(commandResult) {
callback(commandResult.toMessageElement().textContent);
});
};
/*
* Waits for 'setbreakpoint' response, checks that corresponding breakpoint
* was successfully set and invokes the callback if it was.
* @param {string} scriptUrl
* @param {number} breakpointLine
* @param {function()} callback
*/
TestSuite.prototype.waitForSetBreakpointResponse_ = function(scriptUrl,
breakpointLine,
callback) {
var test = this;
test.addSniffer(
devtools.DebuggerAgent.prototype,
'handleSetBreakpointResponse_',
function(msg) {
var bps = this.urlToBreakpoints_[scriptUrl];
test.assertTrue(!!bps, 'No breakpoints for line ' + breakpointLine);
var line = devtools.DebuggerAgent.webkitToV8LineNumber_(breakpointLine);
test.assertTrue(!!bps[line].getV8Id(),
'Breakpoint id was not assigned.');
callback();
});
};
/**
* Tests eval on call frame.
*/
TestSuite.prototype.testEvalOnCallFrame = function() {
this.showPanel('scripts');
var breakpointLine = 16;
var test = this;
this.addSniffer(devtools.DebuggerAgent.prototype, 'handleScriptsResponse_',
function(msg) {
test.showMainPageScriptSource_(
'debugger_test_page.html',
function(view, url) {
view._addBreakpoint(breakpointLine);
// Force v8 execution.
RemoteToolsAgent.ExecuteVoidJavaScript();
test.waitForSetBreakpointResponse_(url, breakpointLine,
setBreakpointCallback);
});
});
function setBreakpointCallback() {
// Since breakpoints are ignored in evals' calculate() function is
// execute after zero-timeout so that the breakpoint is hit.
test.evaluateInConsole_(
'setTimeout("calculate(123)" , 0)',
function(resultText) {
test.assertTrue(!isNaN(resultText),
'Failed to get timer id: ' + resultText);
waitForBreakpointHit();
});
}
function waitForBreakpointHit() {
test.addSniffer(
devtools.DebuggerAgent.prototype,
'handleBacktraceResponse_',
function(msg) {
test.assertEquals(2, this.callFrames_.length,
'Unexpected stack depth on the breakpoint. ' +
JSON.stringify(msg));
test.assertEquals('calculate', this.callFrames_[0].functionName,
'Unexpected top frame function.');
// Evaluate 'e+1' where 'e' is an argument of 'calculate' function.
test.evaluateInConsole_(
'e+1',
function(resultText) {
test.assertEquals('124', resultText, 'Unexpected "e+1" value.');
test.releaseControl();
});
});
}
this.takeControl();
};
/**
* Tests 'Pause' button will pause debugger when a snippet is evaluated.
*/
TestSuite.prototype.testPauseInEval = function() {
this.showPanel('scripts');
var test = this;
var pauseButton = document.getElementById('scripts-pause');
pauseButton.click();
devtools.tools.evaluateJavaScript('fib(10)');
this.addSniffer(WebInspector, 'pausedScript',
function() {
test.releaseControl();
});
test.takeControl();
};
/**
* Key event with given key identifier.
*/
TestSuite.KeyEvent = function(key) {
this.keyIdentifier = key;
};
TestSuite.KeyEvent.prototype.preventDefault = function() {};
TestSuite.KeyEvent.prototype.stopPropagation = function() {};
/**
* Tests console eval.
*/
TestSuite.prototype.testConsoleEval = function() {
WebInspector.console.visible = true;
WebInspector.console.prompt.text = '123';
WebInspector.console.promptElement.handleKeyEvent(
new TestSuite.KeyEvent('Enter'));
var test = this;
this.addSniffer(WebInspector.ConsoleView.prototype, 'addMessage',
function(commandResult) {
test.assertEquals('123', commandResult.toMessageElement().textContent);
test.releaseControl();
});
this.takeControl();
};
/**
* Tests console log.
*/
TestSuite.prototype.testConsoleLog = function() {
WebInspector.console.visible = true;
var messages = WebInspector.console.messages;
var index = 0;
var test = this;
var assertNext = function(line, message, opt_class, opt_count, opt_substr) {
var elem = messages[index++].toMessageElement();
var clazz = elem.getAttribute('class');
var expectation = (opt_count || '') + 'console_test_page.html:' +
line + message;
if (opt_substr) {
test.assertContains(elem.textContent, expectation);
} else {
test.assertEquals(expectation, elem.textContent);
}
if (opt_class) {
test.assertContains(clazz, 'console-' + opt_class);
}
};
assertNext('5', 'log', 'log-level');
assertNext('7', 'debug', 'log-level');
assertNext('9', 'info', 'log-level');
assertNext('11', 'warn', 'warning-level');
assertNext('13', 'error', 'error-level');
assertNext('15', 'Message format number 1, 2 and 3.5');
assertNext('17', 'Message format for string');
assertNext('19', 'Object Object');
assertNext('22', 'repeated', 'log-level', 5);
assertNext('26', 'count: 1');
assertNext('26', 'count: 2');
assertNext('29', 'group', 'group-title');
index++;
assertNext('33', 'timer:', 'log-level', '', true);
assertNext('35', '1 2 3', 'log-level');
assertNext('37', 'HTMLDocument', 'log-level');
assertNext('39', '<html>', 'log-level', '', true);
};
/**
* Tests eval of global objects.
*/
TestSuite.prototype.testEvalGlobal = function() {
WebInspector.console.visible = true;
var inputs = ['foo', 'foobar'];
var expectations = ['foo', 'fooValue',
'foobar', 'ReferenceError: foobar is not defined'];
// Do not change code below - simply add inputs and expectations above.
var initEval = function(input) {
WebInspector.console.prompt.text = input;
WebInspector.console.promptElement.handleKeyEvent(
new TestSuite.KeyEvent('Enter'));
};
var test = this;
var messagesCount = 0;
var inputIndex = 0;
this.addSniffer(WebInspector.ConsoleView.prototype, 'addMessage',
function(commandResult) {
messagesCount++;
if (messagesCount == expectations.length) {
var messages = WebInspector.console.messages;
for (var i = 0; i < expectations; ++i) {
var elem = messages[i++].toMessageElement();
test.assertEquals(elem.textContent, expectations[i]);
}
test.releaseControl();
} else if (messagesCount % 2 == 0) {
initEval(inputs[inputIndex++]);
}
}, true);
initEval(inputs[inputIndex++]);
this.takeControl();
};
/**
* Test runner for the test suite.
*/
var uiTests = {};
/**
* Run each test from the test suit on a fresh instance of the suite.
*/
uiTests.runAllTests = function() {
// For debugging purposes.
for (var name in TestSuite.prototype) {
if (name.substring(0, 4) == 'test' &&
typeof TestSuite.prototype[name] == 'function') {
uiTests.runTest(name);
}
}
};
/**
* Run specified test on a fresh instance of the test suite.
* @param {string} name Name of a test method from TestSuite class.
*/
uiTests.runTest = function(name) {
new TestSuite().runTest(name);
};
}
|