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_WEBKIT_TEST_RUNNER_H_
6 #define CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/public/common/page_state.h"
13 #include "content/public/renderer/render_view_observer.h"
14 #include "content/public/renderer/render_view_observer_tracker.h"
15 #include "content/shell/common/shell_test_configuration.h"
16 #include "content/shell/common/test_runner/test_preferences.h"
17 #include "content/shell/renderer/test_runner/web_test_delegate.h"
18 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
19 #include "v8/include/v8.h"
25 class WebBatteryStatus;
26 class WebDeviceMotionData;
27 class WebDeviceOrientationData;
34 class WebTestProxyBase;
35 struct LeakDetectionResult;
37 // This is the renderer side of the webkit test runner.
38 class WebKitTestRunner : public RenderViewObserver,
39 public RenderViewObserverTracker<WebKitTestRunner>,
40 public WebTestDelegate {
42 explicit WebKitTestRunner(RenderView* render_view);
43 ~WebKitTestRunner() override;
45 // RenderViewObserver implementation.
46 bool OnMessageReceived(const IPC::Message& message) override;
47 void DidClearWindowObject(blink::WebLocalFrame* frame) override;
48 void Navigate(const GURL& url) override;
49 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
50 bool is_new_navigation) override;
51 void DidFailProvisionalLoad(blink::WebLocalFrame* frame,
52 const blink::WebURLError& error) override;
54 // WebTestDelegate implementation.
55 void ClearEditCommand() override;
56 void SetEditCommand(const std::string& name,
57 const std::string& value) override;
58 void SetGamepadProvider(scoped_ptr<RendererGamepadProvider>) override;
59 void SetDeviceLightData(const double data) override;
60 void SetDeviceMotionData(const blink::WebDeviceMotionData& data) override;
61 void SetDeviceOrientationData(
62 const blink::WebDeviceOrientationData& data) override;
63 void SetScreenOrientation(
64 const blink::WebScreenOrientationType& orientation) override;
65 void ResetScreenOrientation() override;
66 void DidChangeBatteryStatus(const blink::WebBatteryStatus& status) override;
67 void PrintMessage(const std::string& message) override;
68 void PostTask(WebTask* task) override;
69 void PostDelayedTask(WebTask* task, long long ms) override;
70 blink::WebString RegisterIsolatedFileSystem(
71 const blink::WebVector<blink::WebString>& absolute_filenames) override;
72 long long GetCurrentTimeInMillisecond() override;
73 blink::WebString GetAbsoluteWebStringFromUTF8Path(
74 const std::string& utf8_path) override;
75 blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) override;
76 blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url) override;
77 TestPreferences* Preferences() override;
78 void ApplyPreferences() override;
79 virtual std::string makeURLErrorDescription(const blink::WebURLError& error);
80 void UseUnfortunateSynchronousResizeMode(bool enable) override;
81 void EnableAutoResizeMode(const blink::WebSize& min_size,
82 const blink::WebSize& max_size) override;
83 void DisableAutoResizeMode(const blink::WebSize& new_size) override;
84 void ClearDevToolsLocalStorage() override;
85 void ShowDevTools(const std::string& settings,
86 const std::string& frontend_url) override;
87 void CloseDevTools() override;
88 void EvaluateInWebInspector(long call_id, const std::string& script) override;
89 void ClearAllDatabases() override;
90 void SetDatabaseQuota(int quota) override;
91 blink::WebNotificationPresenter::Permission CheckWebNotificationPermission(
92 const GURL& origin) override;
93 void GrantWebNotificationPermission(const GURL& origin,
94 bool permission_granted) override;
95 void ClearWebNotificationPermissions() override;
96 void SimulateWebNotificationClick(const std::string& title) override;
97 void SetDeviceScaleFactor(float factor) override;
98 void SetDeviceColorProfile(const std::string& name) override;
99 void SetBluetoothMockDataSet(const std::string& name) override;
100 void SetFocus(WebTestProxyBase* proxy, bool focus) override;
101 void SetAcceptAllCookies(bool accept) override;
102 std::string PathToLocalResource(const std::string& resource) override;
103 void SetLocale(const std::string& locale) override;
104 void TestFinished() override;
105 void CloseRemainingWindows() override;
106 void DeleteAllCookies() override;
107 int NavigationEntryCount() override;
108 void GoToOffset(int offset) override;
109 void Reload() override;
110 void LoadURLForFrame(const blink::WebURL& url,
111 const std::string& frame_name) override;
112 bool AllowExternalPages() override;
113 std::string DumpHistoryForWindow(WebTestProxyBase* proxy) override;
117 void set_proxy(WebTestProxyBase* proxy) { proxy_ = proxy; }
118 WebTestProxyBase* proxy() const { return proxy_; }
120 void ReportLeakDetectionResult(const LeakDetectionResult& result);
124 void OnSetTestConfiguration(const ShellTestConfiguration& params);
125 void OnSessionHistory(
126 const std::vector<int>& routing_ids,
127 const std::vector<std::vector<PageState> >& session_histories,
128 const std::vector<unsigned>& current_entry_indexes);
131 void OnTryLeakDetection();
133 // After finishing the test, retrieves the audio, text, and pixel dumps from
134 // the TestRunner library and sends them to the browser process.
136 void CaptureDumpPixels(const SkBitmap& snapshot);
137 void CaptureDumpComplete();
139 WebTestProxyBase* proxy_;
141 RenderView* focused_view_;
143 TestPreferences prefs_;
145 ShellTestConfiguration test_config_;
147 std::vector<int> routing_ids_;
148 std::vector<std::vector<PageState> > session_histories_;
149 std::vector<unsigned> current_entry_indexes_;
151 bool is_main_window_;
153 bool focus_on_next_commit_;
155 scoped_ptr<LeakDetector> leak_detector_;
156 bool needs_leak_detector_;
158 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
161 } // namespace content
163 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_