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

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

Issue 2751193003: [DevTools] Move ConsoleModel to it's own module (Closed)
Patch Set: 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.consoleModel.messages().filter(a => a.source !== SDK.ConsoleMes sage.MessageSource.Violation); 517 return ConsoleModel.consoleModel.messages().filter(
518 a => a.source !== ConsoleModel.ConsoleMessage.MessageSource.Violation) ;
518 } 519 }
519 520
520 if (filteredMessages().length === 1) 521 if (filteredMessages().length === 1) {
521 firstConsoleMessageReceived.call(this, null); 522 firstConsoleMessageReceived.call(this, null);
522 else 523 } else {
523 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, fi rstConsoleMessageReceived, this); 524 ConsoleModel.consoleModel.addEventListener(
525 ConsoleModel.ConsoleModel.Events.MessageAdded, firstConsoleMessageRece ived, this);
526 }
524 527
525 528
526 function firstConsoleMessageReceived(event) { 529 function firstConsoleMessageReceived(event) {
527 if (event && event.data.source === SDK.ConsoleMessage.MessageSource.Violat ion) 530 if (event && event.data.source === ConsoleModel.ConsoleMessage.MessageSour ce.Violation)
528 return; 531 return;
529 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this); 532 ConsoleModel.consoleModel.removeEventListener(
533 ConsoleModel.ConsoleModel.Events.MessageAdded, firstConsoleMessageRece ived, this);
530 this.evaluateInConsole_('clickLink();', didClickLink.bind(this)); 534 this.evaluateInConsole_('clickLink();', didClickLink.bind(this));
531 } 535 }
532 536
533 function didClickLink() { 537 function didClickLink() {
534 // Check that there are no new messages(command is not a message). 538 // Check that there are no new messages(command is not a message).
535 this.assertEquals(3, filteredMessages().length); 539 this.assertEquals(3, filteredMessages().length);
536 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this)); 540 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this));
537 } 541 }
538 542
539 function didNavigateBack() { 543 function didNavigateBack() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 function testPreset(preset, messages, next) { 679 function testPreset(preset, messages, next) {
676 function onConsoleMessage(event) { 680 function onConsoleMessage(event) {
677 var index = messages.indexOf(event.data.messageText); 681 var index = messages.indexOf(event.data.messageText);
678 if (index === -1) { 682 if (index === -1) {
679 test.fail('Unexpected message: ' + event.data.messageText); 683 test.fail('Unexpected message: ' + event.data.messageText);
680 return; 684 return;
681 } 685 }
682 686
683 messages.splice(index, 1); 687 messages.splice(index, 1);
684 if (!messages.length) { 688 if (!messages.length) {
685 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAd ded, onConsoleMessage, this); 689 ConsoleModel.consoleModel.removeEventListener(
690 ConsoleModel.ConsoleModel.Events.MessageAdded, onConsoleMessage, t his);
686 next(); 691 next();
687 } 692 }
688 } 693 }
689 694
690 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, on ConsoleMessage, this); 695 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Event s.MessageAdded, onConsoleMessage, this);
691 SDK.multitargetNetworkManager.setNetworkConditions(preset); 696 SDK.multitargetNetworkManager.setNetworkConditions(preset);
692 } 697 }
693 698
694 test.takeControl(); 699 test.takeControl();
695 step1(); 700 step1();
696 701
697 function step1() { 702 function step1() {
698 testPreset( 703 testPreset(
699 NetworkConditions.NetworkConditionsSelector.presets[0], 704 NetworkConditions.NetworkConditionsSelector.presets[0],
700 ['offline event: online = false', 'connection change event: type = non e; downlinkMax = 0'], step2); 705 ['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
825 test.assertEquals(1, localSetting.get().n); 830 test.assertEquals(1, localSetting.get().n);
826 var globalSetting = Common.settings.createSetting('global', undefined); 831 var globalSetting = Common.settings.createSetting('global', undefined);
827 test.assertEquals('object', typeof globalSetting.get()); 832 test.assertEquals('object', typeof globalSetting.get());
828 test.assertEquals('global', globalSetting.get().s); 833 test.assertEquals('global', globalSetting.get().s);
829 test.assertEquals(2, globalSetting.get().n); 834 test.assertEquals(2, globalSetting.get().n);
830 test.releaseControl(); 835 test.releaseControl();
831 } 836 }
832 }; 837 };
833 838
834 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() { 839 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() {
835 var messages = SDK.consoleModel.messages(); 840 var messages = ConsoleModel.consoleModel.messages();
836 this.assertEquals(1, messages.length); 841 this.assertEquals(1, messages.length);
837 var text = messages[0].messageText; 842 var text = messages[0].messageText;
838 if (text.indexOf('Uncaught') !== -1) 843 if (text.indexOf('Uncaught') !== -1)
839 this.fail(text); 844 this.fail(text);
840 }; 845 };
841 846
842 TestSuite.prototype.testConsoleContextNames = function() { 847 TestSuite.prototype.testConsoleContextNames = function() {
843 var test = this; 848 var test = this;
844 test.takeControl(); 849 test.takeControl();
845 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this))); 850 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this)));
(...skipping 14 matching lines...) Expand all
860 this.takeControl(); 865 this.takeControl();
861 Bindings.TempFile.ensureTempStorageCleared().then(() => this.releaseControl( )); 866 Bindings.TempFile.ensureTempStorageCleared().then(() => this.releaseControl( ));
862 }; 867 };
863 868
864 TestSuite.prototype.testTempFile = function() { 869 TestSuite.prototype.testTempFile = function() {
865 this.takeControl(); 870 this.takeControl();
866 Bindings.TempFile.create('test-file', 'test').then(() => this.releaseControl (), error => this.fail(String(error))); 871 Bindings.TempFile.create('test-file', 'test').then(() => this.releaseControl (), error => this.fail(String(error)));
867 }; 872 };
868 873
869 TestSuite.prototype.waitForTestResultsInConsole = function() { 874 TestSuite.prototype.waitForTestResultsInConsole = function() {
870 var messages = SDK.consoleModel.messages(); 875 var messages = ConsoleModel.consoleModel.messages();
871 for (var i = 0; i < messages.length; ++i) { 876 for (var i = 0; i < messages.length; ++i) {
872 var text = messages[i].messageText; 877 var text = messages[i].messageText;
873 if (text === 'PASS') 878 if (text === 'PASS')
874 return; 879 return;
875 else if (/^FAIL/.test(text)) 880 else if (/^FAIL/.test(text))
876 this.fail(text); // This will throw. 881 this.fail(text); // This will throw.
877 } 882 }
878 // Neither PASS nor FAIL, so wait for more messages. 883 // Neither PASS nor FAIL, so wait for more messages.
879 function onConsoleMessage(event) { 884 function onConsoleMessage(event) {
880 var text = event.data.messageText; 885 var text = event.data.messageText;
881 if (text === 'PASS') 886 if (text === 'PASS')
882 this.releaseControl(); 887 this.releaseControl();
883 else if (/^FAIL/.test(text)) 888 else if (/^FAIL/.test(text))
884 this.fail(text); 889 this.fail(text);
885 } 890 }
886 891
887 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onCo nsoleMessage, this); 892 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events. MessageAdded, onConsoleMessage, this);
888 this.takeControl(); 893 this.takeControl();
889 }; 894 };
890 895
891 TestSuite.prototype._overrideMethod = function(receiver, methodName, override) { 896 TestSuite.prototype._overrideMethod = function(receiver, methodName, override) {
892 var original = receiver[methodName]; 897 var original = receiver[methodName];
893 if (typeof original !== 'function') { 898 if (typeof original !== 'function') {
894 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`); 899 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`);
895 return; 900 return;
896 } 901 }
897 receiver[methodName] = function() { 902 receiver[methodName] = function() {
(...skipping 23 matching lines...) Expand all
921 }; 926 };
922 927
923 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) { 928 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) {
924 var callback = arguments[arguments.length - 1]; 929 var callback = arguments[arguments.length - 1];
925 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; 930 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`;
926 var argsString = arguments.length < 3 ? 931 var argsString = arguments.length < 3 ?
927 '' : 932 '' :
928 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a rg)).join(',') + ','; 933 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a rg)).join(',') + ',';
929 this.evaluateInConsole_( 934 this.evaluateInConsole_(
930 `${functionName}(${argsString} function() { console.log('${doneMessage}' ); });`, function() {}); 935 `${functionName}(${argsString} function() { console.log('${doneMessage}' ); });`, function() {});
931 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onCo nsoleMessage); 936 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events. MessageAdded, onConsoleMessage);
932 937
933 function onConsoleMessage(event) { 938 function onConsoleMessage(event) {
934 var text = event.data.messageText; 939 var text = event.data.messageText;
935 if (text === doneMessage) { 940 if (text === doneMessage) {
936 SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdde d, onConsoleMessage); 941 ConsoleModel.consoleModel.removeEventListener(ConsoleModel.ConsoleModel. Events.MessageAdded, onConsoleMessage);
937 callback(); 942 callback();
938 } 943 }
939 } 944 }
940 }; 945 };
941 946
942 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback ) { 947 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback ) {
943 var test = this; 948 var test = this;
944 949
945 this.startTimeline(onRecordingStarted); 950 this.startTimeline(onRecordingStarted);
946 951
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 if (runtimeModel.executionContexts().length >= n) 1104 if (runtimeModel.executionContexts().length >= n)
1100 callback.call(null); 1105 callback.call(null);
1101 else 1106 else
1102 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExecutionContexts.bind(this)); 1107 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExecutionContexts.bind(this));
1103 } 1108 }
1104 }; 1109 };
1105 1110
1106 1111
1107 window.uiTests = new TestSuite(window.domAutomationController); 1112 window.uiTests = new TestSuite(window.domAutomationController);
1108 })(window); 1113 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698