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
3 // found in the LICENSE file.
5 #ifndef CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_
6 #define CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/test_runner/test_preferences.h"
13 #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/WebScreenOrientationType.h"
19 #include "v8/include/v8.h"
25 class WebBatteryStatus
;
26 class WebDeviceMotionData
;
27 class WebDeviceOrientationData
;
31 namespace test_runner
{
32 class WebTestProxyBase
;
38 struct LeakDetectionResult
;
40 // This is the renderer side of the webkit test runner.
41 class BlinkTestRunner
: public RenderViewObserver
,
42 public RenderViewObserverTracker
<BlinkTestRunner
>,
43 public test_runner::WebTestDelegate
{
45 explicit BlinkTestRunner(RenderView
* render_view
);
46 ~BlinkTestRunner() override
;
48 // RenderViewObserver implementation.
49 bool OnMessageReceived(const IPC::Message
& message
) override
;
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
;
57 // WebTestDelegate implementation.
58 void ClearEditCommand() override
;
59 void SetEditCommand(const std::string
& name
,
60 const std::string
& value
) override
;
61 void SetGamepadProvider(test_runner::GamepadController
* controller
) override
;
62 void SetDeviceLightData(const double data
) override
;
63 void SetDeviceMotionData(const blink::WebDeviceMotionData
& data
) override
;
64 void SetDeviceOrientationData(
65 const blink::WebDeviceOrientationData
& data
) override
;
66 void SetScreenOrientation(
67 const blink::WebScreenOrientationType
& orientation
) override
;
68 void ResetScreenOrientation() override
;
69 void DidChangeBatteryStatus(const blink::WebBatteryStatus
& status
) override
;
70 void PrintMessage(const std::string
& message
) override
;
71 void PostTask(test_runner::WebTask
* task
) override
;
72 void PostDelayedTask(test_runner::WebTask
* task
, long long ms
) override
;
73 blink::WebString
RegisterIsolatedFileSystem(
74 const blink::WebVector
<blink::WebString
>& absolute_filenames
) override
;
75 long long GetCurrentTimeInMillisecond() override
;
76 blink::WebString
GetAbsoluteWebStringFromUTF8Path(
77 const std::string
& utf8_path
) override
;
78 blink::WebURL
LocalFileToDataURL(const blink::WebURL
& file_url
) override
;
79 blink::WebURL
RewriteLayoutTestsURL(const std::string
& utf8_url
) override
;
80 test_runner::TestPreferences
* Preferences() override
;
81 void ApplyPreferences() override
;
82 virtual std::string
makeURLErrorDescription(const blink::WebURLError
& error
);
83 void UseUnfortunateSynchronousResizeMode(bool enable
) override
;
84 void EnableAutoResizeMode(const blink::WebSize
& min_size
,
85 const blink::WebSize
& max_size
) override
;
86 void DisableAutoResizeMode(const blink::WebSize
& new_size
) override
;
87 void ClearDevToolsLocalStorage() override
;
88 void ShowDevTools(const std::string
& settings
,
89 const std::string
& frontend_url
) override
;
90 void CloseDevTools() override
;
91 void EvaluateInWebInspector(long call_id
, const std::string
& script
) override
;
92 void ClearAllDatabases() override
;
93 void SetDatabaseQuota(int quota
) override
;
94 void SimulateWebNotificationClick(const std::string
& title
,
95 int action_index
) override
;
96 void SetDeviceScaleFactor(float factor
) override
;
97 void SetDeviceColorProfile(const std::string
& name
) override
;
98 void SetBluetoothMockDataSet(const std::string
& name
) override
;
99 void SetBluetoothManualChooser() override
;
100 std::vector
<std::string
> GetBluetoothManualChooserEvents() override
;
101 void SendBluetoothManualChooserEvent(const std::string
& event
,
102 const std::string
& argument
) override
;
103 void SetGeofencingMockProvider(bool service_available
) override
;
104 void ClearGeofencingMockProvider() override
;
105 void SetGeofencingMockPosition(double latitude
, double longitude
) override
;
106 void SetFocus(test_runner::WebTestProxyBase
* proxy
, bool focus
) override
;
107 void SetAcceptAllCookies(bool accept
) override
;
108 std::string
PathToLocalResource(const std::string
& resource
) override
;
109 void SetLocale(const std::string
& locale
) override
;
110 void TestFinished() override
;
111 void CloseRemainingWindows() override
;
112 void DeleteAllCookies() override
;
113 int NavigationEntryCount() override
;
114 void GoToOffset(int offset
) override
;
115 void Reload() override
;
116 void LoadURLForFrame(const blink::WebURL
& url
,
117 const std::string
& frame_name
) override
;
118 bool AllowExternalPages() override
;
119 std::string
DumpHistoryForWindow(
120 test_runner::WebTestProxyBase
* proxy
) override
;
122 blink::WebView
* view
,
124 const base::Callback
<void(const blink::WebURLResponse
& response
,
125 const std::string
& data
)>& callback
) override
;
126 void SetPermission(const std::string
& name
,
127 const std::string
& value
,
129 const GURL
& embedding_origin
) override
;
130 void ResetPermissions() override
;
131 cc::SharedBitmapManager
* GetSharedBitmapManager() override
;
132 void DispatchBeforeInstallPromptEvent(
134 const std::vector
<std::string
>& event_platforms
,
135 const base::Callback
<void(bool)>& callback
) override
;
136 void ResolveBeforeInstallPromptPromise(
138 const std::string
& platform
) override
;
139 blink::WebPlugin
* CreatePluginPlaceholder(
140 blink::WebLocalFrame
* frame
,
141 const blink::WebPluginParams
& params
) override
;
142 void OnWebTestProxyBaseDestroy(test_runner::WebTestProxyBase
* proxy
) override
;
146 void set_proxy(test_runner::WebTestProxyBase
* proxy
) { proxy_
= proxy
; }
147 test_runner::WebTestProxyBase
* proxy() const { return proxy_
; }
149 void ReportLeakDetectionResult(const LeakDetectionResult
& result
);
153 void OnSetTestConfiguration(const ShellTestConfiguration
& params
);
154 void OnSessionHistory(
155 const std::vector
<int>& routing_ids
,
156 const std::vector
<std::vector
<PageState
> >& session_histories
,
157 const std::vector
<unsigned>& current_entry_indexes
);
160 void OnTryLeakDetection();
162 // After finishing the test, retrieves the audio, text, and pixel dumps from
163 // the TestRunner library and sends them to the browser process.
165 void CaptureDumpPixels(const SkBitmap
& snapshot
);
166 void CaptureDumpComplete();
168 test_runner::WebTestProxyBase
* proxy_
;
170 RenderView
* focused_view_
;
172 test_runner::TestPreferences prefs_
;
174 ShellTestConfiguration test_config_
;
176 std::vector
<int> routing_ids_
;
177 std::vector
<std::vector
<PageState
> > session_histories_
;
178 std::vector
<unsigned> current_entry_indexes_
;
180 bool is_main_window_
;
182 bool focus_on_next_commit_
;
184 scoped_ptr
<LeakDetector
> leak_detector_
;
185 bool needs_leak_detector_
;
187 DISALLOW_COPY_AND_ASSIGN(BlinkTestRunner
);
190 } // namespace content
192 #endif // CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_