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