Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / main / Tests.js
blob684ba91079ce708ea3f9418c050d9c786d5c1dea
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 /**
33 * @fileoverview This file contains small testing framework along with the
34 * test suite for the frontend. These tests are a part of the continues build
35 * and are executed by the devtools_sanity_unittest.cc as a part of the
36 * Interactive UI Test suite.
37 * FIXME: change field naming style to use trailing underscore.
40 function createTestSuite(domAutomationController)
43 /**
44 * Test suite for interactive UI tests.
45 * @constructor
47 function TestSuite()
49 WebInspector.TestBase.call(this, domAutomationController);
52 TestSuite.prototype = {
53 __proto__: WebInspector.TestBase.prototype
57 /**
58 * @param {string} panelName Name of the panel to show.
60 TestSuite.prototype.showPanel = function(panelName)
62 return WebInspector.inspectorView.showPanel(panelName);
65 // UI Tests
68 /**
69 * Tests that scripts tab can be open and populated with inspected scripts.
71 TestSuite.prototype.testShowScriptsTab = function()
73 var test = this;
74 this.showPanel("sources").then(function() {
75 // There should be at least main page script.
76 this._waitUntilScriptsAreParsed(["debugger_test_page.html"],
77 function() {
78 test.releaseControl();
79 });
80 }.bind(this));
81 // Wait until all scripts are added to the debugger.
82 this.takeControl();
86 /**
87 * Tests that scripts tab is populated with inspected scripts even if it
88 * hadn't been shown by the moment inspected paged refreshed.
89 * @see http://crbug.com/26312
91 TestSuite.prototype.testScriptsTabIsPopulatedOnInspectedPageRefresh = function()
93 var test = this;
94 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targetManager.mainTarget());
95 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed);
97 this.showPanel("elements").then(function() {
98 // Reload inspected page. It will reset the debugger agent.
99 test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
102 function waitUntilScriptIsParsed()
104 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed);
105 test.showPanel("sources").then(function() {
106 test._waitUntilScriptsAreParsed(["debugger_test_page.html"],
107 function() {
108 test.releaseControl();
113 // Wait until all scripts are added to the debugger.
114 this.takeControl();
119 * Tests that scripts list contains content scripts.
121 TestSuite.prototype.testContentScriptIsPresent = function()
123 var test = this;
124 this.showPanel("sources").then(function() {
125 test._waitUntilScriptsAreParsed(
126 ["page_with_content_script.html", "simple_content_script.js"],
127 function() {
128 test.releaseControl();
132 // Wait until all scripts are added to the debugger.
133 this.takeControl();
138 * Tests that scripts are not duplicaed on Scripts tab switch.
140 TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function()
142 var test = this;
144 // There should be two scripts: one for the main page and another
145 // one which is source of console API(see
146 // InjectedScript._ensureCommandLineAPIInstalled).
147 var expectedScriptsCount = 2;
148 var parsedScripts = [];
150 function switchToElementsTab() {
151 test.showPanel("elements").then(function() {
152 setTimeout(switchToScriptsTab, 0);
156 function switchToScriptsTab() {
157 test.showPanel("sources").then(function() {
158 setTimeout(checkScriptsPanel, 0);
162 function checkScriptsPanel() {
163 test.assertTrue(test._scriptsAreParsed(["debugger_test_page.html"]), "Some scripts are missing.");
164 checkNoDuplicates();
165 test.releaseControl();
168 function checkNoDuplicates() {
169 var uiSourceCodes = test.nonAnonymousUISourceCodes_();
170 for (var i = 0; i < uiSourceCodes.length; i++) {
171 var scriptName = WebInspector.networkMapping.networkURL(uiSourceCodes[i]);
172 for (var j = i + 1; j < uiSourceCodes.length; j++)
173 test.assertTrue(scriptName !== WebInspector.networkMapping.networkURL(uiSourceCodes[j]), "Found script duplicates: " + test.uiSourceCodesToString_(uiSourceCodes));
177 this.showPanel("sources").then(function() {
178 test._waitUntilScriptsAreParsed(
179 ["debugger_test_page.html"],
180 function() {
181 checkNoDuplicates();
182 setTimeout(switchToElementsTab, 0);
186 // Wait until all scripts are added to the debugger.
187 this.takeControl();
191 // Tests that debugger works correctly if pause event occurs when DevTools
192 // frontend is being loaded.
193 TestSuite.prototype.testPauseWhenLoadingDevTools = function()
195 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targetManager.mainTarget());
196 if (debuggerModel.debuggerPausedDetails)
197 return;
199 this.showPanel("sources").then(function() {
200 // Script execution can already be paused.
202 this._waitForScriptPause(this.releaseControl.bind(this));
203 }.bind(this));
205 this.takeControl();
209 // Tests that pressing "Pause" will pause script execution if the script
210 // is already running.
211 TestSuite.prototype.testPauseWhenScriptIsRunning = function()
213 this.showPanel("sources").then(function() {
214 this.evaluateInConsole_(
215 'setTimeout("handleClick()", 0)',
216 didEvaluateInConsole.bind(this));
217 }.bind(this));
219 function didEvaluateInConsole(resultText) {
220 this.assertTrue(!isNaN(resultText), "Failed to get timer id: " + resultText);
221 // Wait for some time to make sure that inspected page is running the
222 // infinite loop.
223 setTimeout(testScriptPause.bind(this), 300);
226 function testScriptPause() {
227 // The script should be in infinite loop. Click "Pause" button to
228 // pause it and wait for the result.
229 WebInspector.panels.sources._pauseButton.element.click();
231 this._waitForScriptPause(this.releaseControl.bind(this));
234 this.takeControl();
239 * Tests network size.
241 TestSuite.prototype.testNetworkSize = function()
243 var test = this;
245 function finishResource(resource, finishTime)
247 test.assertEquals(219, resource.transferSize, "Incorrect total encoded data length");
248 test.assertEquals(25, resource.resourceSize, "Incorrect total data length");
249 test.releaseControl();
252 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
254 // Reload inspected page to sniff network events
255 test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
257 this.takeControl();
262 * Tests network sync size.
264 TestSuite.prototype.testNetworkSyncSize = function()
266 var test = this;
268 function finishResource(resource, finishTime)
270 test.assertEquals(219, resource.transferSize, "Incorrect total encoded data length");
271 test.assertEquals(25, resource.resourceSize, "Incorrect total data length");
272 test.releaseControl();
275 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
277 // Send synchronous XHR to sniff network events
278 test.evaluateInConsole_("var xhr = new XMLHttpRequest(); xhr.open(\"GET\", \"chunked\", false); xhr.send(null);", function() {});
280 this.takeControl();
285 * Tests network raw headers text.
287 TestSuite.prototype.testNetworkRawHeadersText = function()
289 var test = this;
291 function finishResource(resource, finishTime)
293 if (!resource.responseHeadersText)
294 test.fail("Failure: resource does not have response headers text");
295 test.assertEquals(164, resource.responseHeadersText.length, "Incorrect response headers text length");
296 test.releaseControl();
299 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
301 // Reload inspected page to sniff network events
302 test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
304 this.takeControl();
309 * Tests network timing.
311 TestSuite.prototype.testNetworkTiming = function()
313 var test = this;
315 function finishResource(resource, finishTime)
317 // Setting relaxed expectations to reduce flakiness.
318 // Server sends headers after 100ms, then sends data during another 100ms.
319 // We expect these times to be measured at least as 70ms.
320 test.assertTrue(resource.timing.receiveHeadersEnd - resource.timing.connectStart >= 70,
321 "Time between receiveHeadersEnd and connectStart should be >=70ms, but was " +
322 "receiveHeadersEnd=" + resource.timing.receiveHeadersEnd + ", connectStart=" + resource.timing.connectStart + ".");
323 test.assertTrue(resource.responseReceivedTime - resource.startTime >= 0.07,
324 "Time between responseReceivedTime and startTime should be >=0.07s, but was " +
325 "responseReceivedTime=" + resource.responseReceivedTime + ", startTime=" + resource.startTime + ".");
326 test.assertTrue(resource.endTime - resource.startTime >= 0.14,
327 "Time between endTime and startTime should be >=0.14s, but was " +
328 "endtime=" + resource.endTime + ", startTime=" + resource.startTime + ".");
330 test.releaseControl();
333 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
335 // Reload inspected page to sniff network events
336 test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
338 this.takeControl();
342 TestSuite.prototype.testConsoleOnNavigateBack = function()
344 if (WebInspector.multitargetConsoleModel.messages().length === 1)
345 firstConsoleMessageReceived.call(this);
346 else
347 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this);
349 function firstConsoleMessageReceived() {
350 WebInspector.multitargetConsoleModel.removeEventListener(WebInspector.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this);
351 this.evaluateInConsole_("clickLink();", didClickLink.bind(this));
354 function didClickLink() {
355 // Check that there are no new messages(command is not a message).
356 this.assertEquals(3, WebInspector.multitargetConsoleModel.messages().length);
357 this.evaluateInConsole_("history.back();", didNavigateBack.bind(this));
360 function didNavigateBack()
362 // Make sure navigation completed and possible console messages were pushed.
363 this.evaluateInConsole_("void 0;", didCompleteNavigation.bind(this));
366 function didCompleteNavigation() {
367 this.assertEquals(7, WebInspector.multitargetConsoleModel.messages().length);
368 this.releaseControl();
371 this.takeControl();
374 TestSuite.prototype.testReattachAfterCrash = function()
376 var target = WebInspector.targetManager.mainTarget();
377 target.pageAgent().navigate("about:crash");
378 target.pageAgent().navigate("about:blank");
379 target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextCreated, this.releaseControl, this);
383 TestSuite.prototype.testSharedWorker = function()
385 function didEvaluateInConsole(resultText) {
386 this.assertEquals("2011", resultText);
387 this.releaseControl();
389 this.evaluateInConsole_("globalVar", didEvaluateInConsole.bind(this));
390 this.takeControl();
394 TestSuite.prototype.testPauseInSharedWorkerInitialization1 = function()
396 // Make sure the worker is loaded.
397 function isReady()
399 return WebInspector.targetManager.targets().length == 2;
402 if (isReady())
403 return;
404 this.takeControl();
405 this.addSniffer(WebInspector.TargetManager.prototype, "addTarget", targetAdded.bind(this));
407 function targetAdded()
409 if (isReady()) {
410 this.releaseControl();
411 return;
413 this.addSniffer(WebInspector.TargetManager.prototype, "addTarget", targetAdded.bind(this));
417 TestSuite.prototype.testPauseInSharedWorkerInitialization2 = function()
419 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targetManager.mainTarget());
420 if (debuggerModel.isPaused())
421 return;
422 this._waitForScriptPause(this.releaseControl.bind(this));
423 this.takeControl();
426 TestSuite.prototype.enableTouchEmulation = function()
428 WebInspector.overridesSupport._emulateTouchEventsInTarget(WebInspector.targetManager.mainTarget(), true, "mobile");
432 // Regression test for crbug.com/370035.
433 TestSuite.prototype.testDeviceMetricsOverrides = function()
435 const dumpPageMetrics = function()
437 return JSON.stringify({
438 width: window.innerWidth,
439 height: window.innerHeight,
440 deviceScaleFactor: window.devicePixelRatio
444 var test = this;
446 function testOverrides(params, metrics, callback)
448 WebInspector.targetManager.mainTarget().emulationAgent().invoke_setDeviceMetricsOverride(params, getMetrics);
450 function getMetrics()
452 test.evaluateInConsole_("(" + dumpPageMetrics.toString() + ")()", checkMetrics);
455 function checkMetrics(consoleResult)
457 test.assertEquals('"' + JSON.stringify(metrics) + '"', consoleResult, "Wrong metrics for params: " + JSON.stringify(params));
458 callback();
462 function step1()
464 testOverrides({width: 1200, height: 1000, deviceScaleFactor: 1, mobile: false, fitWindow: true}, {width: 1200, height: 1000, deviceScaleFactor: 1}, step2);
467 function step2()
469 testOverrides({width: 1200, height: 1000, deviceScaleFactor: 1, mobile: false, fitWindow: false}, {width: 1200, height: 1000, deviceScaleFactor: 1}, step3);
472 function step3()
474 testOverrides({width: 1200, height: 1000, deviceScaleFactor: 3, mobile: false, fitWindow: true}, {width: 1200, height: 1000, deviceScaleFactor: 3}, step4);
477 function step4()
479 testOverrides({width: 1200, height: 1000, deviceScaleFactor: 3, mobile: false, fitWindow: false}, {width: 1200, height: 1000, deviceScaleFactor: 3}, finish);
482 function finish()
484 test.releaseControl();
487 WebInspector.overridesSupport._deviceMetricsChangedListenerMuted = true;
488 test.takeControl();
489 this.waitForThrottler(WebInspector.overridesSupport._deviceMetricsThrottler, step1);
492 TestSuite.prototype.testScreenshotRecording = function()
494 var test = this;
496 function performActionsInPage(callback)
498 var count = 0;
499 var div = document.createElement("div");
500 div.setAttribute("style", "left: 0px; top: 0px; width: 100px; height: 100px; position: absolute;");
501 document.body.appendChild(div);
502 requestAnimationFrame(frame);
503 function frame()
505 var color = [0, 0, 0];
506 color[count % 3] = 255;
507 div.style.backgroundColor = "rgb(" + color.join(",") + ")";
508 if (++count > 10)
509 requestAnimationFrame(callback);
510 else
511 requestAnimationFrame(frame);
515 var captureFilmStripSetting = WebInspector.settings.createSetting("timelineCaptureFilmStrip", false);
516 captureFilmStripSetting.set(true);
517 test.evaluateInConsole_(performActionsInPage.toString(), function() {});
518 test.invokeAsyncWithTimeline_("performActionsInPage", onTimelineDone);
520 function onTimelineDone()
522 captureFilmStripSetting.set(false);
523 var filmStripModel = new WebInspector.FilmStripModel(WebInspector.panels.timeline._tracingModel);
524 var frames = filmStripModel.frames();
525 test.assertTrue(frames.length > 4 && typeof frames.length === "number");
526 loadFrameImages(frames);
529 function loadFrameImages(frames)
531 var readyImages = [];
532 for (var frame of frames)
533 frame.imageDataPromise().then(onGotImageData)
535 function onGotImageData(data)
537 var image = new Image();
538 test.assertTrue(!!data, "No image data for frame");
539 image.addEventListener("load", onLoad);
540 image.src = "data:image/jpg;base64," + data;
543 function onLoad(event)
545 readyImages.push(event.target);
546 if (readyImages.length === frames.length)
547 validateImagesAndCompleteTest(readyImages);
551 function validateImagesAndCompleteTest(images)
553 var redString = [255, 0, 0, 255].join(",");
554 var greenString = [0, 255, 0, 255].join(",");
555 var blueString = [0, 0, 255, 255].join(",");
556 var redCount = 0;
557 var greenCount = 0;
558 var blueCount = 0;
560 var canvas = document.createElement("canvas");
561 var ctx = canvas.getContext("2d");
562 for (var image of images) {
563 test.assertTrue(image.naturalWidth > 10);
564 test.assertTrue(image.naturalHeight > 10);
565 canvas.width = image.naturalWidth;
566 canvas.height = image.naturalHeight;
567 ctx.drawImage(image, 0, 0);
568 var data = ctx.getImageData(0, 0, 1, 1);
569 var color = Array.prototype.join.call(data.data, ",");
570 if (color === redString)
571 redCount++;
572 else if (color === greenString)
573 greenCount++;
574 else if (color === blueString)
575 blueCount++;
576 else
577 test.fail("Unexpected color: " + color);
579 test.assertTrue(redCount && greenCount && blueCount, "Color sanity check failed");
580 test.releaseControl();
583 test.takeControl();
586 TestSuite.prototype.testSettings = function()
588 var test = this;
590 createSettings();
591 test.takeControl();
592 setTimeout(reset, 0);
594 function createSettings()
596 var localSetting = WebInspector.settings.createSetting("local", undefined, true);
597 localSetting.set({s: "local", n: 1 });
598 var globalSetting = WebInspector.settings.createSetting("global", undefined, false);
599 globalSetting.set({s: "global", n: 2 });
602 function reset()
604 Runtime.experiments.clearForTest();
605 InspectorFrontendHost.getPreferences(gotPreferences);
608 function gotPreferences(prefs)
610 WebInspector.Main._instanceForTest._createSettings(prefs);
612 var localSetting = WebInspector.settings.createSetting("local", undefined, true);
613 test.assertEquals("object", typeof localSetting.get());
614 test.assertEquals("local", localSetting.get().s);
615 test.assertEquals(1, localSetting.get().n);
616 var globalSetting = WebInspector.settings.createSetting("global", undefined, false);
617 test.assertEquals("object", typeof globalSetting.get());
618 test.assertEquals("global", globalSetting.get().s);
619 test.assertEquals(2, globalSetting.get().n);
620 test.releaseControl();
624 TestSuite.prototype.waitForTestResultsInConsole = function()
626 var messages = WebInspector.multitargetConsoleModel.messages();
627 for (var i = 0; i < messages.length; ++i) {
628 var text = messages[i].messageText;
629 if (text === "PASS")
630 return;
631 else if (/^FAIL/.test(text))
632 this.fail(text); // This will throw.
634 // Neither PASS nor FAIL, so wait for more messages.
635 function onConsoleMessage(event)
637 var text = event.data.messageText;
638 if (text === "PASS")
639 this.releaseControl();
640 else if (/^FAIL/.test(text))
641 this.fail(text);
644 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, this);
645 this.takeControl();
648 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback)
650 var test = this;
651 test.showPanel("timeline").then(function() {
652 WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStarted, onRecordingStarted);
653 WebInspector.panels.timeline.toggleTimelineButton.element.click();
656 function onRecordingStarted()
658 WebInspector.panels.timeline._model.removeEventListener(WebInspector.TimelineModel.Events.RecordingStarted, onRecordingStarted);
659 test.evaluateInConsole_(functionName + "(function() { console.log('DONE'); });", function() {});
660 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage);
663 function onConsoleMessage(event)
665 var text = event.data.messageText;
666 if (text === "DONE") {
667 WebInspector.multitargetConsoleModel.removeEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage);
668 pageActionsDone();
672 function pageActionsDone()
674 WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped);
675 WebInspector.panels.timeline.toggleTimelineButton.element.click();
678 function onRecordingStopped()
680 WebInspector.panels.timeline._model.removeEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped);
681 callback();
686 * Serializes array of uiSourceCodes to string.
687 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes
688 * @return {string}
690 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes)
692 var names = [];
693 for (var i = 0; i < uiSourceCodes.length; i++)
694 names.push('"' + WebInspector.networkMapping.networkURL(uiSourceCodes[i]) + '"');
695 return names.join(",");
700 * Returns all loaded non anonymous uiSourceCodes.
701 * @return {!Array.<!WebInspectorUISourceCode>}
703 TestSuite.prototype.nonAnonymousUISourceCodes_ = function()
705 function filterOutAnonymous(uiSourceCode)
707 return !!WebInspector.networkMapping.networkURL(uiSourceCode);
710 function filterOutService(uiSourceCode)
712 return !uiSourceCode.project().isServiceProject();
715 var uiSourceCodes = WebInspector.workspace.uiSourceCodes();
716 uiSourceCodes = uiSourceCodes.filter(filterOutService);
717 return uiSourceCodes.filter(filterOutAnonymous);
722 * Evaluates the code in the console as if user typed it manually and invokes
723 * the callback when the result message is received and added to the console.
724 * @param {string} code
725 * @param {function(string)} callback
727 TestSuite.prototype.evaluateInConsole_ = function(code, callback)
729 function innerEvaluate()
731 WebInspector.context.removeFlavorChangeListener(WebInspector.ExecutionContext, showConsoleAndEvaluate, this);
732 var consoleView = WebInspector.ConsolePanel._view();
733 consoleView._prompt.setText(code);
734 consoleView._promptElement.dispatchEvent(TestSuite.createKeyEvent("Enter"));
736 this.addSniffer(WebInspector.ConsoleView.prototype, "_consoleMessageAddedForTest",
737 function(viewMessage) {
738 callback(viewMessage.toMessageElement().deepTextContent());
739 }.bind(this));
742 function showConsoleAndEvaluate()
744 WebInspector.console.showPromise().then(innerEvaluate.bind(this));
747 if (!WebInspector.context.flavor(WebInspector.ExecutionContext)) {
748 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, showConsoleAndEvaluate, this);
749 return;
751 showConsoleAndEvaluate.call(this);
755 * Checks that all expected scripts are present in the scripts list
756 * in the Scripts panel.
757 * @param {!Array.<string>} expected Regular expressions describing
758 * expected script names.
759 * @return {boolean} Whether all the scripts are in "scripts-files" select
760 * box
762 TestSuite.prototype._scriptsAreParsed = function(expected)
764 var uiSourceCodes = this.nonAnonymousUISourceCodes_();
765 // Check that at least all the expected scripts are present.
766 var missing = expected.slice(0);
767 for (var i = 0; i < uiSourceCodes.length; ++i) {
768 for (var j = 0; j < missing.length; ++j) {
769 if (uiSourceCodes[i].name().search(missing[j]) !== -1) {
770 missing.splice(j, 1);
771 break;
775 return missing.length === 0;
780 * Waits for script pause, checks expectations, and invokes the callback.
781 * @param {function():void} callback
783 TestSuite.prototype._waitForScriptPause = function(callback)
785 this.addSniffer(WebInspector.DebuggerModel.prototype, "_pausedScript", callback);
790 * Waits until all the scripts are parsed and invokes the callback.
792 TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, callback)
794 var test = this;
796 function waitForAllScripts() {
797 if (test._scriptsAreParsed(expectedScripts))
798 callback();
799 else
800 test.addSniffer(WebInspector.panels.sources.sourcesView(), "_addUISourceCode", waitForAllScripts);
803 waitForAllScripts();
808 * Key event with given key identifier.
810 TestSuite.createKeyEvent = function(keyIdentifier)
812 var evt = document.createEvent("KeyboardEvent");
813 evt.initKeyboardEvent("keydown", true /* can bubble */, true /* can cancel */, null /* view */, keyIdentifier, "");
814 return evt;
818 * Run specified test.
819 * @param {string} name Name of a test method from TestSuite class.
820 * @override
822 TestSuite.prototype.runTest = function(name)
824 var test = WebInspector.TestBase.prototype.runTest.bind(this, name);
825 if (TestSuite._populatedInterface)
826 test();
827 else
828 TestSuite._pendingTest = test;
831 function runTests()
833 TestSuite._populatedInterface = true;
834 var test = TestSuite._pendingTest;
835 delete TestSuite._pendingTest;
836 if (test)
837 test();
840 WebInspector.notifications.addEventListener(WebInspector.NotificationService.Events.InspectorAgentEnabledForTests, runTests);
842 return new TestSuite();
846 if (window.uiTests)
847 window.uiTests.testSuiteReady(createTestSuite, WebInspector.TestBase);