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

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

Issue 1032313002: Add a notification about auto-granted access to file systems. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Strings committed separately. Rebased. Created 5 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #else 78 #else
79 #define ToStringType 79 #define ToStringType
80 #endif 80 #endif
81 81
82 #if defined(OS_CHROMEOS) 82 #if defined(OS_CHROMEOS)
83 class TestingConsentProviderDelegate 83 class TestingConsentProviderDelegate
84 : public ConsentProvider::DelegateInterface { 84 : public ConsentProvider::DelegateInterface {
85 public: 85 public:
86 TestingConsentProviderDelegate() 86 TestingConsentProviderDelegate()
87 : show_dialog_counter_(0), 87 : show_dialog_counter_(0),
88 show_notification_counter_(0),
88 dialog_button_(ui::DIALOG_BUTTON_NONE), 89 dialog_button_(ui::DIALOG_BUTTON_NONE),
89 is_auto_launched_(false) {} 90 is_auto_launched_(false) {}
90 91
91 ~TestingConsentProviderDelegate() {} 92 ~TestingConsentProviderDelegate() {}
92 93
93 // Sets a fake dialog response. 94 // Sets a fake dialog response.
94 void SetDialogButton(ui::DialogButton button) { dialog_button_ = button; } 95 void SetDialogButton(ui::DialogButton button) { dialog_button_ = button; }
95 96
96 // Sets a fake result of detection the auto launch kiosk mode. 97 // Sets a fake result of detection the auto launch kiosk mode.
97 void SetIsAutoLaunched(bool is_auto_launched) { 98 void SetIsAutoLaunched(bool is_auto_launched) {
98 is_auto_launched_ = is_auto_launched; 99 is_auto_launched_ = is_auto_launched;
99 } 100 }
100 101
101 // Sets a whitelisted components list with a single id. 102 // Sets a whitelisted components list with a single id.
102 void SetComponentWhitelist(const std::string& extension_id) { 103 void SetComponentWhitelist(const std::string& extension_id) {
103 whitelisted_component_id_ = extension_id; 104 whitelisted_component_id_ = extension_id;
104 } 105 }
105 106
106 int show_dialog_counter() const { return show_dialog_counter_; } 107 int show_dialog_counter() const { return show_dialog_counter_; }
108 int show_notification_counter() const { return show_notification_counter_; }
107 109
108 private: 110 private:
109 // ConsentProvider::DelegateInterface overrides: 111 // ConsentProvider::DelegateInterface overrides:
110 void ShowDialog( 112 void ShowDialog(
111 const extensions::Extension& extension, 113 const extensions::Extension& extension,
112 base::WeakPtr<Volume> volume, 114 const base::WeakPtr<Volume>& volume,
113 bool writable, 115 bool writable,
114 const ConsentProvider::ShowDialogCallback& callback) override { 116 const ConsentProvider::ShowDialogCallback& callback) override {
115 ++show_dialog_counter_; 117 ++show_dialog_counter_;
116 callback.Run(dialog_button_); 118 callback.Run(dialog_button_);
117 } 119 }
118 120
121 void ShowNotification(const extensions::Extension& extension,
122 const base::WeakPtr<Volume>& volume,
123 bool writable) override {
124 ++show_notification_counter_;
125 }
126
119 bool IsAutoLaunched(const extensions::Extension& extension) override { 127 bool IsAutoLaunched(const extensions::Extension& extension) override {
120 return is_auto_launched_; 128 return is_auto_launched_;
121 } 129 }
122 130
123 bool IsWhitelistedComponent(const extensions::Extension& extension) override { 131 bool IsWhitelistedComponent(const extensions::Extension& extension) override {
124 return whitelisted_component_id_.compare(extension.id()) == 0; 132 return whitelisted_component_id_.compare(extension.id()) == 0;
125 } 133 }
126 134
127 int show_dialog_counter_; 135 int show_dialog_counter_;
136 int show_notification_counter_;
128 ui::DialogButton dialog_button_; 137 ui::DialogButton dialog_button_;
129 bool is_auto_launched_; 138 bool is_auto_launched_;
130 std::string whitelisted_component_id_; 139 std::string whitelisted_component_id_;
131 140
132 DISALLOW_COPY_AND_ASSIGN(TestingConsentProviderDelegate); 141 DISALLOW_COPY_AND_ASSIGN(TestingConsentProviderDelegate);
133 }; 142 };
134 143
135 // Rewrites result of a consent request from |result| to |log|. 144 // Rewrites result of a consent request from |result| to |log|.
136 void OnConsentReceived(ConsentProvider::Consent* log, 145 void OnConsentReceived(ConsentProvider::Consent* log,
137 const ConsentProvider::Consent result) { 146 const ConsentProvider::Consent result) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ConsentProvider provider(&delegate); 332 ConsentProvider provider(&delegate);
324 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension)); 333 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension));
325 334
326 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 335 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
327 provider.RequestConsent(*whitelisted_component_extension.get(), volume_, 336 provider.RequestConsent(*whitelisted_component_extension.get(), volume_,
328 true /* writable */, 337 true /* writable */,
329 base::Bind(&OnConsentReceived, &result)); 338 base::Bind(&OnConsentReceived, &result));
330 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
331 340
332 EXPECT_EQ(0, delegate.show_dialog_counter()); 341 EXPECT_EQ(0, delegate.show_dialog_counter());
342 EXPECT_EQ(0, delegate.show_notification_counter());
333 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 343 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
334 } 344 }
335 345
336 // Non-component apps in non-kiosk mode will be rejected instantly, without 346 // Non-component apps in non-kiosk mode will be rejected instantly, without
337 // asking for user consent. 347 // asking for user consent.
338 { 348 {
339 scoped_refptr<Extension> non_component_extension( 349 scoped_refptr<Extension> non_component_extension(
340 test_util::CreateEmptyExtension()); 350 test_util::CreateEmptyExtension());
341 TestingConsentProviderDelegate delegate; 351 TestingConsentProviderDelegate delegate;
342 ConsentProvider provider(&delegate); 352 ConsentProvider provider(&delegate);
343 EXPECT_FALSE(provider.IsGrantable(*non_component_extension)); 353 EXPECT_FALSE(provider.IsGrantable(*non_component_extension));
344 } 354 }
345 } 355 }
346 356
347 TEST_F(FileSystemApiConsentProviderTest, ForKioskApps) { 357 TEST_F(FileSystemApiConsentProviderTest, ForKioskApps) {
348 // Non-component apps in auto-launch kiosk mode will be granted access 358 // Non-component apps in auto-launch kiosk mode will be granted access
349 // instantly without asking for user consent. 359 // instantly without asking for user consent, but with a notification.
350 { 360 {
351 scoped_refptr<Extension> auto_launch_kiosk_app( 361 scoped_refptr<Extension> auto_launch_kiosk_app(
352 test_util::BuildApp(ExtensionBuilder().Pass()) 362 test_util::BuildApp(ExtensionBuilder().Pass())
353 .MergeManifest(DictionaryBuilder() 363 .MergeManifest(DictionaryBuilder()
354 .SetBoolean("kiosk_enabled", true) 364 .SetBoolean("kiosk_enabled", true)
355 .SetBoolean("kiosk_only", true)) 365 .SetBoolean("kiosk_only", true))
356 .Build()); 366 .Build());
357 user_manager_->AddKioskAppUser(auto_launch_kiosk_app->id()); 367 user_manager_->AddKioskAppUser(auto_launch_kiosk_app->id());
358 user_manager_->LoginUser(auto_launch_kiosk_app->id()); 368 user_manager_->LoginUser(auto_launch_kiosk_app->id());
359 369
360 TestingConsentProviderDelegate delegate; 370 TestingConsentProviderDelegate delegate;
361 delegate.SetIsAutoLaunched(true); 371 delegate.SetIsAutoLaunched(true);
362 ConsentProvider provider(&delegate); 372 ConsentProvider provider(&delegate);
363 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app)); 373 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app));
364 374
365 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 375 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
366 provider.RequestConsent(*auto_launch_kiosk_app.get(), volume_, 376 provider.RequestConsent(*auto_launch_kiosk_app.get(), volume_,
367 true /* writable */, 377 true /* writable */,
368 base::Bind(&OnConsentReceived, &result)); 378 base::Bind(&OnConsentReceived, &result));
369 base::RunLoop().RunUntilIdle(); 379 base::RunLoop().RunUntilIdle();
370 380
371 EXPECT_EQ(0, delegate.show_dialog_counter()); 381 EXPECT_EQ(0, delegate.show_dialog_counter());
382 EXPECT_EQ(1, delegate.show_notification_counter());
372 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 383 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
373 } 384 }
374 385
375 // Non-component apps in manual-launch kiosk mode will be granted access after 386 // Non-component apps in manual-launch kiosk mode will be granted access after
376 // receiving approval from the user. 387 // receiving approval from the user.
377 scoped_refptr<Extension> manual_launch_kiosk_app( 388 scoped_refptr<Extension> manual_launch_kiosk_app(
378 test_util::BuildApp(ExtensionBuilder().Pass()) 389 test_util::BuildApp(ExtensionBuilder().Pass())
379 .MergeManifest(DictionaryBuilder() 390 .MergeManifest(DictionaryBuilder()
380 .SetBoolean("kiosk_enabled", true) 391 .SetBoolean("kiosk_enabled", true)
381 .SetBoolean("kiosk_only", true)) 392 .SetBoolean("kiosk_only", true))
382 .Build()); 393 .Build());
383 user_manager_->KioskAppLoggedIn(manual_launch_kiosk_app->id()); 394 user_manager_->KioskAppLoggedIn(manual_launch_kiosk_app->id());
384 { 395 {
385 TestingConsentProviderDelegate delegate; 396 TestingConsentProviderDelegate delegate;
386 delegate.SetDialogButton(ui::DIALOG_BUTTON_OK); 397 delegate.SetDialogButton(ui::DIALOG_BUTTON_OK);
387 ConsentProvider provider(&delegate); 398 ConsentProvider provider(&delegate);
388 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 399 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
389 400
390 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 401 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
391 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_, 402 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_,
392 true /* writable */, 403 true /* writable */,
393 base::Bind(&OnConsentReceived, &result)); 404 base::Bind(&OnConsentReceived, &result));
394 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
395 406
396 EXPECT_EQ(1, delegate.show_dialog_counter()); 407 EXPECT_EQ(1, delegate.show_dialog_counter());
408 EXPECT_EQ(0, delegate.show_notification_counter());
397 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 409 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
398 } 410 }
399 411
400 // Non-component apps in manual-launch kiosk mode will be rejected access 412 // Non-component apps in manual-launch kiosk mode will be rejected access
401 // after rejecting by a user. 413 // after rejecting by a user.
402 { 414 {
403 TestingConsentProviderDelegate delegate; 415 TestingConsentProviderDelegate delegate;
404 ConsentProvider provider(&delegate); 416 ConsentProvider provider(&delegate);
405 delegate.SetDialogButton(ui::DIALOG_BUTTON_CANCEL); 417 delegate.SetDialogButton(ui::DIALOG_BUTTON_CANCEL);
406 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 418 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
407 419
408 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 420 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
409 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_, 421 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_,
410 true /* writable */, 422 true /* writable */,
411 base::Bind(&OnConsentReceived, &result)); 423 base::Bind(&OnConsentReceived, &result));
412 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
413 425
414 EXPECT_EQ(1, delegate.show_dialog_counter()); 426 EXPECT_EQ(1, delegate.show_dialog_counter());
427 EXPECT_EQ(0, delegate.show_notification_counter());
415 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 428 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
416 } 429 }
417 } 430 }
418 #endif 431 #endif
419 432
420 } // namespace extensions 433 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698