testing_automation_provider.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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 CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_
6#define CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "base/scoped_ptr.h"
11#include "chrome/browser/automation/automation_provider.h"
12#include "chrome/browser/browser_list.h"
13#include "chrome/browser/history/history.h"
14#include "chrome/browser/importer/importer_list.h"
15#include "chrome/browser/sync/profile_sync_service_harness.h"
16#include "chrome/common/notification_registrar.h"
17#include "chrome/common/page_type.h"
18
19class DictionaryValue;
20class TemplateURLModel;
21
22// This is an automation provider containing testing calls.
23class TestingAutomationProvider : public AutomationProvider,
24                                  public BrowserList::Observer,
25                                  public ImporterList::Observer,
26                                  public NotificationObserver {
27 public:
28  explicit TestingAutomationProvider(Profile* profile);
29
30  // BrowserList::Observer implementation.
31  virtual void OnBrowserAdded(const Browser* browser);
32  virtual void OnBrowserRemoved(const Browser* browser);
33
34  // IPC::Channel::Listener implementation.
35  virtual bool OnMessageReceived(const IPC::Message& msg);
36  virtual void OnChannelError();
37
38 private:
39  class PopupMenuWaiter;
40
41  // Storage for ImportSettings() to resume operations after a callback.
42  struct ImportSettingsData {
43    string16 browser_name;
44    int import_items;
45    bool first_run;
46    Browser* browser;
47    IPC::Message* reply_message;
48  };
49
50  virtual ~TestingAutomationProvider();
51
52  // ImporterList::Observer implementation.
53  virtual void SourceProfilesLoaded();
54
55  // NotificationObserver implementation.
56  virtual void Observe(NotificationType type,
57                       const NotificationSource& source,
58                       const NotificationDetails& details);
59
60  // IPC Message callbacks.
61  void CloseBrowser(int handle, IPC::Message* reply_message);
62  void CloseBrowserAsync(int browser_handle);
63  void ActivateTab(int handle, int at_index, int* status);
64  void AppendTab(int handle, const GURL& url, IPC::Message* reply_message);
65  void GetActiveTabIndex(int handle, int* active_tab_index);
66  void CloseTab(int tab_handle, bool wait_until_closed,
67                IPC::Message* reply_message);
68  void GetCookies(const GURL& url, int handle, int* value_size,
69                  std::string* value);
70  void SetCookie(const GURL& url,
71                 const std::string value,
72                 int handle,
73                 int* response_value);
74  void DeleteCookie(const GURL& url, const std::string& cookie_name,
75                    int handle, bool* success);
76  void ShowCollectedCookiesDialog(int handle, bool* success);
77  void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url,
78                                                  int number_of_navigations,
79                                                  IPC::Message* reply_message);
80  void NavigationAsync(int handle, const GURL& url, bool* status);
81  void NavigationAsyncWithDisposition(int handle,
82                                      const GURL& url,
83                                      WindowOpenDisposition disposition,
84                                      bool* status);
85  void Reload(int handle, IPC::Message* reply_message);
86  void SetAuth(int tab_handle, const std::wstring& username,
87               const std::wstring& password, IPC::Message* reply_message);
88  void CancelAuth(int tab_handle, IPC::Message* reply_message);
89  void NeedsAuth(int tab_handle, bool* needs_auth);
90  void GetRedirectsFrom(int tab_handle,
91                        const GURL& source_url,
92                        IPC::Message* reply_message);
93  void GetBrowserWindowCount(int* window_count);
94  void GetNormalBrowserWindowCount(int* window_count);
95  // Be aware that the browser window returned might be of non TYPE_NORMAL
96  // or in incognito mode.
97  void GetBrowserWindow(int index, int* handle);
98  void FindNormalBrowserWindow(int* handle);
99  void GetLastActiveBrowserWindow(int* handle);
100  void GetActiveWindow(int* handle);
101  void ExecuteBrowserCommandAsync(int handle, int command, bool* success);
102  void ExecuteBrowserCommand(int handle, int command,
103                             IPC::Message* reply_message);
104  void GetBrowserLocale(string16* locale);
105  void IsWindowActive(int handle, bool* success, bool* is_active);
106  void ActivateWindow(int handle);
107  void IsWindowMaximized(int handle, bool* is_maximized, bool* success);
108  void TerminateSession(int handle, bool* success);
109  void WindowGetViewBounds(int handle, int view_id, bool screen_coordinates,
110                           bool* success, gfx::Rect* bounds);
111  void GetWindowBounds(int handle, gfx::Rect* bounds, bool* result);
112  void SetWindowBounds(int handle, const gfx::Rect& bounds, bool* result);
113  void SetWindowVisible(int handle, bool visible, bool* result);
114  void WindowSimulateClick(const IPC::Message& message,
115                           int handle,
116                           const gfx::Point& click,
117                           int flags);
118  void WindowSimulateMouseMove(const IPC::Message& message,
119                               int handle,
120                               const gfx::Point& location);
121  void WindowSimulateKeyPress(const IPC::Message& message,
122                              int handle,
123                              int key,
124                              int flags);
125  void GetTabCount(int handle, int* tab_count);
126  void GetType(int handle, int* type_as_int);
127  void GetTab(int win_handle, int tab_index, int* tab_handle);
128  void GetTabProcessID(int handle, int* process_id);
129  void GetTabTitle(int handle, int* title_string_size, std::wstring* title);
130  void GetTabIndex(int handle, int* tabstrip_index);
131  void GetTabURL(int handle, bool* success, GURL* url);
132  void GetShelfVisibility(int handle, bool* visible);
133  void IsFullscreen(int handle, bool* is_fullscreen);
134  void GetFullscreenBubbleVisibility(int handle, bool* is_visible);
135  void GetAutocompleteEditForBrowser(int browser_handle, bool* success,
136                                     int* autocomplete_edit_handle);
137
138  // Retrieves the visible text from the autocomplete edit.
139  void GetAutocompleteEditText(int autocomplete_edit_handle,
140                               bool* success, string16* text);
141
142  // Sets the visible text from the autocomplete edit.
143  void SetAutocompleteEditText(int autocomplete_edit_handle,
144                               const string16& text,
145                               bool* success);
146
147  // Retrieves if a query to an autocomplete provider is in progress.
148  void AutocompleteEditIsQueryInProgress(int autocomplete_edit_handle,
149                                         bool* success,
150                                         bool* query_in_progress);
151
152  // Retrieves the individual autocomplete matches displayed by the popup.
153  void AutocompleteEditGetMatches(int autocomplete_edit_handle,
154                                  bool* success,
155                                  std::vector<AutocompleteMatchData>* matches);
156
157  // Waits for the autocomplete edit to receive focus
158  void WaitForAutocompleteEditFocus(int autocomplete_edit_handle,
159                                    IPC::Message* reply_message);
160
161  void ExecuteJavascript(int handle,
162                         const std::wstring& frame_xpath,
163                         const std::wstring& script,
164                         IPC::Message* reply_message);
165
166  void GetConstrainedWindowCount(int handle, int* count);
167
168#if defined(TOOLKIT_VIEWS)
169  void GetFocusedViewID(int handle, int* view_id);
170
171  // Block until the focused view ID changes to something other than
172  // previous_view_id.
173  void WaitForFocusedViewIDToChange(int handle,
174                                    int previous_view_id,
175                                    IPC::Message* reply_message);
176
177  // Start tracking popup menus. Must be called before executing the
178  // command that might open the popup menu; then call WaitForPopupMenuToOpen.
179  void StartTrackingPopupMenus(int browser_handle, bool* success);
180
181  // Wait until a popup menu has opened.
182  void WaitForPopupMenuToOpen(IPC::Message* reply_message);
183#endif  // defined(TOOLKIT_VIEWS)
184
185  void HandleInspectElementRequest(int handle,
186                                   int x,
187                                   int y,
188                                   IPC::Message* reply_message);
189
190  void GetDownloadDirectory(int handle, FilePath* download_directory);
191
192  // If |show| is true, call Show() on the new window after creating it.
193  void OpenNewBrowserWindowOfType(int type,
194                                  bool show,
195                                  IPC::Message* reply_message);
196
197  // Retrieves a Browser from a Window and vice-versa.
198  void GetWindowForBrowser(int window_handle, bool* success, int* handle);
199  void GetBrowserForWindow(int window_handle, bool* success,
200                           int* browser_handle);
201
202  void ShowInterstitialPage(int tab_handle,
203                            const std::string& html_text,
204                            IPC::Message* reply_message);
205  void HideInterstitialPage(int tab_handle, bool* success);
206
207  void WaitForTabToBeRestored(int tab_handle, IPC::Message* reply_message);
208
209  // Gets the security state for the tab associated to the specified |handle|.
210  void GetSecurityState(int handle, bool* success,
211                        SecurityStyle* security_style, int* ssl_cert_status,
212                        int* insecure_content_status);
213
214  // Gets the page type for the tab associated to the specified |handle|.
215  void GetPageType(int handle, bool* success, PageType* page_type);
216
217  // Gets the duration in ms of the last event matching |event_name|.
218  // |duration_ms| is -1 if the event hasn't occurred yet.
219  void GetMetricEventDuration(const std::string& event_name, int* duration_ms);
220
221  // Simulates an action on the SSL blocking page at the tab specified by
222  // |handle|. If |proceed| is true, it is equivalent to the user pressing the
223  // 'Proceed' button, if false the 'Get me out of there button'.
224  // Not that this fails if the tab is not displaying a SSL blocking page.
225  void ActionOnSSLBlockingPage(int handle,
226                               bool proceed,
227                               IPC::Message* reply_message);
228
229  // Brings the browser window to the front and activates it.
230  void BringBrowserToFront(int browser_handle, bool* success);
231
232  // Checks to see if a command on the browser's CommandController is enabled.
233  void IsMenuCommandEnabled(int browser_handle,
234                            int message_num,
235                            bool* menu_item_enabled);
236
237  // Prints the current tab immediately.
238  void PrintNow(int tab_handle, IPC::Message* reply_message);
239
240  // Save the current web page.
241  void SavePage(int tab_handle,
242                const FilePath& file_name,
243                const FilePath& dir_path,
244                int type,
245                bool* success);
246
247  // Responds to requests to open the FindInPage window.
248  void HandleOpenFindInPageRequest(const IPC::Message& message,
249                                   int handle);
250
251  // Get the visibility state of the Find window.
252  void GetFindWindowVisibility(int handle, bool* visible);
253
254  // Responds to requests to find the location of the Find window.
255  void HandleFindWindowLocationRequest(int handle, int* x, int* y);
256
257  // Get the visibility state of the Bookmark bar.
258  void GetBookmarkBarVisibility(int handle, bool* visible, bool* animating);
259
260  // Get the bookmarks as a JSON string.
261  void GetBookmarksAsJSON(int handle, std::string* bookmarks_as_json,
262                          bool *success);
263
264  // Wait for the bookmark model to load.
265  void WaitForBookmarkModelToLoad(int handle, IPC::Message* reply_message);
266
267  // Set |loaded| to true if the bookmark model has loaded, else false.
268  void BookmarkModelHasLoaded(int handle, bool* loaded);
269
270  // Editing, modification, and removal of bookmarks.
271  // Bookmarks are referenced by id.
272  void AddBookmarkGroup(int handle,
273                        int64 parent_id, int index, std::wstring title,
274                        bool* success);
275  void AddBookmarkURL(int handle,
276                      int64 parent_id, int index,
277                      std::wstring title, const GURL& url,
278                      bool* success);
279  void ReparentBookmark(int handle,
280                        int64 id, int64 new_parent_id, int index,
281                        bool* success);
282  void SetBookmarkTitle(int handle,
283                        int64 id, std::wstring title,
284                        bool* success);
285  void SetBookmarkURL(int handle,
286                      int64 id, const GURL& url,
287                      bool* success);
288  void RemoveBookmark(int handle,
289                      int64 id,
290                      bool* success);
291
292  // Retrieves the number of info-bars currently showing in |count|.
293  void GetInfoBarCount(int handle, size_t* count);
294
295  // Causes a click on the "accept" button of the info-bar at |info_bar_index|.
296  // If |wait_for_navigation| is true, it sends the reply after a navigation has
297  // occurred.
298  void ClickInfoBarAccept(int handle,
299                          size_t info_bar_index,
300                          bool wait_for_navigation,
301                          IPC::Message* reply_message);
302
303  // Retrieves the last time a navigation occurred for the tab.
304  void GetLastNavigationTime(int handle, int64* last_navigation_time);
305
306  // Waits for a new navigation in the tab if none has happened since
307  // |last_navigation_time|.
308  void WaitForNavigation(int handle,
309                         int64 last_navigation_time,
310                         IPC::Message* reply_message);
311
312  // Sets the int value for preference with name |name|.
313  void SetIntPreference(int handle,
314                        const std::string& name,
315                        int value,
316                        bool* success);
317
318  // Sets the string value for preference with name |name|.
319  void SetStringPreference(int handle,
320                           const std::string& name,
321                           const std::string& value,
322                           bool* success);
323
324  // Gets the bool value for preference with name |name|.
325  void GetBooleanPreference(int handle,
326                            const std::string& name,
327                            bool* success,
328                            bool* value);
329
330  // Sets the bool value for preference with name |name|.
331  void SetBooleanPreference(int handle,
332                            const std::string& name,
333                            bool value,
334                            bool* success);
335
336  void GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button);
337  void ClickAppModalDialogButton(int button, bool* success);
338
339  void WaitForBrowserWindowCountToBecome(int target_count,
340                                         IPC::Message* reply_message);
341
342  void WaitForAppModalDialogToBeShown(IPC::Message* reply_message);
343
344  void GoBackBlockUntilNavigationsComplete(int handle,
345                                           int number_of_navigations,
346                                           IPC::Message* reply_message);
347
348  void GoForwardBlockUntilNavigationsComplete(int handle,
349                                              int number_of_navigations,
350                                              IPC::Message* reply_message);
351
352  void SavePackageShouldPromptUser(bool should_prompt);
353
354  void GetWindowTitle(int handle, string16* text);
355
356  void SetShelfVisibility(int handle, bool visible);
357
358  // Returns the number of blocked popups in the tab |handle|.
359  void GetBlockedPopupCount(int handle, int* count);
360
361  // Captures the entire page for the given tab and saves it as PNG at the
362  // given path.
363  void CaptureEntirePageAsPNG(int tab_handle, const FilePath& path,
364                              IPC::Message* reply_message);
365
366  // Generic pattern for pyautolib
367  // Uses the JSON interface for input/output.
368  void SendJSONRequest(int handle,
369                       std::string json_request,
370                       IPC::Message* reply_message);
371
372  // Method ptr for json handlers.
373  // Uses the JSON interface for input/output.
374  typedef void (TestingAutomationProvider::*JsonHandler)(DictionaryValue*,
375                                                         IPC::Message*);
376
377  // Method ptr for json handlers that take a browser argument.
378  // Uses the JSON interface for input/output.
379  typedef void (TestingAutomationProvider::*BrowserJsonHandler)(
380      Browser* browser,
381      DictionaryValue*,
382      IPC::Message*);
383
384    // Set window dimensions.
385  // Uses the JSON interface for input/output.
386  void SetWindowDimensions(Browser* browser,
387                           DictionaryValue* args,
388                           IPC::Message* reply_message);
389
390  // Get info about infobars in the given TabContents object.
391  // This includes info about the type of infobars, the message text,
392  // buttons, etc.
393  // Caller owns the returned object.
394  ListValue* GetInfobarsInfo(TabContents* tc);
395
396  // Perform actions on an infobar like dismiss, accept, cancel.
397  // Uses the JSON interface for input/output.
398  void PerformActionOnInfobar(Browser* browser,
399                              DictionaryValue* args,
400                              IPC::Message* reply_message);
401
402  // Get info about the chromium/chrome in use.
403  // This includes things like version, executable name, executable path.
404  // Uses the JSON interface for input/output.
405  void GetBrowserInfo(Browser* browser,
406                      DictionaryValue* args,
407                      IPC::Message* reply_message);
408
409  // Get info about the state of navigation in a given tab.
410  // This includes ssl info.
411  // Uses the JSON interface for input/output.
412  void GetNavigationInfo(Browser* browser,
413                         DictionaryValue* args,
414                         IPC::Message* reply_message);
415
416  // Get info about downloads. This includes only ones that have been
417  // registered by the history system.
418  // Uses the JSON interface for input/output.
419  void GetDownloadsInfo(Browser* browser,
420                        DictionaryValue* args,
421                        IPC::Message* reply_message);
422
423  // Wait for all downloads to complete.
424  // Uses the JSON interface for input/output.
425  void WaitForDownloadsToComplete(Browser* browser,
426                                  DictionaryValue* args,
427                                  IPC::Message* reply_message);
428
429  // Performs the given action on the specified download.
430  // Uses the JSON interface for input/output.
431  void PerformActionOnDownload(Browser* browser,
432                               DictionaryValue* args,
433                               IPC::Message* reply_message);
434
435  // Get info about history.
436  // Uses the JSON interface for input/output.
437  void GetHistoryInfo(Browser* browser,
438                      DictionaryValue* args,
439                      IPC::Message* reply_message);
440
441  // Add an item to the history service.
442  // Uses the JSON interface for input/output.
443  void AddHistoryItem(Browser* browser,
444                      DictionaryValue* args,
445                      IPC::Message* reply_message);
446
447  // Invoke loading of template url model.
448  // Uses the JSON interface for input/output.
449  void LoadSearchEngineInfo(Browser* browser,
450                            DictionaryValue* args,
451                            IPC::Message* reply_message);
452
453  // Get search engines list.
454  // Assumes that the profile's template url model is loaded.
455  // Uses the JSON interface for input/output.
456  void GetSearchEngineInfo(Browser* browser,
457                           DictionaryValue* args,
458                           IPC::Message* reply_message);
459
460  // Add or edit search engine.
461  // Assumes that the profile's template url model is loaded.
462  // Uses the JSON interface for input/output.
463  void AddOrEditSearchEngine(Browser* browser,
464                             DictionaryValue* args,
465                             IPC::Message* reply_message);
466
467  // Perform a given action on an existing search engine.
468  // Assumes that the profile's template url model is loaded.
469  // Uses the JSON interface for input/output.
470  void PerformActionOnSearchEngine(Browser* browser,
471                                   DictionaryValue* args,
472                                   IPC::Message* reply_message);
473
474  // Get info about preferences.
475  // Uses the JSON interface for input/output.
476  void GetPrefsInfo(Browser* browser,
477                    DictionaryValue* args,
478                    IPC::Message* reply_message);
479
480  // Set prefs.
481  // Uses the JSON interface for input/output.
482  void SetPrefs(Browser* browser,
483                DictionaryValue* args,
484                IPC::Message* reply_message);
485
486  // Return load times of initial tabs.
487  // Uses the JSON interface for input/output.
488  // Only includes tabs from command line arguments or session restore.
489  // See declaration of InitialLoadObserver in automation_provider_observers.h
490  // for example response.
491  void GetInitialLoadTimes(Browser* browser,
492                           DictionaryValue* args,
493                           IPC::Message* reply_message);
494
495  // Get info about plugins.
496  // Uses the JSON interface for input/output.
497  void GetPluginsInfo(Browser* browser,
498                      DictionaryValue* args,
499                      IPC::Message* reply_message);
500
501  // Enable a plugin.
502  // Uses the JSON interface for input/output.
503  void EnablePlugin(Browser* browser,
504                    DictionaryValue* args,
505                    IPC::Message* reply_message);
506
507  // Disable a plugin.
508  // Uses the JSON interface for input/output.
509  void DisablePlugin(Browser* browser,
510                     DictionaryValue* args,
511                     IPC::Message* reply_message);
512
513  // Get info about omnibox.
514  // Contains data about the matches (url, content, description)
515  // in the omnibox popup, the text in the omnibox.
516  // Uses the JSON interface for input/output.
517  void GetOmniboxInfo(Browser* browser,
518                      DictionaryValue* args,
519                      IPC::Message* reply_message);
520
521  // Set text in the omnibox. This sets focus to the omnibox.
522  // Uses the JSON interface for input/output.
523  void SetOmniboxText(Browser* browser,
524                      DictionaryValue* args,
525                      IPC::Message* reply_message);
526
527  // Move omnibox popup selection up or down.
528  // Uses the JSON interface for input/output.
529  void OmniboxMovePopupSelection(Browser* browser,
530                                 DictionaryValue* args,
531                                 IPC::Message* reply_message);
532
533  // Accept the current string of text in the omnibox.
534  // This is equivalent to clicking or hiting enter on a popup selection.
535  // Blocks until the page loads.
536  // Uses the JSON interface for input/output.
537  void OmniboxAcceptInput(Browser* browser,
538                          DictionaryValue* args,
539                          IPC::Message* reply_message);
540
541  // Generate dictionary info about instant tab.
542  // Uses the JSON interface for input/output.
543  void GetInstantInfo(Browser* browser,
544                      DictionaryValue* args,
545                      IPC::Message* reply_message);
546
547  // Save the contents of a tab into a file.
548  // Uses the JSON interface for input/output.
549  void SaveTabContents(Browser* browser,
550                       DictionaryValue* args,
551                       IPC::Message* reply_message);
552
553  // Import the given settings from the given browser.
554  // Uses the JSON interface for input/output.
555  void ImportSettings(Browser* browser,
556                      DictionaryValue* args,
557                      IPC::Message* reply_message);
558
559  // Add a new entry to the password store based on the password information
560  // provided. This method can also be used to add a blacklisted site (which
561  // will never fill in the password).
562  // Uses the JSON interface for input/output.
563  void AddSavedPassword(Browser* browser,
564                        DictionaryValue* args,
565                        IPC::Message* reply_message);
566
567  // Removes the password matching the information provided. This method can
568  // also be used to remove a blacklisted site.
569  // Uses the JSON interface for input/output.
570  void RemoveSavedPassword(Browser* browser,
571                           DictionaryValue* args,
572                           IPC::Message* reply_message);
573
574  // Return the saved username/password combinations.
575  // Uses the JSON interface for input/output.
576  void GetSavedPasswords(Browser* browser,
577                         DictionaryValue* args,
578                         IPC::Message* reply_message);
579
580  // Clear the specified browsing data. This call provides similar
581  // functionality to RemoveBrowsingData but is synchronous.
582  // Uses the JSON interface for input/output.
583  void ClearBrowsingData(Browser* browser,
584                         DictionaryValue* args,
585                         IPC::Message* reply_message);
586
587  // Get info about blocked popups in a tab.
588  // Uses the JSON interface for input/output.
589  void GetBlockedPopupsInfo(Browser* browser,
590                            DictionaryValue* args,
591                            IPC::Message* reply_message);
592
593  // Launch a blocked popup.
594  // Uses the JSON interface for input/output.
595  void UnblockAndLaunchBlockedPopup(Browser* browser,
596                                    DictionaryValue* args,
597                                    IPC::Message* reply_message);
598
599  // Get info about theme.
600  // Uses the JSON interface for input/output.
601  void GetThemeInfo(Browser* browser,
602                    DictionaryValue* args,
603                    IPC::Message* reply_message);
604
605  // Get info about all intalled extensions.
606  // Uses the JSON interface for input/output.
607  void GetExtensionsInfo(Browser* browser,
608                         DictionaryValue* args,
609                         IPC::Message* reply_message);
610
611  // Uninstalls the extension with the given id.
612  // Uses the JSON interface for input/output.
613  void UninstallExtensionById(Browser* browser,
614                              DictionaryValue* args,
615                              IPC::Message* reply_message);
616
617  // Responds to the Find request and returns the match count.
618  void FindInPage(Browser* browser,
619                  DictionaryValue* args,
620                  IPC::Message* reply_message);
621
622  // Returns information about translation for a given tab. Includes
623  // information about the translate bar if it is showing.
624  void GetTranslateInfo(Browser* browser,
625                        DictionaryValue* args,
626                        IPC::Message* reply_message);
627
628  // Takes the specified action on the translate bar.
629  // Uses the JSON interface for input/output.
630  void SelectTranslateOption(Browser* browser,
631                             DictionaryValue* args,
632                             IPC::Message* reply_message);
633
634  // Get the profiles that are currently saved to the DB.
635  // Uses the JSON interface for input/output.
636  void GetAutoFillProfile(Browser* browser,
637                          DictionaryValue* args,
638                          IPC::Message* reply_message);
639
640  // Fill in an AutoFillProfile with the given profile information.
641  // Uses the JSON interface for input/output.
642  void FillAutoFillProfile(Browser* browser,
643                           DictionaryValue* args,
644                           IPC::Message* reply_message);
645
646  // Signs in to sync using the given username and password.
647  // Uses the JSON interface for input/output.
648  void SignInToSync(Browser* browser,
649                    DictionaryValue* args,
650                    IPC::Message* reply_message);
651
652  // Returns info about sync.
653  // Uses the JSON interface for input/output.
654  void GetSyncInfo(Browser* browser,
655                   DictionaryValue* args,
656                   IPC::Message* reply_message);
657
658  // Waits for the ongoing sync cycle to complete.
659  // Uses the JSON interface for input/output.
660  void AwaitSyncCycleCompletion(Browser* browser,
661                                DictionaryValue* args,
662                                IPC::Message* reply_message);
663
664  // Enables sync for one or more sync datatypes.
665  // Uses the JSON interface for input/output.
666  void EnableSyncForDatatypes(Browser* browser,
667                              DictionaryValue* args,
668                              IPC::Message* reply_message);
669
670  // Disables sync for one or more sync datatypes.
671  // Uses the JSON interface for input/output.
672  void DisableSyncForDatatypes(Browser* browser,
673                               DictionaryValue* args,
674                               IPC::Message* reply_message);
675
676  // Translate DictionaryValues of autofill profiles and credit cards to the
677  // data structure used in the browser.
678  // Args:
679  //   profiles/cards: the ListValue of profiles/credit cards to translate.
680  //   error_message: a pointer to the return string in case of error.
681  static std::vector<AutoFillProfile> GetAutoFillProfilesFromList(
682      const ListValue& profiles, std::string* error_message);
683  static std::vector<CreditCard> GetCreditCardsFromList(
684      const ListValue& cards, std::string* error_message);
685
686  // The opposite of the above: translates from the internal data structure
687  // for profiles and credit cards to a ListValue of DictionaryValues. The
688  // caller owns the returned object.
689  static ListValue* GetListFromAutoFillProfiles(
690      const std::vector<AutoFillProfile*>& autofill_profiles);
691  static ListValue* GetListFromCreditCards(
692      const std::vector<CreditCard*>& credit_cards);
693
694  // Return the map from the internal data representation to the string value
695  // of auto fill fields and credit card fields.
696  static std::map<AutofillFieldType, std::string>
697      GetAutofillFieldToStringMap();
698  static std::map<AutofillFieldType, std::string>
699      GetCreditCardFieldToStringMap();
700
701  // Get a list of active HTML5 notifications.
702  // Uses the JSON interface for input/output.
703  void GetActiveNotifications(Browser* browser,
704                              DictionaryValue* args,
705                              IPC::Message* reply_message);
706
707  // Close an active HTML5 notification.
708  // Uses the JSON interface for input/output.
709  void CloseNotification(Browser* browser,
710                         DictionaryValue* args,
711                         IPC::Message* reply_message);
712
713  // Waits for the number of active HTML5 notifications to reach a given count.
714  // Uses the JSON interface for input/output.
715  void WaitForNotificationCount(Browser* browser,
716                                DictionaryValue* args,
717                                IPC::Message* reply_message);
718
719  // Gets info about the elements in the NTP.
720  // Uses the JSON interface for input/output.
721  void GetNTPInfo(Browser* browser,
722                  DictionaryValue* args,
723                  IPC::Message* reply_message);
724
725  // Moves a thumbnail in the NTP's Most Visited sites section to a different
726  // index.
727  // Uses the JSON interface for input/output.
728  void MoveNTPMostVisitedThumbnail(Browser* browser,
729                                   DictionaryValue* args,
730                                   IPC::Message* reply_message);
731
732  // Removes a thumbnail from the NTP's Most Visited sites section.
733  // Uses the JSON interface for input/output.
734  void RemoveNTPMostVisitedThumbnail(Browser* browser,
735                                     DictionaryValue* args,
736                                     IPC::Message* reply_message);
737
738  // Unpins a thumbnail in the NTP's Most Visited sites section.
739  // Uses the JSON interface for input/output.
740  void UnpinNTPMostVisitedThumbnail(Browser* browser,
741                                    DictionaryValue* args,
742                                    IPC::Message* reply_message);
743
744  // Restores all thumbnails that have been removed (i.e., blacklisted) from the
745  // NTP's Most Visited sites section.
746  // Uses the JSON interface for input/output.
747  void RestoreAllNTPMostVisitedThumbnails(Browser* browser,
748                                          DictionaryValue* args,
749                                          IPC::Message* reply_message);
750
751  // Kills the given renderer process and returns after the associated
752  // RenderProcessHost receives notification of its closing.
753  void KillRendererProcess(Browser* browser,
754                           DictionaryValue* args,
755                           IPC::Message* reply_message);
756
757  // Sends a web keyboard event to the active tab. This should not trigger any
758  // browser hotkeys.
759  // Uses the JSON interface for input/output.
760  void SendKeyEventToActiveTab(Browser* browser,
761                               DictionaryValue* args,
762                               IPC::Message* reply_message);
763
764  // Determines whether each relevant section of the NTP is in thumbnail mode.
765  void GetNTPThumbnailMode(Browser* browser,
766                           DictionaryValue* args,
767                           IPC::Message* reply_message);
768
769  // Puts or removes the specified section of the NTP into/from thumbnail mode.
770  // If the section is put into thumbnail mode, all other relevant sections are
771  // removed from thumbnail mode.
772  void SetNTPThumbnailMode(Browser* browser,
773                           DictionaryValue* args,
774                           IPC::Message* reply_message);
775
776  // Determines whether each relevant section of the NTP is in menu mode.
777  void GetNTPMenuMode(Browser* browser,
778                      DictionaryValue* args,
779                      IPC::Message* reply_message);
780
781  // Puts or removes the specified section of the NTP into/from menu mode.
782  void SetNTPMenuMode(Browser* browser,
783                      DictionaryValue* args,
784                      IPC::Message* reply_message);
785
786  // Waits for all tabs to stop loading.
787  void WaitForAllTabsToStopLoading(DictionaryValue* args,
788                                   IPC::Message* reply_message);
789
790  // Gets the browser and tab index of the given tab. Uses the JSON interface.
791  // Either "tab_id" or "tab_handle" must be specified, but not both. "tab_id"
792  // refers to the ID from the |NavigationController|, while "tab_handle" is
793  // the handle number assigned by the automation system.
794  // Example:
795  //   input: { "tab_id": 1,     // optional
796  //            "tab_handle": 3  // optional
797  //          }
798  //   output: { "windex": 1, "tab_index": 5 }
799  void GetIndicesFromTab(DictionaryValue* args, IPC::Message* reply_message);
800
801  // Navigates to the given URL. Uses the JSON interface.
802  // Example:
803  //   input: { "windex": 1,
804  //            "tab_index": 3,
805  //            "url": "http://www.google.com",
806  //            "navigation_count": 1  // number of navigations to wait for
807  //          }
808  //   output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS }
809  void NavigateToURL(DictionaryValue* args, IPC::Message* reply_message);
810
811  // Executes javascript in the specified frame. Uses the JSON interface.
812  // Waits for a result from the |DOMAutomationController|. The javascript
813  // must send a string.
814  // Example:
815  //   input: { "windex": 1,
816  //            "tab_index": 1,
817  //            "frame_xpath": "//frames[1]",
818  //            "javascript":
819  //                "window.domAutomationController.send(window.name)",
820  //           }
821  //   output: { "result": "My Window Name" }
822  // This and some following methods have a suffix of JSON to distingush them
823  // from already existing methods which perform the same function, but use
824  // custom IPC messages instead of the JSON IPC message. These functions will
825  // eventually be replaced with the JSON ones and the JSON suffix will be
826  // dropped.
827  // TODO(kkania): Replace the non-JSON counterparts and drop the JSON suffix.
828  void ExecuteJavascriptJSON(
829      DictionaryValue* args, IPC::Message* reply_message);
830
831  // Goes forward in the specified tab. Uses the JSON interface.
832  // Example:
833  //   input: { "windex": 1, "tab_index": 1 }
834  //   output: { "did_go_forward": true,                      // optional
835  //             "result": AUTOMATION_MSG_NAVIGATION_SUCCESS  // optional
836  //           }
837  void GoForward(DictionaryValue* args, IPC::Message* reply_message);
838
839  // Goes back in the specified tab. Uses the JSON interface.
840  // Example:
841  //   input: { "windex": 1, "tab_index": 1 }
842  //   output: { "did_go_back": true,                         // optional
843  //             "result": AUTOMATION_MSG_NAVIGATION_SUCCESS  // optional
844  //           }
845  void GoBack(DictionaryValue* args, IPC::Message* reply_message);
846
847  // Reload the specified tab. Uses the JSON interface.
848  // Example:
849  //   input: { "windex": 1, "tab_index": 1 }
850  //   output: { "result": AUTOMATION_MSG_NAVIGATION_SUCCESS  // optional }
851  void ReloadJSON(DictionaryValue* args, IPC::Message* reply_message);
852
853  // Get the current url of the specified tab. Uses the JSON interface.
854  // Example:
855  //   input: { "windex": 1, "tab_index": 1 }
856  //   output: { "url": "http://www.google.com" }
857  void GetTabURLJSON(DictionaryValue* args, IPC::Message* reply_message);
858
859  // Get the current url of the specified tab. Uses the JSON interface.
860  // Example:
861  //   input: { "windex": 1, "tab_index": 1 }
862  //   output: { "title": "Google" }
863  void GetTabTitleJSON(DictionaryValue* args, IPC::Message* reply_message);
864
865  // Gets the cookies for the given URL. Uses the JSON interface.
866  // Example:
867  //   input: { "windex": 1, "tab_index": 1, "url": "http://www.google.com" }
868  //   output: { "cookies": "PREF=12012" }
869  void GetCookiesJSON(DictionaryValue* args, IPC::Message* reply_message);
870
871  // Deletes the cookie with the given name for the URL. Uses the JSON
872  // interface.
873  // Example:
874  //   input: { "windex": 1,
875  //            "tab_index": 1,
876  //            "url": "http://www.google.com",
877  //            "name": "my_cookie"
878  //          }
879  //   output: none
880  void DeleteCookieJSON(DictionaryValue* args, IPC::Message* reply_message);
881
882  // Sets a cookie for the given URL. Uses the JSON interface.
883  // Example:
884  //   input: { "windex": 1,
885  //            "tab_index": 1,
886  //            "url": "http://www.google.com",
887  //            "cookie": "PREF=21321"
888  //          }
889  //   output: none
890  void SetCookieJSON(DictionaryValue* args, IPC::Message* reply_message);
891
892  // Gets the ID for every open tab. This ID is unique per session.
893  // Example:
894  //   input: none
895  //   output: { "ids": [4124, 213, 1] }
896  void GetTabIds(DictionaryValue* args, IPC::Message* reply_message);
897
898  // Checks if the given tab ID refers to an open tab.
899  // Example:
900  //   input: { "id": 41 }
901  //   output: { "is_valid": false }
902  void IsTabIdValid(DictionaryValue* args, IPC::Message* reply_message);
903
904  // Closes the specified tab.
905  // Example:
906  //   input: { "windex": 1, "tab_index": 1 }
907  //   output: none
908  void CloseTabJSON(DictionaryValue* args, IPC::Message* reply_message);
909
910  // Sends the WebKit events for a mouse click at a given coordinate.
911  // Example:
912  //   input: { "windex": 1,
913  //            "tab_index": 1,
914  //            "button": automation::kLeftButton,
915  //            "x": 100,
916  //            "y": 100
917  //          }
918  //   output: none
919  void WebkitMouseClick(DictionaryValue* args,
920                        IPC::Message* message);
921
922  // Sends the WebKit event for a mouse move to a given coordinate.
923  // Example:
924  //   input: { "windex": 1,
925  //            "tab_index": 1,
926  //            "x": 100,
927  //            "y": 100
928  //          }
929  //   output: none
930  void WebkitMouseMove(DictionaryValue* args,
931                       IPC::Message* message);
932
933  // Sends the WebKit events for a mouse drag between two coordinates.
934  // Example:
935  //   input: { "windex": 1,
936  //            "tab_index": 1,
937  //            "start_x": 100,
938  //            "start_y": 100,
939  //            "end_x": 100,
940  //            "end_y": 100
941  //          }
942  //   output: none
943  void WebkitMouseDrag(DictionaryValue* args,
944                       IPC::Message* message);
945
946  // Sends the WebKit key event with the specified properties.
947  // Example:
948  //   input: { "windex": 1,
949  //            "tab_index": 1,
950  //            "type": automation::kRawKeyDownType,
951  //            "nativeKeyCode": ui::VKEY_X,
952  //            "windowsKeyCode": ui::VKEY_X,
953  //            "unmodifiedText": "x",
954  //            "text": "X",
955  //            "modifiers": automation::kShiftKeyMask,
956  //            "isSystemKey": false
957  //          }
958  //   output: none
959  void SendWebkitKeyEvent(DictionaryValue* args,
960                          IPC::Message* message);
961
962  // Activates the given tab.
963  // Example:
964  //   input: { "windex": 1,
965  //            "tab_index": 1,
966  //          }
967  //   output: none
968  void ActivateTabJSON(DictionaryValue* args, IPC::Message* message);
969
970#if defined(OS_CHROMEOS)
971  void LoginAsGuest(DictionaryValue* args, IPC::Message* reply_message);
972
973  void Login(DictionaryValue* args, IPC::Message* reply_message);
974
975  void Logout(DictionaryValue* args, IPC::Message* reply_message);
976
977  void ScreenLock(DictionaryValue* args, IPC::Message* reply_message);
978
979  void ScreenUnlock(DictionaryValue* args, IPC::Message* reply_message);
980#endif  // defined(OS_CHROMEOS)
981
982  void WaitForTabCountToBecome(int browser_handle,
983                               int target_tab_count,
984                               IPC::Message* reply_message);
985
986  void WaitForInfoBarCount(int tab_handle,
987                           size_t target_count,
988                           IPC::Message* reply_message);
989
990  // Gets the current used encoding name of the page in the specified tab.
991  void GetPageCurrentEncoding(int tab_handle, std::string* current_encoding);
992
993  void ShutdownSessionService(int handle, bool* result);
994
995  void SetContentSetting(int handle,
996                         const std::string& host,
997                         ContentSettingsType content_type,
998                         ContentSetting setting,
999                         bool* success);
1000
1001  // Load all plug-ins on the page.
1002  void LoadBlockedPlugins(int tab_handle, bool* success);
1003
1004  // Resets to the default theme.
1005  void ResetToDefaultTheme();
1006
1007  void WaitForProcessLauncherThreadToGoIdle(IPC::Message* reply_message);
1008
1009  // Gets the browser that contains the given tab.
1010  void GetParentBrowserOfTab(
1011      int tab_handle, int* browser_handle, bool* success);
1012
1013  // Callback for history redirect queries.
1014  virtual void OnRedirectQueryComplete(
1015      HistoryService::Handle request_handle,
1016      GURL from_url,
1017      bool success,
1018      history::RedirectList* redirects);
1019
1020  void OnRemoveProvider();  // Called via PostTask
1021
1022#if defined(TOOLKIT_VIEWS)
1023  // Keep track of whether a popup menu has been opened since the last time
1024  // that StartTrackingPopupMenus has been called.
1025  bool popup_menu_opened_;
1026
1027  // A temporary object that receives a notification when a popup menu opens.
1028  PopupMenuWaiter* popup_menu_waiter_;
1029#endif  // defined(TOOLKIT_VIEWS)
1030
1031  // Used to wait on various browser sync events.
1032  scoped_ptr<ProfileSyncServiceHarness> sync_waiter_;
1033
1034  // Handle for an in-process redirect query. We expect only one redirect query
1035  // at a time (we should have only one caller, and it will block while waiting
1036  // for the results) so there is only one handle. When non-0, indicates a
1037  // query in progress.
1038  HistoryService::Handle redirect_query_;
1039
1040  NotificationRegistrar registrar_;
1041
1042  // Used to enumerate browser profiles.
1043  scoped_refptr<ImporterList> importer_list_;
1044
1045  // The stored data for the ImportSettings operation.
1046  ImportSettingsData import_settings_data_;
1047
1048  DISALLOW_COPY_AND_ASSIGN(TestingAutomationProvider);
1049};
1050
1051#endif  // CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_
1052