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/renderer/render_view_observer.h"
13 #include "content/public/renderer/render_view_observer_tracker.h"
14 #include "content/shell/shell_test_configuration.h"
15 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebPreferences.h"
16 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h"
17 #include "v8/include/v8.h"
23 class WebMediaPlayerClient
;
27 namespace WebTestRunner
{
28 class WebTestProxyBase
;
31 namespace webkit_glue
{
32 class TestMediaStreamClient
;
37 // This is the renderer side of the webkit test runner.
38 class WebKitTestRunner
: public RenderViewObserver
,
39 public RenderViewObserverTracker
<WebKitTestRunner
>,
40 public WebTestRunner::WebTestDelegate
{
42 explicit WebKitTestRunner(RenderView
* render_view
);
43 virtual ~WebKitTestRunner();
45 // RenderViewObserver implementation.
46 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
47 virtual void DidClearWindowObject(WebKit::WebFrame
* frame
) OVERRIDE
;
48 virtual void Navigate(const GURL
& url
) OVERRIDE
;
49 virtual void DidCommitProvisionalLoad(WebKit::WebFrame
* frame
,
50 bool is_new_navigation
) OVERRIDE
;
51 virtual void DidFailProvisionalLoad(
52 WebKit::WebFrame
* frame
, const WebKit::WebURLError
& error
) OVERRIDE
;
54 // WebTestDelegate implementation.
55 virtual void clearEditCommand();
56 virtual void setEditCommand(const std::string
& name
,
57 const std::string
& value
);
58 virtual void setGamepadData(const WebKit::WebGamepads
& gamepads
);
59 virtual void printMessage(const std::string
& message
);
60 virtual void postTask(::WebTestRunner::WebTask
* task
);
61 virtual void postDelayedTask(::WebTestRunner::WebTask
* task
,
63 virtual WebKit::WebString
registerIsolatedFileSystem(
64 const WebKit::WebVector
<WebKit::WebString
>& absolute_filenames
);
65 virtual long long getCurrentTimeInMillisecond();
66 virtual WebKit::WebString
getAbsoluteWebStringFromUTF8Path(
67 const std::string
& utf8_path
);
68 virtual WebKit::WebURL
localFileToDataURL(const WebKit::WebURL
& file_url
);
69 virtual WebKit::WebURL
rewriteLayoutTestsURL(const std::string
& utf8_url
);
70 virtual ::WebTestRunner::WebPreferences
* preferences();
71 virtual void applyPreferences();
72 virtual std::string
makeURLErrorDescription(const WebKit::WebURLError
& error
);
73 virtual void setClientWindowRect(const WebKit::WebRect
& rect
);
74 virtual void showDevTools();
75 virtual void closeDevTools();
76 virtual void evaluateInWebInspector(long call_id
, const std::string
& script
);
77 virtual void clearAllDatabases();
78 virtual void setDatabaseQuota(int quota
);
79 virtual void setDeviceScaleFactor(float factor
);
80 virtual void setFocus(WebTestRunner::WebTestProxyBase
* proxy
, bool focus
);
81 virtual void setAcceptAllCookies(bool accept
);
82 virtual std::string
pathToLocalResource(const std::string
& resource
);
83 virtual void setLocale(const std::string
& locale
);
84 virtual void testFinished();
85 virtual void testTimedOut();
86 virtual bool isBeingDebugged();
87 virtual int layoutTestTimeout();
88 virtual void closeRemainingWindows();
89 virtual int navigationEntryCount();
90 virtual void goToOffset(int offset
);
91 virtual void reload();
92 virtual void loadURLForFrame(const WebKit::WebURL
& url
,
93 const std::string
& frame_name
);
94 virtual bool allowExternalPages();
95 virtual void captureHistoryForWindow(
96 WebTestRunner::WebTestProxyBase
* proxy
,
97 WebKit::WebVector
<WebKit::WebHistoryItem
>* history
,
98 size_t* currentEntryIndex
);
99 virtual WebKit::WebMediaPlayer
* createWebMediaPlayer(
100 WebKit::WebFrame
* frame
,
101 const WebKit::WebURL
& url
,
102 WebKit::WebMediaPlayerClient
* client
);
106 void set_proxy(::WebTestRunner::WebTestProxyBase
* proxy
) { proxy_
= proxy
; }
107 ::WebTestRunner::WebTestProxyBase
* proxy() const { return proxy_
; }
111 void OnSetTestConfiguration(const ShellTestConfiguration
& params
);
112 void OnSessionHistory(
113 const std::vector
<int>& routing_ids
,
114 const std::vector
<std::vector
<std::string
> >& session_histories
,
115 const std::vector
<unsigned>& current_entry_indexes
);
119 // After finishing the test, retrieves the audio, text, and pixel dumps from
120 // the TestRunner library and sends them to the browser process.
123 ::WebTestRunner::WebTestProxyBase
* proxy_
;
125 RenderView
* focused_view_
;
127 ::WebTestRunner::WebPreferences prefs_
;
129 ShellTestConfiguration test_config_
;
131 std::vector
<int> routing_ids_
;
132 std::vector
<std::vector
<std::string
> > session_histories_
;
133 std::vector
<unsigned> current_entry_indexes_
;
135 bool is_main_window_
;
137 bool focus_on_next_commit_
;
139 scoped_ptr
<webkit_glue::TestMediaStreamClient
> test_media_stream_client_
;
141 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner
);
144 } // namespace content
146 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_