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/WebPreferences.h"
17 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
18 #include "v8/include/v8.h"
23 class WebDeviceMotionData;
24 class WebDeviceOrientationData;
28 namespace WebTestRunner {
29 class WebTestProxyBase;
36 // This is the renderer side of the webkit test runner.
37 class WebKitTestRunner : public RenderViewObserver,
38 public RenderViewObserverTracker<WebKitTestRunner>,
39 public WebTestRunner::WebTestDelegate {
41 explicit WebKitTestRunner(RenderView* render_view);
42 virtual ~WebKitTestRunner();
44 // RenderViewObserver implementation.
45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
46 virtual void DidClearWindowObject(blink::WebFrame* frame,
47 int world_id) OVERRIDE;
48 virtual void Navigate(const GURL& url) OVERRIDE;
49 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame,
50 bool is_new_navigation) OVERRIDE;
51 virtual void DidFailProvisionalLoad(
52 blink::WebFrame* frame, const blink::WebURLError& error) OVERRIDE;
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 setDeviceMotionData(
60 const blink::WebDeviceMotionData& data) OVERRIDE;
61 virtual void setDeviceOrientationData(
62 const blink::WebDeviceOrientationData& data) OVERRIDE;
63 virtual void printMessage(const std::string& message) OVERRIDE;
64 virtual void postTask(::WebTestRunner::WebTask* task) OVERRIDE;
65 virtual void postDelayedTask(::WebTestRunner::WebTask* task,
66 long long ms) OVERRIDE;
67 virtual blink::WebString registerIsolatedFileSystem(
68 const blink::WebVector<blink::WebString>& absolute_filenames) OVERRIDE;
69 virtual long long getCurrentTimeInMillisecond() OVERRIDE;
70 virtual blink::WebString getAbsoluteWebStringFromUTF8Path(
71 const std::string& utf8_path) OVERRIDE;
72 virtual blink::WebURL localFileToDataURL(
73 const blink::WebURL& file_url) OVERRIDE;
74 virtual blink::WebURL rewriteLayoutTestsURL(
75 const std::string& utf8_url) OVERRIDE;
76 virtual ::WebTestRunner::WebPreferences* preferences() OVERRIDE;
77 virtual void applyPreferences() OVERRIDE;
78 virtual std::string makeURLErrorDescription(const blink::WebURLError& error);
79 virtual void useUnfortunateSynchronousResizeMode(bool enable) OVERRIDE;
80 virtual void enableAutoResizeMode(const blink::WebSize& min_size,
81 const blink::WebSize& max_size) OVERRIDE;
82 virtual void disableAutoResizeMode(const blink::WebSize& new_size) OVERRIDE;
83 virtual void clearDevToolsLocalStorage() OVERRIDE;
84 virtual void showDevTools(const std::string& settings) OVERRIDE;
85 virtual void closeDevTools() OVERRIDE;
86 virtual void evaluateInWebInspector(long call_id,
87 const std::string& script) OVERRIDE;
88 virtual void clearAllDatabases() OVERRIDE;
89 virtual void setDatabaseQuota(int quota) OVERRIDE;
90 virtual void setDeviceScaleFactor(float factor) OVERRIDE;
91 virtual void setFocus(WebTestRunner::WebTestProxyBase* proxy,
93 virtual void setAcceptAllCookies(bool accept) OVERRIDE;
94 virtual std::string pathToLocalResource(const std::string& resource) OVERRIDE;
95 virtual void setLocale(const std::string& locale) OVERRIDE;
96 virtual void testFinished() OVERRIDE;
97 virtual void closeRemainingWindows() OVERRIDE;
98 virtual void deleteAllCookies() OVERRIDE;
99 virtual int navigationEntryCount() OVERRIDE;
100 virtual void goToOffset(int offset) OVERRIDE;
101 virtual void reload() OVERRIDE;
102 virtual void loadURLForFrame(const blink::WebURL& url,
103 const std::string& frame_name) OVERRIDE;
104 virtual bool allowExternalPages() OVERRIDE;
105 virtual void captureHistoryForWindow(
106 WebTestRunner::WebTestProxyBase* proxy,
107 blink::WebVector<blink::WebHistoryItem>* history,
108 size_t* currentEntryIndex) OVERRIDE;
112 void set_proxy(::WebTestRunner::WebTestProxyBase* proxy) { proxy_ = proxy; }
113 ::WebTestRunner::WebTestProxyBase* proxy() const { return proxy_; }
117 void OnSetTestConfiguration(const ShellTestConfiguration& params);
118 void OnSessionHistory(
119 const std::vector<int>& routing_ids,
120 const std::vector<std::vector<PageState> >& session_histories,
121 const std::vector<unsigned>& current_entry_indexes);
124 void OnTryLeakDetection();
126 // After finishing the test, retrieves the audio, text, and pixel dumps from
127 // the TestRunner library and sends them to the browser process.
130 void TryLeakDetection();
132 ::WebTestRunner::WebTestProxyBase* proxy_;
134 RenderView* focused_view_;
136 ::WebTestRunner::WebPreferences prefs_;
138 ShellTestConfiguration test_config_;
140 std::vector<int> routing_ids_;
141 std::vector<std::vector<PageState> > session_histories_;
142 std::vector<unsigned> current_entry_indexes_;
144 bool is_main_window_;
146 bool focus_on_next_commit_;
148 scoped_ptr<LeakDetector> leak_detector_;
149 bool needs_leak_detector_;
151 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
154 } // namespace content
156 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_