Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / common / extensions / manifest_handlers / automation_unittest.cc
blob125119021b1849803ecc6304afba46ea54f83438
1 // Copyright 2014 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.
5 #include "chrome/common/extensions/features/feature_channel.h"
6 #include "chrome/common/extensions/manifest_handlers/automation.h"
7 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
8 #include "chrome/grit/generated_resources.h"
9 #include "extensions/common/error_utils.h"
10 #include "extensions/common/manifest_constants.h"
11 #include "extensions/common/permissions/permission_message_test_util.h"
12 #include "extensions/common/permissions/permissions_data.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace extensions {
18 class AutomationManifestTest : public ChromeManifestTest {
19 public:
20 AutomationManifestTest() : channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
22 protected:
23 AutomationInfo* GetAutomationInfo(scoped_refptr<Extension> extension) {
24 return static_cast<AutomationInfo*>(
25 extension->GetManifestData(manifest_keys::kAutomation));
28 private:
29 ScopedCurrentChannel channel_;
32 TEST_F(AutomationManifestTest, AsBooleanFalse) {
33 scoped_refptr<Extension> extension =
34 LoadAndExpectSuccess("automation_boolean_false.json");
35 ASSERT_TRUE(extension.get());
37 EXPECT_TRUE(VerifyNoPermissionMessages(extension->permissions_data()));
39 const AutomationInfo* info = AutomationInfo::Get(extension.get());
40 ASSERT_FALSE(info);
43 TEST_F(AutomationManifestTest, AsBooleanTrue) {
44 scoped_refptr<Extension> extension =
45 LoadAndExpectSuccess("automation_boolean_true.json");
46 ASSERT_TRUE(extension.get());
48 EXPECT_TRUE(VerifyOnePermissionMessage(
49 extension->permissions_data(),
50 "Read and change your data on www.google.com"));
52 const AutomationInfo* info = AutomationInfo::Get(extension.get());
53 ASSERT_TRUE(info);
55 EXPECT_FALSE(info->desktop);
56 EXPECT_FALSE(info->interact);
57 EXPECT_TRUE(info->matches.is_empty());
60 TEST_F(AutomationManifestTest, InteractTrue) {
61 scoped_refptr<Extension> extension =
62 LoadAndExpectSuccess("automation_interact_true.json");
63 ASSERT_TRUE(extension.get());
65 EXPECT_TRUE(VerifyOnePermissionMessage(
66 extension->permissions_data(),
67 "Read and change your data on www.google.com"));
69 const AutomationInfo* info = AutomationInfo::Get(extension.get());
70 ASSERT_TRUE(info);
72 EXPECT_FALSE(info->desktop);
73 EXPECT_TRUE(info->interact);
74 EXPECT_TRUE(info->matches.is_empty());
77 TEST_F(AutomationManifestTest, Matches) {
78 scoped_refptr<Extension> extension = LoadAndExpectWarning(
79 "automation_matches.json",
80 ErrorUtils::FormatErrorMessage(
81 automation_errors::kErrorInvalidMatch,
82 "www.badpattern.com",
83 URLPattern::GetParseResultString(
84 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR)));
85 ASSERT_TRUE(extension.get());
87 EXPECT_TRUE(VerifyOnePermissionMessage(
88 extension->permissions_data(),
89 "Read your data on www.google.com and www.twitter.com"));
91 const AutomationInfo* info = AutomationInfo::Get(extension.get());
92 ASSERT_TRUE(info);
94 EXPECT_FALSE(info->desktop);
95 EXPECT_FALSE(info->interact);
96 EXPECT_FALSE(info->matches.is_empty());
98 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/")));
99 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com")));
100 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/")));
101 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com")));
103 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com/")));
104 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com")));
107 TEST_F(AutomationManifestTest, MatchesAndPermissions) {
108 scoped_refptr<Extension> extension =
109 LoadAndExpectSuccess("automation_matches_and_permissions.json");
110 ASSERT_TRUE(extension.get());
112 EXPECT_TRUE(
113 VerifyTwoPermissionMessages(extension->permissions_data(),
114 "Read and change your data on www.google.com",
115 "Read your data on www.twitter.com", false));
117 const AutomationInfo* info = AutomationInfo::Get(extension.get());
118 ASSERT_TRUE(info);
120 EXPECT_FALSE(info->desktop);
121 EXPECT_FALSE(info->interact);
122 EXPECT_FALSE(info->matches.is_empty());
124 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/")));
125 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com")));
128 TEST_F(AutomationManifestTest, EmptyMatches) {
129 scoped_refptr<Extension> extension =
130 LoadAndExpectWarning("automation_empty_matches.json",
131 automation_errors::kErrorNoMatchesProvided);
132 ASSERT_TRUE(extension.get());
134 EXPECT_TRUE(VerifyNoPermissionMessages(extension->permissions_data()));
136 const AutomationInfo* info = AutomationInfo::Get(extension.get());
137 ASSERT_TRUE(info);
139 EXPECT_FALSE(info->desktop);
140 EXPECT_FALSE(info->interact);
141 EXPECT_TRUE(info->matches.is_empty());
144 TEST_F(AutomationManifestTest, NoValidMatches) {
145 std::string error;
146 scoped_refptr<Extension> extension =
147 LoadExtension(ManifestData("automation_no_valid_matches.json"), &error);
148 ASSERT_TRUE(extension.get());
149 EXPECT_EQ("", error);
150 EXPECT_EQ(2u, extension->install_warnings().size());
151 EXPECT_EQ(ErrorUtils::FormatErrorMessage(
152 automation_errors::kErrorInvalidMatch,
153 "www.badpattern.com",
154 URLPattern::GetParseResultString(
155 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR)),
156 extension->install_warnings()[0].message);
157 EXPECT_EQ(automation_errors::kErrorNoMatchesProvided,
158 extension->install_warnings()[1].message);
160 EXPECT_TRUE(VerifyNoPermissionMessages(extension->permissions_data()));
162 const AutomationInfo* info = AutomationInfo::Get(extension.get());
163 ASSERT_TRUE(info);
165 EXPECT_FALSE(info->desktop);
166 EXPECT_FALSE(info->interact);
167 EXPECT_TRUE(info->matches.is_empty());
170 TEST_F(AutomationManifestTest, DesktopFalse) {
171 scoped_refptr<Extension> extension =
172 LoadAndExpectSuccess("automation_desktop_false.json");
173 ASSERT_TRUE(extension.get());
175 EXPECT_TRUE(VerifyOnePermissionMessage(
176 extension->permissions_data(),
177 "Read and change your data on www.google.com"));
179 const AutomationInfo* info = AutomationInfo::Get(extension.get());
180 ASSERT_TRUE(info);
182 EXPECT_FALSE(info->desktop);
183 EXPECT_FALSE(info->interact);
184 EXPECT_TRUE(info->matches.is_empty());
187 TEST_F(AutomationManifestTest, DesktopTrue) {
188 scoped_refptr<Extension> extension =
189 LoadAndExpectSuccess("automation_desktop_true.json");
190 ASSERT_TRUE(extension.get());
192 EXPECT_TRUE(VerifyOnePermissionMessage(
193 extension->permissions_data(),
194 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS)));
196 const AutomationInfo* info = AutomationInfo::Get(extension.get());
197 ASSERT_TRUE(info);
199 EXPECT_TRUE(info->desktop);
200 EXPECT_TRUE(info->interact);
201 EXPECT_TRUE(info->matches.is_empty());
204 TEST_F(AutomationManifestTest, Desktop_InteractTrue) {
205 scoped_refptr<Extension> extension =
206 LoadAndExpectSuccess("automation_desktop_interact_true.json");
207 ASSERT_TRUE(extension.get());
209 EXPECT_TRUE(VerifyOnePermissionMessage(
210 extension->permissions_data(),
211 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS)));
213 const AutomationInfo* info = AutomationInfo::Get(extension.get());
214 ASSERT_TRUE(info);
216 EXPECT_TRUE(info->desktop);
217 EXPECT_TRUE(info->interact);
218 EXPECT_TRUE(info->matches.is_empty());
221 TEST_F(AutomationManifestTest, Desktop_InteractFalse) {
222 scoped_refptr<Extension> extension =
223 LoadAndExpectWarning("automation_desktop_interact_false.json",
224 automation_errors::kErrorDesktopTrueInteractFalse);
225 ASSERT_TRUE(extension.get());
227 EXPECT_TRUE(VerifyOnePermissionMessage(
228 extension->permissions_data(),
229 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS)));
231 const AutomationInfo* info = AutomationInfo::Get(extension.get());
232 ASSERT_TRUE(info);
234 EXPECT_TRUE(info->desktop);
235 EXPECT_TRUE(info->interact);
236 EXPECT_TRUE(info->matches.is_empty());
239 TEST_F(AutomationManifestTest, Desktop_MatchesSpecified) {
240 scoped_refptr<Extension> extension = LoadAndExpectWarning(
241 "automation_desktop_matches_specified.json",
242 automation_errors::kErrorDesktopTrueMatchesSpecified);
243 ASSERT_TRUE(extension.get());
245 EXPECT_TRUE(VerifyOnePermissionMessage(
246 extension->permissions_data(),
247 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS)));
249 const AutomationInfo* info = AutomationInfo::Get(extension.get());
250 ASSERT_TRUE(info);
252 EXPECT_TRUE(info->desktop);
253 EXPECT_TRUE(info->interact);
254 EXPECT_TRUE(info->matches.is_empty());
257 TEST_F(AutomationManifestTest, AllHostsInteractFalse) {
258 scoped_refptr<Extension> extension =
259 LoadAndExpectSuccess("automation_all_hosts_interact_false.json");
260 ASSERT_TRUE(extension.get());
262 EXPECT_TRUE(VerifyOnePermissionMessage(
263 extension->permissions_data(),
264 l10n_util::GetStringUTF16(
265 IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS_READ_ONLY)));
267 const AutomationInfo* info = AutomationInfo::Get(extension.get());
268 ASSERT_TRUE(info);
270 EXPECT_FALSE(info->desktop);
271 EXPECT_FALSE(info->interact);
272 EXPECT_FALSE(info->matches.is_empty());
273 EXPECT_TRUE(info->matches.MatchesAllURLs());
276 TEST_F(AutomationManifestTest, AllHostsInteractTrue) {
277 scoped_refptr<Extension> extension =
278 LoadAndExpectSuccess("automation_all_hosts_interact_true.json");
279 ASSERT_TRUE(extension.get());
281 EXPECT_TRUE(VerifyOnePermissionMessage(
282 extension->permissions_data(),
283 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS)));
285 const AutomationInfo* info = AutomationInfo::Get(extension.get());
286 ASSERT_TRUE(info);
288 EXPECT_FALSE(info->desktop);
289 EXPECT_TRUE(info->interact);
290 EXPECT_FALSE(info->matches.is_empty());
291 EXPECT_TRUE(info->matches.MatchesAllURLs());
293 } // namespace extensions