webkit_test_runner.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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.
4
5#ifndef CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
6#define CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
7
8#include <vector>
9
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/WebTestDelegate.h"
18#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
19#include "v8/include/v8.h"
20
21class SkBitmap;
22class SkCanvas;
23
24namespace blink {
25class WebBatteryStatus;
26class WebDeviceMotionData;
27class WebDeviceOrientationData;
28struct WebRect;
29}
30
31namespace content {
32
33class LeakDetector;
34class WebTestProxyBase;
35struct LeakDetectionResult;
36
37// This is the renderer side of the webkit test runner.
38class WebKitTestRunner : public RenderViewObserver,
39                         public RenderViewObserverTracker<WebKitTestRunner>,
40                         public WebTestDelegate {
41 public:
42  explicit WebKitTestRunner(RenderView* render_view);
43  virtual ~WebKitTestRunner();
44
45  // RenderViewObserver implementation.
46  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
47  virtual void DidClearWindowObject(blink::WebLocalFrame* frame) OVERRIDE;
48  virtual void Navigate(const GURL& url) OVERRIDE;
49  virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
50                                        bool is_new_navigation) OVERRIDE;
51  virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame,
52                                      const blink::WebURLError& error) OVERRIDE;
53
54  // WebTestDelegate implementation.
55  virtual void clearEditCommand() OVERRIDE;
56  virtual void setEditCommand(const std::string& name,
57                              const std::string& value) OVERRIDE;
58  virtual void setGamepadData(const blink::WebGamepads& gamepads) OVERRIDE;
59  virtual void didConnectGamepad(int index,
60                                const blink::WebGamepad& gamepad) OVERRIDE;
61  virtual void didDisconnectGamepad(int index,
62                                   const blink::WebGamepad& gamepad) OVERRIDE;
63  virtual void setDeviceMotionData(
64      const blink::WebDeviceMotionData& data) OVERRIDE;
65  virtual void setDeviceOrientationData(
66      const blink::WebDeviceOrientationData& data) OVERRIDE;
67  virtual void setScreenOrientation(
68      const blink::WebScreenOrientationType& orientation) OVERRIDE;
69  virtual void resetScreenOrientation() OVERRIDE;
70  virtual void didChangeBatteryStatus(
71      const blink::WebBatteryStatus& status) OVERRIDE;
72  virtual void printMessage(const std::string& message) OVERRIDE;
73  virtual void postTask(WebTask* task) OVERRIDE;
74  virtual void postDelayedTask(WebTask* task, long long ms) OVERRIDE;
75  virtual blink::WebString registerIsolatedFileSystem(
76      const blink::WebVector<blink::WebString>& absolute_filenames) OVERRIDE;
77  virtual long long getCurrentTimeInMillisecond() OVERRIDE;
78  virtual blink::WebString getAbsoluteWebStringFromUTF8Path(
79      const std::string& utf8_path) OVERRIDE;
80  virtual blink::WebURL localFileToDataURL(
81      const blink::WebURL& file_url) OVERRIDE;
82  virtual blink::WebURL rewriteLayoutTestsURL(
83      const std::string& utf8_url) OVERRIDE;
84  virtual TestPreferences* preferences() OVERRIDE;
85  virtual void applyPreferences() OVERRIDE;
86  virtual std::string makeURLErrorDescription(const blink::WebURLError& error);
87  virtual void useUnfortunateSynchronousResizeMode(bool enable) OVERRIDE;
88  virtual void enableAutoResizeMode(const blink::WebSize& min_size,
89                                    const blink::WebSize& max_size) OVERRIDE;
90  virtual void disableAutoResizeMode(const blink::WebSize& new_size) OVERRIDE;
91  virtual void clearDevToolsLocalStorage() OVERRIDE;
92  virtual void showDevTools(const std::string& settings,
93                            const std::string& frontend_url) OVERRIDE;
94  virtual void closeDevTools() OVERRIDE;
95  virtual void evaluateInWebInspector(long call_id,
96                                      const std::string& script) OVERRIDE;
97  virtual void clearAllDatabases() OVERRIDE;
98  virtual void setDatabaseQuota(int quota) OVERRIDE;
99  virtual void setDeviceScaleFactor(float factor) OVERRIDE;
100  virtual void setDeviceColorProfile(const std::string& name) OVERRIDE;
101  virtual void setFocus(WebTestProxyBase* proxy, bool focus) OVERRIDE;
102  virtual void setAcceptAllCookies(bool accept) OVERRIDE;
103  virtual std::string pathToLocalResource(const std::string& resource) OVERRIDE;
104  virtual void setLocale(const std::string& locale) OVERRIDE;
105  virtual void testFinished() OVERRIDE;
106  virtual void closeRemainingWindows() OVERRIDE;
107  virtual void deleteAllCookies() OVERRIDE;
108  virtual int navigationEntryCount() OVERRIDE;
109  virtual void goToOffset(int offset) OVERRIDE;
110  virtual void reload() OVERRIDE;
111  virtual void loadURLForFrame(const blink::WebURL& url,
112                               const std::string& frame_name) OVERRIDE;
113  virtual bool allowExternalPages() OVERRIDE;
114  virtual std::string dumpHistoryForWindow(WebTestProxyBase* proxy) OVERRIDE;
115
116  void Reset();
117
118  void set_proxy(WebTestProxyBase* proxy) { proxy_ = proxy; }
119  WebTestProxyBase* proxy() const { return proxy_; }
120
121  void ReportLeakDetectionResult(const LeakDetectionResult& result);
122
123 private:
124  // Message handlers.
125  void OnSetTestConfiguration(const ShellTestConfiguration& params);
126  void OnSessionHistory(
127      const std::vector<int>& routing_ids,
128      const std::vector<std::vector<PageState> >& session_histories,
129      const std::vector<unsigned>& current_entry_indexes);
130  void OnReset();
131  void OnNotifyDone();
132  void OnTryLeakDetection();
133
134  // After finishing the test, retrieves the audio, text, and pixel dumps from
135  // the TestRunner library and sends them to the browser process.
136  void CaptureDump();
137  void CaptureDumpPixels(const SkBitmap& snapshot);
138  void CaptureDumpComplete();
139
140  WebTestProxyBase* proxy_;
141
142  RenderView* focused_view_;
143
144  TestPreferences prefs_;
145
146  ShellTestConfiguration test_config_;
147
148  std::vector<int> routing_ids_;
149  std::vector<std::vector<PageState> > session_histories_;
150  std::vector<unsigned> current_entry_indexes_;
151
152  bool is_main_window_;
153
154  bool focus_on_next_commit_;
155
156  scoped_ptr<LeakDetector> leak_detector_;
157  bool needs_leak_detector_;
158
159  DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
160};
161
162}  // namespace content
163
164#endif  // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
165