webkit_test_runner.h revision 010d83a9304c5a91596085d917d248abff47903a
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 WebDeviceMotionData; 26class WebDeviceOrientationData; 27struct WebRect; 28} 29 30namespace content { 31 32class LeakDetector; 33class WebTestProxyBase; 34struct LeakDetectionResult; 35 36// This is the renderer side of the webkit test runner. 37class WebKitTestRunner : public RenderViewObserver, 38 public RenderViewObserverTracker<WebKitTestRunner>, 39 public WebTestDelegate { 40 public: 41 explicit WebKitTestRunner(RenderView* render_view); 42 virtual ~WebKitTestRunner(); 43 44 // RenderViewObserver implementation. 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 46 virtual void DidClearWindowObject(blink::WebLocalFrame* frame, 47 int world_id) 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 printMessage(const std::string& message) OVERRIDE; 70 virtual void postTask(WebTask* task) OVERRIDE; 71 virtual void postDelayedTask(WebTask* task, long long ms) OVERRIDE; 72 virtual blink::WebString registerIsolatedFileSystem( 73 const blink::WebVector<blink::WebString>& absolute_filenames) OVERRIDE; 74 virtual long long getCurrentTimeInMillisecond() OVERRIDE; 75 virtual blink::WebString getAbsoluteWebStringFromUTF8Path( 76 const std::string& utf8_path) OVERRIDE; 77 virtual blink::WebURL localFileToDataURL( 78 const blink::WebURL& file_url) OVERRIDE; 79 virtual blink::WebURL rewriteLayoutTestsURL( 80 const std::string& utf8_url) OVERRIDE; 81 virtual TestPreferences* preferences() OVERRIDE; 82 virtual void applyPreferences() OVERRIDE; 83 virtual std::string makeURLErrorDescription(const blink::WebURLError& error); 84 virtual void useUnfortunateSynchronousResizeMode(bool enable) OVERRIDE; 85 virtual void enableAutoResizeMode(const blink::WebSize& min_size, 86 const blink::WebSize& max_size) OVERRIDE; 87 virtual void disableAutoResizeMode(const blink::WebSize& new_size) OVERRIDE; 88 virtual void clearDevToolsLocalStorage() OVERRIDE; 89 virtual void showDevTools(const std::string& settings, 90 const std::string& frontend_url) OVERRIDE; 91 virtual void closeDevTools() OVERRIDE; 92 virtual void evaluateInWebInspector(long call_id, 93 const std::string& script) OVERRIDE; 94 virtual void clearAllDatabases() OVERRIDE; 95 virtual void setDatabaseQuota(int quota) OVERRIDE; 96 virtual void setDeviceScaleFactor(float factor) OVERRIDE; 97 virtual void setDeviceColorProfile(const std::string& name) OVERRIDE; 98 virtual void setFocus(WebTestProxyBase* proxy, bool focus) OVERRIDE; 99 virtual void setAcceptAllCookies(bool accept) OVERRIDE; 100 virtual std::string pathToLocalResource(const std::string& resource) OVERRIDE; 101 virtual void setLocale(const std::string& locale) OVERRIDE; 102 virtual void testFinished() OVERRIDE; 103 virtual void closeRemainingWindows() OVERRIDE; 104 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