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" |
| 11 #include "grit/extensions_strings.h" |
| 12 #include "grit/generated_resources.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
11 | 15 |
12 namespace extensions { | 16 namespace extensions { |
13 | 17 |
14 class AutomationManifestTest : public ExtensionManifestTest { | 18 class AutomationManifestTest : public ExtensionManifestTest { |
15 public: | 19 public: |
16 AutomationManifestTest() : channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} | 20 AutomationManifestTest() : channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} |
17 | 21 |
18 protected: | 22 protected: |
19 AutomationInfo* GetAutomationInfo(scoped_refptr<Extension> extension) { | 23 AutomationInfo* GetAutomationInfo(scoped_refptr<Extension> extension) { |
20 return static_cast<AutomationInfo*>( | 24 return static_cast<AutomationInfo*>( |
21 extension->GetManifestData(manifest_keys::kAutomation)); | 25 extension->GetManifestData(manifest_keys::kAutomation)); |
22 } | 26 } |
23 | 27 |
24 private: | 28 private: |
25 ScopedCurrentChannel channel_; | 29 ScopedCurrentChannel channel_; |
26 }; | 30 }; |
27 | 31 |
28 TEST_F(AutomationManifestTest, AsBooleanFalse) { | 32 TEST_F(AutomationManifestTest, AsBooleanFalse) { |
29 scoped_refptr<Extension> extension = | 33 scoped_refptr<Extension> extension = |
30 LoadAndExpectSuccess("automation_boolean_false.json"); | 34 LoadAndExpectSuccess("automation_boolean_false.json"); |
31 ASSERT_TRUE(extension.get()); | 35 ASSERT_TRUE(extension.get()); |
32 | 36 |
| 37 std::vector<base::string16> warnings = |
| 38 extension->permissions_data()->GetPermissionMessageStrings(); |
| 39 EXPECT_EQ(0u, warnings.size()); |
| 40 |
33 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 41 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
34 ASSERT_FALSE(info); | 42 ASSERT_FALSE(info); |
35 } | 43 } |
36 | 44 |
37 TEST_F(AutomationManifestTest, AsBooleanTrue) { | 45 TEST_F(AutomationManifestTest, AsBooleanTrue) { |
38 scoped_refptr<Extension> extension = | 46 scoped_refptr<Extension> extension = |
39 LoadAndExpectSuccess("automation_boolean_true.json"); | 47 LoadAndExpectSuccess("automation_boolean_true.json"); |
40 ASSERT_TRUE(extension.get()); | 48 ASSERT_TRUE(extension.get()); |
41 | 49 |
| 50 std::vector<base::string16> warnings = |
| 51 extension->permissions_data()->GetPermissionMessageStrings(); |
| 52 ASSERT_EQ(1u, warnings.size()); |
| 53 EXPECT_EQ("Read and modify your data on www.google.com", |
| 54 base::UTF16ToUTF8(warnings[0])); |
| 55 |
42 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 56 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
43 ASSERT_TRUE(info); | 57 ASSERT_TRUE(info); |
44 | 58 |
45 EXPECT_FALSE(info->desktop); | 59 EXPECT_FALSE(info->desktop); |
46 EXPECT_FALSE(info->interact); | 60 EXPECT_FALSE(info->interact); |
47 EXPECT_FALSE(info->specified_matches); | |
48 EXPECT_TRUE(info->matches.is_empty()); | 61 EXPECT_TRUE(info->matches.is_empty()); |
49 } | 62 } |
50 | 63 |
51 TEST_F(AutomationManifestTest, InteractTrue) { | 64 TEST_F(AutomationManifestTest, InteractTrue) { |
52 scoped_refptr<Extension> extension = | 65 scoped_refptr<Extension> extension = |
53 LoadAndExpectSuccess("automation_interact_true.json"); | 66 LoadAndExpectSuccess("automation_interact_true.json"); |
54 ASSERT_TRUE(extension.get()); | 67 ASSERT_TRUE(extension.get()); |
55 | 68 |
| 69 std::vector<base::string16> warnings = |
| 70 extension->permissions_data()->GetPermissionMessageStrings(); |
| 71 ASSERT_EQ(1u, warnings.size()); |
| 72 EXPECT_EQ("Read and modify your data on www.google.com", |
| 73 base::UTF16ToUTF8(warnings[0])); |
| 74 |
56 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 75 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
57 ASSERT_TRUE(info); | 76 ASSERT_TRUE(info); |
58 | 77 |
59 EXPECT_FALSE(info->desktop); | 78 EXPECT_FALSE(info->desktop); |
60 EXPECT_TRUE(info->interact); | 79 EXPECT_TRUE(info->interact); |
61 EXPECT_FALSE(info->specified_matches); | |
62 EXPECT_TRUE(info->matches.is_empty()); | 80 EXPECT_TRUE(info->matches.is_empty()); |
63 } | 81 } |
64 | 82 |
65 TEST_F(AutomationManifestTest, Matches) { | 83 TEST_F(AutomationManifestTest, Matches) { |
66 scoped_refptr<Extension> extension = LoadAndExpectWarning( | 84 scoped_refptr<Extension> extension = LoadAndExpectWarning( |
67 "automation_matches.json", | 85 "automation_matches.json", |
68 ErrorUtils::FormatErrorMessage( | 86 ErrorUtils::FormatErrorMessage( |
69 automation_errors::kErrorInvalidMatch, | 87 automation_errors::kErrorInvalidMatch, |
70 "www.badpattern.com", | 88 "www.badpattern.com", |
71 URLPattern::GetParseResultString( | 89 URLPattern::GetParseResultString( |
72 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR))); | 90 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR))); |
73 ASSERT_TRUE(extension.get()); | 91 ASSERT_TRUE(extension.get()); |
74 | 92 |
| 93 std::vector<base::string16> warnings = |
| 94 extension->permissions_data()->GetPermissionMessageStrings(); |
| 95 ASSERT_EQ(1u, warnings.size()); |
| 96 EXPECT_EQ("Read and modify your data on www.google.com and www.twitter.com", |
| 97 base::UTF16ToUTF8(warnings[0])); |
| 98 |
75 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 99 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
76 ASSERT_TRUE(info); | 100 ASSERT_TRUE(info); |
77 | 101 |
78 EXPECT_FALSE(info->desktop); | 102 EXPECT_FALSE(info->desktop); |
79 EXPECT_FALSE(info->interact); | 103 EXPECT_FALSE(info->interact); |
80 EXPECT_TRUE(info->specified_matches); | |
81 EXPECT_FALSE(info->matches.is_empty()); | 104 EXPECT_FALSE(info->matches.is_empty()); |
82 | 105 |
83 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); | 106 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); |
84 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); | 107 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); |
85 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); | 108 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); |
86 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com"))); | 109 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com"))); |
87 | 110 |
88 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com/"))); | 111 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com/"))); |
89 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com"))); | 112 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://www.bing.com"))); |
90 } | 113 } |
91 | 114 |
| 115 TEST_F(AutomationManifestTest, MatchesAndPermissions) { |
| 116 scoped_refptr<Extension> extension = |
| 117 LoadAndExpectSuccess("automation_matches_and_permissions.json"); |
| 118 ASSERT_TRUE(extension.get()); |
| 119 |
| 120 std::vector<base::string16> warnings = |
| 121 extension->permissions_data()->GetPermissionMessageStrings(); |
| 122 ASSERT_EQ(2u, warnings.size()); |
| 123 EXPECT_EQ("Read and modify your data on www.google.com", |
| 124 base::UTF16ToUTF8(warnings[0])); |
| 125 EXPECT_EQ("Read and modify your data on www.twitter.com", |
| 126 base::UTF16ToUTF8(warnings[1])); |
| 127 |
| 128 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
| 129 ASSERT_TRUE(info); |
| 130 |
| 131 EXPECT_FALSE(info->desktop); |
| 132 EXPECT_FALSE(info->interact); |
| 133 EXPECT_FALSE(info->matches.is_empty()); |
| 134 |
| 135 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com/"))); |
| 136 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.twitter.com"))); |
| 137 } |
| 138 |
92 TEST_F(AutomationManifestTest, EmptyMatches) { | 139 TEST_F(AutomationManifestTest, EmptyMatches) { |
93 scoped_refptr<Extension> extension = | 140 scoped_refptr<Extension> extension = |
94 LoadAndExpectWarning("automation_empty_matches.json", | 141 LoadAndExpectWarning("automation_empty_matches.json", |
95 automation_errors::kErrorNoMatchesProvided); | 142 automation_errors::kErrorNoMatchesProvided); |
96 ASSERT_TRUE(extension.get()); | 143 ASSERT_TRUE(extension.get()); |
97 | 144 |
| 145 std::vector<base::string16> warnings = |
| 146 extension->permissions_data()->GetPermissionMessageStrings(); |
| 147 EXPECT_EQ(0u, warnings.size()); |
| 148 |
98 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 149 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
99 ASSERT_TRUE(info); | 150 ASSERT_TRUE(info); |
100 | 151 |
101 EXPECT_FALSE(info->desktop); | 152 EXPECT_FALSE(info->desktop); |
102 EXPECT_FALSE(info->interact); | 153 EXPECT_FALSE(info->interact); |
103 EXPECT_TRUE(info->specified_matches); | |
104 EXPECT_TRUE(info->matches.is_empty()); | 154 EXPECT_TRUE(info->matches.is_empty()); |
105 } | 155 } |
106 | 156 |
107 TEST_F(AutomationManifestTest, NoValidMatches) { | 157 TEST_F(AutomationManifestTest, NoValidMatches) { |
108 std::string error; | 158 std::string error; |
109 scoped_refptr<Extension> extension = | 159 scoped_refptr<Extension> extension = |
110 LoadExtension(Manifest("automation_no_valid_matches.json"), &error); | 160 LoadExtension(Manifest("automation_no_valid_matches.json"), &error); |
111 ASSERT_TRUE(extension.get()); | 161 ASSERT_TRUE(extension.get()); |
112 EXPECT_EQ("", error); | 162 EXPECT_EQ("", error); |
113 EXPECT_EQ(2u, extension->install_warnings().size()); | 163 EXPECT_EQ(2u, extension->install_warnings().size()); |
114 EXPECT_EQ(ErrorUtils::FormatErrorMessage( | 164 EXPECT_EQ(ErrorUtils::FormatErrorMessage( |
115 automation_errors::kErrorInvalidMatch, | 165 automation_errors::kErrorInvalidMatch, |
116 "www.badpattern.com", | 166 "www.badpattern.com", |
117 URLPattern::GetParseResultString( | 167 URLPattern::GetParseResultString( |
118 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR)), | 168 URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR)), |
119 extension->install_warnings()[0].message); | 169 extension->install_warnings()[0].message); |
120 EXPECT_EQ(automation_errors::kErrorNoMatchesProvided, | 170 EXPECT_EQ(automation_errors::kErrorNoMatchesProvided, |
121 extension->install_warnings()[1].message); | 171 extension->install_warnings()[1].message); |
122 | 172 |
| 173 std::vector<base::string16> warnings = |
| 174 extension->permissions_data()->GetPermissionMessageStrings(); |
| 175 ASSERT_EQ(0u, warnings.size()); |
| 176 |
123 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 177 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
124 ASSERT_TRUE(info); | 178 ASSERT_TRUE(info); |
125 | 179 |
126 EXPECT_FALSE(info->desktop); | 180 EXPECT_FALSE(info->desktop); |
127 EXPECT_FALSE(info->interact); | 181 EXPECT_FALSE(info->interact); |
128 EXPECT_TRUE(info->specified_matches); | |
129 EXPECT_TRUE(info->matches.is_empty()); | 182 EXPECT_TRUE(info->matches.is_empty()); |
130 } | 183 } |
131 | 184 |
132 TEST_F(AutomationManifestTest, DesktopFalse) { | 185 TEST_F(AutomationManifestTest, DesktopFalse) { |
133 scoped_refptr<Extension> extension = | 186 scoped_refptr<Extension> extension = |
134 LoadAndExpectSuccess("automation_desktop_false.json"); | 187 LoadAndExpectSuccess("automation_desktop_false.json"); |
135 ASSERT_TRUE(extension.get()); | 188 ASSERT_TRUE(extension.get()); |
136 | 189 |
| 190 std::vector<base::string16> warnings = |
| 191 extension->permissions_data()->GetPermissionMessageStrings(); |
| 192 ASSERT_EQ(1u, warnings.size()); |
| 193 EXPECT_EQ("Read and modify your data on www.google.com", |
| 194 base::UTF16ToUTF8(warnings[0])); |
| 195 |
137 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 196 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
138 ASSERT_TRUE(info); | 197 ASSERT_TRUE(info); |
139 | 198 |
140 EXPECT_FALSE(info->desktop); | 199 EXPECT_FALSE(info->desktop); |
141 EXPECT_FALSE(info->interact); | 200 EXPECT_FALSE(info->interact); |
142 EXPECT_FALSE(info->specified_matches); | |
143 EXPECT_TRUE(info->matches.is_empty()); | 201 EXPECT_TRUE(info->matches.is_empty()); |
144 } | 202 } |
145 | 203 |
146 TEST_F(AutomationManifestTest, DesktopTrue) { | 204 TEST_F(AutomationManifestTest, DesktopTrue) { |
147 scoped_refptr<Extension> extension = | 205 scoped_refptr<Extension> extension = |
148 LoadAndExpectSuccess("automation_desktop_true.json"); | 206 LoadAndExpectSuccess("automation_desktop_true.json"); |
149 ASSERT_TRUE(extension.get()); | 207 ASSERT_TRUE(extension.get()); |
150 | 208 |
| 209 std::vector<base::string16> warnings = |
| 210 extension->permissions_data()->GetPermissionMessageStrings(); |
| 211 ASSERT_EQ(1u, warnings.size()); |
| 212 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS), |
| 213 warnings[0]); |
| 214 |
151 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 215 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
152 ASSERT_TRUE(info); | 216 ASSERT_TRUE(info); |
153 | 217 |
154 EXPECT_TRUE(info->desktop); | 218 EXPECT_TRUE(info->desktop); |
155 EXPECT_TRUE(info->interact); | 219 EXPECT_TRUE(info->interact); |
156 EXPECT_FALSE(info->specified_matches); | |
157 EXPECT_TRUE(info->matches.is_empty()); | 220 EXPECT_TRUE(info->matches.is_empty()); |
158 } | 221 } |
159 | 222 |
160 TEST_F(AutomationManifestTest, Desktop_InteractTrue) { | 223 TEST_F(AutomationManifestTest, Desktop_InteractTrue) { |
161 scoped_refptr<Extension> extension = | 224 scoped_refptr<Extension> extension = |
162 LoadAndExpectSuccess("automation_desktop_interact_true.json"); | 225 LoadAndExpectSuccess("automation_desktop_interact_true.json"); |
163 ASSERT_TRUE(extension.get()); | 226 ASSERT_TRUE(extension.get()); |
| 227 std::vector<base::string16> warnings = |
| 228 extension->permissions_data()->GetPermissionMessageStrings(); |
| 229 ASSERT_EQ(1u, warnings.size()); |
| 230 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS), |
| 231 warnings[0]); |
164 | 232 |
165 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 233 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
166 ASSERT_TRUE(info); | 234 ASSERT_TRUE(info); |
167 | 235 |
168 EXPECT_TRUE(info->desktop); | 236 EXPECT_TRUE(info->desktop); |
169 EXPECT_TRUE(info->interact); | 237 EXPECT_TRUE(info->interact); |
170 EXPECT_FALSE(info->specified_matches); | |
171 EXPECT_TRUE(info->matches.is_empty()); | 238 EXPECT_TRUE(info->matches.is_empty()); |
172 } | 239 } |
173 | 240 |
174 TEST_F(AutomationManifestTest, Desktop_InteractFalse) { | 241 TEST_F(AutomationManifestTest, Desktop_InteractFalse) { |
175 scoped_refptr<Extension> extension = | 242 scoped_refptr<Extension> extension = |
176 LoadAndExpectWarning("automation_desktop_interact_false.json", | 243 LoadAndExpectWarning("automation_desktop_interact_false.json", |
177 automation_errors::kErrorDesktopTrueInteractFalse); | 244 automation_errors::kErrorDesktopTrueInteractFalse); |
178 ASSERT_TRUE(extension.get()); | 245 ASSERT_TRUE(extension.get()); |
179 | 246 |
| 247 std::vector<base::string16> warnings = |
| 248 extension->permissions_data()->GetPermissionMessageStrings(); |
| 249 ASSERT_EQ(1u, warnings.size()); |
| 250 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS), |
| 251 warnings[0]); |
| 252 |
180 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 253 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
181 ASSERT_TRUE(info); | 254 ASSERT_TRUE(info); |
182 | 255 |
183 EXPECT_TRUE(info->desktop); | 256 EXPECT_TRUE(info->desktop); |
184 EXPECT_TRUE(info->interact); | 257 EXPECT_TRUE(info->interact); |
185 EXPECT_FALSE(info->specified_matches); | |
186 EXPECT_TRUE(info->matches.is_empty()); | 258 EXPECT_TRUE(info->matches.is_empty()); |
187 } | 259 } |
188 | 260 |
189 TEST_F(AutomationManifestTest, Desktop_MatchesSpecified) { | 261 TEST_F(AutomationManifestTest, Desktop_MatchesSpecified) { |
190 scoped_refptr<Extension> extension = LoadAndExpectWarning( | 262 scoped_refptr<Extension> extension = LoadAndExpectWarning( |
191 "automation_desktop_matches_specified.json", | 263 "automation_desktop_matches_specified.json", |
192 automation_errors::kErrorDesktopTrueMatchesSpecified); | 264 automation_errors::kErrorDesktopTrueMatchesSpecified); |
193 ASSERT_TRUE(extension.get()); | 265 ASSERT_TRUE(extension.get()); |
194 | 266 |
| 267 std::vector<base::string16> warnings = |
| 268 extension->permissions_data()->GetPermissionMessageStrings(); |
| 269 ASSERT_EQ(1u, warnings.size()); |
| 270 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS), |
| 271 warnings[0]); |
| 272 |
195 const AutomationInfo* info = AutomationInfo::Get(extension.get()); | 273 const AutomationInfo* info = AutomationInfo::Get(extension.get()); |
196 ASSERT_TRUE(info); | 274 ASSERT_TRUE(info); |
197 | 275 |
198 EXPECT_TRUE(info->desktop); | 276 EXPECT_TRUE(info->desktop); |
199 EXPECT_TRUE(info->interact); | 277 EXPECT_TRUE(info->interact); |
200 EXPECT_FALSE(info->specified_matches); | |
201 EXPECT_TRUE(info->matches.is_empty()); | 278 EXPECT_TRUE(info->matches.is_empty()); |
202 } | 279 } |
203 | 280 |
204 } // namespace extensions | 281 } // namespace extensions |
OLD | NEW |