webkit_test_runner.h revision 010d83a9304c5a91596085d917d248abff47903a
10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Copyright (c) 2012 The Chromium Authors. All rights reserved.
20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Use of this source code is governed by a BSD-style license that can be
30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// found in the LICENSE file.
40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "base/files/file_path.h"
110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "base/memory/scoped_ptr.h"
120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/public/common/page_state.h"
130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/public/renderer/render_view_observer.h"
140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/public/renderer/render_view_observer_tracker.h"
150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/shell/common/shell_test_configuration.h"
160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/shell/common/test_runner/test_preferences.h"
170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "content/shell/renderer/test_runner/WebTestDelegate.h"
180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "v8/include/v8.h"
200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass SkBitmap;
220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass SkCanvas;
230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace blink {
250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebDeviceMotionData;
260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebDeviceOrientationData;
270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgstruct WebRect;
280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace content {
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
32cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.orgclass LeakDetector;
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebTestProxyBase;
342a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.orgstruct LeakDetectionResult;
350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// This is the renderer side of the webkit test runner.
370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebKitTestRunner : public RenderViewObserver,
380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                         public RenderViewObserverTracker<WebKitTestRunner>,
390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                         public WebTestDelegate {
400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  explicit WebKitTestRunner(RenderView* render_view);
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual ~WebKitTestRunner();
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // RenderViewObserver implementation.
450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void DidClearWindowObject(blink::WebLocalFrame* frame,
470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                    int world_id) OVERRIDE;
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void Navigate(const GURL& url) OVERRIDE;
492a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                        bool is_new_navigation) OVERRIDE;
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame,
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                      const blink::WebURLError& error) OVERRIDE;
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // WebTestDelegate implementation.
55e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  virtual void clearEditCommand() OVERRIDE;
56e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  virtual void setEditCommand(const std::string& name,
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              const std::string& value) OVERRIDE;
58e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  virtual void setGamepadData(const blink::WebGamepads& gamepads) OVERRIDE;
59e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  virtual void didConnectGamepad(int index,
600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                const blink::WebGamepad& gamepad) OVERRIDE;
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void didDisconnectGamepad(int index,
620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                   const blink::WebGamepad& gamepad) OVERRIDE;
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setDeviceMotionData(
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const blink::WebDeviceMotionData& data) OVERRIDE;
650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setDeviceOrientationData(
660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const blink::WebDeviceOrientationData& data) OVERRIDE;
670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setScreenOrientation(
682a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org      const blink::WebScreenOrientationType& orientation) OVERRIDE;
690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void printMessage(const std::string& message) OVERRIDE;
700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void postTask(WebTask* task) OVERRIDE;
712a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void postDelayedTask(WebTask* task, long long ms) OVERRIDE;
722a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual blink::WebString registerIsolatedFileSystem(
73391247d05a663265807c400947ab6eb01ae3d690mallinath@webrtc.org      const blink::WebVector<blink::WebString>& absolute_filenames) OVERRIDE;
742a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual long long getCurrentTimeInMillisecond() OVERRIDE;
752a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual blink::WebString getAbsoluteWebStringFromUTF8Path(
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const std::string& utf8_path) OVERRIDE;
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual blink::WebURL localFileToDataURL(
780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const blink::WebURL& file_url) OVERRIDE;
790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual blink::WebURL rewriteLayoutTestsURL(
800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const std::string& utf8_url) OVERRIDE;
812a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual TestPreferences* preferences() OVERRIDE;
820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void applyPreferences() OVERRIDE;
832a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual std::string makeURLErrorDescription(const blink::WebURLError& error);
840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void useUnfortunateSynchronousResizeMode(bool enable) OVERRIDE;
850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void enableAutoResizeMode(const blink::WebSize& min_size,
860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                    const blink::WebSize& max_size) OVERRIDE;
870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void disableAutoResizeMode(const blink::WebSize& new_size) OVERRIDE;
880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void clearDevToolsLocalStorage() OVERRIDE;
890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void showDevTools(const std::string& settings,
900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                            const std::string& frontend_url) OVERRIDE;
912a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void closeDevTools() OVERRIDE;
920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void evaluateInWebInspector(long call_id,
930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                      const std::string& script) OVERRIDE;
940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void clearAllDatabases() OVERRIDE;
950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setDatabaseQuota(int quota) OVERRIDE;
960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setDeviceScaleFactor(float factor) OVERRIDE;
970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setDeviceColorProfile(const std::string& name) OVERRIDE;
980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setFocus(WebTestProxyBase* proxy, bool focus) OVERRIDE;
990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setAcceptAllCookies(bool accept) OVERRIDE;
1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual std::string pathToLocalResource(const std::string& resource) OVERRIDE;
1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void setLocale(const std::string& locale) OVERRIDE;
1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void testFinished() OVERRIDE;
1030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void closeRemainingWindows() OVERRIDE;
1040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void deleteAllCookies() OVERRIDE;
105  virtual int navigationEntryCount() OVERRIDE;
106  virtual void goToOffset(int offset) OVERRIDE;
107  virtual void reload() OVERRIDE;
108  virtual void loadURLForFrame(const blink::WebURL& url,
109                               const std::string& frame_name) OVERRIDE;
110  virtual bool allowExternalPages() OVERRIDE;
111  virtual std::string dumpHistoryForWindow(WebTestProxyBase* proxy) OVERRIDE;
112
113  void Reset();
114
115  void set_proxy(WebTestProxyBase* proxy) { proxy_ = proxy; }
116  WebTestProxyBase* proxy() const { return proxy_; }
117
118  void ReportLeakDetectionResult(const LeakDetectionResult& result);
119
120 private:
121  // Message handlers.
122  void OnSetTestConfiguration(const ShellTestConfiguration& params);
123  void OnSessionHistory(
124      const std::vector<int>& routing_ids,
125      const std::vector<std::vector<PageState> >& session_histories,
126      const std::vector<unsigned>& current_entry_indexes);
127  void OnReset();
128  void OnNotifyDone();
129  void OnTryLeakDetection();
130
131  // After finishing the test, retrieves the audio, text, and pixel dumps from
132  // the TestRunner library and sends them to the browser process.
133  void CaptureDump();
134  void CaptureDumpPixels(const SkBitmap& snapshot);
135  void CaptureDumpComplete();
136
137  WebTestProxyBase* proxy_;
138
139  RenderView* focused_view_;
140
141  TestPreferences prefs_;
142
143  ShellTestConfiguration test_config_;
144
145  std::vector<int> routing_ids_;
146  std::vector<std::vector<PageState> > session_histories_;
147  std::vector<unsigned> current_entry_indexes_;
148
149  bool is_main_window_;
150
151  bool focus_on_next_commit_;
152
153  scoped_ptr<LeakDetector> leak_detector_;
154  bool needs_leak_detector_;
155
156  DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
157};
158
159}  // namespace content
160
161#endif  // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
162