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
) override
;
95 void SetDeviceScaleFactor(float factor
) override
;
96 void SetDeviceColorProfile(const std::string
& name
) override
;
97 void SetBluetoothMockDataSet(const std::string
& name
) override
;
98 void SetGeofencingMockProvider(bool service_available
) override
;
99 void ClearGeofencingMockProvider() override
;
100 void SetGeofencingMockPosition(double latitude
, double longitude
) override
;
101 void SetFocus(test_runner::WebTestProxyBase
* proxy
, bool focus
) override
;
102 void SetAcceptAllCookies(bool accept
) override
;
103 std::string
PathToLocalResource(const std::string
& resource
) override
;
104 void SetLocale(const std::string
& locale
) override
;
105 void TestFinished() override
;
106 void CloseRemainingWindows() override
;
107 void DeleteAllCookies() override
;
108 int NavigationEntryCount() override
;
109 void GoToOffset(int offset
) override
;
110 void Reload() override
;
111 void LoadURLForFrame(const blink::WebURL
& url
,
112 const std::string
& frame_name
) override
;
113 bool AllowExternalPages() override
;
114 std::string
DumpHistoryForWindow(
115 test_runner::WebTestProxyBase
* proxy
) override
;
117 blink::WebView
* view
,
119 const base::Callback
<void(const blink::WebURLResponse
& response
,
120 const std::string
& data
)>& callback
) override
;
121 void SetPermission(const std::string
& name
,
122 const std::string
& value
,
124 const GURL
& embedding_origin
) override
;
125 void ResetPermissions() override
;
126 scoped_refptr
<cc::TextureLayer
> CreateTextureLayerForMailbox(
127 cc::TextureLayerClient
* client
) override
;
128 blink::WebLayer
* InstantiateWebLayer(
129 scoped_refptr
<cc::TextureLayer
> layer
) override
;
130 cc::SharedBitmapManager
* GetSharedBitmapManager() override
;
131 void DispatchBeforeInstallPromptEvent(
133 const std::vector
<std::string
>& event_platforms
,
134 const base::Callback
<void(bool)>& callback
) override
;
135 void ResolveBeforeInstallPromptPromise(
137 const std::string
& platform
) override
;
138 blink::WebPlugin
* CreatePluginPlaceholder(
139 blink::WebLocalFrame
* frame
,
140 const blink::WebPluginParams
& params
) override
;
144 void set_proxy(test_runner::WebTestProxyBase
* proxy
) { proxy_
= proxy
; }
145 test_runner::WebTestProxyBase
* proxy() const { return proxy_
; }
147 void ReportLeakDetectionResult(const LeakDetectionResult
& result
);
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
);
158 void OnTryLeakDetection();
160 // After finishing the test, retrieves the audio, text, and pixel dumps from
161 // the TestRunner library and sends them to the browser process.
163 void CaptureDumpPixels(const SkBitmap
& snapshot
);
164 void CaptureDumpComplete();
166 test_runner::WebTestProxyBase
* proxy_
;
168 RenderView
* focused_view_
;
170 test_runner::TestPreferences prefs_
;
172 ShellTestConfiguration test_config_
;
174 std::vector
<int> routing_ids_
;
175 std::vector
<std::vector
<PageState
> > session_histories_
;
176 std::vector
<unsigned> current_entry_indexes_
;
178 bool is_main_window_
;
180 bool focus_on_next_commit_
;
182 scoped_ptr
<LeakDetector
> leak_detector_
;
183 bool needs_leak_detector_
;
185 DISALLOW_COPY_AND_ASSIGN(BlinkTestRunner
);
188 } // namespace content
190 #endif // CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_