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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// 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.
#include "chrome/test/automation/extension_proxy.h"
#include "base/string_number_conversions.h"
#include "chrome/common/automation_messages.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
ExtensionProxy::ExtensionProxy(AutomationMessageSender* sender,
AutomationHandleTracker* tracker,
int handle)
: AutomationResourceProxy(tracker, sender, handle) {
}
bool ExtensionProxy::Uninstall() {
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(new AutomationMsg_UninstallExtension(handle_, &success)))
return false;
return success;
}
bool ExtensionProxy::Enable() {
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(new AutomationMsg_EnableExtension(handle_, &success)))
return false;
return success;
}
bool ExtensionProxy::Disable() {
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(new AutomationMsg_DisableExtension(handle_, &success)))
return false;
return success;
}
bool ExtensionProxy::ExecuteActionInActiveTabAsync(BrowserProxy* browser) {
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(new AutomationMsg_ExecuteExtensionActionInActiveTabAsync(
handle_, browser->handle(), &success)))
return false;
return success;
}
bool ExtensionProxy::MoveBrowserAction(int index) {
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(
new AutomationMsg_MoveExtensionBrowserAction(handle_, index, &success)))
return false;
return success;
}
bool ExtensionProxy::GetId(std::string* id) {
DCHECK(id);
return GetProperty(AUTOMATION_MSG_EXTENSION_ID, id);
}
bool ExtensionProxy::GetName(std::string* name) {
DCHECK(name);
return GetProperty(AUTOMATION_MSG_EXTENSION_NAME, name);
}
bool ExtensionProxy::GetVersion(std::string* version) {
DCHECK(version);
return GetProperty(AUTOMATION_MSG_EXTENSION_VERSION, version);
}
bool ExtensionProxy::GetBrowserActionIndex(int* index) {
DCHECK(index);
std::string index_string;
if (!GetProperty(AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX,
&index_string))
return false;
// Do not modify |index| until we are sure we can get the value, just to be
// nice to the caller.
int converted_index;
if (!base::StringToInt(index_string, &converted_index)) {
LOG(ERROR) << "Received index string could not be converted to int: "
<< index_string;
return false;
}
*index = converted_index;
return true;
}
void ExtensionProxy::EnsureIdMatches(const std::string& expected_id) {
std::string id;
ASSERT_TRUE(GetId(&id));
ASSERT_EQ(expected_id, id);
}
void ExtensionProxy::EnsureNameMatches(const std::string& expected_name) {
std::string name;
ASSERT_TRUE(GetName(&name));
ASSERT_EQ(expected_name, name);
}
void ExtensionProxy::EnsureVersionMatches(const std::string& expected_version) {
std::string version;
ASSERT_TRUE(GetVersion(&version));
ASSERT_EQ(expected_version, version);
}
void ExtensionProxy::EnsureBrowserActionIndexMatches(int expected_index) {
int index;
ASSERT_TRUE(GetBrowserActionIndex(&index));
ASSERT_EQ(expected_index, index);
}
bool ExtensionProxy::GetProperty(AutomationMsg_ExtensionProperty type,
std::string* value) {
DCHECK(value);
if (!is_valid())
return false;
bool success = false;
if (!sender_->Send(new AutomationMsg_GetExtensionProperty(handle_, type,
&success, value)))
return false;
return success;
}
|