OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview This file contains small testing framework along with the | 7 * @fileoverview This file contains small testing framework along with the |
8 * test suite for the frontend. These tests are a part of the continues build | 8 * test suite for the frontend. These tests are a part of the continues build |
9 * and are executed by the devtools_sanity_unittest.cc as a part of the | 9 * and are executed by the devtools_sanity_unittest.cc as a part of the |
10 * Interactive UI Test suite. | 10 * Interactive UI Test suite. |
(...skipping 510 matching lines...) Loading... |
521 */ | 521 */ |
522 TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function() { | 522 TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function() { |
523 var test = this; | 523 var test = this; |
524 | 524 |
525 // There should be two scripts: one for the main page and another | 525 // There should be two scripts: one for the main page and another |
526 // one which is source of console API(see | 526 // one which is source of console API(see |
527 // InjectedScript._ensureCommandLineAPIInstalled). | 527 // InjectedScript._ensureCommandLineAPIInstalled). |
528 var expectedScriptsCount = 2; | 528 var expectedScriptsCount = 2; |
529 var parsedScripts = []; | 529 var parsedScripts = []; |
530 | 530 |
| 531 this.showPanel('scripts'); |
| 532 |
531 | 533 |
532 function switchToElementsTab() { | 534 function switchToElementsTab() { |
533 test.showPanel('elements'); | 535 test.showPanel('elements'); |
534 setTimeout(switchToScriptsTab, 0); | 536 setTimeout(switchToScriptsTab, 0); |
535 } | 537 } |
536 | 538 |
537 function switchToScriptsTab() { | 539 function switchToScriptsTab() { |
538 test.showPanel('scripts'); | 540 test.showPanel('scripts'); |
539 setTimeout(checkScriptsPanel, 0); | 541 setTimeout(checkScriptsPanel, 0); |
540 } | 542 } |
541 | 543 |
542 function checkScriptsPanel() { | 544 function checkScriptsPanel() { |
543 test.assertTrue(!!WebInspector.panels.scripts.visibleView, | 545 test.assertTrue(!!WebInspector.panels.scripts.visibleView, |
544 'No visible script view.'); | 546 'No visible script view.'); |
545 var select = WebInspector.panels.scripts.filesSelectElement; | 547 test.assertTrue(test._scriptsAreParsed(['debugger_test_page.html$']), |
546 test.assertEquals(expectedScriptsCount, select.options.length, | 548 'Some scripts are missing.'); |
547 'Unexpected options count'); | 549 checkNoDuplicates(); |
548 test.releaseControl(); | 550 test.releaseControl(); |
549 } | 551 } |
550 | 552 |
551 this.addSniffer(WebInspector, 'parsedScriptSource', | 553 function checkNoDuplicates() { |
552 function(sourceID, sourceURL, source, startingLine) { | 554 var scriptSelect = document.getElementById('scripts-files'); |
553 test.assertTrue( | 555 var options = scriptSelect.options; |
554 parsedScripts.indexOf(sourceURL) == -1, | 556 for (var i = 0; i < options.length; i++) { |
555 'Duplicated script: ' + sourceURL); | 557 var scriptName = options[i].text; |
556 test.assertTrue( | 558 for (var j = i + 1; j < options.length; j++) { |
557 parsedScripts.length < expectedScriptsCount, | 559 test.assertTrue(scriptName != options[j].text, |
558 'Too many scripts: ' + sourceURL); | 560 'Found script duplicates: ' + test.optionsToString_(options)); |
559 parsedScripts.push(sourceURL); | 561 } |
| 562 } |
| 563 } |
560 | 564 |
561 if (parsedScripts.length == expectedScriptsCount) { | 565 test._waitUntilScriptsAreParsed( |
562 setTimeout(switchToElementsTab, 0); | 566 ['debugger_test_page.html$'], |
563 } | 567 function() { |
564 }, true /* sticky */); | 568 checkNoDuplicates(); |
| 569 setTimeout(switchToElementsTab, 0); |
| 570 }); |
565 | 571 |
566 this.showPanel('scripts'); | |
567 | 572 |
568 // Wait until all scripts are added to the debugger. | 573 // Wait until all scripts are added to the debugger. |
569 this.takeControl(); | 574 this.takeControl(); |
570 }; | 575 }; |
571 | 576 |
572 | 577 |
573 /** | 578 /** |
574 * Tests that a breakpoint can be set. | 579 * Tests that a breakpoint can be set. |
575 */ | 580 */ |
576 TestSuite.prototype.testSetBreakpoint = function() { | 581 TestSuite.prototype.testSetBreakpoint = function() { |
577 var parsedDebuggerTestPageHtml = false; | 582 var test = this; |
578 var parsedDebuggerTestJs = false; | |
579 | |
580 this.showPanel('scripts'); | 583 this.showPanel('scripts'); |
581 | 584 |
582 var scriptUrl = null; | |
583 var breakpointLine = 12; | 585 var breakpointLine = 12; |
584 | 586 |
585 var test = this; | 587 this._waitUntilScriptsAreParsed(['debugger_test_page.html'], |
586 this.addSniffer(devtools.DebuggerAgent.prototype, 'handleScriptsResponse_', | 588 function() { |
587 function(msg) { | |
588 var scriptSelect = document.getElementById('scripts-files'); | |
589 var options = scriptSelect.options; | |
590 | |
591 // There should be console API source (see | |
592 // InjectedScript._ensureCommandLineAPIInstalled) and the page script. | |
593 test.assertEquals(2, options.length, 'Unexpected number of scripts(' + | |
594 test.optionsToString_(options) + ')'); | |
595 | |
596 test.showMainPageScriptSource_( | 589 test.showMainPageScriptSource_( |
597 'debugger_test_page.html', | 590 'debugger_test_page.html', |
598 function(view, url) { | 591 function(view, url) { |
599 view._addBreakpoint(breakpointLine); | 592 view._addBreakpoint(breakpointLine); |
600 // Force v8 execution. | 593 // Force v8 execution. |
601 RemoteToolsAgent.ExecuteVoidJavaScript(); | 594 RemoteToolsAgent.ExecuteVoidJavaScript(); |
602 test.waitForSetBreakpointResponse_(url, breakpointLine, | 595 test.waitForSetBreakpointResponse_(url, breakpointLine, |
603 function() { | 596 function() { |
604 test.releaseControl(); | 597 test.releaseControl(); |
605 }); | 598 }); |
606 }); | 599 }); |
607 }); | 600 }); |
608 | 601 |
609 | |
610 this.takeControl(); | 602 this.takeControl(); |
611 }; | 603 }; |
612 | 604 |
613 | 605 |
614 /** | 606 /** |
615 * Serializes options collection to string. | 607 * Serializes options collection to string. |
616 * @param {HTMLOptionsCollection} options | 608 * @param {HTMLOptionsCollection} options |
617 * @return {string} | 609 * @return {string} |
618 */ | 610 */ |
619 TestSuite.prototype.optionsToString_ = function(options) { | 611 TestSuite.prototype.optionsToString_ = function(options) { |
(...skipping 10 matching lines...) Loading... |
630 * source frame is setup. Invokes the callback when the condition is satisfied. | 622 * source frame is setup. Invokes the callback when the condition is satisfied. |
631 * @param {HTMLOptionsCollection} options | 623 * @param {HTMLOptionsCollection} options |
632 * @param {function(WebInspector.SourceView,string)} callback | 624 * @param {function(WebInspector.SourceView,string)} callback |
633 */ | 625 */ |
634 TestSuite.prototype.showMainPageScriptSource_ = function(scriptName, callback) { | 626 TestSuite.prototype.showMainPageScriptSource_ = function(scriptName, callback) { |
635 var test = this; | 627 var test = this; |
636 | 628 |
637 var scriptSelect = document.getElementById('scripts-files'); | 629 var scriptSelect = document.getElementById('scripts-files'); |
638 var options = scriptSelect.options; | 630 var options = scriptSelect.options; |
639 | 631 |
640 // There should be console API source (see | 632 test.assertTrue(options.length, 'Scripts list is empty'); |
641 // InjectedScript._ensureCommandLineAPIInstalled) and the page script. | |
642 test.assertEquals(2, options.length, | |
643 'Unexpected number of scripts(' + test.optionsToString_(options) + ')'); | |
644 | 633 |
645 // Select page's script if it's not current option. | 634 // Select page's script if it's not current option. |
646 var scriptResource; | 635 var scriptResource; |
647 if (options[scriptSelect.selectedIndex].text === scriptName) { | 636 if (options[scriptSelect.selectedIndex].text === scriptName) { |
648 scriptResource = options[scriptSelect.selectedIndex].representedObject; | 637 scriptResource = options[scriptSelect.selectedIndex].representedObject; |
649 } else { | 638 } else { |
650 var pageScriptIndex = -1; | 639 var pageScriptIndex = -1; |
651 for (var i = 0; i < options.length; i++) { | 640 for (var i = 0; i < options.length; i++) { |
652 if (options[i].text === scriptName) { | 641 if (options[i].text === scriptName) { |
653 pageScriptIndex = i; | 642 pageScriptIndex = i; |
(...skipping 1099 matching lines...) Loading... |
1753 /** | 1742 /** |
1754 * Run specified test on a fresh instance of the test suite. | 1743 * Run specified test on a fresh instance of the test suite. |
1755 * @param {string} name Name of a test method from TestSuite class. | 1744 * @param {string} name Name of a test method from TestSuite class. |
1756 */ | 1745 */ |
1757 uiTests.runTest = function(name) { | 1746 uiTests.runTest = function(name) { |
1758 new TestSuite().runTest(name); | 1747 new TestSuite().runTest(name); |
1759 }; | 1748 }; |
1760 | 1749 |
1761 | 1750 |
1762 } | 1751 } |
OLD | NEW |