Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: chrome/browser/extensions/api/file_system/consent_provider_unittest.cc

Issue 2934143002: Move chrome.fileSystem implementation to //extensions (Closed)
Patch Set: benwells, test fix Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/extensions/api/file_system/consent_provider.h" 5 #include "chrome/browser/extensions/api/file_system/consent_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 whitelisted_component_id_ = extension_id; 53 whitelisted_component_id_ = extension_id;
54 } 54 }
55 55
56 int show_dialog_counter() const { return show_dialog_counter_; } 56 int show_dialog_counter() const { return show_dialog_counter_; }
57 int show_notification_counter() const { return show_notification_counter_; } 57 int show_notification_counter() const { return show_notification_counter_; }
58 58
59 private: 59 private:
60 // ConsentProvider::DelegateInterface overrides: 60 // ConsentProvider::DelegateInterface overrides:
61 void ShowDialog( 61 void ShowDialog(
62 const extensions::Extension& extension, 62 const extensions::Extension& extension,
63 content::RenderFrameHost* host,
63 const base::WeakPtr<Volume>& volume, 64 const base::WeakPtr<Volume>& volume,
64 bool writable, 65 bool writable,
65 const ConsentProvider::ShowDialogCallback& callback) override { 66 const ConsentProvider::ShowDialogCallback& callback) override {
66 ++show_dialog_counter_; 67 ++show_dialog_counter_;
67 callback.Run(dialog_button_); 68 callback.Run(dialog_button_);
68 } 69 }
69 70
70 void ShowNotification(const extensions::Extension& extension, 71 void ShowNotification(const extensions::Extension& extension,
71 const base::WeakPtr<Volume>& volume, 72 const base::WeakPtr<Volume>& volume,
72 bool writable) override { 73 bool writable) override {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 scoped_refptr<Extension> whitelisted_component_extension( 147 scoped_refptr<Extension> whitelisted_component_extension(
147 test_util::BuildApp( 148 test_util::BuildApp(
148 std::move(ExtensionBuilder().SetLocation(Manifest::COMPONENT))) 149 std::move(ExtensionBuilder().SetLocation(Manifest::COMPONENT)))
149 .Build()); 150 .Build());
150 TestingConsentProviderDelegate delegate; 151 TestingConsentProviderDelegate delegate;
151 delegate.SetComponentWhitelist(whitelisted_component_extension->id()); 152 delegate.SetComponentWhitelist(whitelisted_component_extension->id());
152 ConsentProvider provider(&delegate); 153 ConsentProvider provider(&delegate);
153 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension)); 154 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension));
154 155
155 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 156 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
156 provider.RequestConsent(*whitelisted_component_extension.get(), volume_, 157 provider.RequestConsent(*whitelisted_component_extension.get(), nullptr,
157 true /* writable */, 158 volume_, true /* writable */,
158 base::Bind(&OnConsentReceived, &result)); 159 base::Bind(&OnConsentReceived, &result));
159 base::RunLoop().RunUntilIdle(); 160 base::RunLoop().RunUntilIdle();
160 161
161 EXPECT_EQ(0, delegate.show_dialog_counter()); 162 EXPECT_EQ(0, delegate.show_dialog_counter());
162 EXPECT_EQ(0, delegate.show_notification_counter()); 163 EXPECT_EQ(0, delegate.show_notification_counter());
163 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 164 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
164 } 165 }
165 166
166 // Non-component apps in non-kiosk mode will be rejected instantly, without 167 // Non-component apps in non-kiosk mode will be rejected instantly, without
167 // asking for user consent. 168 // asking for user consent.
(...skipping 21 matching lines...) Expand all
189 AccountId::FromUserEmail(auto_launch_kiosk_app->id())); 190 AccountId::FromUserEmail(auto_launch_kiosk_app->id()));
190 user_manager_->LoginUser( 191 user_manager_->LoginUser(
191 AccountId::FromUserEmail(auto_launch_kiosk_app->id())); 192 AccountId::FromUserEmail(auto_launch_kiosk_app->id()));
192 193
193 TestingConsentProviderDelegate delegate; 194 TestingConsentProviderDelegate delegate;
194 delegate.SetIsAutoLaunched(true); 195 delegate.SetIsAutoLaunched(true);
195 ConsentProvider provider(&delegate); 196 ConsentProvider provider(&delegate);
196 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app)); 197 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app));
197 198
198 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 199 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
199 provider.RequestConsent(*auto_launch_kiosk_app.get(), volume_, 200 provider.RequestConsent(*auto_launch_kiosk_app.get(), nullptr, volume_,
200 true /* writable */, 201 true /* writable */,
201 base::Bind(&OnConsentReceived, &result)); 202 base::Bind(&OnConsentReceived, &result));
202 base::RunLoop().RunUntilIdle(); 203 base::RunLoop().RunUntilIdle();
203 204
204 EXPECT_EQ(0, delegate.show_dialog_counter()); 205 EXPECT_EQ(0, delegate.show_dialog_counter());
205 EXPECT_EQ(1, delegate.show_notification_counter()); 206 EXPECT_EQ(1, delegate.show_notification_counter());
206 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 207 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
207 } 208 }
208 209
209 // Non-component apps in manual-launch kiosk mode will be granted access after 210 // Non-component apps in manual-launch kiosk mode will be granted access after
210 // receiving approval from the user. 211 // receiving approval from the user.
211 scoped_refptr<Extension> manual_launch_kiosk_app( 212 scoped_refptr<Extension> manual_launch_kiosk_app(
212 test_util::BuildApp(ExtensionBuilder()) 213 test_util::BuildApp(ExtensionBuilder())
213 .MergeManifest(DictionaryBuilder() 214 .MergeManifest(DictionaryBuilder()
214 .SetBoolean("kiosk_enabled", true) 215 .SetBoolean("kiosk_enabled", true)
215 .SetBoolean("kiosk_only", true) 216 .SetBoolean("kiosk_only", true)
216 .Build()) 217 .Build())
217 .Build()); 218 .Build());
218 user_manager::User* const manual_kiosk_app_user = 219 user_manager::User* const manual_kiosk_app_user =
219 user_manager_->AddKioskAppUser( 220 user_manager_->AddKioskAppUser(
220 AccountId::FromUserEmail(manual_launch_kiosk_app->id())); 221 AccountId::FromUserEmail(manual_launch_kiosk_app->id()));
221 user_manager_->KioskAppLoggedIn(manual_kiosk_app_user); 222 user_manager_->KioskAppLoggedIn(manual_kiosk_app_user);
222 { 223 {
223 TestingConsentProviderDelegate delegate; 224 TestingConsentProviderDelegate delegate;
224 delegate.SetDialogButton(ui::DIALOG_BUTTON_OK); 225 delegate.SetDialogButton(ui::DIALOG_BUTTON_OK);
225 ConsentProvider provider(&delegate); 226 ConsentProvider provider(&delegate);
226 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 227 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
227 228
228 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 229 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
229 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_, 230 provider.RequestConsent(*manual_launch_kiosk_app.get(), nullptr, volume_,
230 true /* writable */, 231 true /* writable */,
231 base::Bind(&OnConsentReceived, &result)); 232 base::Bind(&OnConsentReceived, &result));
232 base::RunLoop().RunUntilIdle(); 233 base::RunLoop().RunUntilIdle();
233 234
234 EXPECT_EQ(1, delegate.show_dialog_counter()); 235 EXPECT_EQ(1, delegate.show_dialog_counter());
235 EXPECT_EQ(0, delegate.show_notification_counter()); 236 EXPECT_EQ(0, delegate.show_notification_counter());
236 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 237 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
237 } 238 }
238 239
239 // Non-component apps in manual-launch kiosk mode will be rejected access 240 // Non-component apps in manual-launch kiosk mode will be rejected access
240 // after rejecting by a user. 241 // after rejecting by a user.
241 { 242 {
242 TestingConsentProviderDelegate delegate; 243 TestingConsentProviderDelegate delegate;
243 ConsentProvider provider(&delegate); 244 ConsentProvider provider(&delegate);
244 delegate.SetDialogButton(ui::DIALOG_BUTTON_CANCEL); 245 delegate.SetDialogButton(ui::DIALOG_BUTTON_CANCEL);
245 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 246 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
246 247
247 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 248 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
248 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_, 249 provider.RequestConsent(*manual_launch_kiosk_app.get(), nullptr, volume_,
249 true /* writable */, 250 true /* writable */,
250 base::Bind(&OnConsentReceived, &result)); 251 base::Bind(&OnConsentReceived, &result));
251 base::RunLoop().RunUntilIdle(); 252 base::RunLoop().RunUntilIdle();
252 253
253 EXPECT_EQ(1, delegate.show_dialog_counter()); 254 EXPECT_EQ(1, delegate.show_dialog_counter());
254 EXPECT_EQ(0, delegate.show_notification_counter()); 255 EXPECT_EQ(0, delegate.show_notification_counter());
255 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 256 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
256 } 257 }
257 } 258 }
258 259
259 } // namespace extensions 260 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698