1 // Copyright 2013 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 CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_
6 #define CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/automation/automation_event_observers.h"
16 #include "chrome/browser/automation/automation_event_queue.h"
17 #include "chrome/browser/automation/automation_provider.h"
18 #include "chrome/browser/automation/automation_provider_json.h"
19 #include "chrome/browser/history/history_service.h"
20 #include "chrome/browser/ui/browser_list_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/common/page_type.h"
23 #include "content/public/common/security_style.h"
24 #include "net/cert/cert_status_flags.h"
25 #include "third_party/WebKit/public/web/WebInputEvent.h"
27 #if defined(OS_CHROMEOS)
28 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
29 #include "chromeos/dbus/power_manager_client.h"
35 class DictionaryValue;
40 struct NativeWebKeyboardEvent;
48 // This is an automation provider containing testing calls.
49 class TestingAutomationProvider : public AutomationProvider,
50 public chrome::BrowserListObserver,
51 #if defined(OS_CHROMEOS)
52 public chromeos::PowerManagerClient::Observer,
54 public content::NotificationObserver {
56 explicit TestingAutomationProvider(Profile* profile);
58 virtual IPC::Channel::Mode GetChannelMode(bool use_named_interface);
61 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
62 virtual void OnChannelError() OVERRIDE;
65 virtual ~TestingAutomationProvider();
67 // chrome::BrowserListObserver:
68 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
69 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
71 // content::NotificationObserver:
72 virtual void Observe(int type,
73 const content::NotificationSource& source,
74 const content::NotificationDetails& details) OVERRIDE;
76 #if defined(OS_CHROMEOS)
77 // chromeos::PowerManagerClient::Observer:
78 virtual void PowerChanged(const power_manager::PowerSupplyProperties& proto);
81 // IPC Message callbacks.
82 void CloseBrowser(int handle, IPC::Message* reply_message);
83 void ActivateTab(int handle, int at_index, int* status);
84 void AppendTab(int handle, const GURL& url, IPC::Message* reply_message);
85 void GetMachPortCount(int* port_count);
86 void GetActiveTabIndex(int handle, int* active_tab_index);
87 void CloseTab(int tab_handle, bool wait_until_closed,
88 IPC::Message* reply_message);
89 void GetCookies(const GURL& url, int handle, int* value_size,
91 void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url,
92 int number_of_navigations,
93 IPC::Message* reply_message);
94 void NavigationAsync(int handle, const GURL& url, bool* status);
95 void Reload(int handle, IPC::Message* reply_message);
96 void GetRedirectsFrom(int tab_handle,
97 const GURL& source_url,
98 IPC::Message* reply_message);
99 void GetBrowserWindowCount(int* window_count);
100 void GetNormalBrowserWindowCount(int* window_count);
101 // Be aware that the browser window returned might be of non TYPE_TABBED
102 // or in incognito mode.
103 void GetBrowserWindow(int index, int* handle);
104 void ExecuteBrowserCommandAsync(int handle, int command, bool* success);
105 void ExecuteBrowserCommand(int handle, int command,
106 IPC::Message* reply_message);
107 void TerminateSession(int handle, bool* success);
108 void WindowGetViewBounds(int handle, int view_id, bool screen_coordinates,
109 bool* success, gfx::Rect* bounds);
110 void SetWindowBounds(int handle, const gfx::Rect& bounds, bool* result);
111 void SetWindowVisible(int handle, bool visible, bool* result);
112 void GetTabCount(int handle, int* tab_count);
113 void GetType(int handle, int* type_as_int);
114 void GetTab(int win_handle, int tab_index, int* tab_handle);
115 void GetTabTitle(int handle, int* title_string_size, std::wstring* title);
116 void GetTabIndex(int handle, int* tabstrip_index);
117 void GetTabURL(int handle, bool* success, GURL* url);
118 void ExecuteJavascript(int handle,
119 const std::wstring& frame_xpath,
120 const std::wstring& script,
121 IPC::Message* reply_message);
123 // If |show| is true, call Show() on the new window after creating it.
124 void OpenNewBrowserWindowOfType(int type,
126 IPC::Message* reply_message);
128 // Retrieves a Browser from a Window and vice-versa.
129 void GetWindowForBrowser(int window_handle, bool* success, int* handle);
131 // Gets the duration in ms of the last event matching |event_name|.
132 // |duration_ms| is -1 if the event hasn't occurred yet.
133 void GetMetricEventDuration(const std::string& event_name, int* duration_ms);
135 // Brings the browser window to the front and activates it.
136 void BringBrowserToFront(int browser_handle, bool* success);
138 // Responds to requests to open the FindInPage window.
139 void HandleOpenFindInPageRequest(const IPC::Message& message,
142 // Get the visibility state of the Find window.
143 void GetFindWindowVisibility(int handle, bool* visible);
145 // Wait for the bookmark model to load.
146 void WaitForBookmarkModelToLoad(int handle, IPC::Message* reply_message);
148 // Set |loaded| to true if the bookmark model has loaded, else false.
149 void BookmarkModelHasLoaded(int handle, bool* loaded);
151 // Get the visibility state of the Bookmark bar.
152 // Returns a status dictionary over the JSON interface.
153 void GetBookmarkBarStatus(base::DictionaryValue* args,
154 IPC::Message* reply_message);
156 // Get the bookmarks as a JSON string.
157 void GetBookmarksAsJSON(base::DictionaryValue* args,
158 IPC::Message* reply_message);
160 // Editing, modification, and removal of bookmarks through the JSON interface.
161 // Bookmarks are referenced by id.
162 void WaitForBookmarkModelToLoadJSON(base::DictionaryValue* args,
163 IPC::Message* reply_message);
164 void AddBookmark(base::DictionaryValue* args,
165 IPC::Message* reply_message);
166 void ReparentBookmark(base::DictionaryValue* args,
167 IPC::Message* reply_message);
168 void SetBookmarkTitle(base::DictionaryValue* args,
169 IPC::Message* reply_message);
170 void SetBookmarkURL(base::DictionaryValue* args,
171 IPC::Message* reply_message);
172 void RemoveBookmark(base::DictionaryValue* args,
173 IPC::Message* reply_message);
175 void WaitForBrowserWindowCountToBecome(int target_count,
176 IPC::Message* reply_message);
178 void GoBackBlockUntilNavigationsComplete(int handle,
179 int number_of_navigations,
180 IPC::Message* reply_message);
182 void GoForwardBlockUntilNavigationsComplete(int handle,
183 int number_of_navigations,
184 IPC::Message* reply_message);
186 // Generic pattern for pyautolib
187 // Uses the JSON interface for input/output.
188 void SendJSONRequestWithBrowserHandle(int handle,
189 const std::string& json_request,
190 IPC::Message* reply_message);
191 void SendJSONRequestWithBrowserIndex(int index,
192 const std::string& json_request,
193 IPC::Message* reply_message);
194 void SendJSONRequest(Browser* browser,
195 const std::string& json_request,
196 IPC::Message* reply_message);
198 // Method ptr for json handlers.
199 // Uses the JSON interface for input/output.
200 typedef void (TestingAutomationProvider::*JsonHandler)(base::DictionaryValue*,
203 // Method ptr for json handlers that take a browser argument.
204 // Uses the JSON interface for input/output.
205 typedef void (TestingAutomationProvider::*BrowserJsonHandler)(
207 base::DictionaryValue*,
210 // JSON interface helper functions.
211 static scoped_ptr<base::DictionaryValue> ParseJSONRequestCommand(
212 const std::string& json_request,
213 std::string* command,
215 void BuildJSONHandlerMaps();
217 // Set window dimensions.
218 // Uses the JSON interface for input/output.
219 void SetWindowDimensions(Browser* browser,
220 base::DictionaryValue* args,
221 IPC::Message* reply_message);
223 // Get info about infobars in the given WebContents object.
224 // This includes info about the type of infobars, the message text,
226 // Caller owns the returned object.
227 base::ListValue* GetInfobarsInfo(content::WebContents* tc);
229 // Perform actions on an infobar like dismiss, accept, cancel.
230 // This method can handle dismiss for all infobars. It can also handle
231 // accept / cancel (where it will assume the infobar is a confirm infobar) and
232 // allow / deny (where it will assume the infobar is a media stream infobar).
233 // For the media stream infobar, passing 'allow' will just select the first
234 // video and audio device available to the bar, or report an error if there
235 // are no devices available.
237 // Uses the JSON interface for input/output.
238 void PerformActionOnInfobar(Browser* browser,
239 base::DictionaryValue* args,
240 IPC::Message* reply_message);
242 // Create a new profile and open a new browser window with this profile. Uses
243 // the JSON interface for input/output.
244 void OpenNewBrowserWindowWithNewProfile(
245 base::DictionaryValue* args,
246 IPC::Message* reply_message);
248 // Open a new browser window.
249 // Uses the JSON interface for input/output.
250 void OpenNewBrowserWindow(base::DictionaryValue* args,
251 IPC::Message* reply_message);
252 // Close a browser window.
253 // Uses the JSON interface for input/output.
254 void CloseBrowserWindow(base::DictionaryValue* args,
255 IPC::Message* reply_message);
257 // Get info about multi-profile users.
258 // Uses the JSON interface for input/output.
259 void GetMultiProfileInfo(
260 base::DictionaryValue* args,
261 IPC::Message* reply_message);
262 // Open a new browser window for an existing profile.
263 // Uses the JSON interface for input/output.
264 void OpenProfileWindow(
265 base::DictionaryValue* args, IPC::Message* reply_message);
267 // Get info about the chromium/chrome in use.
268 // This includes things like version, executable name, executable path.
269 // Uses the JSON interface for input/output.
270 void GetBrowserInfo(base::DictionaryValue* args,
271 IPC::Message* reply_message);
273 // Get the browser window count. Uses the JSON interface.
274 void GetBrowserWindowCountJSON(base::DictionaryValue* args,
275 IPC::Message* reply_message);
277 // Get info about browser-related processes that currently exist.
278 void GetProcessInfo(base::DictionaryValue* args,
279 IPC::Message* reply_message);
281 // Get info about the state of navigation in a given tab.
282 // This includes ssl info.
283 // Uses the JSON interface for input/output.
284 void GetNavigationInfo(Browser* browser,
285 base::DictionaryValue* args,
286 IPC::Message* reply_message);
288 // Get info about downloads. This includes only ones that have been
289 // registered by the history system.
290 // Uses the JSON interface for input/output.
291 void GetDownloadsInfo(Browser* browser,
292 base::DictionaryValue* args,
293 IPC::Message* reply_message);
295 // Wait for all downloads to complete.
296 // Uses the JSON interface for input/output.
297 void WaitForAllDownloadsToComplete(Browser* browser,
298 base::DictionaryValue* args,
299 IPC::Message* reply_message);
301 // Performs the given action on the specified download.
302 // Uses the JSON interface for input/output.
303 void PerformActionOnDownload(Browser* browser,
304 base::DictionaryValue* args,
305 IPC::Message* reply_message);
307 // Get info about history.
308 // Uses the JSON interface for input/output.
309 void GetHistoryInfo(Browser* browser,
310 base::DictionaryValue* args,
311 IPC::Message* reply_message);
313 // Invoke loading of template url model.
314 // Uses the JSON interface for input/output.
315 void LoadSearchEngineInfo(Browser* browser,
316 base::DictionaryValue* args,
317 IPC::Message* reply_message);
319 // Sets the visibility of the download shelf. Uses the JSON interface.
321 // input: { "is_visible": true,
325 void SetDownloadShelfVisibleJSON(base::DictionaryValue* args,
326 IPC::Message* reply_message);
328 // Gets the visibility of the download shelf. Uses the JSON interface.
330 // input: { "windex": 1 }
331 // output: { "is_visible": true }
332 void IsDownloadShelfVisibleJSON(base::DictionaryValue* args,
333 IPC::Message* reply_message);
335 // Gets the download path of the given tab. Uses the JSON interface.
337 // input: { "tab_index": 1,
340 // output: { "path": "/home/foobar/Downloads" }
341 void GetDownloadDirectoryJSON(base::DictionaryValue* args,
342 IPC::Message* reply_message);
344 // Get search engines list.
345 // Assumes that the profile's template url model is loaded.
346 // Uses the JSON interface for input/output.
347 void GetSearchEngineInfo(Browser* browser,
348 base::DictionaryValue* args,
349 IPC::Message* reply_message);
351 // Add or edit search engine.
352 // Assumes that the profile's template url model is loaded.
353 // Uses the JSON interface for input/output.
354 void AddOrEditSearchEngine(Browser* browser,
355 base::DictionaryValue* args,
356 IPC::Message* reply_message);
358 // Perform a given action on an existing search engine.
359 // Assumes that the profile's template url model is loaded.
360 // Uses the JSON interface for input/output.
361 void PerformActionOnSearchEngine(Browser* browser,
362 base::DictionaryValue* args,
363 IPC::Message* reply_message);
365 // Get info about preferences stored in Local State.
366 // Uses the JSON interface for input/output.
367 void GetLocalStatePrefsInfo(base::DictionaryValue* args,
368 IPC::Message* reply_message);
370 // Set local state prefs.
371 // Uses the JSON interface for input/output.
372 void SetLocalStatePrefs(base::DictionaryValue* args,
373 IPC::Message* reply_message);
375 // Get info about preferences.
376 // Uses the JSON interface for input/output.
377 void GetPrefsInfo(base::DictionaryValue* args,
378 IPC::Message* reply_message);
381 // Uses the JSON interface for input/output.
382 void SetPrefs(base::DictionaryValue* args,
383 IPC::Message* reply_message);
385 // Return load times of initial tabs.
386 // Uses the JSON interface for input/output.
387 // Only includes tabs from command line arguments or session restore.
388 // See declaration of InitialLoadObserver in automation_provider_observers.h
389 // for example response.
390 void GetInitialLoadTimes(Browser* browser,
391 base::DictionaryValue* args,
392 IPC::Message* reply_message);
394 // Get info about plugins.
395 // Uses the JSON interface for input/output.
396 void GetPluginsInfo(Browser* browser,
397 base::DictionaryValue* args,
398 IPC::Message* reply_message);
399 void GetPluginsInfoCallback(Browser* browser,
400 base::DictionaryValue* args,
401 IPC::Message* reply_message,
402 const std::vector<content::WebPluginInfo>& plugins);
405 // Uses the JSON interface for input/output.
406 void EnablePlugin(Browser* browser,
407 base::DictionaryValue* args,
408 IPC::Message* reply_message);
411 // Uses the JSON interface for input/output.
412 void DisablePlugin(Browser* browser,
413 base::DictionaryValue* args,
414 IPC::Message* reply_message);
416 // Get info about omnibox.
417 // Contains data about the matches (url, content, description)
418 // in the omnibox popup, the text in the omnibox.
419 // Uses the JSON interface for input/output.
420 void GetOmniboxInfo(Browser* browser,
421 base::DictionaryValue* args,
422 IPC::Message* reply_message);
424 // Set text in the omnibox. This sets focus to the omnibox.
425 // Uses the JSON interface for input/output.
426 void SetOmniboxText(Browser* browser,
427 base::DictionaryValue* args,
428 IPC::Message* reply_message);
430 // Move omnibox popup selection up or down.
431 // Uses the JSON interface for input/output.
432 void OmniboxMovePopupSelection(Browser* browser,
433 base::DictionaryValue* args,
434 IPC::Message* reply_message);
436 // Accept the current string of text in the omnibox.
437 // This is equivalent to clicking or hiting enter on a popup selection.
438 // Blocks until the page loads.
439 // Uses the JSON interface for input/output.
440 void OmniboxAcceptInput(Browser* browser,
441 base::DictionaryValue* args,
442 IPC::Message* reply_message);
444 // Save the contents of a tab into a file.
445 // Uses the JSON interface for input/output.
446 void SaveTabContents(Browser* browser,
447 base::DictionaryValue* args,
448 IPC::Message* reply_message);
450 // Return the saved username/password combinations.
451 // Uses the JSON interface for input/output.
452 void GetSavedPasswords(Browser* browser,
453 base::DictionaryValue* args,
454 IPC::Message* reply_message);
456 // Install the given unpacked/packed extension.
457 // Uses the JSON interface for input/output.
458 void InstallExtension(base::DictionaryValue* args,
459 IPC::Message* reply_message);
461 // Get info about all intalled extensions.
462 // Uses the JSON interface for input/output.
463 void GetExtensionsInfo(base::DictionaryValue* args,
464 IPC::Message* reply_message);
466 // Uninstalls the extension with the given id.
467 // Uses the JSON interface for input/output.
468 void UninstallExtensionById(base::DictionaryValue* args,
469 IPC::Message* reply_message);
471 // Set extension states:
472 // Enable/disable extension.
473 // Allow/disallow extension in incognito mode.
474 // Uses the JSON interface for input/output.
475 void SetExtensionStateById(base::DictionaryValue* args,
476 IPC::Message* reply_message);
478 // Trigger page action asynchronously in the active tab.
479 // Uses the JSON interface for input/output.
480 void TriggerPageActionById(base::DictionaryValue* args,
481 IPC::Message* reply_message);
483 // Trigger browser action asynchronously in the active tab.
484 // Uses the JSON interface for input/output.
485 void TriggerBrowserActionById(base::DictionaryValue* args,
486 IPC::Message* reply_message);
488 // Auto-updates installed extensions.
489 // Uses the JSON interface for input/output.
490 void UpdateExtensionsNow(base::DictionaryValue* args,
491 IPC::Message* reply_message);
493 // Overrides the current geoposition.
494 // Uses the JSON interface for input/output.
495 void OverrideGeoposition(base::DictionaryValue* args,
496 IPC::Message* reply_message);
498 // Responds to the Find request and returns the match count.
499 void FindInPage(Browser* browser,
500 base::DictionaryValue* args,
501 IPC::Message* reply_message);
503 // Opens the find request dialogue in the given browser.
505 // input: { "windex": 1 }
507 void OpenFindInPage(base::DictionaryValue* args,
508 IPC::Message* reply_message);
510 // Returns whether the find request dialogue is visible in the given browser.
512 // input: { "windex": 1 }
513 // output: { "is_visible": true }
514 void IsFindInPageVisible(base::DictionaryValue* args,
515 IPC::Message* reply_message);
517 // Gets info about the elements in the NTP.
518 // Uses the JSON interface for input/output.
519 void GetNTPInfo(Browser* browser,
520 base::DictionaryValue* args,
521 IPC::Message* reply_message);
523 // Removes a thumbnail from the NTP's Most Visited sites section.
524 // Uses the JSON interface for input/output.
525 void RemoveNTPMostVisitedThumbnail(Browser* browser,
526 base::DictionaryValue* args,
527 IPC::Message* reply_message);
529 // Restores all thumbnails that have been removed (i.e., blacklisted) from the
530 // NTP's Most Visited sites section.
531 // Uses the JSON interface for input/output.
532 void RestoreAllNTPMostVisitedThumbnails(Browser* browser,
533 base::DictionaryValue* args,
534 IPC::Message* reply_message);
536 // Kills the given renderer process and returns after the associated
537 // RenderProcessHost receives notification of its closing.
538 void KillRendererProcess(Browser* browser,
539 base::DictionaryValue* args,
540 IPC::Message* reply_message);
542 // Populates the fields of the event parameter with what is found in the
543 // args parameter. Upon failure, returns false and puts the error message in
544 // the error parameter, otherwise returns true.
545 bool BuildWebKeyEventFromArgs(base::DictionaryValue* args,
547 content::NativeWebKeyboardEvent* event);
549 // Launches the specified app from the currently-selected tab.
550 void LaunchApp(Browser* browser,
551 base::DictionaryValue* args,
552 IPC::Message* reply_message);
554 // Sets the launch type for the specified app.
555 void SetAppLaunchType(Browser* browser,
556 base::DictionaryValue* args,
557 IPC::Message* reply_message);
559 // Gets statistics about the v8 heap in a renderer process.
560 void GetV8HeapStats(Browser* browser,
561 base::DictionaryValue* args,
562 IPC::Message* reply_message);
564 // Gets the current FPS associated with a renderer process view.
565 void GetFPS(Browser* browser,
566 base::DictionaryValue* args,
567 IPC::Message* reply_message);
569 // Fullscreen and Mouse Lock hooks. They take no JSON parameters.
570 void IsFullscreenForBrowser(Browser* browser,
571 base::DictionaryValue* args,
572 IPC::Message* reply_message);
573 void IsFullscreenForTab(Browser* browser,
574 base::DictionaryValue* args,
575 IPC::Message* reply_message);
576 void IsMouseLocked(Browser* browser,
577 base::DictionaryValue* args,
578 IPC::Message* reply_message);
579 void IsMouseLockPermissionRequested(Browser* browser,
580 base::DictionaryValue* args,
581 IPC::Message* reply_message);
582 void IsFullscreenPermissionRequested(Browser* browser,
583 base::DictionaryValue* args,
584 IPC::Message* reply_message);
585 void IsFullscreenBubbleDisplayed(Browser* browser,
586 base::DictionaryValue* args,
587 IPC::Message* reply_message);
588 void IsFullscreenBubbleDisplayingButtons(Browser* browser,
589 base::DictionaryValue* args,
590 IPC::Message* reply_message);
591 void AcceptCurrentFullscreenOrMouseLockRequest(Browser* browser,
592 base::DictionaryValue* args,
593 IPC::Message* reply_message);
594 void DenyCurrentFullscreenOrMouseLockRequest(Browser* browser,
595 base::DictionaryValue* args,
596 IPC::Message* reply_message);
598 // Gets the browser and tab index of the given tab. Uses the JSON interface.
599 // Either "tab_id" or "tab_handle" must be specified, but not both. "tab_id"
600 // refers to the ID from the |NavigationController|, while "tab_handle" is
601 // the handle number assigned by the automation system.
603 // input: { "tab_id": 1, // optional
604 // "tab_handle": 3 // optional
606 // output: { "windex": 1, "tab_index": 5 }
607 void GetIndicesFromTab(base::DictionaryValue* args,
608 IPC::Message* reply_message);
610 // Executes a browser command on the given browser window. Does not wait for
611 // the command to complete.
613 // input: { "accelerator": 1,
616 void ExecuteBrowserCommandAsyncJSON(base::DictionaryValue* args,
617 IPC::Message* reply_message);
619 // Executes a browser command on the given browser window. Waits for the
620 // command to complete before returning.
622 // input: { "accelerator": 1,
625 void ExecuteBrowserCommandJSON(base::DictionaryValue* args,
626 IPC::Message* reply_message);
628 // Checks if a browser command is enabled on the given browser window.
630 // input: { "accelerator": 1,
633 // output: { "enabled": true }
634 void IsMenuCommandEnabledJSON(base::DictionaryValue* args,
635 IPC::Message* reply_message);
637 // Returns a dictionary of information about the given tab.
639 // input: { "tab_index": 1,
642 // output: { "title": "Hello World",
643 // "url": "http://foo.bar" }
644 void GetTabInfo(base::DictionaryValue* args,
645 IPC::Message* reply_message);
647 // Returns the tab count for the given browser window.
649 // input: { "windex": 1 }
650 // output: { "tab_count": 5 }
651 void GetTabCountJSON(base::DictionaryValue* args,
652 IPC::Message* reply_message);
654 // Navigates to the given URL. Uses the JSON interface.
655 // The pair |windex| and |tab_index| or the single |auto_id| must be given
656 // to specify the tab.
658 // input: { "windex": 1,
660 // "auto_id": { "type": 0, "id": "awoein" },
661 // "url": "http://www.google.com",
662 // "navigation_count": 1 // number of navigations to wait for
664 // output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS }
665 void NavigateToURL(base::DictionaryValue* args, IPC::Message* reply_message);
667 // Get the index of the currently active tab. Uses the JSON interface.
668 // The integer |windex| must be given to specify the browser window.
670 // input: { "windex": 1 }
671 // output: { "tab_index": 3 }
672 void GetActiveTabIndexJSON(base::DictionaryValue* args,
673 IPC::Message* reply_message);
675 // Append a new tab. Uses the JSON interface.
676 // The integer |windex| must be given to specify the browser window. The tab
677 // is opened to |url| and blocks until the page loads.
679 // input: { "windex": 1,
680 // "url": "http://google.com"
682 // output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS }
683 void AppendTabJSON(base::DictionaryValue* args, IPC::Message* reply_message);
685 // Waits until any pending navigation completes in the specified tab.
686 // The pair |windex| and |tab_index| or the single |auto_id| must be given
687 // to specify the tab.
689 // input: { "windex": 1,
691 // "auto_id": { "type": 0, "id": "awoein" },
693 // output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS }
694 void WaitUntilNavigationCompletes(
695 base::DictionaryValue* args, IPC::Message* reply_message);
697 // Executes javascript in the specified frame. Uses the JSON interface.
698 // Waits for a result from the |DOMAutomationController|. The javascript
699 // must send a string.
700 // The pair |windex| and |tab_index| or the single |auto_id| must be given
701 // to specify the tab.
703 // input: { "windex": 1,
705 // "auto_id": { "type": 0, "id": "awoein" },
706 // "frame_xpath": "//frames[1]",
708 // "window.domAutomationController.send(window.name)",
710 // output: { "result": "My Window Name" }
711 // This and some following methods have a suffix of JSON to distingush them
712 // from already existing methods which perform the same function, but use
713 // custom IPC messages instead of the JSON IPC message. These functions will
714 // eventually be replaced with the JSON ones and the JSON suffix will be
716 // TODO(kkania): Replace the non-JSON counterparts and drop the JSON suffix.
717 void ExecuteJavascriptJSON(
718 base::DictionaryValue* args, IPC::Message* reply_message);
720 // Creates a DomEventObserver associated with the AutomationEventQueue.
722 // input: { "event_name": "login complete",
723 // "automation_id": 4444,
724 // "recurring": False
726 // output: { "observer_id": 1 }
727 void AddDomEventObserver(
728 base::DictionaryValue* args, IPC::Message* reply_message);
730 // Removes an event observer associated with the AutomationEventQueue.
732 // input: { "observer_id": 1 }
734 void RemoveEventObserver(
735 base::DictionaryValue* args, IPC::Message* reply_message);
737 // Retrieves an event from the AutomationEventQueue.
738 // Blocks if 'blocking' is true, otherwise returns immediately.
740 // input: { "observer_id": 1,
743 // output: { "type": "raised",
744 // "name": "login complete"
747 void GetNextEvent(base::DictionaryValue* args, IPC::Message* reply_message);
749 // Removes all events and observers attached to the AutomationEventQueue.
753 void ClearEventQueue(
754 base::DictionaryValue* args, IPC::Message* reply_message);
756 // Executes javascript in the specified frame of a render view.
757 // Uses the JSON interface. Waits for a result from the
758 // |DOMAutomationController|. The javascript must send a string.
760 // input: { "view": {
761 // "render_process_id": 1,
762 // "render_view_id": 2,
764 // "frame_xpath": "//frames[1]",
766 // "window.domAutomationController.send(window.name)",
768 // output: { "result": "My Window Name" }
769 void ExecuteJavascriptInRenderView(
770 base::DictionaryValue* args, IPC::Message* reply_message);
772 // Goes forward in the specified tab. Uses the JSON interface.
773 // The pair |windex| and |tab_index| or the single |auto_id| must be given
774 // to specify the tab.
776 // input: { "windex": 1,
778 // "auto_id": { "type": 0, "id": "awoein" }
780 // output: { "did_go_forward": true, // optional
781 // "result": AUTOMATION_MSG_NAVIGATION_SUCCESS // optional
783 void GoForward(base::DictionaryValue* args, IPC::Message* reply_message);
785 // Goes back in the specified tab. Uses the JSON interface.
786 // The pair |windex| and |tab_index| or the single |auto_id| must be given
787 // to specify the tab.
789 // input: { "windex": 1,
791 // "auto_id": { "type": 0, "id": "awoein" }
793 // output: { "did_go_back": true, // optional
794 // "result": AUTOMATION_MSG_NAVIGATION_SUCCESS // optional
796 void GoBack(base::DictionaryValue* args, IPC::Message* reply_message);
798 // Reload the specified tab. Uses the JSON interface.
799 // The pair |windex| and |tab_index| or the single |auto_id| must be given
800 // to specify the tab.
802 // input: { "windex": 1,
804 // "auto_id": { "type": 0, "id": "awoein" }
806 // output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS // optional }
807 void ReloadJSON(base::DictionaryValue* args, IPC::Message* reply_message);
809 // Gets the cookies for the given URL. Uses the JSON interface.
810 // "expiry" refers to the amount of seconds since the Unix epoch. If omitted,
811 // the cookie is valid for the duration of the browser session.
813 // input: { "url": "http://www.google.com" }
814 // output: { "cookies": [
817 // "value": "123101",
819 // "domain": "www.google.com",
821 // "expiry": 1401982012
825 void GetCookiesJSON(base::DictionaryValue* args, IPC::Message* reply_message);
827 // Deletes the cookie with the given name for the URL. Uses the JSON
831 // "url": "http://www.google.com",
832 // "name": "my_cookie"
835 void DeleteCookieJSON(base::DictionaryValue* args,
836 IPC::Message* reply_message);
838 // Sets a cookie for the given URL. Uses the JSON interface.
839 // "expiry" refers to the amount of seconds since the Unix epoch. If omitted,
840 // the cookie will be valid for the duration of the browser session.
841 // "domain" refers to the applicable domain for the cookie. Valid domain
842 // choices for the site "http://www.google.com" and resulting cookie
844 // [.]www.google.com - applicable on www.google.com and its subdomains
845 // [.]google.com - applicable on google.com and its subdomains
846 // <none> - applicable only on www.google.com
849 // input: { "url": "http://www.google.com",
852 // "value": "123101",
853 // "path": "/", // optional
854 // "domain": ".www.google.com", // optional
855 // "secure": false, // optional
856 // "expiry": 1401982012 // optional
860 void SetCookieJSON(base::DictionaryValue* args, IPC::Message* reply_message);
862 // Gets the cookies for the given URL in the context of a given browser
863 // window. Uses the JSON interface.
865 // input: { "url": "http://www.google.com",
869 // output: { "cookies": "foo=bar" }
870 void GetCookiesInBrowserContext(base::DictionaryValue* args,
871 IPC::Message* reply_message);
873 // Deletes the cookie with the given name for the URL in the context of a
874 // given browser window. Uses the JSON interface.
876 // input: { "url": "http://www.google.com",
877 // "cookie_name": "my_cookie"
882 void DeleteCookieInBrowserContext(base::DictionaryValue* args,
883 IPC::Message* reply_message);
885 // Sets a cookie for the given URL in the context of a given browser window.
886 // Uses the JSON interface.
889 // input: { "url": "http://www.google.com",
890 // "value": "name=value; Expires=Wed, 09 Jun 2021 10:18:14 GMT",
895 void SetCookieInBrowserContext(base::DictionaryValue* args,
896 IPC::Message* reply_message);
898 // Gets the ID for every open tab. This ID is unique per session.
901 // output: { "ids": [213, 1] }
902 void GetTabIds(base::DictionaryValue* args, IPC::Message* reply_message);
904 // Checks if the given tab ID refers to an open tab.
906 // input: { "id": 41 }
907 // output: { "is_valid": false }
908 void IsTabIdValid(base::DictionaryValue* args, IPC::Message* reply_message);
910 // Closes the specified tab.
911 // The pair |windex| and |tab_index| or the single |auto_id| must be given
912 // to specify the tab.
914 // input: { "windex": 1,
916 // "auto_id": { "type": 0, "id": "awoein" }
919 void CloseTabJSON(base::DictionaryValue* args, IPC::Message* reply_message);
921 // Sets the specified web view bounds.
922 // The single |auto_id| must be given to specify the view.
923 // This method currently is only supported for tabs.
925 // input: { "auto_id": { "type": 0, "id": "awoein" },
934 void SetViewBounds(base::DictionaryValue* args, IPC::Message* reply_message);
936 // Maximizes the web view.
937 // The single |auto_id| must be given to specify the view.
938 // This method currently is only supported for tabs.
940 // input: { "auto_id": { "type": 0, "id": "awoein" } }
942 void MaximizeView(base::DictionaryValue* args, IPC::Message* reply_message);
944 // Sends the WebKit events for a mouse click at a given coordinate.
945 // The pair |windex| and |tab_index| or the single |auto_id| must be given
946 // to specify the render view.
948 // input: { "windex": 1,
950 // "auto_id": { "type": 0, "id": "awoein" },
951 // "button": automation::kLeftButton,
956 void WebkitMouseClick(base::DictionaryValue* args,
957 IPC::Message* message);
959 // Sends the WebKit event for a mouse move to a given coordinate.
960 // The pair |windex| and |tab_index| or the single |auto_id| must be given
961 // to specify the render view.
963 // input: { "windex": 1,
965 // "auto_id": { "type": 0, "id": "awoein" },
970 void WebkitMouseMove(base::DictionaryValue* args,
971 IPC::Message* message);
973 // Sends the WebKit events for a mouse drag between two coordinates.
974 // The pair |windex| and |tab_index| or the single |auto_id| must be given
975 // to specify the render view.
977 // input: { "windex": 1,
979 // "auto_id": { "type": 0, "id": "awoein" },
986 void WebkitMouseDrag(base::DictionaryValue* args,
987 IPC::Message* message);
989 // Sends the WebKit events for a mouse button down at a given coordinate.
990 // The pair |windex| and |tab_index| or the single |auto_id| must be given
991 // to specify the render view.
993 // input: { "windex": 1,
995 // "auto_id": { "type": 0, "id": "awoein" },
1000 void WebkitMouseButtonDown(base::DictionaryValue* args,
1001 IPC::Message* message);
1003 // Sends the WebKit events for a mouse button up at a given coordinate.
1004 // The pair |windex| and |tab_index| or the single |auto_id| must be given
1005 // to specify the render view.
1007 // input: { "windex": 1,
1009 // "auto_id": { "type": 0, "id": "awoein" },
1014 void WebkitMouseButtonUp(base::DictionaryValue* args,
1015 IPC::Message* message);
1017 // Sends the WebKit events for a mouse double click at a given coordinate.
1018 // The pair |windex| and |tab_index| or the single |auto_id| must be given
1019 // to specify the render view.
1021 // input: { "windex": 1,
1023 // "auto_id": { "type": 0, "id": "awoein" },
1028 void WebkitMouseDoubleClick(base::DictionaryValue* args,
1029 IPC::Message* message);
1031 // Drag and drop file paths at a given coordinate.
1032 // The pair |windex| and |tab_index| or the single |auto_id| must be given
1033 // to specify the render view.
1035 // input: { "windex": 1,
1037 // "auto_id": { "type": 0, "id": "awoein" },
1045 void DragAndDropFilePaths(base::DictionaryValue* args,
1046 IPC::Message* message);
1048 // Sends the WebKit key event with the specified properties.
1049 // The pair |windex| and |tab_index| or the single |auto_id| must be given
1050 // to specify the render view.
1052 // input: { "windex": 1,
1054 // "auto_id": { "type": 0, "id": "awoein" },
1055 // "type": automation::kRawKeyDownType,
1056 // "nativeKeyCode": ui::VKEY_X,
1057 // "windowsKeyCode": ui::VKEY_X,
1058 // "unmodifiedText": "x",
1060 // "modifiers": automation::kShiftKeyMask,
1061 // "isSystemKey": false
1064 void SendWebkitKeyEvent(base::DictionaryValue* args,
1065 IPC::Message* message);
1067 // Gets the active JavaScript modal dialog's message.
1070 // output: { "message": "This is an alert!" }
1071 void GetAppModalDialogMessage(
1072 base::DictionaryValue* args, IPC::Message* reply_message);
1074 // Accepts or dismisses the active JavaScript modal dialog. If optional
1075 // prompt text is given, it will be used as the result of the prompt dialog.
1077 // input: { "accept": true,
1078 // "prompt_text": "hello" // optional
1081 void AcceptOrDismissAppModalDialog(
1082 base::DictionaryValue* args, IPC::Message* reply_message);
1084 // Activates the given tab.
1085 // The pair |windex| and |tab_index| or the single |auto_id| must be given
1086 // to specify the tab.
1088 // input: { "windex": 1,
1090 // "auto_id": { "type": 0, "id": "awoein" }
1093 void ActivateTabJSON(base::DictionaryValue* args, IPC::Message* message);
1095 // Blocks until the given tab is restored.
1096 // Uses the JSON interface.
1097 void WaitForTabToBeRestored(base::DictionaryValue* args,
1098 IPC::Message* reply_message);
1100 // Simulates an action on the SSL blocking page at the specified tab.
1101 // If |proceed| is true, it is equivalent to the user pressing the
1102 // 'Proceed' button, if false the 'Get me out of there button'.
1103 // Note that this fails if the tab is not displaying a SSL blocking page.
1104 // Uses the JSON interface.
1106 // input: { "windex": 1,
1111 void ActionOnSSLBlockingPage(base::DictionaryValue* args,
1112 IPC::Message* reply_message);
1114 // Gets the security state for the given tab. Uses the JSON interface.
1116 // input: { "windex": 1,
1119 // output: { "security_style": SECURITY_STYLE_AUTHENTICATED,
1120 // "ssl_cert_status": 3, // bitmask of status flags
1121 // "insecure_content_status": 1, // bitmask of ContentStatusFlags
1123 void GetSecurityState(base::DictionaryValue* args,
1124 IPC::Message* reply_message);
1126 // Brings the given brower's window to the front.
1128 // input: { "windex": 1 }
1130 void BringBrowserToFrontJSON(base::DictionaryValue* args,
1131 IPC::Message* message);
1133 // Determines whether the extension page action is visible in the given tab.
1135 // input: { "auto_id": { "type": 0, "id": "awoein" },
1136 // "extension_id": "byzaaoiea",
1139 void IsPageActionVisible(base::DictionaryValue* args,
1140 IPC::Message* reply_message);
1142 // Creates a new |TestingAutomationProvider| that opens a server channel
1143 // for the given |channel_id|.
1144 // The server channel will be available for connection when this returns.
1146 // input: { "channel_id": "testChannel123" }
1147 void CreateNewAutomationProvider(base::DictionaryValue* args,
1148 IPC::Message* reply_message);
1150 // Triggers a policy update on the platform and cloud providers, if they
1151 // exist. Returns after the update notifications are received.
1155 void RefreshPolicies(base::DictionaryValue* args,
1156 IPC::Message* reply_message);
1158 // Simulates a memory bug (reference an array out of bounds) to cause Address
1159 // Sanitizer (if it was built it) to catch the bug and abort the process.
1163 void SimulateAsanMemoryBug(base::DictionaryValue* args,
1164 IPC::Message* reply_message);
1166 #if defined(OS_CHROMEOS)
1169 // Accepts the network screen and continues to EULA.
1172 // ouput: { "next_screen": "eula" }
1173 void AcceptOOBENetworkScreen(base::DictionaryValue* args,
1174 IPC::Message* reply_message);
1176 // Accepts or declines EULA, moving forward or back from EULA screen.
1178 // input: { "accepted": true, "usage_stats_reporting": false }
1179 // output: { "next_screen": "update" }
1180 void AcceptOOBEEula(base::DictionaryValue* args, IPC::Message* reply_message);
1182 // Forces the ongoing update to cancel and proceed to the login screen.
1185 // output: { "next_screen": "login" }
1186 void CancelOOBEUpdate(base::DictionaryValue* args,
1187 IPC::Message* reply_message);
1189 // Chooses user image on the image picker screen and starts browser session.
1191 // input: { "image": "profile" } - Google profile image
1192 // input: { "image": 2 } - default image number 2 (0-based)
1193 // output: { "next_screen": "session" }
1194 void PickUserImage(base::DictionaryValue* args, IPC::Message* reply_message);
1196 // Skips OOBE to login step. Can be called when already at login screen,
1197 // in which case does nothing and sends return value immediately.
1199 // input: { "skip_image_selection": true }
1200 // output: { "next_screen": "login" }
1201 void SkipToLogin(base::DictionaryValue* args, IPC::Message* reply_message);
1203 // Returns info about the current OOBE screen.
1206 // output: { "screen_name": "network" }
1207 // output: none (when already logged in)
1208 void GetOOBEScreenInfo(base::DictionaryValue* args,
1209 IPC::Message* reply_message);
1212 void GetLoginInfo(base::DictionaryValue* args, IPC::Message* reply_message);
1214 void ShowCreateAccountUI(base::DictionaryValue* args,
1215 IPC::Message* reply_message);
1217 void LoginAsGuest(base::DictionaryValue* args, IPC::Message* reply_message);
1219 // Submits the Chrome OS login form. Watch for the login to complete using
1220 // the AddLoginObserver and GetNextEvent commands.
1222 // input: { "username": "user@gmail.com",
1223 // "password": "fakepassword",
1225 void SubmitLoginForm(base::DictionaryValue* args,
1226 IPC::Message* reply_message);
1228 void AddLoginEventObserver(base::DictionaryValue* args,
1229 IPC::Message* reply_message);
1231 // Executes javascript in the specified frame in the OOBE WebUI on chromeos.
1232 // Waits for a result from the |DOMAutomationController|. The javascript must
1233 // send a string. Must be run before a user has logged in.
1235 // input: { "frame_xpath": "//frames[1]",
1237 // "window.domAutomationController.send(window.name)",
1239 // output: { "result": "My Window Name" }
1240 void ExecuteJavascriptInOOBEWebUI(
1241 base::DictionaryValue* args, IPC::Message* reply_message);
1243 void SignOut(base::DictionaryValue* args, IPC::Message* reply_message);
1246 void LockScreen(base::DictionaryValue* args, IPC::Message* reply_message);
1248 void UnlockScreen(base::DictionaryValue* args, IPC::Message* reply_message);
1250 void SignoutInScreenLocker(base::DictionaryValue* args,
1251 IPC::Message* reply_message);
1254 void GetBatteryInfo(base::DictionaryValue* args, IPC::Message* reply_message);
1257 void EnableSpokenFeedback(base::DictionaryValue* args,
1258 IPC::Message* reply_message);
1260 void IsSpokenFeedbackEnabled(base::DictionaryValue* args,
1261 IPC::Message* reply_message);
1264 void GetTimeInfo(Browser* browser, base::DictionaryValue* args,
1265 IPC::Message* reply_message);
1267 void GetTimeInfo(base::DictionaryValue* args, IPC::Message* reply_message);
1269 void SetTimezone(base::DictionaryValue* args, IPC::Message* reply_message);
1271 void UpdateCheck(base::DictionaryValue* args, IPC::Message* reply_message);
1274 void GetVolumeInfo(base::DictionaryValue* args, IPC::Message* reply_message);
1276 void SetVolume(base::DictionaryValue* args, IPC::Message* reply_message);
1278 void SetMute(base::DictionaryValue* args, IPC::Message* reply_message);
1280 void CaptureProfilePhoto(Browser* browser,
1281 base::DictionaryValue* args,
1282 IPC::Message* reply_message);
1285 void OpenCrosh(base::DictionaryValue* args, IPC::Message* reply_message);
1287 void AddChromeosObservers();
1288 void RemoveChromeosObservers();
1290 #endif // defined(OS_CHROMEOS)
1292 void WaitForTabCountToBecome(int browser_handle,
1293 int target_tab_count,
1294 IPC::Message* reply_message);
1296 void WaitForInfoBarCount(int tab_handle,
1297 size_t target_count,
1298 IPC::Message* reply_message);
1300 void WaitForProcessLauncherThreadToGoIdle(IPC::Message* reply_message);
1302 void OnRemoveProvider(); // Called via PostTask
1304 // Execute Javascript in the context of a specific render view.
1305 void ExecuteJavascriptInRenderViewFrame(
1306 const base::string16& frame_xpath, const base::string16& script,
1307 IPC::Message* reply_message, content::RenderViewHost* render_view_host);
1309 // Selects the given |tab| if not selected already.
1310 void EnsureTabSelected(Browser* browser, content::WebContents* tab);
1312 #if defined(OS_CHROMEOS)
1313 power_manager::PowerSupplyProperties power_supply_properties_;
1314 #endif // defined(OS_CHROMEOS)
1316 std::map<std::string, JsonHandler> handler_map_;
1317 std::map<std::string, BrowserJsonHandler> browser_handler_map_;
1319 content::NotificationRegistrar registrar_;
1321 // The automation event observer queue. It is lazily created when an observer
1322 // is added to avoid overhead when not needed.
1323 scoped_ptr<AutomationEventQueue> automation_event_queue_;
1325 // List of commands which just finish synchronously and don't require
1326 // setting up an observer.
1327 static const int kSynchronousCommands[];
1329 DISALLOW_COPY_AND_ASSIGN(TestingAutomationProvider);
1332 #endif // CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_