OLD | NEW |
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 Loading... |
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" | |
54 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
55 #include "content/public/browser/worker_service.h" | 53 #include "content/public/browser/worker_service.h" |
56 #include "content/public/browser/worker_service_observer.h" | 54 #include "content/public/browser/worker_service_observer.h" |
57 #include "content/public/common/content_switches.h" | 55 #include "content/public/common/content_switches.h" |
58 #include "content/public/test/browser_test_utils.h" | 56 #include "content/public/test/browser_test_utils.h" |
59 #include "content/public/test/test_navigation_observer.h" | 57 #include "content/public/test/test_navigation_observer.h" |
60 #include "extensions/browser/extension_registry.h" | 58 #include "extensions/browser/extension_registry.h" |
61 #include "extensions/browser/extension_system.h" | 59 #include "extensions/browser/extension_system.h" |
62 #include "extensions/browser/notification_types.h" | 60 #include "extensions/browser/notification_types.h" |
63 #include "extensions/common/switches.h" | 61 #include "extensions/common/switches.h" |
64 #include "extensions/common/value_builder.h" | 62 #include "extensions/common/value_builder.h" |
65 #include "net/dns/mock_host_resolver.h" | 63 #include "net/dns/mock_host_resolver.h" |
66 #include "net/test/spawned_test_server/spawned_test_server.h" | 64 #include "net/test/spawned_test_server/spawned_test_server.h" |
67 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
68 #include "ui/compositor/compositor_switches.h" | 65 #include "ui/compositor/compositor_switches.h" |
69 #include "ui/gl/gl_switches.h" | 66 #include "ui/gl/gl_switches.h" |
70 | 67 |
71 using app_modal::AppModalDialog; | 68 using app_modal::AppModalDialog; |
72 using app_modal::JavaScriptAppModalDialog; | 69 using app_modal::JavaScriptAppModalDialog; |
73 using app_modal::NativeAppModalDialog; | 70 using app_modal::NativeAppModalDialog; |
74 using content::BrowserThread; | 71 using content::BrowserThread; |
75 using content::DevToolsAgentHost; | 72 using content::DevToolsAgentHost; |
76 using content::NavigationController; | 73 using content::NavigationController; |
77 using content::RenderViewHost; | 74 using content::RenderViewHost; |
78 using content::WebContents; | 75 using content::WebContents; |
79 using content::WorkerService; | 76 using content::WorkerService; |
80 using content::WorkerServiceObserver; | 77 using content::WorkerServiceObserver; |
81 using extensions::Extension; | 78 using extensions::Extension; |
82 | 79 |
83 namespace { | 80 namespace { |
84 | 81 |
85 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; | 82 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; |
86 const char kPauseWhenLoadingDevTools[] = | 83 const char kPauseWhenLoadingDevTools[] = |
87 "files/devtools/pause_when_loading_devtools.html"; | 84 "files/devtools/pause_when_loading_devtools.html"; |
88 const char kPauseWhenScriptIsRunning[] = | 85 const char kPauseWhenScriptIsRunning[] = |
89 "files/devtools/pause_when_script_is_running.html"; | 86 "files/devtools/pause_when_script_is_running.html"; |
90 const char kPageWithContentScript[] = | 87 const char kPageWithContentScript[] = |
91 "files/devtools/page_with_content_script.html"; | 88 "files/devtools/page_with_content_script.html"; |
92 const char kNavigateBackTestPage[] = | 89 const char kNavigateBackTestPage[] = |
93 "files/devtools/navigate_back.html"; | 90 "files/devtools/navigate_back.html"; |
94 const char kWindowOpenTestPage[] = "files/devtools/window_open.html"; | 91 const char kWindowOpenTestPage[] = "files/devtools/window_open.html"; |
95 const char kLatencyInfoTestPage[] = "files/devtools/latency_info.html"; | |
96 const char kChunkedTestPage[] = "chunked"; | 92 const char kChunkedTestPage[] = "chunked"; |
97 const char kSlowTestPage[] = | 93 const char kSlowTestPage[] = |
98 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; | 94 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
99 const char kSharedWorkerTestPage[] = | 95 const char kSharedWorkerTestPage[] = |
100 "files/workers/workers_ui_shared_worker.html"; | 96 "files/workers/workers_ui_shared_worker.html"; |
101 const char kSharedWorkerTestWorker[] = | 97 const char kSharedWorkerTestWorker[] = |
102 "files/workers/workers_ui_shared_worker.js"; | 98 "files/workers/workers_ui_shared_worker.js"; |
103 const char kReloadSharedWorkerTestPage[] = | 99 const char kReloadSharedWorkerTestPage[] = |
104 "files/workers/debug_shared_worker_initialization.html"; | 100 "files/workers/debug_shared_worker_initialization.html"; |
105 const char kReloadSharedWorkerTestWorker[] = | 101 const char kReloadSharedWorkerTestWorker[] = |
106 "files/workers/debug_shared_worker_initialization.js"; | 102 "files/workers/debug_shared_worker_initialization.js"; |
107 | 103 |
108 template <typename... T> | 104 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> | |
128 void DispatchOnTestSuite(DevToolsWindow* window, | 105 void DispatchOnTestSuite(DevToolsWindow* window, |
129 const char* method, | 106 const char* method, |
130 T... args) { | 107 T... args) { |
131 std::string result; | 108 std::string result; |
132 RenderViewHost* rvh = DevToolsWindowTesting::Get(window) | 109 RenderViewHost* rvh = DevToolsWindowTesting::Get(window) |
133 ->main_web_contents() | 110 ->main_web_contents() |
134 ->GetRenderViewHost(); | 111 ->GetRenderViewHost(); |
135 // At first check that JavaScript part of the front-end is loaded by | 112 // At first check that JavaScript part of the front-end is loaded by |
136 // checking that global variable uiTests exists(it's created after all js | 113 // checking that global variable uiTests exists(it's created after all js |
137 // files have been loaded) and has runTest method. | 114 // files have been loaded) and has runTest method. |
138 ASSERT_TRUE( | 115 ASSERT_TRUE( |
139 content::ExecuteScriptAndExtractString( | 116 content::ExecuteScriptAndExtractString( |
140 rvh, | 117 rvh, |
141 "window.domAutomationController.send(" | 118 "window.domAutomationController.send(" |
142 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));", | 119 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));", |
143 &result)); | 120 &result)); |
144 ASSERT_EQ("function", result) << "DevTools front-end is broken."; | 121 ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
145 DispatchOnTestSuiteSkipCheck(window, method, args...); | 122 |
| 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); |
146 } | 132 } |
147 | 133 |
148 void RunTestFunction(DevToolsWindow* window, const char* test_name) { | 134 void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
149 DispatchOnTestSuite(window, test_name); | 135 DispatchOnTestSuite(window, test_name); |
150 } | 136 } |
151 | 137 |
152 void SwitchToPanel(DevToolsWindow* window, const char* panel) { | 138 void SwitchToPanel(DevToolsWindow* window, const char* panel) { |
153 DispatchOnTestSuite(window, "switchToPanel", panel); | 139 DispatchOnTestSuite(window, "switchToPanel", panel); |
154 } | 140 } |
155 | 141 |
(...skipping 19 matching lines...) Expand all Loading... |
175 host_resolver()->AddRule("*", "127.0.0.1"); | 161 host_resolver()->AddRule("*", "127.0.0.1"); |
176 } | 162 } |
177 | 163 |
178 protected: | 164 protected: |
179 void RunTest(const std::string& test_name, const std::string& test_page) { | 165 void RunTest(const std::string& test_name, const std::string& test_page) { |
180 OpenDevToolsWindow(test_page, false); | 166 OpenDevToolsWindow(test_page, false); |
181 RunTestFunction(window_, test_name.c_str()); | 167 RunTestFunction(window_, test_name.c_str()); |
182 CloseDevToolsWindow(); | 168 CloseDevToolsWindow(); |
183 } | 169 } |
184 | 170 |
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 | |
200 void LoadTestPage(const std::string& test_page) { | 171 void LoadTestPage(const std::string& test_page) { |
201 GURL url = spawned_test_server()->GetURL(test_page); | 172 GURL url = spawned_test_server()->GetURL(test_page); |
202 ui_test_utils::NavigateToURL(browser(), url); | 173 ui_test_utils::NavigateToURL(browser(), url); |
203 } | 174 } |
204 | 175 |
205 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { | 176 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
206 ASSERT_TRUE(spawned_test_server()->Start()); | 177 ASSERT_TRUE(spawned_test_server()->Start()); |
207 LoadTestPage(test_page); | 178 LoadTestPage(test_page); |
208 | 179 |
209 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), | 180 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), |
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 }; | 1138 }; |
1168 | 1139 |
1169 // This test enables switches::kUseGpuInTests which causes false positives | 1140 // This test enables switches::kUseGpuInTests which causes false positives |
1170 // with MemorySanitizer. | 1141 // with MemorySanitizer. |
1171 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \ | 1142 #if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \ |
1172 (defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)) | 1143 (defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)) |
1173 #define MAYBE_TestScreenshotRecording DISABLED_TestScreenshotRecording | 1144 #define MAYBE_TestScreenshotRecording DISABLED_TestScreenshotRecording |
1174 #else | 1145 #else |
1175 #define MAYBE_TestScreenshotRecording TestScreenshotRecording | 1146 #define MAYBE_TestScreenshotRecording TestScreenshotRecording |
1176 #endif | 1147 #endif |
| 1148 // Tests raw headers text. |
1177 IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests, | 1149 IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests, |
1178 MAYBE_TestScreenshotRecording) { | 1150 MAYBE_TestScreenshotRecording) { |
1179 RunTest("testScreenshotRecording", std::string()); | 1151 RunTest("testScreenshotRecording", std::string()); |
1180 } | 1152 } |
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 SimulateMouseEvent(web_contents, blink::WebInputEvent::MouseMove, | |
1198 gfx::Point(30, 60)); | |
1199 DispatchInPageAndWait("waitForEvent", "mousemove"); | |
1200 | |
1201 SimulateMouseClickAt(web_contents, 0, blink::WebPointerProperties::ButtonLeft, | |
1202 gfx::Point(30, 60)); | |
1203 DispatchInPageAndWait("waitForEvent", "click"); | |
1204 | |
1205 SimulateMouseWheelEvent(web_contents, gfx::Point(300, 100), | |
1206 gfx::Vector2d(0, 120)); | |
1207 DispatchInPageAndWait("waitForEvent", "wheel"); | |
1208 | |
1209 SimulateTapAt(web_contents, gfx::Point(30, 60)); | |
1210 DispatchInPageAndWait("waitForEvent", "gesturetap"); | |
1211 | |
1212 DispatchAndWait("stopTimeline"); | |
1213 RunTestMethod("checkInputEventsPresent", "MouseMove", "MouseDown", | |
1214 "MouseWheel", "GestureTap"); | |
1215 | |
1216 CloseDevToolsWindow(); | |
1217 } | |
OLD | NEW |