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