OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/common/extensions/manifest_handlers/automation.h" | 6 #include "chrome/common/extensions/manifest_handlers/automation.h" |
7 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 7 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
8 #include "extensions/common/error_utils.h" | 8 #include "extensions/common/error_utils.h" |
9 #include "extensions/common/manifest_constants.h" | 9 #include "extensions/common/manifest_constants.h" |
10 #include "extensions/common/permissions/permissions_data.h" | 10 #include "extensions/common/permissions/permissions_data.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ErrorUtils::FormatErrorMessage( | 86 ErrorUtils::FormatErrorMessage( |
87 automation_errors::kErrorInvalidMatch, | 87 automation_errors::kErrorInvalidMatch, |
88 "www.badpattern.com", | 88 "www.badpattern.com", |
89 URLPattern::GetParseResultString( | 89 URLPattern::GetParseResultString( |
90 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR))); | 90 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR))); |
91 ASSERT_TRUE(extension.get()); | 91 ASSERT_TRUE(extension.get()); |
92 | 92 |
93 std::vector<base::string16> warnings = | 93 std::vector<base::string16> warnings = |
94 extension->permissions_data()->GetPermissionMessageStrings(); | 94 extension->permissions_data()->GetPermissionMessageStrings(); |
95 ASSERT_EQ(1u, warnings.size()); | 95 ASSERT_EQ(1u, warnings.size()); |
96 EXPECT_EQ("Read and modify your data on www.google.com and www.twitter.com", | 96 EXPECT_EQ("Read your data on www.google.com and www.twitter.com", |
97 base::UTF16ToUTF8(warnings[0])); | 97 base::UTF16ToUTF8(warnings[0])); |
98 | 98 |
99 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 99 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
100 ASSERT_TRUE(info); | 100 ASSERT_TRUE(info); |
101 | 101 |
102 EXPECT_FALSE(info->desktop); | 102 EXPECT_FALSE(info->desktop); |
103 EXPECT_FALSE(info->interact); | 103 EXPECT_FALSE(info->interact); |
104 EXPECT_FALSE(info->matches.is_empty()); | 104 EXPECT_FALSE(info->matches.is_empty()); |
105 | 105 |
106 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); | 106 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); |
107 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); | 107 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); |
108 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); | 108 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); |
109 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com"))); | 109 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com"))); |
110 | 110 |
111 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com/"))); | 111 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com/"))); |
112 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com"))); | 112 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com"))); |
113 } | 113 } |
114 | 114 |
115 TEST_F(AutomationManifestTest, MatchesAndPermissions) { | 115 TEST_F(AutomationManifestTest, MatchesAndPermissions) { |
116 scoped_refptr<Extension> extension = | 116 scoped_refptr<Extension> extension = |
117 LoadAndExpectSuccess("automation_matches_and_permissions.json"); | 117 LoadAndExpectSuccess("automation_matches_and_permissions.json"); |
118 ASSERT_TRUE(extension.get()); | 118 ASSERT_TRUE(extension.get()); |
119 | 119 |
120 std::vector<base::string16> warnings = | 120 std::vector<base::string16> warnings = |
121 extension->permissions_data()->GetPermissionMessageStrings(); | 121 extension->permissions_data()->GetPermissionMessageStrings(); |
122 ASSERT_EQ(2u, warnings.size()); | 122 ASSERT_EQ(2u, warnings.size()); |
123 EXPECT_EQ("Read and modify your data on www.google.com", | 123 EXPECT_EQ("Read and modify your data on www.google.com", |
124 base::UTF16ToUTF8(warnings[0])); | 124 base::UTF16ToUTF8(warnings[0])); |
125 EXPECT_EQ("Read and modify your data on www.twitter.com", | 125 EXPECT_EQ("Read your data on www.twitter.com", |
126 base::UTF16ToUTF8(warnings[1])); | 126 base::UTF16ToUTF8(warnings[1])); |
127 | 127 |
128 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 128 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
129 ASSERT_TRUE(info); | 129 ASSERT_TRUE(info); |
130 | 130 |
131 EXPECT_FALSE(info->desktop); | 131 EXPECT_FALSE(info->desktop); |
132 EXPECT_FALSE(info->interact); | 132 EXPECT_FALSE(info->interact); |
133 EXPECT_FALSE(info->matches.is_empty()); | 133 EXPECT_FALSE(info->matches.is_empty()); |
134 | 134 |
135 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); | 135 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 warnings[0]); | 271 warnings[0]); |
272 | 272 |
273 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 273 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
274 ASSERT_TRUE(info); | 274 ASSERT_TRUE(info); |
275 | 275 |
276 EXPECT_TRUE(info->desktop); | 276 EXPECT_TRUE(info->desktop); |
277 EXPECT_TRUE(info->interact); | 277 EXPECT_TRUE(info->interact); |
278 EXPECT_TRUE(info->matches.is_empty()); | 278 EXPECT_TRUE(info->matches.is_empty()); |
279 } | 279 } |
280 | 280 |
| 281 TEST_F(AutomationManifestTest, AllHostsInteractFalse) { |
| 282 scoped_refptr<Extension> extension = |
| 283 LoadAndExpectSuccess("automation_all_hosts_interact_false.json"); |
| 284 ASSERT_TRUE(extension.get()); |
| 285 |
| 286 std::vector<base::string16> warnings = |
| 287 extension->permissions_data()->GetPermissionMessageStrings(); |
| 288 ASSERT_EQ(1u, warnings.size()); |
| 289 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 290 IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS_READ_ONLY), |
| 291 warnings[0]); |
| 292 |
| 293 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
| 294 ASSERT_TRUE(info); |
| 295 |
| 296 EXPECT_FALSE(info->desktop); |
| 297 EXPECT_FALSE(info->interact); |
| 298 EXPECT_FALSE(info->matches.is_empty()); |
| 299 EXPECT_TRUE(info->matches.MatchesAllURLs()); |
| 300 } |
| 301 |
| 302 TEST_F(AutomationManifestTest, AllHostsInteractTrue) { |
| 303 scoped_refptr<Extension> extension = |
| 304 LoadAndExpectSuccess("automation_all_hosts_interact_true.json"); |
| 305 ASSERT_TRUE(extension.get()); |
| 306 |
| 307 std::vector<base::string16> warnings = |
| 308 extension->permissions_data()->GetPermissionMessageStrings(); |
| 309 ASSERT_EQ(1u, warnings.size()); |
| 310 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS), |
| 311 warnings[0]); |
| 312 |
| 313 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
| 314 ASSERT_TRUE(info); |
| 315 |
| 316 EXPECT_FALSE(info->desktop); |
| 317 EXPECT_TRUE(info->interact); |
| 318 EXPECT_FALSE(info->matches.is_empty()); |
| 319 EXPECT_TRUE(info->matches.MatchesAllURLs()); |
| 320 } |
281 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |