OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_ | 5 #ifndef COMPONENTS_HTML_VIEWER_WEB_TEST_DELEGATE_IMPL_H_ |
6 #define CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_ | 6 #define COMPONENTS_HTML_VIEWER_WEB_TEST_DELEGATE_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include "base/macros.h" |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "components/test_runner/test_preferences.h" | 9 #include "components/test_runner/test_preferences.h" |
13 #include "components/test_runner/web_test_delegate.h" | 10 #include "components/test_runner/web_test_delegate.h" |
14 #include "content/public/common/page_state.h" | |
15 #include "content/public/renderer/render_view_observer.h" | |
16 #include "content/public/renderer/render_view_observer_tracker.h" | |
17 #include "content/shell/common/shell_test_configuration.h" | |
18 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationType.h" | |
19 #include "v8/include/v8.h" | |
20 | |
21 class SkBitmap; | |
22 class SkCanvas; | |
23 | |
24 namespace blink { | |
25 class WebBatteryStatus; | |
26 class WebDeviceMotionData; | |
27 class WebDeviceOrientationData; | |
28 struct WebRect; | |
29 } | |
30 | 11 |
31 namespace test_runner { | 12 namespace test_runner { |
| 13 class WebTestInterfaces; |
32 class WebTestProxyBase; | 14 class WebTestProxyBase; |
33 } | 15 } |
34 | 16 |
35 namespace content { | 17 namespace html_viewer { |
36 | 18 |
37 class LeakDetector; | 19 class WebTestDelegateImpl : public test_runner::WebTestDelegate { |
38 struct LeakDetectionResult; | 20 public: |
| 21 WebTestDelegateImpl(); |
| 22 ~WebTestDelegateImpl(); |
39 | 23 |
40 // This is the renderer side of the webkit test runner. | 24 void set_test_interfaces(test_runner::WebTestInterfaces* test_interfaces) { |
41 class BlinkTestRunner : public RenderViewObserver, | 25 test_interfaces_ = test_interfaces; |
42 public RenderViewObserverTracker<BlinkTestRunner>, | 26 } |
43 public test_runner::WebTestDelegate { | 27 void set_test_proxy(test_runner::WebTestProxyBase* proxy) { |
44 public: | 28 proxy_ = proxy; |
45 explicit BlinkTestRunner(RenderView* render_view); | 29 } |
46 ~BlinkTestRunner() override; | |
47 | 30 |
48 // RenderViewObserver implementation. | 31 private: |
49 bool OnMessageReceived(const IPC::Message& message) override; | 32 // From test_runner::WebTestDelegate: |
50 void DidClearWindowObject(blink::WebLocalFrame* frame) override; | |
51 void Navigate(const GURL& url) override; | |
52 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, | |
53 bool is_new_navigation) override; | |
54 void DidFailProvisionalLoad(blink::WebLocalFrame* frame, | |
55 const blink::WebURLError& error) override; | |
56 | |
57 // WebTestDelegate implementation. | |
58 void ClearEditCommand() override; | 33 void ClearEditCommand() override; |
59 void SetEditCommand(const std::string& name, | 34 void SetEditCommand(const std::string& name, |
60 const std::string& value) override; | 35 const std::string& value) override; |
61 void SetGamepadProvider(test_runner::GamepadController* controller) override; | 36 void SetGamepadProvider(test_runner::GamepadController* controller) override; |
62 void SetDeviceLightData(const double data) override; | 37 void SetDeviceLightData(const double data) override; |
63 void SetDeviceMotionData(const blink::WebDeviceMotionData& data) override; | 38 void SetDeviceMotionData(const blink::WebDeviceMotionData& data) override; |
64 void SetDeviceOrientationData( | 39 void SetDeviceOrientationData( |
65 const blink::WebDeviceOrientationData& data) override; | 40 const blink::WebDeviceOrientationData& data) override; |
66 void SetScreenOrientation( | 41 void SetScreenOrientation( |
67 const blink::WebScreenOrientationType& orientation) override; | 42 const blink::WebScreenOrientationType& orientation) override; |
68 void ResetScreenOrientation() override; | 43 void ResetScreenOrientation() override; |
69 void DidChangeBatteryStatus(const blink::WebBatteryStatus& status) override; | 44 void DidChangeBatteryStatus(const blink::WebBatteryStatus& status) override; |
70 void PrintMessage(const std::string& message) override; | 45 void PrintMessage(const std::string& message) override; |
71 void PostTask(test_runner::WebTask* task) override; | 46 void PostTask(test_runner::WebTask* task) override; |
72 void PostDelayedTask(test_runner::WebTask* task, long long ms) override; | 47 void PostDelayedTask(test_runner::WebTask* task, long long ms) override; |
73 blink::WebString RegisterIsolatedFileSystem( | 48 blink::WebString RegisterIsolatedFileSystem( |
74 const blink::WebVector<blink::WebString>& absolute_filenames) override; | 49 const blink::WebVector<blink::WebString>& absolute_filenames) override; |
75 long long GetCurrentTimeInMillisecond() override; | 50 long long GetCurrentTimeInMillisecond() override; |
76 blink::WebString GetAbsoluteWebStringFromUTF8Path( | 51 blink::WebString GetAbsoluteWebStringFromUTF8Path( |
77 const std::string& utf8_path) override; | 52 const std::string& path) override; |
78 blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) override; | 53 blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) override; |
79 blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url) override; | 54 blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url) override; |
80 test_runner::TestPreferences* Preferences() override; | 55 test_runner::TestPreferences* Preferences() override; |
81 void ApplyPreferences() override; | 56 void ApplyPreferences() override; |
82 virtual std::string makeURLErrorDescription(const blink::WebURLError& error); | |
83 void UseUnfortunateSynchronousResizeMode(bool enable) override; | 57 void UseUnfortunateSynchronousResizeMode(bool enable) override; |
84 void EnableAutoResizeMode(const blink::WebSize& min_size, | 58 void EnableAutoResizeMode(const blink::WebSize& min_size, |
85 const blink::WebSize& max_size) override; | 59 const blink::WebSize& max_size) override; |
86 void DisableAutoResizeMode(const blink::WebSize& new_size) override; | 60 void DisableAutoResizeMode(const blink::WebSize& new_size) override; |
87 void ClearDevToolsLocalStorage() override; | 61 void ClearDevToolsLocalStorage() override; |
88 void ShowDevTools(const std::string& settings, | 62 void ShowDevTools(const std::string& settings, |
89 const std::string& frontend_url) override; | 63 const std::string& frontend_url) override; |
90 void CloseDevTools() override; | 64 void CloseDevTools() override; |
91 void EvaluateInWebInspector(long call_id, const std::string& script) override; | 65 void EvaluateInWebInspector(long call_id, const std::string& script) override; |
92 void ClearAllDatabases() override; | 66 void ClearAllDatabases() override; |
93 void SetDatabaseQuota(int quota) override; | 67 void SetDatabaseQuota(int quota) override; |
94 void SimulateWebNotificationClick(const std::string& title) override; | 68 void SimulateWebNotificationClick(const std::string& title) override; |
95 void SetDeviceScaleFactor(float factor) override; | 69 void SetDeviceScaleFactor(float factor) override; |
96 void SetDeviceColorProfile(const std::string& name) override; | 70 void SetDeviceColorProfile(const std::string& name) override; |
97 void SetBluetoothMockDataSet(const std::string& name) override; | 71 void SetBluetoothMockDataSet(const std::string& data_set) override; |
98 void SetGeofencingMockProvider(bool service_available) override; | 72 void SetGeofencingMockProvider(bool service_available) override; |
99 void ClearGeofencingMockProvider() override; | 73 void ClearGeofencingMockProvider() override; |
100 void SetGeofencingMockPosition(double latitude, double longitude) override; | 74 void SetGeofencingMockPosition(double latitude, double longitude) override; |
101 void SetFocus(test_runner::WebTestProxyBase* proxy, bool focus) override; | 75 void SetFocus(test_runner::WebTestProxyBase* proxy, bool focus) override; |
102 void SetAcceptAllCookies(bool accept) override; | 76 void SetAcceptAllCookies(bool accept) override; |
103 std::string PathToLocalResource(const std::string& resource) override; | 77 std::string PathToLocalResource(const std::string& resource) override; |
104 void SetLocale(const std::string& locale) override; | 78 void SetLocale(const std::string& locale) override; |
105 void TestFinished() override; | 79 void TestFinished() override; |
106 void CloseRemainingWindows() override; | 80 void CloseRemainingWindows() override; |
107 void DeleteAllCookies() override; | 81 void DeleteAllCookies() override; |
108 int NavigationEntryCount() override; | 82 int NavigationEntryCount() override; |
109 void GoToOffset(int offset) override; | 83 void GoToOffset(int offset) override; |
110 void Reload() override; | 84 void Reload() override; |
111 void LoadURLForFrame(const blink::WebURL& url, | 85 void LoadURLForFrame(const blink::WebURL& url, |
112 const std::string& frame_name) override; | 86 const std::string& frame_name) override; |
113 bool AllowExternalPages() override; | 87 bool AllowExternalPages() override; |
114 std::string DumpHistoryForWindow( | 88 std::string DumpHistoryForWindow( |
115 test_runner::WebTestProxyBase* proxy) override; | 89 test_runner::WebTestProxyBase* proxy) override; |
116 void FetchManifest( | 90 void FetchManifest( |
117 blink::WebView* view, | 91 blink::WebView* view, |
118 const GURL& url, | 92 const GURL& url, |
119 const base::Callback<void(const blink::WebURLResponse& response, | 93 const base::Callback<void(const blink::WebURLResponse& response, |
120 const std::string& data)>& callback) override; | 94 const std::string& data)>& callback) override; |
121 void SetPermission(const std::string& name, | 95 void SetPermission(const std::string& permission_name, |
122 const std::string& value, | 96 const std::string& permission_value, |
123 const GURL& origin, | 97 const GURL& origin, |
124 const GURL& embedding_origin) override; | 98 const GURL& embedding_origin) override; |
125 void ResetPermissions() override; | 99 void ResetPermissions() override; |
126 scoped_refptr<cc::TextureLayer> CreateTextureLayerForMailbox( | 100 scoped_refptr<cc::TextureLayer> CreateTextureLayerForMailbox( |
127 cc::TextureLayerClient* client) override; | 101 cc::TextureLayerClient* client) override; |
128 blink::WebLayer* InstantiateWebLayer( | 102 blink::WebLayer* InstantiateWebLayer( |
129 scoped_refptr<cc::TextureLayer> layer) override; | 103 scoped_refptr<cc::TextureLayer> layer) override; |
130 cc::SharedBitmapManager* GetSharedBitmapManager() override; | 104 cc::SharedBitmapManager* GetSharedBitmapManager() override; |
131 void DispatchBeforeInstallPromptEvent( | 105 void DispatchBeforeInstallPromptEvent( |
132 int request_id, | 106 int request_id, |
133 const std::vector<std::string>& event_platforms, | 107 const std::vector<std::string>& event_platforms, |
134 const base::Callback<void(bool)>& callback) override; | 108 const base::Callback<void(bool)>& callback) override; |
135 void ResolveBeforeInstallPromptPromise( | 109 void ResolveBeforeInstallPromptPromise(int request_id, |
136 int request_id, | 110 const std::string& platform) override; |
137 const std::string& platform) override; | |
138 blink::WebPlugin* CreatePluginPlaceholder( | 111 blink::WebPlugin* CreatePluginPlaceholder( |
139 blink::WebLocalFrame* frame, | 112 blink::WebLocalFrame* frame, |
140 const blink::WebPluginParams& params) override; | 113 const blink::WebPluginParams& params) override; |
141 | 114 |
142 void Reset(); | 115 test_runner::TestPreferences prefs_; |
143 | 116 test_runner::WebTestInterfaces* test_interfaces_; |
144 void set_proxy(test_runner::WebTestProxyBase* proxy) { proxy_ = proxy; } | |
145 test_runner::WebTestProxyBase* proxy() const { return proxy_; } | |
146 | |
147 void ReportLeakDetectionResult(const LeakDetectionResult& result); | |
148 | |
149 private: | |
150 // Message handlers. | |
151 void OnSetTestConfiguration(const ShellTestConfiguration& params); | |
152 void OnSessionHistory( | |
153 const std::vector<int>& routing_ids, | |
154 const std::vector<std::vector<PageState> >& session_histories, | |
155 const std::vector<unsigned>& current_entry_indexes); | |
156 void OnReset(); | |
157 void OnNotifyDone(); | |
158 void OnTryLeakDetection(); | |
159 | |
160 // After finishing the test, retrieves the audio, text, and pixel dumps from | |
161 // the TestRunner library and sends them to the browser process. | |
162 void CaptureDump(); | |
163 void CaptureDumpPixels(const SkBitmap& snapshot); | |
164 void CaptureDumpComplete(); | |
165 | |
166 test_runner::WebTestProxyBase* proxy_; | 117 test_runner::WebTestProxyBase* proxy_; |
167 | 118 |
168 RenderView* focused_view_; | 119 DISALLOW_COPY_AND_ASSIGN(WebTestDelegateImpl); |
169 | |
170 test_runner::TestPreferences prefs_; | |
171 | |
172 ShellTestConfiguration test_config_; | |
173 | |
174 std::vector<int> routing_ids_; | |
175 std::vector<std::vector<PageState> > session_histories_; | |
176 std::vector<unsigned> current_entry_indexes_; | |
177 | |
178 bool is_main_window_; | |
179 | |
180 bool focus_on_next_commit_; | |
181 | |
182 scoped_ptr<LeakDetector> leak_detector_; | |
183 bool needs_leak_detector_; | |
184 | |
185 DISALLOW_COPY_AND_ASSIGN(BlinkTestRunner); | |
186 }; | 120 }; |
187 | 121 |
188 } // namespace content | 122 } // namespace html_viewer |
189 | 123 |
190 #endif // CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_ | 124 #endif // COMPONENTS_HTML_VIEWER_WEB_TEST_DELEGATE_IMPL_H_ |
OLD | NEW |