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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // problematic functionality. These tests are prefixed with AntiTest_ and will | 46 // problematic functionality. These tests are prefixed with AntiTest_ and will |
47 // be changed as the correct behaviour is implemented. TODOs in the test explain | 47 // be changed as the correct behaviour is implemented. TODOs in the test explain |
48 // the currently problematic behaviour. | 48 // the currently problematic behaviour. |
49 class PermissionMessagesUnittest : public testing::Test { | 49 class PermissionMessagesUnittest : public testing::Test { |
50 public: | 50 public: |
51 PermissionMessagesUnittest() | 51 PermissionMessagesUnittest() |
52 : message_provider_(new ChromePermissionMessageProvider()) {} | 52 : message_provider_(new ChromePermissionMessageProvider()) {} |
53 ~PermissionMessagesUnittest() override {} | 53 ~PermissionMessagesUnittest() override {} |
54 | 54 |
55 protected: | 55 protected: |
56 void CreateAndInstallAppWithPermissions(ListBuilder required_permissions, | |
57 ListBuilder optional_permissions) { | |
58 app_ = test_util::BuildApp(ExtensionBuilder()) | |
59 .MergeManifest( | |
60 DictionaryBuilder() | |
61 .Set("permissions", std::move(required_permissions)) | |
62 .Set("optional_permissions", | |
63 std::move(optional_permissions))) | |
64 .SetID(crx_file::id_util::GenerateId("app")) | |
65 .SetLocation(Manifest::INTERNAL) | |
66 .Build(); | |
67 env_.GetExtensionService()->AddExtension(app_.get()); | |
68 } | |
69 | |
70 void CreateAndInstallExtensionWithPermissions( | 56 void CreateAndInstallExtensionWithPermissions( |
71 ListBuilder required_permissions, | 57 scoped_ptr<base::ListValue> required_permissions, |
72 ListBuilder optional_permissions) { | 58 scoped_ptr<base::ListValue> optional_permissions) { |
73 app_ = test_util::BuildExtension(ExtensionBuilder()) | 59 app_ = test_util::BuildExtension(ExtensionBuilder()) |
74 .MergeManifest( | 60 .MergeManifest( |
75 DictionaryBuilder() | 61 DictionaryBuilder() |
76 .Set("permissions", std::move(required_permissions)) | 62 .Set("permissions", std::move(required_permissions)) |
77 .Set("optional_permissions", | 63 .Set("optional_permissions", |
78 std::move(optional_permissions))) | 64 std::move(optional_permissions)) |
| 65 .Build()) |
79 .SetID(crx_file::id_util::GenerateId("extension")) | 66 .SetID(crx_file::id_util::GenerateId("extension")) |
80 .SetLocation(Manifest::INTERNAL) | 67 .SetLocation(Manifest::INTERNAL) |
81 .Build(); | 68 .Build(); |
82 env_.GetExtensionService()->AddExtension(app_.get()); | 69 env_.GetExtensionService()->AddExtension(app_.get()); |
83 } | 70 } |
84 | 71 |
85 // Returns the permission messages that would display in the prompt that | 72 // Returns the permission messages that would display in the prompt that |
86 // requests all the optional permissions for the current |app_|. | 73 // requests all the optional permissions for the current |app_|. |
87 std::vector<base::string16> GetOptionalPermissionMessages() { | 74 std::vector<base::string16> GetOptionalPermissionMessages() { |
88 scoped_ptr<const PermissionSet> granted_permissions = | 75 scoped_ptr<const PermissionSet> granted_permissions = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 scoped_ptr<ChromePermissionMessageProvider> message_provider_; | 116 scoped_ptr<ChromePermissionMessageProvider> message_provider_; |
130 scoped_refptr<const Extension> app_; | 117 scoped_refptr<const Extension> app_; |
131 | 118 |
132 DISALLOW_COPY_AND_ASSIGN(PermissionMessagesUnittest); | 119 DISALLOW_COPY_AND_ASSIGN(PermissionMessagesUnittest); |
133 }; | 120 }; |
134 | 121 |
135 // If an app has both the 'history' and 'tabs' permission, one should hide the | 122 // If an app has both the 'history' and 'tabs' permission, one should hide the |
136 // other (the 'history' permission has superset permissions). | 123 // other (the 'history' permission has superset permissions). |
137 TEST_F(PermissionMessagesUnittest, HistoryHidesTabsMessage) { | 124 TEST_F(PermissionMessagesUnittest, HistoryHidesTabsMessage) { |
138 CreateAndInstallExtensionWithPermissions( | 125 CreateAndInstallExtensionWithPermissions( |
139 std::move(ListBuilder().Append("tabs").Append("history")), ListBuilder()); | 126 ListBuilder().Append("tabs").Append("history").Build(), |
| 127 ListBuilder().Build()); |
140 | 128 |
141 ASSERT_EQ(1U, required_permissions().size()); | 129 ASSERT_EQ(1U, required_permissions().size()); |
142 EXPECT_EQ( | 130 EXPECT_EQ( |
143 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), | 131 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), |
144 required_permissions()[0]); | 132 required_permissions()[0]); |
145 | 133 |
146 ASSERT_EQ(0U, optional_permissions().size()); | 134 ASSERT_EQ(0U, optional_permissions().size()); |
147 } | 135 } |
148 | 136 |
149 // If an app requests the 'history' permission, but already has the 'tabs' | 137 // If an app requests the 'history' permission, but already has the 'tabs' |
150 // permission, only the new coalesced message is displayed. | 138 // permission, only the new coalesced message is displayed. |
151 TEST_F(PermissionMessagesUnittest, MixedPermissionMessagesCoalesceOnceGranted) { | 139 TEST_F(PermissionMessagesUnittest, MixedPermissionMessagesCoalesceOnceGranted) { |
152 CreateAndInstallExtensionWithPermissions( | 140 CreateAndInstallExtensionWithPermissions( |
153 std::move(ListBuilder().Append("tabs")), | 141 ListBuilder().Append("tabs").Build(), |
154 std::move(ListBuilder().Append("history"))); | 142 ListBuilder().Append("history").Build()); |
155 | 143 |
156 ASSERT_EQ(1U, required_permissions().size()); | 144 ASSERT_EQ(1U, required_permissions().size()); |
157 EXPECT_EQ( | 145 EXPECT_EQ( |
158 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), | 146 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
159 required_permissions()[0]); | 147 required_permissions()[0]); |
160 | 148 |
161 ASSERT_EQ(1U, optional_permissions().size()); | 149 ASSERT_EQ(1U, optional_permissions().size()); |
162 EXPECT_EQ( | 150 EXPECT_EQ( |
163 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), | 151 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), |
164 optional_permissions()[0]); | 152 optional_permissions()[0]); |
(...skipping 17 matching lines...) Expand all Loading... |
182 } | 170 } |
183 | 171 |
184 // AntiTest: This behavior should be changed and improved. | 172 // AntiTest: This behavior should be changed and improved. |
185 // If an app requests the 'tabs' permission but already has the 'history' | 173 // If an app requests the 'tabs' permission but already has the 'history' |
186 // permission, a prompt is displayed. However, no prompt should appear at all, | 174 // permission, a prompt is displayed. However, no prompt should appear at all, |
187 // since 'tabs' is a subset of 'history' and the final list of permissions are | 175 // since 'tabs' is a subset of 'history' and the final list of permissions are |
188 // not affected by this grant. | 176 // not affected by this grant. |
189 TEST_F(PermissionMessagesUnittest, | 177 TEST_F(PermissionMessagesUnittest, |
190 AntiTest_PromptCanRequestSubsetOfAlreadyGrantedPermissions) { | 178 AntiTest_PromptCanRequestSubsetOfAlreadyGrantedPermissions) { |
191 CreateAndInstallExtensionWithPermissions( | 179 CreateAndInstallExtensionWithPermissions( |
192 std::move(ListBuilder().Append("history")), | 180 ListBuilder().Append("history").Build(), |
193 std::move(ListBuilder().Append("tabs"))); | 181 ListBuilder().Append("tabs").Build()); |
194 | 182 |
195 ASSERT_EQ(1U, required_permissions().size()); | 183 ASSERT_EQ(1U, required_permissions().size()); |
196 EXPECT_EQ( | 184 EXPECT_EQ( |
197 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), | 185 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE), |
198 required_permissions()[0]); | 186 required_permissions()[0]); |
199 | 187 |
200 ASSERT_EQ(1U, optional_permissions().size()); | 188 ASSERT_EQ(1U, optional_permissions().size()); |
201 EXPECT_EQ( | 189 EXPECT_EQ( |
202 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), | 190 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
203 optional_permissions()[0]); | 191 optional_permissions()[0]); |
(...skipping 19 matching lines...) Expand all Loading... |
223 } | 211 } |
224 | 212 |
225 // AntiTest: This behavior should be changed and improved. | 213 // AntiTest: This behavior should be changed and improved. |
226 // If an app requests the 'sessions' permission, nothing is displayed in the | 214 // If an app requests the 'sessions' permission, nothing is displayed in the |
227 // permission request prompt. However, the required permissions for the app are | 215 // permission request prompt. However, the required permissions for the app are |
228 // actually modified, so the prompt *should* display a message to prevent this | 216 // actually modified, so the prompt *should* display a message to prevent this |
229 // permission from being granted for free. | 217 // permission from being granted for free. |
230 TEST_F(PermissionMessagesUnittest, | 218 TEST_F(PermissionMessagesUnittest, |
231 AntiTest_PromptCanBeEmptyButCausesChangeInPermissions) { | 219 AntiTest_PromptCanBeEmptyButCausesChangeInPermissions) { |
232 CreateAndInstallExtensionWithPermissions( | 220 CreateAndInstallExtensionWithPermissions( |
233 std::move(ListBuilder().Append("tabs")), | 221 ListBuilder().Append("tabs").Build(), |
234 std::move(ListBuilder().Append("sessions"))); | 222 ListBuilder().Append("sessions").Build()); |
235 | 223 |
236 ASSERT_EQ(1U, required_permissions().size()); | 224 ASSERT_EQ(1U, required_permissions().size()); |
237 EXPECT_EQ( | 225 EXPECT_EQ( |
238 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), | 226 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
239 required_permissions()[0]); | 227 required_permissions()[0]); |
240 | 228 |
241 ASSERT_EQ(0U, optional_permissions().size()); | 229 ASSERT_EQ(0U, optional_permissions().size()); |
242 | 230 |
243 ASSERT_EQ(1U, active_permissions().size()); | 231 ASSERT_EQ(1U, active_permissions().size()); |
244 EXPECT_EQ( | 232 EXPECT_EQ( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 ASSERT_EQ(1U, messages.size()); | 341 ASSERT_EQ(1U, messages.size()); |
354 EXPECT_EQ(base::ASCIIToUTF16(kMessage), messages.front().message()); | 342 EXPECT_EQ(base::ASCIIToUTF16(kMessage), messages.front().message()); |
355 const std::vector<base::string16>& submessages = | 343 const std::vector<base::string16>& submessages = |
356 messages.front().submessages(); | 344 messages.front().submessages(); |
357 ASSERT_EQ(arraysize(kDetails), submessages.size()); | 345 ASSERT_EQ(arraysize(kDetails), submessages.size()); |
358 for (size_t i = 0; i < submessages.size(); i++) | 346 for (size_t i = 0; i < submessages.size(); i++) |
359 EXPECT_EQ(base::ASCIIToUTF16(kDetails[i]), submessages[i]); | 347 EXPECT_EQ(base::ASCIIToUTF16(kDetails[i]), submessages[i]); |
360 } | 348 } |
361 | 349 |
362 } // namespace extensions | 350 } // namespace extensions |
OLD | NEW |