Retrying previous changelist. I can't get this to fail
[chromium-blink-merge.git] / webkit / tools / test_shell / layout_test_controller.h
blob384be5433570e0015e49d46dfd922a4f2b381788
1 // Copyright (c) 2006-2008 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 /*
6 LayoutTestController class:
7 Bound to a JavaScript window.layoutTestController object using the
8 CppBoundClass::BindToJavascript(), this allows layout tests that are run in
9 the test_shell (or, in principle, any web page loaded into a client app built
10 with this class) to control various aspects of how the tests are run and what
11 sort of output they produce.
14 #ifndef WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H_
15 #define WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H_
17 #include <queue>
19 #include "base/timer.h"
20 #include "webkit/glue/cpp_bound_class.h"
22 class TestShell;
24 class LayoutTestController : public CppBoundClass {
25 public:
26 // Builds the property and method lists needed to bind this class to a JS
27 // object.
28 LayoutTestController(TestShell* shell);
30 // This function sets a flag that tells the test_shell to dump pages as
31 // plain text, rather than as a text representation of the renderer's state.
32 // It takes no arguments, and ignores any that may be present.
33 void dumpAsText(const CppArgumentList& args, CppVariant* result);
35 // This function sets a flag that tells the test_shell to print a line of
36 // descriptive test for each editing command. It takes no arguments, and
37 // ignores any that may be present.
38 void dumpEditingCallbacks(const CppArgumentList& args, CppVariant* result);
40 // This function sets a flag that tells the test_shell to print a line of
41 // descriptive test for each frame load callback. It takes no arguments, and
42 // ignores any that may be present.
43 void dumpFrameLoadCallbacks(const CppArgumentList& args, CppVariant* result);
45 // This function sets a flag that tells the test_shell to print out a text
46 // representation of the back/forward list. It ignores all args.
47 void dumpBackForwardList(const CppArgumentList& args, CppVariant* result);
49 // This function sets a flag that tells the test_shell to print out the
50 // scroll offsets of the child frames. It ignores all args.
51 void dumpChildFrameScrollPositions(const CppArgumentList& args, CppVariant* result);
53 // This function sets a flag that tells the test_shell to recursively
54 // dump all frames as plain text if the dumpAsText flag is set.
55 // It takes no arguments, and ignores any that may be present.
56 void dumpChildFramesAsText(const CppArgumentList& args, CppVariant* result);
58 // This function sets a flag that tells the test_shell to dump all calls
59 // to window.status().
60 // It takes no arguments, and ignores any that may be present.
61 void dumpWindowStatusChanges(const CppArgumentList& args, CppVariant* result);
63 // When called with a boolean argument, this sets a flag that controls
64 // whether content-editable elements accept editing focus when an editing
65 // attempt is made. It ignores any additional arguments.
66 void setAcceptsEditing(const CppArgumentList& args, CppVariant* result);
68 // Functions for dealing with windows. By default we block all new windows.
69 void windowCount(const CppArgumentList& args, CppVariant* result);
70 void setCanOpenWindows(const CppArgumentList& args, CppVariant* result);
71 void setCloseRemainingWindowsWhenComplete(const CppArgumentList& args, CppVariant* result);
73 // By default, tests end when page load is complete. These methods are used
74 // to delay the completion of the test until notifyDone is called.
75 void waitUntilDone(const CppArgumentList& args, CppVariant* result);
76 void notifyDone(const CppArgumentList& args, CppVariant* result);
78 // Methods for adding actions to the work queue. Used in conjunction with
79 // waitUntilDone/notifyDone above.
80 void queueBackNavigation(const CppArgumentList& args, CppVariant* result);
81 void queueForwardNavigation(const CppArgumentList& args, CppVariant* result);
82 void queueReload(const CppArgumentList& args, CppVariant* result);
83 void queueScript(const CppArgumentList& args, CppVariant* result);
84 void queueLoad(const CppArgumentList& args, CppVariant* result);
86 // Although this is named "objC" to match the Mac version, it actually tests
87 // the identity of its two arguments in C++.
88 void objCIdentityIsEqual(const CppArgumentList& args, CppVariant* result);
90 // Gives focus to the window.
91 void setWindowIsKey(const CppArgumentList& args, CppVariant* result);
93 // Method that controls whether pressing Tab key cycles through page elements
94 // or inserts a '\t' char in text area
95 void setTabKeyCyclesThroughElements(const CppArgumentList& args, CppVariant* result);
97 // Passes through to WebPreferences which allows the user to have a custom
98 // style sheet.
99 void setUserStyleSheetEnabled(const CppArgumentList& args, CppVariant* result);
100 void setUserStyleSheetLocation(const CppArgumentList& args, CppVariant* result);
102 // Puts Webkit in "dashboard compatibility mode", which is used in obscure
103 // Mac-only circumstances. It's not really necessary, and will most likely
104 // never be used by Chrome, but some layout tests depend on its presence.
105 void setUseDashboardCompatibilityMode(const CppArgumentList& args, CppVariant* result);
107 // Causes navigation actions just printout the intended navigation instead
108 // of taking you to the page. This is used for cases like mailto, where you
109 // don't actually want to open the mail program.
110 void setCustomPolicyDelegate(const CppArgumentList& args, CppVariant* result);
112 // Converts a URL starting with file:///tmp/ to the local mapping.
113 void pathToLocalResource(const CppArgumentList& args, CppVariant* result);
115 // Sets a bool such that when a drag is started, we fill the drag clipboard
116 // with a fake file object.
117 void addFileToPasteboardOnDrag(const CppArgumentList& args, CppVariant* result);
119 // Executes an internal command (superset of document.execCommand() commands).
120 void execCommand(const CppArgumentList& args, CppVariant* result);
122 // Checks if an internal command is currently available.
123 void isCommandEnabled(const CppArgumentList& args, CppVariant* result);
125 // Set the WebPreference that controls webkit's popup blocking.
126 void setPopupBlockingEnabled(const CppArgumentList& args, CppVariant* result);
128 // If true, causes provisional frame loads to be stopped for the remainder of
129 // the test.
130 void setStopProvisionalFrameLoads(const CppArgumentList& args,
131 CppVariant* result);
133 // Enable or disable smart insert/delete. This is enabled by default.
134 void setSmartInsertDeleteEnabled(const CppArgumentList& args,
135 CppVariant* result);
137 // Enable or disable trailing whitespace selection on double click.
138 void setSelectTrailingWhitespaceEnabled(const CppArgumentList& args,
139 CppVariant* result);
141 void pauseAnimationAtTimeOnElementWithId(const CppArgumentList& args,
142 CppVariant* result);
143 void pauseTransitionAtTimeOnElementWithId(const CppArgumentList& args,
144 CppVariant* result);
145 void elementDoesAutoCompleteForElementWithId(const CppArgumentList& args,
146 CppVariant* result);
147 void numberOfActiveAnimations(const CppArgumentList& args,
148 CppVariant* result);
150 // The following are only stubs. TODO(pamg): Implement any of these that
151 // are needed to pass the layout tests.
152 void dumpAsWebArchive(const CppArgumentList& args, CppVariant* result);
153 void dumpTitleChanges(const CppArgumentList& args, CppVariant* result);
154 void dumpResourceLoadCallbacks(const CppArgumentList& args, CppVariant* result);
155 void setMainFrameIsFirstResponder(const CppArgumentList& args, CppVariant* result);
156 void dumpSelectionRect(const CppArgumentList& args, CppVariant* result);
157 void display(const CppArgumentList& args, CppVariant* result);
158 void testRepaint(const CppArgumentList& args, CppVariant* result);
159 void repaintSweepHorizontally(const CppArgumentList& args, CppVariant* result);
160 void clearBackForwardList(const CppArgumentList& args, CppVariant* result);
161 void keepWebHistory(const CppArgumentList& args, CppVariant* result);
162 void storeWebScriptObject(const CppArgumentList& args, CppVariant* result);
163 void accessStoredWebScriptObject(const CppArgumentList& args, CppVariant* result);
164 void objCClassNameOf(const CppArgumentList& args, CppVariant* result);
165 void addDisallowedURL(const CppArgumentList& args, CppVariant* result);
166 void setCallCloseOnWebViews(const CppArgumentList& args, CppVariant* result);
167 void setPrivateBrowsingEnabled(const CppArgumentList& args, CppVariant* result);
169 // The fallback method is called when a nonexistent method is called on
170 // the layout test controller object.
171 // It is usefull to catch typos in the JavaScript code (a few layout tests
172 // do have typos in them) and it allows the script to continue running in
173 // that case (as the Mac does).
174 void fallbackMethod(const CppArgumentList& args, CppVariant* result);
176 public:
177 // The following methods are not exposed to JavaScript.
178 void SetWorkQueueFrozen(bool frozen) { work_queue_.set_frozen(frozen); }
180 bool ShouldDumpAsText() { return dump_as_text_; }
181 bool ShouldDumpEditingCallbacks() { return dump_editing_callbacks_; }
182 bool ShouldDumpFrameLoadCallbacks() { return dump_frame_load_callbacks_; }
183 void SetShouldDumpFrameLoadCallbacks(bool value) {
184 dump_frame_load_callbacks_ = value;
186 bool ShouldDumpResourceLoadCallbacks() {
187 return dump_resource_load_callbacks_;
189 bool ShouldDumpStatusCallbacks() {
190 return dump_window_status_changes_;
192 bool ShouldDumpBackForwardList() { return dump_back_forward_list_; }
193 bool ShouldDumpTitleChanges() { return dump_title_changes_; }
194 bool ShouldDumpChildFrameScrollPositions() {
195 return dump_child_frame_scroll_positions_;
197 bool ShouldDumpChildFramesAsText() {
198 return dump_child_frames_as_text_;
200 bool AcceptsEditing() { return accepts_editing_; }
201 bool CanOpenWindows() { return can_open_windows_; }
202 bool ShouldAddFileToPasteboard() { return should_add_file_to_pasteboard_; }
203 bool StopProvisionalFrameLoads() { return stop_provisional_frame_loads_; }
205 // Called by the webview delegate when the toplevel frame load is done.
206 void LocationChangeDone();
208 // Reinitializes all static values. The Reset() method should be called
209 // before the start of each test (currently from
210 // TestShell::RunFileTest).
211 void Reset();
213 // A single item in the work queue.
214 class WorkItem {
215 public:
216 virtual ~WorkItem() {}
217 virtual void Run(TestShell* shell) = 0;
220 // Used to clear the value of shell_ from test_shell_tests.
221 static void ClearShell() { shell_ = NULL; }
223 private:
224 friend class WorkItem;
226 // Helper class for managing events queued by methods like queueLoad or
227 // queueScript.
228 class WorkQueue {
229 public:
230 virtual ~WorkQueue();
231 void ProcessWorkSoon();
233 // Reset the state of the class between tests.
234 void Reset();
236 void AddWork(WorkItem* work);
238 void set_frozen(bool frozen) { frozen_ = frozen; }
239 bool empty() { return queue_.empty(); }
241 private:
242 void ProcessWork();
244 base::OneShotTimer<WorkQueue> timer_;
245 std::queue<WorkItem*> queue_;
246 bool frozen_;
249 // Non-owning pointer. The LayoutTestController is owned by the host.
250 static TestShell* shell_;
252 // If true, the test_shell will produce a plain text dump rather than a
253 // text representation of the renderer.
254 static bool dump_as_text_;
256 // If true, the test_shell will write a descriptive line for each editing
257 // command.
258 static bool dump_editing_callbacks_;
260 // If true, the test_shell will output a descriptive line for each frame
261 // load callback.
262 static bool dump_frame_load_callbacks_;
264 // If true, the test_shell will output a descriptive line for each resource
265 // load callback.
266 static bool dump_resource_load_callbacks_;
268 // If true, the test_shell will produce a dump of the back forward list as
269 // well.
270 static bool dump_back_forward_list_;
272 // If true, the test_shell will print out the child frame scroll offsets as
273 // well.
274 static bool dump_child_frame_scroll_positions_;
276 // If true and if dump_as_text_ is true, the test_shell will recursively
277 // dump all frames as plain text.
278 static bool dump_child_frames_as_text_;
280 // If true, the test_shell will dump all changes to window.status.
281 static bool dump_window_status_changes_;
283 // If true, output a message when the page title is changed.
284 static bool dump_title_changes_;
286 // If true, the element will be treated as editable. This value is returned
287 // from various editing callbacks that are called just before edit operations
288 // are allowed.
289 static bool accepts_editing_;
291 // If true, new windows can be opened via javascript or by plugins. By
292 // default, set to false and can be toggled to true using
293 // setCanOpenWindows().
294 static bool can_open_windows_;
296 // When reset is called, go through and close all but the main test shell
297 // window. By default, set to true but toggled to false using
298 // setCloseRemainingWindowsWhenComplete().
299 static bool close_remaining_windows_;
301 // If true and a drag starts, adds a file to the drag&drop clipboard.
302 static bool should_add_file_to_pasteboard_;
304 // If true, stops provisional frame loads during the
305 // DidStartProvisionalLoadForFrame callback.
306 static bool stop_provisional_frame_loads_;
308 // If true, don't dump output until notifyDone is called.
309 static bool wait_until_done_;
311 // To prevent infinite loops, only the first page of a test can add to a
312 // work queue (since we may well come back to that same page).
313 static bool work_queue_frozen_;
316 static WorkQueue work_queue_;
318 static CppVariant globalFlag_;
320 // Bound variable counting the number of top URLs visited.
321 static CppVariant webHistoryItemCount_;
324 #endif // WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H_