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

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

Issue 2440953003: DevTools: use semicolons after each statement. (Closed)
Patch Set: rebaseline Created 4 years, 1 month 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 * Tests network raw headers text. 471 * Tests network raw headers text.
472 */ 472 */
473 TestSuite.prototype.testNetworkRawHeadersText = function() 473 TestSuite.prototype.testNetworkRawHeadersText = function()
474 { 474 {
475 var test = this; 475 var test = this;
476 476
477 function finishResource(resource, finishTime) 477 function finishResource(resource, finishTime)
478 { 478 {
479 if (!resource.responseHeadersText) 479 if (!resource.responseHeadersText)
480 test.fail("Failure: resource does not have response headers text"); 480 test.fail("Failure: resource does not have response headers text");
481 var index = resource.responseHeadersText.indexOf("Date:") 481 var index = resource.responseHeadersText.indexOf("Date:");
482 test.assertEquals(112, resource.responseHeadersText.substring(index).len gth, "Incorrect response headers text length"); 482 test.assertEquals(112, resource.responseHeadersText.substring(index).len gth, "Incorrect response headers text length");
483 test.releaseControl(); 483 test.releaseControl();
484 } 484 }
485 485
486 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkReq uest", finishResource); 486 this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkReq uest", finishResource);
487 487
488 // Reload inspected page to sniff network events 488 // Reload inspected page to sniff network events
489 test.evaluateInConsole_("window.location.reload(true);", function(resultText ) {}); 489 test.evaluateInConsole_("window.location.reload(true);", function(resultText ) {});
490 490
491 this.takeControl(); 491 this.takeControl();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 TestSuite.prototype.enableTouchEmulation = function() 632 TestSuite.prototype.enableTouchEmulation = function()
633 { 633 {
634 var deviceModeModel = new WebInspector.DeviceModeModel(function() {}); 634 var deviceModeModel = new WebInspector.DeviceModeModel(function() {});
635 deviceModeModel._target = WebInspector.targetManager.mainTarget(); 635 deviceModeModel._target = WebInspector.targetManager.mainTarget();
636 deviceModeModel._applyTouch(true, true); 636 deviceModeModel._applyTouch(true, true);
637 }; 637 };
638 638
639 TestSuite.prototype.enableAutoAttachToCreatedPages = function() 639 TestSuite.prototype.enableAutoAttachToCreatedPages = function()
640 { 640 {
641 WebInspector.settingForTest("autoAttachToCreatedPages").set(true); 641 WebInspector.settingForTest("autoAttachToCreatedPages").set(true);
642 } 642 };
643 643
644 TestSuite.prototype.waitForDebuggerPaused = function() 644 TestSuite.prototype.waitForDebuggerPaused = function()
645 { 645 {
646 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targe tManager.mainTarget()); 646 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targe tManager.mainTarget());
647 if (debuggerModel.debuggerPausedDetails) 647 if (debuggerModel.debuggerPausedDetails)
648 return; 648 return;
649 649
650 this.takeControl(); 650 this.takeControl();
651 this._waitForScriptPause(this.releaseControl.bind(this)); 651 this._waitForScriptPause(this.releaseControl.bind(this));
652 } 652 };
653 653
654 TestSuite.prototype.switchToPanel = function(panelName) 654 TestSuite.prototype.switchToPanel = function(panelName)
655 { 655 {
656 this.showPanel(panelName).then(this.releaseControl.bind(this)); 656 this.showPanel(panelName).then(this.releaseControl.bind(this));
657 this.takeControl(); 657 this.takeControl();
658 } 658 };
659 659
660 // Regression test for crbug.com/370035. 660 // Regression test for crbug.com/370035.
661 TestSuite.prototype.testDeviceMetricsOverrides = function() 661 TestSuite.prototype.testDeviceMetricsOverrides = function()
662 { 662 {
663 const dumpPageMetrics = function() 663 const dumpPageMetrics = function()
664 { 664 {
665 return JSON.stringify({ 665 return JSON.stringify({
666 width: window.innerWidth, 666 width: window.innerWidth,
667 height: window.innerHeight, 667 height: window.innerHeight,
668 deviceScaleFactor: window.devicePixelRatio 668 deviceScaleFactor: window.devicePixelRatio
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 var filmStripModel = new WebInspector.FilmStripModel(WebInspector.panels .timeline._tracingModel); 817 var filmStripModel = new WebInspector.FilmStripModel(WebInspector.panels .timeline._tracingModel);
818 var frames = filmStripModel.frames(); 818 var frames = filmStripModel.frames();
819 test.assertTrue(frames.length > 4 && typeof frames.length === "number"); 819 test.assertTrue(frames.length > 4 && typeof frames.length === "number");
820 loadFrameImages(frames); 820 loadFrameImages(frames);
821 } 821 }
822 822
823 function loadFrameImages(frames) 823 function loadFrameImages(frames)
824 { 824 {
825 var readyImages = []; 825 var readyImages = [];
826 for (var frame of frames) 826 for (var frame of frames)
827 frame.imageDataPromise().then(onGotImageData) 827 frame.imageDataPromise().then(onGotImageData);
828 828
829 function onGotImageData(data) 829 function onGotImageData(data)
830 { 830 {
831 var image = new Image(); 831 var image = new Image();
832 test.assertTrue(!!data, "No image data for frame"); 832 test.assertTrue(!!data, "No image data for frame");
833 image.addEventListener("load", onLoad); 833 image.addEventListener("load", onLoad);
834 image.src = "data:image/jpg;base64," + data; 834 image.src = "data:image/jpg;base64," + data;
835 } 835 }
836 836
837 function onLoad(event) 837 function onLoad(event)
(...skipping 27 matching lines...) Expand all
865 else if (data.data[2] > 200) 865 else if (data.data[2] > 200)
866 blueCount++; 866 blueCount++;
867 else 867 else
868 test.fail("Unexpected color: " + color); 868 test.fail("Unexpected color: " + color);
869 } 869 }
870 test.assertTrue(redCount && greenCount && blueCount, "Color sanity check failed"); 870 test.assertTrue(redCount && greenCount && blueCount, "Color sanity check failed");
871 test.releaseControl(); 871 test.releaseControl();
872 } 872 }
873 873
874 test.takeControl(); 874 test.takeControl();
875 } 875 };
876 876
877 TestSuite.prototype.testSettings = function() 877 TestSuite.prototype.testSettings = function()
878 { 878 {
879 var test = this; 879 var test = this;
880 880
881 createSettings(); 881 createSettings();
882 test.takeControl(); 882 test.takeControl();
883 setTimeout(reset, 0); 883 setTimeout(reset, 0);
884 884
885 function createSettings() 885 function createSettings()
(...skipping 17 matching lines...) Expand all
903 var localSetting = WebInspector.settings.createSetting("local", undefine d, true); 903 var localSetting = WebInspector.settings.createSetting("local", undefine d, true);
904 test.assertEquals("object", typeof localSetting.get()); 904 test.assertEquals("object", typeof localSetting.get());
905 test.assertEquals("local", localSetting.get().s); 905 test.assertEquals("local", localSetting.get().s);
906 test.assertEquals(1, localSetting.get().n); 906 test.assertEquals(1, localSetting.get().n);
907 var globalSetting = WebInspector.settings.createSetting("global", undefi ned, false); 907 var globalSetting = WebInspector.settings.createSetting("global", undefi ned, false);
908 test.assertEquals("object", typeof globalSetting.get()); 908 test.assertEquals("object", typeof globalSetting.get());
909 test.assertEquals("global", globalSetting.get().s); 909 test.assertEquals("global", globalSetting.get().s);
910 test.assertEquals(2, globalSetting.get().n); 910 test.assertEquals(2, globalSetting.get().n);
911 test.releaseControl(); 911 test.releaseControl();
912 } 912 }
913 } 913 };
914 914
915 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() 915 TestSuite.prototype.testWindowInitializedOnNavigateBack = function()
916 { 916 {
917 var messages = WebInspector.multitargetConsoleModel.messages(); 917 var messages = WebInspector.multitargetConsoleModel.messages();
918 this.assertEquals(1, messages.length); 918 this.assertEquals(1, messages.length);
919 var text = messages[0].messageText; 919 var text = messages[0].messageText;
920 if (text.indexOf("Uncaught") !== -1) 920 if (text.indexOf("Uncaught") !== -1)
921 this.fail(text); 921 this.fail(text);
922 }; 922 };
923 923
924 TestSuite.prototype.testConsoleContextNames = function() 924 TestSuite.prototype.testConsoleContextNames = function()
925 { 925 {
926 var test = this; 926 var test = this;
927 test.takeControl(); 927 test.takeControl();
928 this.showPanel("console").then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this))); 928 this.showPanel("console").then(() => this._waitForExecutionContexts(2, onExe cutionContexts.bind(this)));
929 929
930 function onExecutionContexts() 930 function onExecutionContexts()
931 { 931 {
932 var consoleView = WebInspector.ConsoleView.instance(); 932 var consoleView = WebInspector.ConsoleView.instance();
933 var options = consoleView._consoleContextSelector._selectElement.options ; 933 var options = consoleView._consoleContextSelector._selectElement.options ;
934 var values = []; 934 var values = [];
935 for (var i = 0; i < options.length; ++i) 935 for (var i = 0; i < options.length; ++i)
936 values.push(options[i].value.trim()); 936 values.push(options[i].value.trim());
937 test.assertEquals("top", values[0]); 937 test.assertEquals("top", values[0]);
938 test.assertEquals("Simple content script", values[1]); 938 test.assertEquals("Simple content script", values[1]);
939 test.releaseControl(); 939 test.releaseControl();
940 } 940 }
941 } 941 };
942 942
943 TestSuite.prototype.testDevToolsSharedWorker = function() 943 TestSuite.prototype.testDevToolsSharedWorker = function()
944 { 944 {
945 this.takeControl(); 945 this.takeControl();
946 WebInspector.TempFile.ensureTempStorageCleared().then(() => this.releaseCont rol()); 946 WebInspector.TempFile.ensureTempStorageCleared().then(() => this.releaseCont rol());
947 } 947 };
948 948
949 TestSuite.prototype.waitForTestResultsInConsole = function() 949 TestSuite.prototype.waitForTestResultsInConsole = function()
950 { 950 {
951 var messages = WebInspector.multitargetConsoleModel.messages(); 951 var messages = WebInspector.multitargetConsoleModel.messages();
952 for (var i = 0; i < messages.length; ++i) { 952 for (var i = 0; i < messages.length; ++i) {
953 var text = messages[i].messageText; 953 var text = messages[i].messageText;
954 if (text === "PASS") 954 if (text === "PASS")
955 return; 955 return;
956 else if (/^FAIL/.test(text)) 956 else if (/^FAIL/.test(text))
957 this.fail(text); // This will throw. 957 this.fail(text); // This will throw.
(...skipping 21 matching lines...) Expand all
979 } 979 }
980 receiver[methodName] = function() 980 receiver[methodName] = function()
981 { 981 {
982 try { 982 try {
983 var value = original.apply(receiver, arguments); 983 var value = original.apply(receiver, arguments);
984 } finally { 984 } finally {
985 receiver[methodName] = original; 985 receiver[methodName] = original;
986 } 986 }
987 override.apply(original, arguments); 987 override.apply(original, arguments);
988 return value; 988 return value;
989 } 989 };
990 } 990 };
991 991
992 TestSuite.prototype.startTimeline = function(callback) 992 TestSuite.prototype.startTimeline = function(callback)
993 { 993 {
994 var test = this; 994 var test = this;
995 this.showPanel("timeline").then(function() { 995 this.showPanel("timeline").then(function() {
996 var timeline = WebInspector.panels.timeline; 996 var timeline = WebInspector.panels.timeline;
997 test._overrideMethod(timeline, "recordingStarted", callback); 997 test._overrideMethod(timeline, "recordingStarted", callback);
998 timeline._toggleRecording(); 998 timeline._toggleRecording();
999 }); 999 });
1000 } 1000 };
1001 1001
1002 TestSuite.prototype.stopTimeline = function(callback) 1002 TestSuite.prototype.stopTimeline = function(callback)
1003 { 1003 {
1004 var timeline = WebInspector.panels.timeline; 1004 var timeline = WebInspector.panels.timeline;
1005 this._overrideMethod(timeline, "loadingComplete", callback); 1005 this._overrideMethod(timeline, "loadingComplete", callback);
1006 timeline._toggleRecording(); 1006 timeline._toggleRecording();
1007 } 1007 };
1008 1008
1009 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, c allback_is_always_last) 1009 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, c allback_is_always_last)
1010 { 1010 {
1011 var callback = arguments[arguments.length - 1]; 1011 var callback = arguments[arguments.length - 1];
1012 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; 1012 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`;
1013 var argsString = arguments.length < 3 ? "" : Array.prototype.slice.call(argu ments, 1, -1).map(arg => JSON.stringify(arg)).join(",") + ","; 1013 var argsString = arguments.length < 3 ? "" : Array.prototype.slice.call(argu ments, 1, -1).map(arg => JSON.stringify(arg)).join(",") + ",";
1014 this.evaluateInConsole_(`${functionName}(${argsString} function() { console. log('${doneMessage}'); });`, function() {}); 1014 this.evaluateInConsole_(`${functionName}(${argsString} function() { console. log('${doneMessage}'); });`, function() {});
1015 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, onConsoleMessage); 1015 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, onConsoleMessage);
1016 1016
1017 function onConsoleMessage(event) 1017 function onConsoleMessage(event)
1018 { 1018 {
1019 var text = event.data.messageText; 1019 var text = event.data.messageText;
1020 if (text === doneMessage) { 1020 if (text === doneMessage) {
1021 WebInspector.multitargetConsoleModel.removeEventListener(WebInspecto r.ConsoleModel.Events.MessageAdded, onConsoleMessage); 1021 WebInspector.multitargetConsoleModel.removeEventListener(WebInspecto r.ConsoleModel.Events.MessageAdded, onConsoleMessage);
1022 callback(); 1022 callback();
1023 } 1023 }
1024 } 1024 }
1025 } 1025 };
1026 1026
1027 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) 1027 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback)
1028 { 1028 {
1029 var test = this; 1029 var test = this;
1030 1030
1031 this.startTimeline(onRecordingStarted); 1031 this.startTimeline(onRecordingStarted);
1032 1032
1033 function onRecordingStarted() 1033 function onRecordingStarted()
1034 { 1034 {
1035 test.invokePageFunctionAsync(functionName, pageActionsDone); 1035 test.invokePageFunctionAsync(functionName, pageActionsDone);
1036 } 1036 }
1037 1037
1038 function pageActionsDone() 1038 function pageActionsDone()
1039 { 1039 {
1040 test.stopTimeline(callback); 1040 test.stopTimeline(callback);
1041 } 1041 }
1042 }; 1042 };
1043 1043
1044 TestSuite.prototype.enableExperiment = function(name) 1044 TestSuite.prototype.enableExperiment = function(name)
1045 { 1045 {
1046 Runtime.experiments.enableForTest(name); 1046 Runtime.experiments.enableForTest(name);
1047 } 1047 };
1048 1048
1049 TestSuite.prototype.checkInputEventsPresent = function() 1049 TestSuite.prototype.checkInputEventsPresent = function()
1050 { 1050 {
1051 var expectedEvents = new Set(arguments); 1051 var expectedEvents = new Set(arguments);
1052 var model = WebInspector.panels.timeline._model; 1052 var model = WebInspector.panels.timeline._model;
1053 var asyncEvents = model.mainThreadAsyncEvents(); 1053 var asyncEvents = model.mainThreadAsyncEvents();
1054 var input = asyncEvents.get(WebInspector.TimelineModel.AsyncEventGroup.input ) || []; 1054 var input = asyncEvents.get(WebInspector.TimelineModel.AsyncEventGroup.input ) || [];
1055 var prefix = "InputLatency::"; 1055 var prefix = "InputLatency::";
1056 for (var e of input) { 1056 for (var e of input) {
1057 if (!e.name.startsWith(prefix)) 1057 if (!e.name.startsWith(prefix))
1058 continue; 1058 continue;
1059 if (e.steps.length < 2) 1059 if (e.steps.length < 2)
1060 continue; 1060 continue;
1061 if (e.name.startsWith(prefix + "Mouse") && typeof e.steps[0].timeWaiting ForMainThread !== "number") 1061 if (e.name.startsWith(prefix + "Mouse") && typeof e.steps[0].timeWaiting ForMainThread !== "number")
1062 throw `Missing timeWaitingForMainThread on ${e.name}`; 1062 throw `Missing timeWaitingForMainThread on ${e.name}`;
1063 expectedEvents.delete(e.name.substr(prefix.length)); 1063 expectedEvents.delete(e.name.substr(prefix.length));
1064 } 1064 }
1065 if (expectedEvents.size) 1065 if (expectedEvents.size)
1066 throw "Some expected events are not found: " + Array.from(expectedEvents .keys()).join(","); 1066 throw "Some expected events are not found: " + Array.from(expectedEvents .keys()).join(",");
1067 } 1067 };
1068 1068
1069 /** 1069 /**
1070 * Serializes array of uiSourceCodes to string. 1070 * Serializes array of uiSourceCodes to string.
1071 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes 1071 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes
1072 * @return {string} 1072 * @return {string}
1073 */ 1073 */
1074 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) 1074 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes)
1075 { 1075 {
1076 var names = []; 1076 var names = [];
1077 for (var i = 0; i < uiSourceCodes.length; i++) 1077 for (var i = 0; i < uiSourceCodes.length; i++)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 { 1187 {
1188 checkTargets.call(this); 1188 checkTargets.call(this);
1189 1189
1190 function checkTargets() 1190 function checkTargets()
1191 { 1191 {
1192 if (WebInspector.targetManager.targets().length >= n) 1192 if (WebInspector.targetManager.targets().length >= n)
1193 callback.call(null); 1193 callback.call(null);
1194 else 1194 else
1195 this.addSniffer(WebInspector.TargetManager.prototype, "addTarget", c heckTargets.bind(this)); 1195 this.addSniffer(WebInspector.TargetManager.prototype, "addTarget", c heckTargets.bind(this));
1196 } 1196 }
1197 } 1197 };
1198 1198
1199 TestSuite.prototype._waitForExecutionContexts = function(n, callback) 1199 TestSuite.prototype._waitForExecutionContexts = function(n, callback)
1200 { 1200 {
1201 var runtimeModel = WebInspector.targetManager.mainTarget().runtimeModel; 1201 var runtimeModel = WebInspector.targetManager.mainTarget().runtimeModel;
1202 checkForExecutionContexts.call(this); 1202 checkForExecutionContexts.call(this);
1203 1203
1204 function checkForExecutionContexts() 1204 function checkForExecutionContexts()
1205 { 1205 {
1206 if (runtimeModel.executionContexts().length >= n) 1206 if (runtimeModel.executionContexts().length >= n)
1207 callback.call(null); 1207 callback.call(null);
1208 else 1208 else
1209 this.addSniffer(WebInspector.RuntimeModel.prototype, "_executionCont extCreated", checkForExecutionContexts.bind(this)); 1209 this.addSniffer(WebInspector.RuntimeModel.prototype, "_executionCont extCreated", checkForExecutionContexts.bind(this));
1210 } 1210 }
1211 } 1211 };
1212 1212
1213 /** 1213 /**
1214 * Key event with given key identifier. 1214 * Key event with given key identifier.
1215 */ 1215 */
1216 TestSuite.createKeyEvent = function(key) 1216 TestSuite.createKeyEvent = function(key)
1217 { 1217 {
1218 return new KeyboardEvent("keydown", {bubbles: true, cancelable:true, key: ke y}); 1218 return new KeyboardEvent("keydown", {bubbles: true, cancelable:true, key: ke y});
1219 }; 1219 };
1220 1220
1221 window.uiTests = new TestSuite(window.domAutomationController); 1221 window.uiTests = new TestSuite(window.domAutomationController);
1222 })(window); 1222 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698