Home | History | Annotate | Download | only in automation
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_UTIL_H_
      6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_UTIL_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 
     12 class AutomationId;
     13 class AutomationProvider;
     14 class Browser;
     15 class GURL;
     16 class Profile;
     17 
     18 namespace content {
     19 class RenderViewHost;
     20 class WebContents;
     21 }
     22 
     23 namespace base {
     24 class DictionaryValue;
     25 }
     26 
     27 namespace extensions {
     28 class Extension;
     29 }
     30 
     31 namespace IPC {
     32 class Message;
     33 }
     34 
     35 // This file contains automation utility functions.
     36 
     37 namespace automation_util {
     38 
     39 // Returns the browser at the given index of the |BrowserList| or NULL if the
     40 // index is out of range.
     41 Browser* GetBrowserAt(int index);
     42 
     43 // Returns the tab at |tab_index| within the browser at |browser_index| in the
     44 // |BrowserList|. If any of these indices are invalid, NULL will be returned.
     45 content::WebContents* GetWebContentsAt(int browser_index, int tab_index);
     46 
     47 #if defined(OS_CHROMEOS)
     48 // Returns the appropriate profile depending on signed in state of user.
     49 Profile* GetCurrentProfileOnChromeOS(std::string* error_message);
     50 #endif
     51 
     52 // Returns the browser that contains the given tab, or NULL if none exists.
     53 Browser* GetBrowserForTab(content::WebContents* tab);
     54 
     55 // Gets the size and value of the cookie string for |url| in the given tab.
     56 // Can be called from any thread.
     57 void GetCookies(const GURL& url,
     58                 content::WebContents* contents,
     59                 int* value_size,
     60                 std::string* value);
     61 
     62 // Sets a cookie for |url| in the given tab.  Can be called from any thread.
     63 void SetCookie(const GURL& url,
     64                const std::string& value,
     65                content::WebContents* contents,
     66                int* response_value);
     67 
     68 // Deletes a cookie for |url| in the given tab.  Can be called from any thread.
     69 void DeleteCookie(const GURL& url,
     70                   const std::string& cookie_name,
     71                   content::WebContents* contents,
     72                   bool* success);
     73 
     74 // Gets the cookies for the given URL. Uses the JSON interface.
     75 // See |TestingAutomationProvider| for example input.
     76 void GetCookiesJSON(AutomationProvider* provider,
     77                     base::DictionaryValue* args,
     78                     IPC::Message* reply_message);
     79 
     80 // Deletes the cookie with the given name for the URL. Uses the JSON interface.
     81 // See |TestingAutomationProvider| for example input.
     82 void DeleteCookieJSON(AutomationProvider* provider,
     83                       base::DictionaryValue* args,
     84                       IPC::Message* reply_message);
     85 
     86 // Sets a cookie for the given URL. Uses the JSON interface.
     87 // See |TestingAutomationProvider| for example input.
     88 void SetCookieJSON(AutomationProvider* provider,
     89                    base::DictionaryValue* args,
     90                    IPC::Message* reply_message);
     91 
     92 // Sends a JSON error reply if an app modal dialog is active. Returns whether
     93 // an error reply was sent.
     94 bool SendErrorIfModalDialogActive(AutomationProvider* provider,
     95                                   IPC::Message* message);
     96 
     97 // Returns a valid automation ID for the given tab.
     98 AutomationId GetIdForTab(const content::WebContents* tab);
     99 
    100 // Returns a valid automation ID for the extension view.
    101 AutomationId GetIdForExtensionView(
    102     const content::RenderViewHost* render_view_host);
    103 
    104 // Returns a valid automation ID for the extension.
    105 AutomationId GetIdForExtension(const extensions::Extension* extension);
    106 
    107 // Gets the tab for the given ID. Returns true on success.
    108 bool GetTabForId(const AutomationId& id, content::WebContents** tab);
    109 
    110 // Gets the render view for the given ID. Returns true on success.
    111 bool GetRenderViewForId(const AutomationId& id,
    112                         Profile* profile,
    113                         content::RenderViewHost** rvh);
    114 
    115 // Gets the extension for the given ID. Returns true on success.
    116 bool GetExtensionForId(const AutomationId& id,
    117                        Profile* profile,
    118                        const extensions::Extension** extension);
    119 
    120 // Returns whether the given ID refers to an actual automation entity.
    121 bool DoesObjectWithIdExist(const AutomationId& id, Profile* profile);
    122 
    123 }  // namespace automation_util
    124 
    125 #endif  // CHROME_BROWSER_AUTOMATION_AUTOMATION_UTIL_H_
    126