Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/Tests.js

Issue 2751173003: [DevTools] Turn ConsoleModel into a singleton (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi nishRequest, true); 507 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi nishRequest, true);
508 508
509 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {} ); 509 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {} );
510 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func tion(resultText) {}); 510 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func tion(resultText) {});
511 this.takeControl(); 511 this.takeControl();
512 }; 512 };
513 513
514 TestSuite.prototype.testConsoleOnNavigateBack = function() { 514 TestSuite.prototype.testConsoleOnNavigateBack = function() {
515 515
516 function filteredMessages() { 516 function filteredMessages() {
517 return SDK.multitargetConsoleModel.messages().filter( 517 return SDK.consoleModel.messages().filter(a => a.source !== SDK.ConsoleMes sage.MessageSource.Violation);
518 a => a.source !== SDK.ConsoleMessage.MessageSource.Violation);
519 } 518 }
520 519
521 if (filteredMessages().length === 1) { 520 if (filteredMessages().length === 1)
522 firstConsoleMessageReceived.call(this, null); 521 firstConsoleMessageReceived.call(this, null);
523 } else { 522 else
524 SDK.multitargetConsoleModel.addEventListener( 523 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, fi rstConsoleMessageReceived, this);
525 SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, thi s); 524
526 }
527 525
528 function firstConsoleMessageReceived(event) { 526 function firstConsoleMessageReceived(event) {
529 if (event && event.data.source === SDK.ConsoleMessage.MessageSource.Violat ion) 527 if (event && event.data.source === SDK.ConsoleMessage.MessageSource.Violat ion)
530 return; 528 return;
531 SDK.multitargetConsoleModel.removeEventListener( 529 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this);
532 SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, thi s);
533 this.evaluateInConsole_('clickLink();', didClickLink.bind(this)); 530 this.evaluateInConsole_('clickLink();', didClickLink.bind(this));
534 } 531 }
535 532
536 function didClickLink() { 533 function didClickLink() {
537 // Check that there are no new messages(command is not a message). 534 // Check that there are no new messages(command is not a message).
538 this.assertEquals(3, filteredMessages().length); 535 this.assertEquals(3, filteredMessages().length);
539 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this)); 536 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this));
540 } 537 }
541 538
542 function didNavigateBack() { 539 function didNavigateBack() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 function testPreset(preset, messages, next) { 675 function testPreset(preset, messages, next) {
679 function onConsoleMessage(event) { 676 function onConsoleMessage(event) {
680 var index = messages.indexOf(event.data.messageText); 677 var index = messages.indexOf(event.data.messageText);
681 if (index === -1) { 678 if (index === -1) {
682 test.fail('Unexpected message: ' + event.data.messageText); 679 test.fail('Unexpected message: ' + event.data.messageText);
683 return; 680 return;
684 } 681 }
685 682
686 messages.splice(index, 1); 683 messages.splice(index, 1);
687 if (!messages.length) { 684 if (!messages.length) {
688 SDK.multitargetConsoleModel.removeEventListener(SDK.ConsoleModel.Event s.MessageAdded, onConsoleMessage, this); 685 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAd ded, onConsoleMessage, this);
689 next(); 686 next();
690 } 687 }
691 } 688 }
692 689
693 SDK.multitargetConsoleModel.addEventListener(SDK.ConsoleModel.Events.Messa geAdded, onConsoleMessage, this); 690 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, on ConsoleMessage, this);
694 SDK.multitargetNetworkManager.setNetworkConditions(preset); 691 SDK.multitargetNetworkManager.setNetworkConditions(preset);
695 } 692 }
696 693
697 test.takeControl(); 694 test.takeControl();
698 step1(); 695 step1();
699 696
700 function step1() { 697 function step1() {
701 testPreset( 698 testPreset(
702 NetworkConditions.NetworkConditionsSelector.presets[0], 699 NetworkConditions.NetworkConditionsSelector.presets[0],
703 ['offline event: online = false', 'connection change event: type = non e; downlinkMax = 0'], step2); 700 ['offline event: online = false', 'connection change event: type = non e; downlinkMax = 0'], step2);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 test.assertEquals(1, localSetting.get().n); 825 test.assertEquals(1, localSetting.get().n);
829 var globalSetting = Common.settings.createSetting('global', undefined); 826 var globalSetting = Common.settings.createSetting('global', undefined);
830 test.assertEquals('object', typeof globalSetting.get()); 827 test.assertEquals('object', typeof globalSetting.get());
831 test.assertEquals('global', globalSetting.get().s); 828 test.assertEquals('global', globalSetting.get().s);
832 test.assertEquals(2, globalSetting.get().n); 829 test.assertEquals(2, globalSetting.get().n);
833 test.releaseControl(); 830 test.releaseControl();
834 } 831 }
835 }; 832 };
836 833
837 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() { 834 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() {
838 var messages = SDK.multitargetConsoleModel.messages(); 835 var messages = SDK.consoleModel.messages();
839 this.assertEquals(1, messages.length); 836 this.assertEquals(1, messages.length);
840 var text = messages[0].messageText; 837 var text = messages[0].messageText;
841 if (text.indexOf('Uncaught') !== -1) 838 if (text.indexOf('Uncaught') !== -1)
842 this.fail(text); 839 this.fail(text);
843 }; 840 };
844 841
845 TestSuite.prototype.testConsoleContextNames = function() { 842 TestSuite.prototype.testConsoleContextNames = function() {
846 var test = this; 843 var test = this;
847 test.takeControl(); 844 test.takeControl();
848 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this))); 845 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this)));
(...skipping 14 matching lines...) Expand all
863 this.takeControl(); 860 this.takeControl();
864 Bindings.TempFile.ensureTempStorageCleared().then(() => this.releaseControl( )); 861 Bindings.TempFile.ensureTempStorageCleared().then(() => this.releaseControl( ));
865 }; 862 };
866 863
867 TestSuite.prototype.testTempFile = function() { 864 TestSuite.prototype.testTempFile = function() {
868 this.takeControl(); 865 this.takeControl();
869 Bindings.TempFile.create('test-file', 'test').then(() => this.releaseControl (), error => this.fail(String(error))); 866 Bindings.TempFile.create('test-file', 'test').then(() => this.releaseControl (), error => this.fail(String(error)));
870 }; 867 };
871 868
872 TestSuite.prototype.waitForTestResultsInConsole = function() { 869 TestSuite.prototype.waitForTestResultsInConsole = function() {
873 var messages = SDK.multitargetConsoleModel.messages(); 870 var messages = SDK.consoleModel.messages();
874 for (var i = 0; i < messages.length; ++i) { 871 for (var i = 0; i < messages.length; ++i) {
875 var text = messages[i].messageText; 872 var text = messages[i].messageText;
876 if (text === 'PASS') 873 if (text === 'PASS')
877 return; 874 return;
878 else if (/^FAIL/.test(text)) 875 else if (/^FAIL/.test(text))
879 this.fail(text); // This will throw. 876 this.fail(text); // This will throw.
880 } 877 }
881 // Neither PASS nor FAIL, so wait for more messages. 878 // Neither PASS nor FAIL, so wait for more messages.
882 function onConsoleMessage(event) { 879 function onConsoleMessage(event) {
883 var text = event.data.messageText; 880 var text = event.data.messageText;
884 if (text === 'PASS') 881 if (text === 'PASS')
885 this.releaseControl(); 882 this.releaseControl();
886 else if (/^FAIL/.test(text)) 883 else if (/^FAIL/.test(text))
887 this.fail(text); 884 this.fail(text);
888 } 885 }
889 886
890 SDK.multitargetConsoleModel.addEventListener(SDK.ConsoleModel.Events.Message Added, onConsoleMessage, this); 887 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onCo nsoleMessage, this);
891 this.takeControl(); 888 this.takeControl();
892 }; 889 };
893 890
894 TestSuite.prototype._overrideMethod = function(receiver, methodName, override) { 891 TestSuite.prototype._overrideMethod = function(receiver, methodName, override) {
895 var original = receiver[methodName]; 892 var original = receiver[methodName];
896 if (typeof original !== 'function') { 893 if (typeof original !== 'function') {
897 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`); 894 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`);
898 return; 895 return;
899 } 896 }
900 receiver[methodName] = function() { 897 receiver[methodName] = function() {
(...skipping 23 matching lines...) Expand all
924 }; 921 };
925 922
926 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) { 923 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) {
927 var callback = arguments[arguments.length - 1]; 924 var callback = arguments[arguments.length - 1];
928 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; 925 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`;
929 var argsString = arguments.length < 3 ? 926 var argsString = arguments.length < 3 ?
930 '' : 927 '' :
931 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a rg)).join(',') + ','; 928 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a rg)).join(',') + ',';
932 this.evaluateInConsole_( 929 this.evaluateInConsole_(
933 `${functionName}(${argsString} function() { console.log('${doneMessage}' ); });`, function() {}); 930 `${functionName}(${argsString} function() { console.log('${doneMessage}' ); });`, function() {});
934 SDK.multitargetConsoleModel.addEventListener(SDK.ConsoleModel.Events.Message Added, onConsoleMessage); 931 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onCo nsoleMessage);
935 932
936 function onConsoleMessage(event) { 933 function onConsoleMessage(event) {
937 var text = event.data.messageText; 934 var text = event.data.messageText;
938 if (text === doneMessage) { 935 if (text === doneMessage) {
939 SDK.multitargetConsoleModel.removeEventListener(SDK.ConsoleModel.Events. MessageAdded, onConsoleMessage); 936 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdde d, onConsoleMessage);
940 callback(); 937 callback();
941 } 938 }
942 } 939 }
943 }; 940 };
944 941
945 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback ) { 942 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback ) {
946 var test = this; 943 var test = this;
947 944
948 this.startTimeline(onRecordingStarted); 945 this.startTimeline(onRecordingStarted);
949 946
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 if (runtimeModel.executionContexts().length >= n) 1099 if (runtimeModel.executionContexts().length >= n)
1103 callback.call(null); 1100 callback.call(null);
1104 else 1101 else
1105 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExecutionContexts.bind(this)); 1102 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExecutionContexts.bind(this));
1106 } 1103 }
1107 }; 1104 };
1108 1105
1109 1106
1110 window.uiTests = new TestSuite(window.domAutomationController); 1107 window.uiTests = new TestSuite(window.domAutomationController);
1111 })(window); 1108 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698