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

Side by Side Diff: chrome/browser/devtools/devtools_sanity_browsertest.cc

Issue 1704723002: DevTools: add input event instrumentation test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: speculative attempt to fix MacOS 10.6 flakiness Created 4 years, 10 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
« no previous file with comments | « no previous file | chrome/test/data/devtools/latency_info.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/cancelable_callback.h" 8 #include "base/cancelable_callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/test/base/ui_test_utils.h" 42 #include "chrome/test/base/ui_test_utils.h"
43 #include "components/app_modal/javascript_app_modal_dialog.h" 43 #include "components/app_modal/javascript_app_modal_dialog.h"
44 #include "components/app_modal/native_app_modal_dialog.h" 44 #include "components/app_modal/native_app_modal_dialog.h"
45 #include "components/prefs/pref_service.h" 45 #include "components/prefs/pref_service.h"
46 #include "content/public/browser/child_process_data.h" 46 #include "content/public/browser/child_process_data.h"
47 #include "content/public/browser/content_browser_client.h" 47 #include "content/public/browser/content_browser_client.h"
48 #include "content/public/browser/devtools_agent_host.h" 48 #include "content/public/browser/devtools_agent_host.h"
49 #include "content/public/browser/notification_registrar.h" 49 #include "content/public/browser/notification_registrar.h"
50 #include "content/public/browser/notification_service.h" 50 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/render_view_host.h" 51 #include "content/public/browser/render_view_host.h"
52 #include "content/public/browser/render_widget_host.h"
53 #include "content/public/browser/render_widget_host_view.h"
52 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
53 #include "content/public/browser/worker_service.h" 55 #include "content/public/browser/worker_service.h"
54 #include "content/public/browser/worker_service_observer.h" 56 #include "content/public/browser/worker_service_observer.h"
55 #include "content/public/common/content_switches.h" 57 #include "content/public/common/content_switches.h"
56 #include "content/public/test/browser_test_utils.h" 58 #include "content/public/test/browser_test_utils.h"
57 #include "content/public/test/test_navigation_observer.h" 59 #include "content/public/test/test_navigation_observer.h"
58 #include "extensions/browser/extension_registry.h" 60 #include "extensions/browser/extension_registry.h"
59 #include "extensions/browser/extension_system.h" 61 #include "extensions/browser/extension_system.h"
60 #include "extensions/browser/notification_types.h" 62 #include "extensions/browser/notification_types.h"
61 #include "extensions/common/switches.h" 63 #include "extensions/common/switches.h"
62 #include "extensions/common/value_builder.h" 64 #include "extensions/common/value_builder.h"
63 #include "net/dns/mock_host_resolver.h" 65 #include "net/dns/mock_host_resolver.h"
64 #include "net/test/spawned_test_server/spawned_test_server.h" 66 #include "net/test/spawned_test_server/spawned_test_server.h"
67 #include "third_party/WebKit/public/web/WebInputEvent.h"
65 #include "ui/compositor/compositor_switches.h" 68 #include "ui/compositor/compositor_switches.h"
66 #include "ui/gl/gl_switches.h" 69 #include "ui/gl/gl_switches.h"
67 70
68 using app_modal::AppModalDialog; 71 using app_modal::AppModalDialog;
69 using app_modal::JavaScriptAppModalDialog; 72 using app_modal::JavaScriptAppModalDialog;
70 using app_modal::NativeAppModalDialog; 73 using app_modal::NativeAppModalDialog;
71 using content::BrowserThread; 74 using content::BrowserThread;
72 using content::DevToolsAgentHost; 75 using content::DevToolsAgentHost;
73 using content::NavigationController; 76 using content::NavigationController;
74 using content::RenderViewHost; 77 using content::RenderViewHost;
75 using content::WebContents; 78 using content::WebContents;
76 using content::WorkerService; 79 using content::WorkerService;
77 using content::WorkerServiceObserver; 80 using content::WorkerServiceObserver;
78 using extensions::Extension; 81 using extensions::Extension;
79 82
80 namespace { 83 namespace {
81 84
82 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; 85 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html";
83 const char kPauseWhenLoadingDevTools[] = 86 const char kPauseWhenLoadingDevTools[] =
84 "files/devtools/pause_when_loading_devtools.html"; 87 "files/devtools/pause_when_loading_devtools.html";
85 const char kPauseWhenScriptIsRunning[] = 88 const char kPauseWhenScriptIsRunning[] =
86 "files/devtools/pause_when_script_is_running.html"; 89 "files/devtools/pause_when_script_is_running.html";
87 const char kPageWithContentScript[] = 90 const char kPageWithContentScript[] =
88 "files/devtools/page_with_content_script.html"; 91 "files/devtools/page_with_content_script.html";
89 const char kNavigateBackTestPage[] = 92 const char kNavigateBackTestPage[] =
90 "files/devtools/navigate_back.html"; 93 "files/devtools/navigate_back.html";
91 const char kWindowOpenTestPage[] = "files/devtools/window_open.html"; 94 const char kWindowOpenTestPage[] = "files/devtools/window_open.html";
95 const char kLatencyInfoTestPage[] = "files/devtools/latency_info.html";
92 const char kChunkedTestPage[] = "chunked"; 96 const char kChunkedTestPage[] = "chunked";
93 const char kSlowTestPage[] = 97 const char kSlowTestPage[] =
94 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; 98 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2";
95 const char kSharedWorkerTestPage[] = 99 const char kSharedWorkerTestPage[] =
96 "files/workers/workers_ui_shared_worker.html"; 100 "files/workers/workers_ui_shared_worker.html";
97 const char kSharedWorkerTestWorker[] = 101 const char kSharedWorkerTestWorker[] =
98 "files/workers/workers_ui_shared_worker.js"; 102 "files/workers/workers_ui_shared_worker.js";
99 const char kReloadSharedWorkerTestPage[] = 103 const char kReloadSharedWorkerTestPage[] =
100 "files/workers/debug_shared_worker_initialization.html"; 104 "files/workers/debug_shared_worker_initialization.html";
101 const char kReloadSharedWorkerTestWorker[] = 105 const char kReloadSharedWorkerTestWorker[] =
102 "files/workers/debug_shared_worker_initialization.js"; 106 "files/workers/debug_shared_worker_initialization.js";
103 107
104 template <typename... T> 108 template <typename... T>
109 void DispatchOnTestSuiteSkipCheck(DevToolsWindow* window,
110 const char* method,
111 T... args) {
112 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)
113 ->main_web_contents()
114 ->GetRenderViewHost();
115 std::string result;
116 const char* args_array[] = {method, args...};
117 std::ostringstream script;
118 script << "uiTests.dispatchOnTestSuite([";
119 for (size_t i = 0; i < arraysize(args_array); ++i)
120 script << (i ? "," : "") << '\"' << args_array[i] << '\"';
121 script << "])";
122 ASSERT_TRUE(
123 content::ExecuteScriptAndExtractString(rvh, script.str(), &result));
124 EXPECT_EQ("[OK]", result);
125 }
126
127 template <typename... T>
105 void DispatchOnTestSuite(DevToolsWindow* window, 128 void DispatchOnTestSuite(DevToolsWindow* window,
106 const char* method, 129 const char* method,
107 T... args) { 130 T... args) {
108 std::string result; 131 std::string result;
109 RenderViewHost* rvh = DevToolsWindowTesting::Get(window) 132 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)
110 ->main_web_contents() 133 ->main_web_contents()
111 ->GetRenderViewHost(); 134 ->GetRenderViewHost();
112 // At first check that JavaScript part of the front-end is loaded by 135 // At first check that JavaScript part of the front-end is loaded by
113 // checking that global variable uiTests exists(it's created after all js 136 // checking that global variable uiTests exists(it's created after all js
114 // files have been loaded) and has runTest method. 137 // files have been loaded) and has runTest method.
115 ASSERT_TRUE( 138 ASSERT_TRUE(
116 content::ExecuteScriptAndExtractString( 139 content::ExecuteScriptAndExtractString(
117 rvh, 140 rvh,
118 "window.domAutomationController.send(" 141 "window.domAutomationController.send("
119 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));", 142 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));",
120 &result)); 143 &result));
121 ASSERT_EQ("function", result) << "DevTools front-end is broken."; 144 ASSERT_EQ("function", result) << "DevTools front-end is broken.";
122 145 DispatchOnTestSuiteSkipCheck(window, method, args...);
123 const char* args_array[] = {method, args...};
124 std::ostringstream script;
125 script << "uiTests.dispatchOnTestSuite([";
126 for (size_t i = 0; i < arraysize(args_array); ++i)
127 script << (i ? "," : "") << '\"' << args_array[i] << '\"';
128 script << "])";
129 ASSERT_TRUE(
130 content::ExecuteScriptAndExtractString(rvh, script.str(), &result));
131 EXPECT_EQ("[OK]", result);
132 } 146 }
133 147
134 void RunTestFunction(DevToolsWindow* window, const char* test_name) { 148 void RunTestFunction(DevToolsWindow* window, const char* test_name) {
135 DispatchOnTestSuite(window, test_name); 149 DispatchOnTestSuite(window, test_name);
136 } 150 }
137 151
138 void SwitchToPanel(DevToolsWindow* window, const char* panel) { 152 void SwitchToPanel(DevToolsWindow* window, const char* panel) {
139 DispatchOnTestSuite(window, "switchToPanel", panel); 153 DispatchOnTestSuite(window, "switchToPanel", panel);
140 } 154 }
141 155
(...skipping 19 matching lines...) Expand all
161 host_resolver()->AddRule("*", "127.0.0.1"); 175 host_resolver()->AddRule("*", "127.0.0.1");
162 } 176 }
163 177
164 protected: 178 protected:
165 void RunTest(const std::string& test_name, const std::string& test_page) { 179 void RunTest(const std::string& test_name, const std::string& test_page) {
166 OpenDevToolsWindow(test_page, false); 180 OpenDevToolsWindow(test_page, false);
167 RunTestFunction(window_, test_name.c_str()); 181 RunTestFunction(window_, test_name.c_str());
168 CloseDevToolsWindow(); 182 CloseDevToolsWindow();
169 } 183 }
170 184
185 template <typename... T>
186 void RunTestMethod(const char* method, T... args) {
187 DispatchOnTestSuiteSkipCheck(window_, method, args...);
188 }
189
190 template <typename... T>
191 void DispatchAndWait(const char* method, T... args) {
192 DispatchOnTestSuiteSkipCheck(window_, "waitForAsync", method, args...);
193 }
194
195 template <typename... T>
196 void DispatchInPageAndWait(const char* method, T... args) {
197 DispatchAndWait("invokePageFunctionAsync", method, args...);
198 }
199
171 void LoadTestPage(const std::string& test_page) { 200 void LoadTestPage(const std::string& test_page) {
172 GURL url = spawned_test_server()->GetURL(test_page); 201 GURL url = spawned_test_server()->GetURL(test_page);
173 ui_test_utils::NavigateToURL(browser(), url); 202 ui_test_utils::NavigateToURL(browser(), url);
174 } 203 }
175 204
176 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { 205 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) {
177 ASSERT_TRUE(spawned_test_server()->Start()); 206 ASSERT_TRUE(spawned_test_server()->Start());
178 LoadTestPage(test_page); 207 LoadTestPage(test_page);
179 208
180 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), 209 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(),
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 }; 1167 };
1139 1168
1140 // This test enables switches::kUseGpuInTests which causes false positives 1169 // This test enables switches::kUseGpuInTests which causes false positives
1141 // with MemorySanitizer. 1170 // with MemorySanitizer.
1142 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \ 1171 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
1143 (defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)) 1172 (defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
1144 #define MAYBE_TestScreenshotRecording DISABLED_TestScreenshotRecording 1173 #define MAYBE_TestScreenshotRecording DISABLED_TestScreenshotRecording
1145 #else 1174 #else
1146 #define MAYBE_TestScreenshotRecording TestScreenshotRecording 1175 #define MAYBE_TestScreenshotRecording TestScreenshotRecording
1147 #endif 1176 #endif
1148 // Tests raw headers text.
1149 IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests, 1177 IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
1150 MAYBE_TestScreenshotRecording) { 1178 MAYBE_TestScreenshotRecording) {
1151 RunTest("testScreenshotRecording", std::string()); 1179 RunTest("testScreenshotRecording", std::string());
1152 } 1180 }
1181
1182 // This test enables switches::kUseGpuInTests which causes false positives
1183 // with MemorySanitizer.
1184 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER)
1185 #define MAYBE_TestLatencyInfoInstrumentation \
1186 DISABLED_TestLatencyInfoInstrumentation
1187 #else
1188 #define MAYBE_TestLatencyInfoInstrumentation TestLatencyInfoInstrumentation
1189 #endif
1190 IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
1191 MAYBE_TestLatencyInfoInstrumentation) {
1192 WebContents* web_contents = GetInspectedTab();
1193 OpenDevToolsWindow(kLatencyInfoTestPage, false);
1194 RunTestMethod("enableExperiment", "timelineLatencyInfo");
1195 DispatchAndWait("startTimeline");
1196
1197 for (int i = 0; i < 3; ++i) {
1198 SimulateMouseEvent(web_contents, blink::WebInputEvent::MouseMove,
1199 gfx::Point(30, 60));
1200 DispatchInPageAndWait("waitForEvent", "mousemove");
1201 }
1202
1203 SimulateMouseClickAt(web_contents, 0, blink::WebPointerProperties::ButtonLeft,
1204 gfx::Point(30, 60));
1205 DispatchInPageAndWait("waitForEvent", "click");
1206
1207 SimulateMouseWheelEvent(web_contents, gfx::Point(300, 100),
1208 gfx::Vector2d(0, 120));
1209 DispatchInPageAndWait("waitForEvent", "wheel");
1210
1211 SimulateTapAt(web_contents, gfx::Point(30, 60));
1212 DispatchInPageAndWait("waitForEvent", "gesturetap");
1213
1214 DispatchAndWait("stopTimeline");
1215 RunTestMethod("checkInputEventsPresent", "MouseMove", "MouseDown",
1216 "MouseWheel", "GestureTap");
1217
1218 CloseDevToolsWindow();
1219 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/devtools/latency_info.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698