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

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: Created 5 years, 9 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #if defined(OS_WIN) 75 #if defined(OS_WIN)
76 #define ToStringType base::UTF8ToWide 76 #define ToStringType base::UTF8ToWide
77 #else 77 #else
78 #define ToStringType 78 #define ToStringType
79 #endif 79 #endif
80 80
81 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
82 // Registers a request for a user consent by incrementing the counter. 82 // Registers a request for a user consent by incrementing the counter.
83 // Additionally simulates completing the user consent request with the 83 // Additionally simulates completing the user consent request with the
84 // |response| result. 84 // |response| result.
85 void OnUserConsentRequested(int* counter, 85 void OnAskUser(int* counter,
86 const ConsentProvider::Consent response, 86 const ConsentProvider::Consent response,
87 const VolumeInfo& volume_info, 87 const VolumeInfo& volume_info,
88 bool writable, 88 bool writable,
89 const ConsentProvider::ConsentCallback& callback) { 89 const ConsentProvider::ConsentCallback& callback) {
90 (*counter)++; 90 (*counter)++;
91 callback.Run(response); 91 callback.Run(response);
92 } 92 }
93 93
94 // Registers user notifications about auto-granting permissions.
95 void OnNotifyUser(int* counter, const VolumeInfo& volume_info, bool writable) {
96 (*counter)++;
97 }
98
94 // Rewrites result of a consent request from |result| to |log|. 99 // Rewrites result of a consent request from |result| to |log|.
95 void OnConsentReceived(ConsentProvider::Consent* log, 100 void OnConsentReceived(ConsentProvider::Consent* log,
96 const ConsentProvider::Consent result) { 101 const ConsentProvider::Consent result) {
97 *log = result; 102 *log = result;
98 } 103 }
99 104
100 // Returns a fake value whether an extension is auto launched or not. 105 // Returns a fake value whether an extension is auto launched or not.
101 bool OnIsAutoLaunched(bool response, const Extension& extension) { 106 bool OnIsAutoLaunched(bool response, const Extension& extension) {
102 return response; 107 return response;
103 } 108 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 #endif 269 #endif
265 } 270 }
266 271
267 #if defined(OS_CHROMEOS) 272 #if defined(OS_CHROMEOS)
268 TEST_F(FileSystemApiConsentProviderTest, ForNonKioskApps) { 273 TEST_F(FileSystemApiConsentProviderTest, ForNonKioskApps) {
269 // Component apps are not granted unless they are whitelisted. 274 // Component apps are not granted unless they are whitelisted.
270 { 275 {
271 scoped_refptr<Extension> component_extension( 276 scoped_refptr<Extension> component_extension(
272 test_util::BuildApp(ExtensionBuilder().SetLocation(Manifest::COMPONENT)) 277 test_util::BuildApp(ExtensionBuilder().SetLocation(Manifest::COMPONENT))
273 .Build()); 278 .Build());
274 int user_consent_counter = 0; 279 int ask_user_counter = 0;
275 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 280 int notify_user_counter = 0;
276 &user_consent_counter, 281 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
277 ConsentProvider::CONSENT_GRANTED)); 282 ConsentProvider::CONSENT_GRANTED),
283 base::Bind(&OnNotifyUser, &notify_user_counter));
278 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false)); 284 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false));
279 EXPECT_FALSE(provider.IsGrantable(*component_extension)); 285 EXPECT_FALSE(provider.IsGrantable(*component_extension));
280 286
281 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 287 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
282 provider.RequestConsent(*component_extension.get(), volume_info_, 288 provider.RequestConsent(*component_extension.get(), volume_info_,
283 true /* writable */, 289 true /* writable */,
284 base::Bind(&OnConsentReceived, &result)); 290 base::Bind(&OnConsentReceived, &result));
285 base::RunLoop().RunUntilIdle(); 291 base::RunLoop().RunUntilIdle();
286 292
287 EXPECT_EQ(0, user_consent_counter); 293 EXPECT_EQ(0, ask_user_counter);
294 EXPECT_EQ(0, notify_user_counter);
288 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 295 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
289 } 296 }
290 297
291 // Whitelitsted component apps are instantly granted access without asking 298 // Whitelitsted component apps are instantly granted access without asking
292 // user. 299 // user.
293 { 300 {
294 scoped_refptr<Extension> whitelisted_component_extension( 301 scoped_refptr<Extension> whitelisted_component_extension(
295 test_util::BuildApp(ExtensionBuilder().SetLocation(Manifest::COMPONENT)) 302 test_util::BuildApp(ExtensionBuilder().SetLocation(Manifest::COMPONENT))
296 .Build()); 303 .Build());
297 int user_consent_counter = 0; 304 int ask_user_counter = 0;
298 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 305 int notify_user_counter = 0;
299 &user_consent_counter, 306 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
300 ConsentProvider::CONSENT_REJECTED)); 307 ConsentProvider::CONSENT_REJECTED),
308 base::Bind(&OnNotifyUser, &notify_user_counter));
301 std::set<std::string> whitelist; 309 std::set<std::string> whitelist;
302 whitelist.insert(whitelisted_component_extension->id()); 310 whitelist.insert(whitelisted_component_extension->id());
303 provider.SetComponentWhitelistForTesting(whitelist); 311 provider.SetComponentWhitelistForTesting(whitelist);
304 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false)); 312 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false));
305 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension)); 313 EXPECT_TRUE(provider.IsGrantable(*whitelisted_component_extension));
306 314
307 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 315 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
308 provider.RequestConsent(*whitelisted_component_extension.get(), 316 provider.RequestConsent(*whitelisted_component_extension.get(),
309 volume_info_, true /* writable */, 317 volume_info_, true /* writable */,
310 base::Bind(&OnConsentReceived, &result)); 318 base::Bind(&OnConsentReceived, &result));
311 base::RunLoop().RunUntilIdle(); 319 base::RunLoop().RunUntilIdle();
312 320
313 EXPECT_EQ(0, user_consent_counter); 321 EXPECT_EQ(0, ask_user_counter);
322 EXPECT_EQ(0, notify_user_counter);
314 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 323 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
315 } 324 }
316 325
317 // Non-component apps in non-kiosk mode will be rejected instantly, without 326 // Non-component apps in non-kiosk mode will be rejected instantly, without
318 // asking for user consent. 327 // asking for user consent.
319 { 328 {
320 scoped_refptr<Extension> non_component_extension( 329 scoped_refptr<Extension> non_component_extension(
321 test_util::CreateEmptyExtension()); 330 test_util::CreateEmptyExtension());
322 int user_consent_counter = 0; 331 int ask_user_counter = 0;
323 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 332 int notify_user_counter = 0;
324 &user_consent_counter, 333 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
325 ConsentProvider::CONSENT_GRANTED)); 334 ConsentProvider::CONSENT_GRANTED),
335 base::Bind(&OnNotifyUser, &notify_user_counter));
326 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false)); 336 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false));
327 EXPECT_FALSE(provider.IsGrantable(*non_component_extension)); 337 EXPECT_FALSE(provider.IsGrantable(*non_component_extension));
328 338
329 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 339 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
330 provider.RequestConsent(*non_component_extension.get(), volume_info_, 340 provider.RequestConsent(*non_component_extension.get(), volume_info_,
331 true /* writable */, 341 true /* writable */,
332 base::Bind(&OnConsentReceived, &result)); 342 base::Bind(&OnConsentReceived, &result));
333 base::RunLoop().RunUntilIdle(); 343 base::RunLoop().RunUntilIdle();
334 344
335 EXPECT_EQ(0, user_consent_counter); 345 EXPECT_EQ(0, ask_user_counter);
346 EXPECT_EQ(0, notify_user_counter);
336 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 347 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
337 } 348 }
338 } 349 }
339 350
340 TEST_F(FileSystemApiConsentProviderTest, ForKioskApps) { 351 TEST_F(FileSystemApiConsentProviderTest, ForKioskApps) {
341 // Non-component apps in auto-launch kiosk mode will be granted access 352 // Non-component apps in auto-launch kiosk mode will be granted access
342 // instantly without asking for user consent. 353 // instantly without asking for user consent, but with a notification.
343 { 354 {
344 scoped_refptr<Extension> auto_launch_kiosk_app( 355 scoped_refptr<Extension> auto_launch_kiosk_app(
345 test_util::BuildApp(ExtensionBuilder().Pass()) 356 test_util::BuildApp(ExtensionBuilder().Pass())
346 .MergeManifest(DictionaryBuilder() 357 .MergeManifest(DictionaryBuilder()
347 .SetBoolean("kiosk_enabled", true) 358 .SetBoolean("kiosk_enabled", true)
348 .SetBoolean("kiosk_only", true)) 359 .SetBoolean("kiosk_only", true))
349 .Build()); 360 .Build());
350 user_manager_->AddKioskAppUser(auto_launch_kiosk_app->id()); 361 user_manager_->AddKioskAppUser(auto_launch_kiosk_app->id());
351 user_manager_->LoginUser(auto_launch_kiosk_app->id()); 362 user_manager_->LoginUser(auto_launch_kiosk_app->id());
352 363
353 int user_consent_counter = 0; 364 int ask_user_counter = 0;
354 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 365 int notify_user_counter = 0;
355 &user_consent_counter, 366 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
356 ConsentProvider::CONSENT_REJECTED)); 367 ConsentProvider::CONSENT_REJECTED),
368 base::Bind(&OnNotifyUser, &notify_user_counter));
357 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, true)); 369 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, true));
358 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app)); 370 EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app));
359 371
360 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 372 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
361 provider.RequestConsent(*auto_launch_kiosk_app.get(), volume_info_, 373 provider.RequestConsent(*auto_launch_kiosk_app.get(), volume_info_,
362 true /* writable */, 374 true /* writable */,
363 base::Bind(&OnConsentReceived, &result)); 375 base::Bind(&OnConsentReceived, &result));
364 base::RunLoop().RunUntilIdle(); 376 base::RunLoop().RunUntilIdle();
365 377
366 EXPECT_EQ(0, user_consent_counter); 378 EXPECT_EQ(0, ask_user_counter);
379 EXPECT_EQ(1, notify_user_counter);
367 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 380 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
368 } 381 }
369 382
370 // Non-component apps in manual-launch kiosk mode will be granted access after 383 // Non-component apps in manual-launch kiosk mode will be granted access after
371 // receiving a user consent. 384 // receiving a user consent.
372 scoped_refptr<Extension> manual_launch_kiosk_app( 385 scoped_refptr<Extension> manual_launch_kiosk_app(
373 test_util::BuildApp(ExtensionBuilder().Pass()) 386 test_util::BuildApp(ExtensionBuilder().Pass())
374 .MergeManifest(DictionaryBuilder() 387 .MergeManifest(DictionaryBuilder()
375 .SetBoolean("kiosk_enabled", true) 388 .SetBoolean("kiosk_enabled", true)
376 .SetBoolean("kiosk_only", true)) 389 .SetBoolean("kiosk_only", true))
377 .Build()); 390 .Build());
378 user_manager_->KioskAppLoggedIn(manual_launch_kiosk_app->id()); 391 user_manager_->KioskAppLoggedIn(manual_launch_kiosk_app->id());
379 { 392 {
380 int user_consent_counter = 0; 393 int ask_user_counter = 0;
381 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 394 int notify_user_counter = 0;
382 &user_consent_counter, 395 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
383 ConsentProvider::CONSENT_GRANTED)); 396 ConsentProvider::CONSENT_GRANTED),
397 base::Bind(&OnNotifyUser, &notify_user_counter));
384 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false)); 398 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false));
385 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 399 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
386 400
387 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 401 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
388 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_info_, 402 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_info_,
389 true /* writable */, 403 true /* writable */,
390 base::Bind(&OnConsentReceived, &result)); 404 base::Bind(&OnConsentReceived, &result));
391 base::RunLoop().RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
392 406
393 EXPECT_EQ(1, user_consent_counter); 407 EXPECT_EQ(1, ask_user_counter);
408 EXPECT_EQ(0, notify_user_counter);
394 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); 409 EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result);
395 } 410 }
396 411
397 // 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
398 // after rejecting by a user. 413 // after rejecting by a user.
399 { 414 {
400 int user_consent_counter = 0; 415 int ask_user_counter = 0;
401 ConsentProvider provider(base::Bind(&OnUserConsentRequested, 416 int notify_user_counter = 0;
402 &user_consent_counter, 417 ConsentProvider provider(base::Bind(&OnAskUser, &ask_user_counter,
403 ConsentProvider::CONSENT_REJECTED)); 418 ConsentProvider::CONSENT_REJECTED),
419 base::Bind(&OnNotifyUser, &notify_user_counter));
404 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false)); 420 provider.SetIsAutoLaunchedForTesting(base::Bind(&OnIsAutoLaunched, false));
405 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); 421 EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app));
406 422
407 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; 423 ConsentProvider::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE;
408 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_info_, 424 provider.RequestConsent(*manual_launch_kiosk_app.get(), volume_info_,
409 true /* writable */, 425 true /* writable */,
410 base::Bind(&OnConsentReceived, &result)); 426 base::Bind(&OnConsentReceived, &result));
411 base::RunLoop().RunUntilIdle(); 427 base::RunLoop().RunUntilIdle();
412 428
413 EXPECT_EQ(1, user_consent_counter); 429 EXPECT_EQ(1, ask_user_counter);
430 EXPECT_EQ(0, notify_user_counter);
414 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 431 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
415 } 432 }
416 } 433 }
417 #endif 434 #endif
418 435
419 } // namespace extensions 436 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698