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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_tasks_unittest.cc

Issue 381583007: Ephemeral apps should not appear in ChromeOS file manager menus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_tasks.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/file_manager/file_tasks.h" 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/testing_pref_service.h" 12 #include "base/prefs/testing_pref_service.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chromeos/drive/file_system_util.h" 14 #include "chrome/browser/chromeos/drive/file_system_util.h"
15 #include "chrome/browser/chromeos/file_manager/app_id.h" 15 #include "chrome/browser/chromeos/file_manager/app_id.h"
16 #include "chrome/browser/chromeos/login/users/user_manager.h" 16 #include "chrome/browser/chromeos/login/users/user_manager.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" 18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
19 #include "chrome/browser/drive/drive_app_registry.h" 19 #include "chrome/browser/drive/drive_app_registry.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/test_extension_system.h" 21 #include "chrome/browser/extensions/test_extension_system.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "extensions/browser/extension_prefs.h"
25 #include "extensions/browser/extension_system.h" 26 #include "extensions/browser/extension_system.h"
26 #include "extensions/common/extension_builder.h" 27 #include "extensions/common/extension_builder.h"
27 #include "google_apis/drive/drive_api_parser.h" 28 #include "google_apis/drive/drive_api_parser.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "url/gurl.h" 30 #include "url/gurl.h"
30 31
31 namespace file_manager { 32 namespace file_manager {
32 namespace file_tasks { 33 namespace file_tasks {
33 namespace { 34 namespace {
34 35
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 CommandLine command_line_; 373 CommandLine command_line_;
373 ExtensionService* extension_service_; // Owned by test_profile_; 374 ExtensionService* extension_service_; // Owned by test_profile_;
374 }; 375 };
375 376
376 // The basic logic is similar to a test case for FindDriveAppTasks above. 377 // The basic logic is similar to a test case for FindDriveAppTasks above.
377 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) { 378 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) {
378 // Random IDs generated by 379 // Random IDs generated by
379 // % ruby -le 'print (0...32).to_a.map{(?a + rand(16)).chr}.join' 380 // % ruby -le 'print (0...32).to_a.map{(?a + rand(16)).chr}.join'
380 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; 381 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
381 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; 382 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca";
383 const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel";
382 384
383 // Foo.app can handle "text/plain" and "text/html". 385 // Foo.app can handle "text/plain" and "text/html".
384 extensions::ExtensionBuilder foo_app; 386 extensions::ExtensionBuilder foo_app;
385 foo_app.SetManifest(extensions::DictionaryBuilder() 387 foo_app.SetManifest(extensions::DictionaryBuilder()
386 .Set("name", "Foo") 388 .Set("name", "Foo")
387 .Set("version", "1.0.0") 389 .Set("version", "1.0.0")
388 .Set("manifest_version", 2) 390 .Set("manifest_version", 2)
389 .Set("app", 391 .Set("app",
390 extensions::DictionaryBuilder() 392 extensions::DictionaryBuilder()
391 .Set("background", 393 .Set("background",
(...skipping 30 matching lines...) Expand all
422 extensions::DictionaryBuilder() 424 extensions::DictionaryBuilder()
423 .Set("text", 425 .Set("text",
424 extensions::DictionaryBuilder() 426 extensions::DictionaryBuilder()
425 .Set("title", "Text") 427 .Set("title", "Text")
426 .Set("types", 428 .Set("types",
427 extensions::ListBuilder() 429 extensions::ListBuilder()
428 .Append("text/plain"))))); 430 .Append("text/plain")))));
429 bar_app.SetID(kBarId); 431 bar_app.SetID(kBarId);
430 extension_service_->AddExtension(bar_app.Build().get()); 432 extension_service_->AddExtension(bar_app.Build().get());
431 433
434 // Ephemeral.app is an ephemeral app that can handle "text/plain".
435 // It should not ever be found as ephemeral apps cannot be file handlers.
436 extensions::ExtensionBuilder ephemeral_app;
437 ephemeral_app.SetManifest(
438 extensions::DictionaryBuilder()
439 .Set("name", "Ephemeral")
440 .Set("version", "1.0.0")
441 .Set("manifest_version", 2)
442 .Set("app",
443 extensions::DictionaryBuilder().Set(
444 "background",
445 extensions::DictionaryBuilder().Set(
446 "scripts",
447 extensions::ListBuilder().Append("background.js"))))
448 .Set("file_handlers",
449 extensions::DictionaryBuilder().Set(
450 "text",
451 extensions::DictionaryBuilder().Set("title", "Text").Set(
452 "types",
453 extensions::ListBuilder().Append("text/plain")))));
454 ephemeral_app.SetID(kEphemeralId);
455 scoped_refptr<extensions::Extension> built_ephemeral_app(
456 ephemeral_app.Build());
457 extension_service_->AddExtension(built_ephemeral_app.get());
458 extensions::ExtensionPrefs* extension_prefs =
459 extensions::ExtensionPrefs::Get(&test_profile_);
460 extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(),
461 extensions::Extension::ENABLED,
462 syncer::StringOrdinal(),
463 extensions::kInstallFlagIsEphemeral,
464 std::string());
465
432 // Find apps for a "text/plain" file. Foo.app and Bar.app should be found. 466 // Find apps for a "text/plain" file. Foo.app and Bar.app should be found.
433 PathAndMimeTypeSet path_mime_set; 467 PathAndMimeTypeSet path_mime_set;
434 path_mime_set.insert( 468 path_mime_set.insert(
435 std::make_pair( 469 std::make_pair(
436 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( 470 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII(
437 "foo.txt"), 471 "foo.txt"),
438 "text/plain")); 472 "text/plain"));
439 473
440 std::vector<FullTaskDescriptor> tasks; 474 std::vector<FullTaskDescriptor> tasks;
441 FindFileHandlerTasks(&test_profile_, path_mime_set, &tasks); 475 FindFileHandlerTasks(&test_profile_, path_mime_set, &tasks);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 FindFileHandlerTasks(&test_profile_, path_mime_set, &tasks); 510 FindFileHandlerTasks(&test_profile_, path_mime_set, &tasks);
477 // Confirm no tasks are found. 511 // Confirm no tasks are found.
478 ASSERT_TRUE(tasks.empty()); 512 ASSERT_TRUE(tasks.empty());
479 } 513 }
480 514
481 // The basic logic is similar to a test case for FindDriveAppTasks above. 515 // The basic logic is similar to a test case for FindDriveAppTasks above.
482 TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) { 516 TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) {
483 // Copied from FindFileHandlerTasks test above. 517 // Copied from FindFileHandlerTasks test above.
484 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; 518 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
485 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; 519 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca";
520 const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel";
486 521
487 // Foo.app can handle ".txt" and ".html". 522 // Foo.app can handle ".txt" and ".html".
488 // This one is an extension, and has "file_browser_handlers" 523 // This one is an extension, and has "file_browser_handlers"
489 extensions::ExtensionBuilder foo_app; 524 extensions::ExtensionBuilder foo_app;
490 foo_app.SetManifest(extensions::DictionaryBuilder() 525 foo_app.SetManifest(extensions::DictionaryBuilder()
491 .Set("name", "Foo") 526 .Set("name", "Foo")
492 .Set("version", "1.0.0") 527 .Set("version", "1.0.0")
493 .Set("manifest_version", 2) 528 .Set("manifest_version", 2)
494 .Set("file_browser_handlers", 529 .Set("file_browser_handlers",
495 extensions::ListBuilder() 530 extensions::ListBuilder()
(...skipping 17 matching lines...) Expand all
513 extensions::ListBuilder() 548 extensions::ListBuilder()
514 .Append(extensions::DictionaryBuilder() 549 .Append(extensions::DictionaryBuilder()
515 .Set("id", "open") 550 .Set("id", "open")
516 .Set("default_title", "open") 551 .Set("default_title", "open")
517 .Set("file_filters", 552 .Set("file_filters",
518 extensions::ListBuilder() 553 extensions::ListBuilder()
519 .Append("filesystem:*.txt"))))); 554 .Append("filesystem:*.txt")))));
520 bar_app.SetID(kBarId); 555 bar_app.SetID(kBarId);
521 extension_service_->AddExtension(bar_app.Build().get()); 556 extension_service_->AddExtension(bar_app.Build().get());
522 557
558 // Ephemeral.app is an ephemeral app that can handle ".txt".
559 // It should not ever be found as ephemeral apps cannot be file browser
560 // handlers.
561 extensions::ExtensionBuilder ephemeral_app;
562 ephemeral_app.SetManifest(
563 extensions::DictionaryBuilder()
564 .Set("name", "Ephemeral")
565 .Set("version", "1.0.0")
566 .Set("manifest_version", 2)
567 .Set("file_browser_handlers",
568 extensions::ListBuilder().Append(
569 extensions::DictionaryBuilder()
570 .Set("id", "open")
571 .Set("default_title", "open")
572 .Set("file_filters",
573 extensions::ListBuilder().Append(
574 "filesystem:*.txt")))));
575 ephemeral_app.SetID(kEphemeralId);
576 scoped_refptr<extensions::Extension> built_ephemeral_app(
577 ephemeral_app.Build());
578 extension_service_->AddExtension(built_ephemeral_app.get());
579 extensions::ExtensionPrefs* extension_prefs =
580 extensions::ExtensionPrefs::Get(&test_profile_);
581 extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(),
582 extensions::Extension::ENABLED,
583 syncer::StringOrdinal(),
584 extensions::kInstallFlagIsEphemeral,
585 std::string());
586
523 // Find apps for a ".txt" file. Foo.app and Bar.app should be found. 587 // Find apps for a ".txt" file. Foo.app and Bar.app should be found.
524 std::vector<GURL> file_urls; 588 std::vector<GURL> file_urls;
525 file_urls.push_back(GURL("filesystem:chrome-extension://id/dir/foo.txt")); 589 file_urls.push_back(GURL("filesystem:chrome-extension://id/dir/foo.txt"));
526 590
527 std::vector<FullTaskDescriptor> tasks; 591 std::vector<FullTaskDescriptor> tasks;
528 FindFileBrowserHandlerTasks(&test_profile_, file_urls, &tasks); 592 FindFileBrowserHandlerTasks(&test_profile_, file_urls, &tasks);
529 ASSERT_EQ(2U, tasks.size()); 593 ASSERT_EQ(2U, tasks.size());
530 // Sort the app IDs, as the order is not guaranteed. 594 // Sort the app IDs, as the order is not guaranteed.
531 std::vector<std::string> app_ids; 595 std::vector<std::string> app_ids;
532 app_ids.push_back(tasks[0].task_descriptor().app_id); 596 app_ids.push_back(tasks[0].task_descriptor().app_id);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 &drive_app_registry, 793 &drive_app_registry,
730 path_mime_set, 794 path_mime_set,
731 file_urls, 795 file_urls,
732 &tasks); 796 &tasks);
733 ASSERT_EQ(1U, tasks.size()); 797 ASSERT_EQ(1U, tasks.size());
734 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id); 798 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id);
735 } 799 }
736 800
737 } // namespace file_tasks 801 } // namespace file_tasks
738 } // namespace file_manager. 802 } // namespace file_manager.
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_tasks.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698