summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/extension_proxy.h
blob: 1257b9e184c023e356880f5bcb85f8ff0636fbce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_AUTOMATION_EXTENSION_PROXY_H_
#define CHROME_TEST_AUTOMATION_EXTENSION_PROXY_H_
#pragma once

#include <string>

#include "base/compiler_specific.h"
#include "base/weak_ptr.h"
#include "chrome/test/automation/automation_constants.h"
#include "chrome/test/automation/automation_handle_tracker.h"

class AutomationMessageSender;
class BrowserProxy;

// This class presents the interface to actions that can be performed on
// a given extension. This refers to a particular version of that extension.
// For example, it refers to Google Translate 1.0. If the extension is
// updated to a newer version, this proxy is invalidated.
class ExtensionProxy : public AutomationResourceProxy {
 public:
  // Creates an extension proxy referring to an extension id.
  ExtensionProxy(AutomationMessageSender* sender,
                 AutomationHandleTracker* tracker,
                 int handle);

  // Uninstalls this extension. Returns true on success.
  bool Uninstall() WARN_UNUSED_RESULT;

  // Enables this extension. Returns true on success. The extension
  // should be disabled when this is called.
  bool Enable() WARN_UNUSED_RESULT;

  // Disables this extension. Returns true on success. The extension
  // should be enabled when this is called.
  bool Disable() WARN_UNUSED_RESULT;

  // Executes the action associated with this extension. This may be a page
  // action or a browser action. This is similar to clicking, but does not
  // work with popups. Also, for page actions, this will execute the action
  // even if the page action is not shown for the active tab. Returns true on
  // success.
  // TODO(kkania): Add support for popups.
  bool ExecuteActionInActiveTabAsync(BrowserProxy* browser)
      WARN_UNUSED_RESULT;

  // Moves the browser action from its current location in the browser action
  // toolbar to a new |index|. Index should be less than the number of browser
  // actions in the toolbar. Returns true on success.
  bool MoveBrowserAction(int index) WARN_UNUSED_RESULT;

  // Gets the id of this extension. Returns true on success.
  bool GetId(std::string* id) WARN_UNUSED_RESULT;

  // Gets the name of this extension. Returns true on success.
  bool GetName(std::string* name) WARN_UNUSED_RESULT;

  // Gets the version string of this extension. Returns true on success.
  bool GetVersion(std::string* version) WARN_UNUSED_RESULT;

  // Gets the index (zero-based) of this extension's browser action in
  // the browser action toolbar. |index| will be set to -1 if the extension
  // does not have a browser action in the toolbar. Returns true on success.
  bool GetBrowserActionIndex(int* index) WARN_UNUSED_RESULT;

  // Asserts that |expected_id| matches this extension's id.
  void EnsureIdMatches(const std::string& expected_id);

  // Asserts that |expected_name| matches this extension's name.
  void EnsureNameMatches(const std::string& expected_name);

  // Asserts that |expected_version| matches this extension's name.
  void EnsureVersionMatches(const std::string& expected_version);

  // Asserts that |expected_index| matches the index (zero-based) of this
  // extension's browser action in the browser action toolbar.
  void EnsureBrowserActionIndexMatches(int expected_index);

 private:
  // Gets the string value of the property of type |type|. Returns true on
  // success.
  bool GetProperty(AutomationMsg_ExtensionProperty type, std::string* value)
      WARN_UNUSED_RESULT;
};

#endif  // CHROME_TEST_AUTOMATION_EXTENSION_PROXY_H_