1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Browser test for basic Chrome OS file manager functionality:
6 // - The file list is updated when a file is added externally to the Downloads
8 // - Selecting a file and copy-pasting it with the keyboard copies the file.
9 // - Selecting a file and pressing delete deletes it.
14 #include "base/bind.h"
15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h"
17 #include "base/json/json_reader.h"
18 #include "base/json/json_value_converter.h"
19 #include "base/json/json_writer.h"
20 #include "base/path_service.h"
21 #include "base/prefs/pref_service.h"
22 #include "base/strings/string_piece.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/time/time.h"
25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
27 #include "chrome/browser/chromeos/drive/file_system_interface.h"
28 #include "chrome/browser/chromeos/drive/test_util.h"
29 #include "chrome/browser/chromeos/file_manager/app_id.h"
30 #include "chrome/browser/chromeos/file_manager/drive_test_util.h"
31 #include "chrome/browser/chromeos/file_manager/path_util.h"
32 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
33 #include "chrome/browser/chromeos/profiles/profile_helper.h"
34 #include "chrome/browser/drive/fake_drive_service.h"
35 #include "chrome/browser/extensions/component_loader.h"
36 #include "chrome/browser/extensions/extension_apitest.h"
37 #include "chrome/browser/notifications/notification.h"
38 #include "chrome/browser/notifications/notification_ui_manager.h"
39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/signin/signin_manager_factory.h"
41 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
42 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
43 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/pref_names.h"
45 #include "chromeos/chromeos_switches.h"
46 #include "components/signin/core/browser/signin_manager.h"
47 #include "components/user_manager/user_manager.h"
48 #include "content/public/browser/notification_service.h"
49 #include "content/public/test/test_utils.h"
50 #include "extensions/browser/api/test/test_api.h"
51 #include "extensions/browser/app_window/app_window.h"
52 #include "extensions/browser/app_window/app_window_registry.h"
53 #include "extensions/browser/notification_types.h"
54 #include "extensions/common/extension.h"
55 #include "extensions/test/extension_test_message_listener.h"
56 #include "google_apis/drive/drive_api_parser.h"
57 #include "google_apis/drive/test_util.h"
58 #include "net/test/embedded_test_server/embedded_test_server.h"
59 #include "storage/browser/fileapi/external_mount_points.h"
61 using drive::DriveIntegrationServiceFactory
;
63 namespace file_manager
{
71 enum TargetVolume
{ LOCAL_VOLUME
, DRIVE_VOLUME
, USB_VOLUME
, };
84 // This global operator is used from Google Test to format error messages.
85 std::ostream
& operator<<(std::ostream
& os
, const GuestMode
& guest_mode
) {
86 return os
<< (guest_mode
== IN_GUEST_MODE
?
87 "IN_GUEST_MODE" : "NOT_IN_GUEST_MODE");
90 // Maps the given string to EntryType. Returns true on success.
91 bool MapStringToEntryType(const base::StringPiece
& value
, EntryType
* output
) {
94 else if (value
== "directory")
101 // Maps the given string to SharedOption. Returns true on success.
102 bool MapStringToSharedOption(const base::StringPiece
& value
,
103 SharedOption
* output
) {
104 if (value
== "shared")
106 else if (value
== "none")
113 // Maps the given string to TargetVolume. Returns true on success.
114 bool MapStringToTargetVolume(const base::StringPiece
& value
,
115 TargetVolume
* output
) {
116 if (value
== "drive")
117 *output
= DRIVE_VOLUME
;
118 else if (value
== "local")
119 *output
= LOCAL_VOLUME
;
120 else if (value
== "usb")
121 *output
= USB_VOLUME
;
127 // Maps the given string to base::Time. Returns true on success.
128 bool MapStringToTime(const base::StringPiece
& value
, base::Time
* time
) {
129 return base::Time::FromString(value
.as_string().c_str(), time
);
132 // Test data of file or directory.
133 struct TestEntryInfo
{
134 TestEntryInfo() : type(FILE), shared_option(NONE
) {}
136 TestEntryInfo(EntryType type
,
137 const std::string
& source_file_name
,
138 const std::string
& target_path
,
139 const std::string
& mime_type
,
140 SharedOption shared_option
,
141 const base::Time
& last_modified_time
) :
143 source_file_name(source_file_name
),
144 target_path(target_path
),
145 mime_type(mime_type
),
146 shared_option(shared_option
),
147 last_modified_time(last_modified_time
) {
151 std::string source_file_name
; // Source file name to be used as a prototype.
152 std::string target_path
; // Target file or directory path.
153 std::string mime_type
;
154 SharedOption shared_option
;
155 base::Time last_modified_time
;
157 // Registers the member information to the given converter.
158 static void RegisterJSONConverter(
159 base::JSONValueConverter
<TestEntryInfo
>* converter
);
163 void TestEntryInfo::RegisterJSONConverter(
164 base::JSONValueConverter
<TestEntryInfo
>* converter
) {
165 converter
->RegisterCustomField("type",
166 &TestEntryInfo::type
,
167 &MapStringToEntryType
);
168 converter
->RegisterStringField("sourceFileName",
169 &TestEntryInfo::source_file_name
);
170 converter
->RegisterStringField("targetPath", &TestEntryInfo::target_path
);
171 converter
->RegisterStringField("mimeType", &TestEntryInfo::mime_type
);
172 converter
->RegisterCustomField("sharedOption",
173 &TestEntryInfo::shared_option
,
174 &MapStringToSharedOption
);
175 converter
->RegisterCustomField("lastModifiedTime",
176 &TestEntryInfo::last_modified_time
,
180 // Message from JavaScript to add entries.
181 struct AddEntriesMessage
{
182 // Target volume to be added the |entries|.
185 // Entries to be added.
186 ScopedVector
<TestEntryInfo
> entries
;
188 // Registers the member information to the given converter.
189 static void RegisterJSONConverter(
190 base::JSONValueConverter
<AddEntriesMessage
>* converter
);
194 void AddEntriesMessage::RegisterJSONConverter(
195 base::JSONValueConverter
<AddEntriesMessage
>* converter
) {
196 converter
->RegisterCustomField("volume",
197 &AddEntriesMessage::volume
,
198 &MapStringToTargetVolume
);
199 converter
->RegisterRepeatedMessage
<TestEntryInfo
>(
201 &AddEntriesMessage::entries
);
207 explicit TestVolume(const std::string
& name
) : name_(name
) {}
208 virtual ~TestVolume() {}
210 bool CreateRootDirectory(const Profile
* profile
) {
211 const base::FilePath path
= profile
->GetPath().Append(name_
);
212 return root_
.path() == path
|| root_
.Set(path
);
215 const std::string
& name() { return name_
; }
216 const base::FilePath
root_path() { return root_
.path(); }
220 base::ScopedTempDir root_
;
223 // The local volume class for test.
224 // This class provides the operations for a test volume that simulates local
226 class LocalTestVolume
: public TestVolume
{
228 explicit LocalTestVolume(const std::string
& name
) : TestVolume(name
) {}
229 ~LocalTestVolume() override
{}
231 // Adds this volume to the file system as a local volume. Returns true on
233 virtual bool Mount(Profile
* profile
) = 0;
235 void CreateEntry(const TestEntryInfo
& entry
) {
236 const base::FilePath target_path
=
237 root_path().AppendASCII(entry
.target_path
);
239 entries_
.insert(std::make_pair(target_path
, entry
));
240 switch (entry
.type
) {
242 const base::FilePath source_path
=
243 google_apis::test_util::GetTestFilePath("chromeos/file_manager").
244 AppendASCII(entry
.source_file_name
);
245 ASSERT_TRUE(base::CopyFile(source_path
, target_path
))
246 << "Copy from " << source_path
.value()
247 << " to " << target_path
.value() << " failed.";
251 ASSERT_TRUE(base::CreateDirectory(target_path
)) <<
252 "Failed to create a directory: " << target_path
.value();
255 ASSERT_TRUE(UpdateModifiedTime(entry
));
259 // Updates ModifiedTime of the entry and its parents by referring
260 // TestEntryInfo. Returns true on success.
261 bool UpdateModifiedTime(const TestEntryInfo
& entry
) {
262 const base::FilePath path
= root_path().AppendASCII(entry
.target_path
);
263 if (!base::TouchFile(path
, entry
.last_modified_time
,
264 entry
.last_modified_time
))
267 // Update the modified time of parent directories because it may be also
268 // affected by the update of child items.
269 if (path
.DirName() != root_path()) {
270 const std::map
<base::FilePath
, const TestEntryInfo
>::iterator it
=
271 entries_
.find(path
.DirName());
272 if (it
== entries_
.end())
274 return UpdateModifiedTime(it
->second
);
279 std::map
<base::FilePath
, const TestEntryInfo
> entries_
;
282 class DownloadsTestVolume
: public LocalTestVolume
{
284 DownloadsTestVolume() : LocalTestVolume("Downloads") {}
285 ~DownloadsTestVolume() override
{}
287 bool Mount(Profile
* profile
) override
{
288 return CreateRootDirectory(profile
) &&
289 VolumeManager::Get(profile
)
290 ->RegisterDownloadsDirectoryForTesting(root_path());
294 // Test volume for mimicing a specified type of volumes by a local folder.
295 class FakeTestVolume
: public LocalTestVolume
{
297 FakeTestVolume(const std::string
& name
,
298 VolumeType volume_type
,
299 chromeos::DeviceType device_type
)
300 : LocalTestVolume(name
),
301 volume_type_(volume_type
),
302 device_type_(device_type
) {}
303 ~FakeTestVolume() override
{}
305 // Simple test entries used for testing, e.g., read-only volumes.
306 bool PrepareTestEntries(Profile
* profile
) {
307 if (!CreateRootDirectory(profile
))
309 // Must be in sync with BASIC_FAKE_ENTRY_SET in the JS test code.
311 TestEntryInfo(FILE, "text.txt", "hello.txt", "text/plain", NONE
,
314 TestEntryInfo(DIRECTORY
, std::string(), "A", std::string(), NONE
,
319 bool Mount(Profile
* profile
) override
{
320 if (!CreateRootDirectory(profile
))
322 storage::ExternalMountPoints
* const mount_points
=
323 storage::ExternalMountPoints::GetSystemInstance();
325 // First revoke the existing mount point (if any).
326 mount_points
->RevokeFileSystem(name());
328 mount_points
->RegisterFileSystem(name(),
329 storage::kFileSystemTypeNativeLocal
,
330 storage::FileSystemMountOption(),
335 VolumeManager::Get(profile
)->AddVolumeInfoForTesting(
336 root_path(), volume_type_
, device_type_
);
341 const VolumeType volume_type_
;
342 const chromeos::DeviceType device_type_
;
345 // The drive volume class for test.
346 // This class provides the operations for a test volume that simulates Google
348 class DriveTestVolume
: public TestVolume
{
350 DriveTestVolume() : TestVolume("drive"), integration_service_(NULL
) {}
351 ~DriveTestVolume() override
{}
353 void CreateEntry(const TestEntryInfo
& entry
) {
354 const base::FilePath path
=
355 base::FilePath::FromUTF8Unsafe(entry
.target_path
);
356 const std::string target_name
= path
.BaseName().AsUTF8Unsafe();
358 // Obtain the parent entry.
359 drive::FileError error
= drive::FILE_ERROR_OK
;
360 scoped_ptr
<drive::ResourceEntry
> parent_entry(new drive::ResourceEntry
);
361 integration_service_
->file_system()->GetResourceEntry(
362 drive::util::GetDriveMyDriveRootPath().Append(path
).DirName(),
363 google_apis::test_util::CreateCopyResultCallback(
364 &error
, &parent_entry
));
365 content::RunAllBlockingPoolTasksUntilIdle();
366 ASSERT_EQ(drive::FILE_ERROR_OK
, error
);
367 ASSERT_TRUE(parent_entry
);
369 switch (entry
.type
) {
371 CreateFile(entry
.source_file_name
,
372 parent_entry
->resource_id(),
375 entry
.shared_option
== SHARED
,
376 entry
.last_modified_time
);
380 parent_entry
->resource_id(), target_name
, entry
.last_modified_time
);
385 // Creates an empty directory with the given |name| and |modification_time|.
386 void CreateDirectory(const std::string
& parent_id
,
387 const std::string
& target_name
,
388 const base::Time
& modification_time
) {
389 google_apis::DriveApiErrorCode error
= google_apis::DRIVE_OTHER_ERROR
;
390 scoped_ptr
<google_apis::FileResource
> entry
;
391 fake_drive_service_
->AddNewDirectory(
394 drive::DriveServiceInterface::AddNewDirectoryOptions(),
395 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
396 base::MessageLoop::current()->RunUntilIdle();
397 ASSERT_EQ(google_apis::HTTP_CREATED
, error
);
400 fake_drive_service_
->SetLastModifiedTime(
403 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
404 base::MessageLoop::current()->RunUntilIdle();
405 ASSERT_TRUE(error
== google_apis::HTTP_SUCCESS
);
410 // Creates a test file with the given spec.
411 // Serves |test_file_name| file. Pass an empty string for an empty file.
412 void CreateFile(const std::string
& source_file_name
,
413 const std::string
& parent_id
,
414 const std::string
& target_name
,
415 const std::string
& mime_type
,
417 const base::Time
& modification_time
) {
418 google_apis::DriveApiErrorCode error
= google_apis::DRIVE_OTHER_ERROR
;
420 std::string content_data
;
421 if (!source_file_name
.empty()) {
422 base::FilePath source_file_path
=
423 google_apis::test_util::GetTestFilePath("chromeos/file_manager").
424 AppendASCII(source_file_name
);
425 ASSERT_TRUE(base::ReadFileToString(source_file_path
, &content_data
));
428 scoped_ptr
<google_apis::FileResource
> entry
;
429 fake_drive_service_
->AddNewFile(
435 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
436 base::MessageLoop::current()->RunUntilIdle();
437 ASSERT_EQ(google_apis::HTTP_CREATED
, error
);
440 fake_drive_service_
->SetLastModifiedTime(
443 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
444 base::MessageLoop::current()->RunUntilIdle();
445 ASSERT_EQ(google_apis::HTTP_SUCCESS
, error
);
451 // Notifies FileSystem that the contents in FakeDriveService are
452 // changed, hence the new contents should be fetched.
453 void CheckForUpdates() {
454 if (integration_service_
&& integration_service_
->file_system()) {
455 integration_service_
->file_system()->CheckForUpdates();
459 // Sets the url base for the test server to be used to generate share urls
460 // on the files and directories.
461 void ConfigureShareUrlBase(const GURL
& share_url_base
) {
462 fake_drive_service_
->set_share_url_base(share_url_base
);
465 drive::DriveIntegrationService
* CreateDriveIntegrationService(
468 fake_drive_service_
= new drive::FakeDriveService
;
469 fake_drive_service_
->LoadAppListForDriveApi("drive/applist.json");
471 if (!CreateRootDirectory(profile
))
473 integration_service_
= new drive::DriveIntegrationService(
474 profile
, NULL
, fake_drive_service_
, std::string(), root_path(), NULL
);
475 return integration_service_
;
480 drive::FakeDriveService
* fake_drive_service_
;
481 drive::DriveIntegrationService
* integration_service_
;
484 // Listener to obtain the test relative messages synchronously.
485 class FileManagerTestListener
: public content::NotificationObserver
{
490 scoped_refptr
<extensions::TestSendMessageFunction
> function
;
493 FileManagerTestListener() {
495 extensions::NOTIFICATION_EXTENSION_TEST_PASSED
,
496 content::NotificationService::AllSources());
498 extensions::NOTIFICATION_EXTENSION_TEST_FAILED
,
499 content::NotificationService::AllSources());
501 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
,
502 content::NotificationService::AllSources());
505 Message
GetNextMessage() {
506 if (messages_
.empty())
507 content::RunMessageLoop();
508 const Message entry
= messages_
.front();
509 messages_
.pop_front();
513 void Observe(int type
,
514 const content::NotificationSource
& source
,
515 const content::NotificationDetails
& details
) override
{
518 entry
.message
= type
!= extensions::NOTIFICATION_EXTENSION_TEST_PASSED
519 ? *content::Details
<std::string
>(details
).ptr()
522 type
== extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
523 ? content::Source
<extensions::TestSendMessageFunction
>(source
).ptr()
525 messages_
.push_back(entry
);
526 base::MessageLoopForUI::current()->Quit();
530 std::deque
<Message
> messages_
;
531 content::NotificationRegistrar registrar_
;
534 // The base test class.
535 class FileManagerBrowserTestBase
: public ExtensionApiTest
{
537 void SetUpInProcessBrowserTestFixture() override
;
539 void SetUpOnMainThread() override
;
541 // Adds an incognito and guest-mode flags for tests in the guest mode.
542 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
544 // Loads our testing extension and sends it a string identifying the current
546 virtual void StartTest();
547 void RunTestMessageLoop();
549 // Overriding point for test configurations.
550 virtual const char* GetTestManifestName() const {
551 return "file_manager_test_manifest.json";
553 virtual GuestMode
GetGuestModeParam() const = 0;
554 virtual const char* GetTestCaseNameParam() const = 0;
555 virtual void OnMessage(const std::string
& name
,
556 const base::DictionaryValue
& value
,
557 std::string
* output
);
559 scoped_ptr
<LocalTestVolume
> local_volume_
;
560 linked_ptr
<DriveTestVolume
> drive_volume_
;
561 std::map
<Profile
*, linked_ptr
<DriveTestVolume
> > drive_volumes_
;
562 scoped_ptr
<FakeTestVolume
> usb_volume_
;
563 scoped_ptr
<FakeTestVolume
> mtp_volume_
;
566 drive::DriveIntegrationService
* CreateDriveIntegrationService(
568 DriveIntegrationServiceFactory::FactoryCallback
569 create_drive_integration_service_
;
570 scoped_ptr
<DriveIntegrationServiceFactory::ScopedFactoryForTest
>
571 service_factory_for_test_
;
574 void FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() {
575 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
576 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
578 local_volume_
.reset(new DownloadsTestVolume
);
579 if (GetGuestModeParam() != IN_GUEST_MODE
) {
580 create_drive_integration_service_
=
581 base::Bind(&FileManagerBrowserTestBase::CreateDriveIntegrationService
,
582 base::Unretained(this));
583 service_factory_for_test_
.reset(
584 new DriveIntegrationServiceFactory::ScopedFactoryForTest(
585 &create_drive_integration_service_
));
589 void FileManagerBrowserTestBase::SetUpOnMainThread() {
590 ExtensionApiTest::SetUpOnMainThread();
591 ASSERT_TRUE(local_volume_
->Mount(profile()));
593 if (GetGuestModeParam() != IN_GUEST_MODE
) {
594 // Install the web server to serve the mocked share dialog.
595 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
596 const GURL
share_url_base(embedded_test_server()->GetURL(
597 "/chromeos/file_manager/share_dialog_mock/index.html"));
598 drive_volume_
= drive_volumes_
[profile()->GetOriginalProfile()];
599 drive_volume_
->ConfigureShareUrlBase(share_url_base
);
600 test_util::WaitUntilDriveMountPointIsAdded(profile());
603 net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
606 void FileManagerBrowserTestBase::SetUpCommandLine(
607 base::CommandLine
* command_line
) {
608 if (GetGuestModeParam() == IN_GUEST_MODE
) {
609 command_line
->AppendSwitch(chromeos::switches::kGuestSession
);
610 command_line
->AppendSwitchNative(chromeos::switches::kLoginUser
, "");
611 command_line
->AppendSwitch(switches::kIncognito
);
613 if (GetGuestModeParam() == IN_INCOGNITO
) {
614 command_line
->AppendSwitch(switches::kIncognito
);
616 ExtensionApiTest::SetUpCommandLine(command_line
);
619 void FileManagerBrowserTestBase::StartTest() {
620 base::FilePath root_path
;
621 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT
, &root_path
));
623 // Launch the extension.
624 const base::FilePath path
=
625 root_path
.Append(FILE_PATH_LITERAL("ui/file_manager/integration_tests"));
626 const extensions::Extension
* const extension
=
627 LoadExtensionAsComponentWithManifest(path
, GetTestManifestName());
628 ASSERT_TRUE(extension
);
630 RunTestMessageLoop();
633 void FileManagerBrowserTestBase::RunTestMessageLoop() {
634 // Handle the messages from JavaScript.
635 // The while loop is break when the test is passed or failed.
636 FileManagerTestListener listener
;
638 FileManagerTestListener::Message entry
= listener
.GetNextMessage();
639 if (entry
.type
== extensions::NOTIFICATION_EXTENSION_TEST_PASSED
) {
642 } else if (entry
.type
== extensions::NOTIFICATION_EXTENSION_TEST_FAILED
) {
644 ADD_FAILURE() << entry
.message
;
648 // Parse the message value as JSON.
649 const scoped_ptr
<const base::Value
> value(
650 base::JSONReader::Read(entry
.message
));
652 // If the message is not the expected format, just ignore it.
653 const base::DictionaryValue
* message_dictionary
= NULL
;
655 if (!value
|| !value
->GetAsDictionary(&message_dictionary
) ||
656 !message_dictionary
->GetString("name", &name
))
660 OnMessage(name
, *message_dictionary
, &output
);
661 if (HasFatalFailure())
664 entry
.function
->Reply(output
);
668 void FileManagerBrowserTestBase::OnMessage(const std::string
& name
,
669 const base::DictionaryValue
& value
,
670 std::string
* output
) {
671 if (name
== "getTestName") {
672 // Pass the test case name.
673 *output
= GetTestCaseNameParam();
677 if (name
== "getRootPaths") {
678 // Pass the root paths.
679 const scoped_ptr
<base::DictionaryValue
> res(new base::DictionaryValue());
680 res
->SetString("downloads",
681 "/" + util::GetDownloadsMountPointName(profile()));
682 res
->SetString("drive",
683 "/" + drive::util::GetDriveMountPointPath(profile()
684 ).BaseName().AsUTF8Unsafe() + "/root");
685 base::JSONWriter::Write(res
.get(), output
);
689 if (name
== "isInGuestMode") {
690 // Obtain whether the test is in guest mode or not.
691 *output
= GetGuestModeParam() != NOT_IN_GUEST_MODE
? "true" : "false";
695 if (name
== "getCwsWidgetContainerMockUrl") {
696 // Obtain whether the test is in guest mode or not.
697 const GURL url
= embedded_test_server()->GetURL(
698 "/chromeos/file_manager/cws_container_mock/index.html");
699 std::string origin
= url
.GetOrigin().spec();
701 // Removes trailing a slash.
702 if (*origin
.rbegin() == '/')
703 origin
.resize(origin
.length() - 1);
705 const scoped_ptr
<base::DictionaryValue
> res(new base::DictionaryValue());
706 res
->SetString("url", url
.spec());
707 res
->SetString("origin", origin
);
708 base::JSONWriter::Write(res
.get(), output
);
712 if (name
== "addEntries") {
713 // Add entries to the specified volume.
714 base::JSONValueConverter
<AddEntriesMessage
> add_entries_message_converter
;
715 AddEntriesMessage message
;
716 ASSERT_TRUE(add_entries_message_converter
.Convert(value
, &message
));
718 for (size_t i
= 0; i
< message
.entries
.size(); ++i
) {
719 switch (message
.volume
) {
721 local_volume_
->CreateEntry(*message
.entries
[i
]);
724 if (drive_volume_
.get())
725 drive_volume_
->CreateEntry(*message
.entries
[i
]);
729 usb_volume_
->CreateEntry(*message
.entries
[i
]);
740 if (name
== "mountFakeUsb") {
741 usb_volume_
.reset(new FakeTestVolume("fake-usb",
742 VOLUME_TYPE_REMOVABLE_DISK_PARTITION
,
743 chromeos::DEVICE_TYPE_USB
));
744 usb_volume_
->Mount(profile());
748 if (name
== "mountFakeMtp") {
749 mtp_volume_
.reset(new FakeTestVolume("fake-mtp",
751 chromeos::DEVICE_TYPE_UNKNOWN
));
752 ASSERT_TRUE(mtp_volume_
->PrepareTestEntries(profile()));
754 mtp_volume_
->Mount(profile());
758 if (name
== "useCellularNetwork") {
759 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
760 net::NetworkChangeNotifier::CONNECTION_3G
);
764 if (name
== "clickNotificationButton") {
765 std::string extension_id
;
766 std::string notification_id
;
768 ASSERT_TRUE(value
.GetString("extensionId", &extension_id
));
769 ASSERT_TRUE(value
.GetString("notificationId", ¬ification_id
));
770 ASSERT_TRUE(value
.GetInteger("index", &index
));
772 const std::string delegate_id
= extension_id
+ "-" + notification_id
;
773 const Notification
* notification
= g_browser_process
->
774 notification_ui_manager()->FindById(delegate_id
, profile());
775 ASSERT_TRUE(notification
);
777 notification
->delegate()->ButtonClick(index
);
781 FAIL() << "Unknown test message: " << name
;
784 drive::DriveIntegrationService
*
785 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile
* profile
) {
786 drive_volumes_
[profile
->GetOriginalProfile()].reset(new DriveTestVolume());
787 return drive_volumes_
[profile
->GetOriginalProfile()]->
788 CreateDriveIntegrationService(profile
);
791 // Parameter of FileManagerBrowserTest.
792 // The second value is the case name of JavaScript.
793 typedef std::tr1::tuple
<GuestMode
, const char*> TestParameter
;
795 // Test fixture class for normal (not multi-profile related) tests.
796 class FileManagerBrowserTest
:
797 public FileManagerBrowserTestBase
,
798 public ::testing::WithParamInterface
<TestParameter
> {
799 GuestMode
GetGuestModeParam() const override
{
800 return std::tr1::get
<0>(GetParam());
802 const char* GetTestCaseNameParam() const override
{
803 return std::tr1::get
<1>(GetParam());
807 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest
, Test
) {
811 // Unlike TEST/TEST_F, which are macros that expand to further macros,
812 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
813 // stringizes the arguments. As a result, macros passed as parameters (such as
814 // prefix or test_case_name) will not be expanded by the preprocessor. To work
815 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
816 // pre-processor will expand macros such as MAYBE_test_name before
817 // instantiating the test.
818 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
819 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
821 // Slow tests are disabled on debug build. http://crbug.com/327719
822 // Fails on official build. http://crbug.com/429294
823 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
824 #define MAYBE_FileDisplay DISABLED_FileDisplay
826 #define MAYBE_FileDisplay FileDisplay
828 WRAPPED_INSTANTIATE_TEST_CASE_P(
830 FileManagerBrowserTest
,
831 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayDownloads"),
832 TestParameter(IN_GUEST_MODE
, "fileDisplayDownloads"),
833 TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayDrive"),
834 TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayMtp")));
836 // Slow tests are disabled on debug build. http://crbug.com/327719
837 // Fails on official build. http://crbug.com/429294
838 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
839 #define MAYBE_OpenVideoFiles DISABLED_OpenVideoFiles
841 #define MAYBE_OpenVideoFiles OpenVideoFiles
843 WRAPPED_INSTANTIATE_TEST_CASE_P(
844 MAYBE_OpenVideoFiles
,
845 FileManagerBrowserTest
,
846 ::testing::Values(TestParameter(IN_GUEST_MODE
, "videoOpenDownloads"),
847 TestParameter(NOT_IN_GUEST_MODE
, "videoOpenDownloads"),
848 TestParameter(NOT_IN_GUEST_MODE
, "videoOpenDrive")));
850 // Slow tests are disabled on debug build. http://crbug.com/327719
851 // Fails on official build. http://crbug.com/429294
852 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
853 #define MAYBE_OpenAudioFiles DISABLED_OpenAudioFiles
855 #define MAYBE_OpenAudioFiles OpenAudioFiles
857 WRAPPED_INSTANTIATE_TEST_CASE_P(
858 MAYBE_OpenAudioFiles
,
859 FileManagerBrowserTest
,
861 TestParameter(IN_GUEST_MODE
, "audioOpenDownloads"),
862 TestParameter(NOT_IN_GUEST_MODE
, "audioOpenDownloads"),
863 TestParameter(NOT_IN_GUEST_MODE
, "audioOpenDrive"),
864 TestParameter(NOT_IN_GUEST_MODE
, "audioAutoAdvanceDrive"),
865 TestParameter(NOT_IN_GUEST_MODE
, "audioRepeatSingleFileDrive"),
866 TestParameter(NOT_IN_GUEST_MODE
, "audioNoRepeatSingleFileDrive"),
867 TestParameter(NOT_IN_GUEST_MODE
, "audioRepeatMultipleFileDrive"),
868 TestParameter(NOT_IN_GUEST_MODE
, "audioNoRepeatMultipleFileDrive")));
870 // Slow tests are disabled on debug build. http://crbug.com/327719
871 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
872 #define MAYBE_CreateNewFolder DISABLED_CreateNewFolder
874 #define MAYBE_CreateNewFolder CreateNewFolder
876 WRAPPED_INSTANTIATE_TEST_CASE_P(
877 MAYBE_CreateNewFolder
,
878 FileManagerBrowserTest
,
879 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
880 "createNewFolderAfterSelectFile"),
881 TestParameter(IN_GUEST_MODE
,
882 "createNewFolderDownloads"),
883 TestParameter(NOT_IN_GUEST_MODE
,
884 "createNewFolderDownloads"),
885 TestParameter(NOT_IN_GUEST_MODE
,
886 "createNewFolderDrive")));
888 // Slow tests are disabled on debug build. http://crbug.com/327719
889 // Fails on official build. http://crbug.com/429294
890 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
891 #define MAYBE_KeyboardOperations DISABLED_KeyboardOperations
893 #define MAYBE_KeyboardOperations KeyboardOperations
895 WRAPPED_INSTANTIATE_TEST_CASE_P(
896 MAYBE_KeyboardOperations
,
897 FileManagerBrowserTest
,
898 ::testing::Values(TestParameter(IN_GUEST_MODE
, "keyboardDeleteDownloads"),
899 TestParameter(NOT_IN_GUEST_MODE
,
900 "keyboardDeleteDownloads"),
901 TestParameter(NOT_IN_GUEST_MODE
, "keyboardDeleteDrive"),
902 TestParameter(IN_GUEST_MODE
, "keyboardCopyDownloads"),
903 TestParameter(NOT_IN_GUEST_MODE
, "keyboardCopyDownloads"),
904 TestParameter(NOT_IN_GUEST_MODE
, "keyboardCopyDrive"),
905 TestParameter(IN_GUEST_MODE
, "renameFileDownloads"),
906 TestParameter(NOT_IN_GUEST_MODE
, "renameFileDownloads"),
907 TestParameter(NOT_IN_GUEST_MODE
, "renameFileDrive"),
908 TestParameter(IN_GUEST_MODE
,
909 "renameNewDirectoryDownloads"),
910 TestParameter(NOT_IN_GUEST_MODE
,
911 "renameNewDirectoryDownloads"),
912 TestParameter(NOT_IN_GUEST_MODE
,
913 "renameNewDirectoryDrive")));
915 // Slow tests are disabled on debug build. http://crbug.com/327719
916 // Fails on official build. http://crbug.com/429294
917 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
918 #define MAYBE_DriveSpecific DISABLED_DriveSpecific
920 #define MAYBE_DriveSpecific DriveSpecific
922 WRAPPED_INSTANTIATE_TEST_CASE_P(
924 FileManagerBrowserTest
,
926 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarRecent"),
927 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarOffline"),
928 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarSharedWithMe"),
929 TestParameter(NOT_IN_GUEST_MODE
, "autocomplete"),
930 TestParameter(NOT_IN_GUEST_MODE
, "pinFileOnMobileNetwork")));
932 // Slow tests are disabled on debug build. http://crbug.com/327719
933 // Fails on official build. http://crbug.com/429294
934 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
935 #define MAYBE_Transfer DISABLED_Transfer
937 #define MAYBE_Transfer Transfer
939 WRAPPED_INSTANTIATE_TEST_CASE_P(
941 FileManagerBrowserTest
,
943 TestParameter(NOT_IN_GUEST_MODE
, "transferFromDriveToDownloads"),
944 TestParameter(NOT_IN_GUEST_MODE
, "transferFromDownloadsToDrive"),
945 TestParameter(NOT_IN_GUEST_MODE
, "transferFromSharedToDownloads"),
946 TestParameter(NOT_IN_GUEST_MODE
, "transferFromSharedToDrive"),
947 TestParameter(NOT_IN_GUEST_MODE
, "transferFromRecentToDownloads"),
948 TestParameter(NOT_IN_GUEST_MODE
, "transferFromRecentToDrive"),
949 TestParameter(NOT_IN_GUEST_MODE
, "transferFromOfflineToDownloads"),
950 TestParameter(NOT_IN_GUEST_MODE
, "transferFromOfflineToDrive")));
952 // Slow tests are disabled on debug build. http://crbug.com/327719
953 // Fails on official build. http://crbug.com/429294
954 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
955 #define MAYBE_RestorePrefs DISABLED_RestorePrefs
957 #define MAYBE_RestorePrefs RestorePrefs
959 WRAPPED_INSTANTIATE_TEST_CASE_P(
961 FileManagerBrowserTest
,
962 ::testing::Values(TestParameter(IN_GUEST_MODE
, "restoreSortColumn"),
963 TestParameter(NOT_IN_GUEST_MODE
, "restoreSortColumn"),
964 TestParameter(IN_GUEST_MODE
, "restoreCurrentView"),
965 TestParameter(NOT_IN_GUEST_MODE
, "restoreCurrentView")));
967 // Slow tests are disabled on debug build. http://crbug.com/327719
969 #define MAYBE_ShareDialog DISABLED_ShareDialog
971 #define MAYBE_ShareDialog ShareDialog
973 WRAPPED_INSTANTIATE_TEST_CASE_P(
975 FileManagerBrowserTest
,
976 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "shareFile"),
977 TestParameter(NOT_IN_GUEST_MODE
, "shareDirectory")));
979 // Slow tests are disabled on debug build. http://crbug.com/327719
981 #define MAYBE_RestoreGeometry DISABLED_RestoreGeometry
983 #define MAYBE_RestoreGeometry RestoreGeometry
985 WRAPPED_INSTANTIATE_TEST_CASE_P(
986 MAYBE_RestoreGeometry
,
987 FileManagerBrowserTest
,
988 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "restoreGeometry"),
989 TestParameter(IN_GUEST_MODE
, "restoreGeometry")));
991 // Slow tests are disabled on debug and msan build.
992 // http://crbug.com/327719, 457365
994 #define MAYBE_Traverse DISABLED_Traverse
996 #define MAYBE_Traverse Traverse
998 WRAPPED_INSTANTIATE_TEST_CASE_P(
1000 FileManagerBrowserTest
,
1001 ::testing::Values(TestParameter(IN_GUEST_MODE
, "traverseDownloads"),
1002 TestParameter(NOT_IN_GUEST_MODE
, "traverseDownloads"),
1003 TestParameter(NOT_IN_GUEST_MODE
, "traverseDrive")));
1005 // Slow tests are disabled on debug build. http://crbug.com/327719
1006 #if !defined(NDEBUG)
1007 #define MAYBE_SuggestAppDialog DISABLED_SuggestAppDialog
1009 #define MAYBE_SuggestAppDialog SuggestAppDialog
1011 WRAPPED_INSTANTIATE_TEST_CASE_P(
1012 MAYBE_SuggestAppDialog
,
1013 FileManagerBrowserTest
,
1014 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "suggestAppDialog")));
1016 // Slow tests are disabled on debug build. http://crbug.com/327719
1017 #if !defined(NDEBUG)
1018 #define MAYBE_ExecuteDefaultTaskOnDownloads \
1019 DISABLED_ExecuteDefaultTaskOnDownloads
1021 #define MAYBE_ExecuteDefaultTaskOnDownloads ExecuteDefaultTaskOnDownloads
1023 WRAPPED_INSTANTIATE_TEST_CASE_P(
1024 MAYBE_ExecuteDefaultTaskOnDownloads
,
1025 FileManagerBrowserTest
,
1027 TestParameter(NOT_IN_GUEST_MODE
, "executeDefaultTaskOnDownloads"),
1028 TestParameter(IN_GUEST_MODE
, "executeDefaultTaskOnDownloads")));
1030 // Slow tests are disabled on debug build. http://crbug.com/327719
1031 #if !defined(NDEBUG)
1032 #define MAYBE_ExecuteDefaultTaskOnDrive DISABLED_ExecuteDefaultTaskOnDrive
1034 #define MAYBE_ExecuteDefaultTaskOnDrive ExecuteDefaultTaskOnDrive
1036 INSTANTIATE_TEST_CASE_P(
1037 MAYBE_ExecuteDefaultTaskOnDrive
,
1038 FileManagerBrowserTest
,
1040 TestParameter(NOT_IN_GUEST_MODE
, "executeDefaultTaskOnDrive")));
1042 // Slow tests are disabled on debug build. http://crbug.com/327719
1043 #if !defined(NDEBUG)
1044 #define MAYBE_DefaultActionDialog DISABLED_DefaultActionDialog
1046 #define MAYBE_DefaultActionDialog DefaultActionDialog
1048 WRAPPED_INSTANTIATE_TEST_CASE_P(
1049 MAYBE_DefaultActionDialog
,
1050 FileManagerBrowserTest
,
1052 TestParameter(NOT_IN_GUEST_MODE
, "defaultActionDialogOnDownloads"),
1053 TestParameter(IN_GUEST_MODE
, "defaultActionDialogOnDownloads"),
1054 TestParameter(NOT_IN_GUEST_MODE
, "defaultActionDialogOnDrive")));
1056 // Slow tests are disabled on debug build. http://crbug.com/327719
1057 #if !defined(NDEBUG)
1058 #define MAYBE_GenericTask DISABLED_GenericTask
1060 #define MAYBE_GenericTask GenericTask
1062 WRAPPED_INSTANTIATE_TEST_CASE_P(
1064 FileManagerBrowserTest
,
1066 TestParameter(NOT_IN_GUEST_MODE
, "genericTaskIsNotExecuted"),
1067 TestParameter(NOT_IN_GUEST_MODE
, "genericAndNonGenericTasksAreMixed")));
1069 // Slow tests are disabled on debug build. http://crbug.com/327719
1070 #if !defined(NDEBUG)
1071 #define MAYBE_FolderShortcuts DISABLED_FolderShortcuts
1073 #define MAYBE_FolderShortcuts FolderShortcuts
1075 WRAPPED_INSTANTIATE_TEST_CASE_P(
1076 MAYBE_FolderShortcuts
,
1077 FileManagerBrowserTest
,
1079 TestParameter(NOT_IN_GUEST_MODE
, "traverseFolderShortcuts"),
1080 TestParameter(NOT_IN_GUEST_MODE
, "addRemoveFolderShortcuts")));
1082 INSTANTIATE_TEST_CASE_P(
1084 FileManagerBrowserTest
,
1085 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "searchBoxFocus")));
1087 // Fails on official build. http://crbug.com/429294
1088 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
1089 #define MAYBE_OpenFileDialog DISABLED_OpenFileDialog
1091 #define MAYBE_OpenFileDialog OpenFileDialog
1093 WRAPPED_INSTANTIATE_TEST_CASE_P(
1094 MAYBE_OpenFileDialog
,
1095 FileManagerBrowserTest
,
1096 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
1097 "openFileDialogOnDownloads"),
1098 TestParameter(IN_GUEST_MODE
,
1099 "openFileDialogOnDownloads"),
1100 TestParameter(NOT_IN_GUEST_MODE
,
1101 "openFileDialogOnDrive"),
1102 TestParameter(IN_INCOGNITO
,
1103 "openFileDialogOnDownloads"),
1104 TestParameter(IN_INCOGNITO
,
1105 "openFileDialogOnDrive"),
1106 TestParameter(NOT_IN_GUEST_MODE
,
1107 "unloadFileDialog")));
1109 // Slow tests are disabled on debug build. http://crbug.com/327719
1110 #if !defined(NDEBUG)
1111 #define MAYBE_CopyBetweenWindows DISABLED_CopyBetweenWindows
1113 #define MAYBE_CopyBetweenWindows CopyBetweenWindows
1115 WRAPPED_INSTANTIATE_TEST_CASE_P(
1116 MAYBE_CopyBetweenWindows
,
1117 FileManagerBrowserTest
,
1119 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsLocalToDrive"),
1120 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsLocalToUsb"),
1121 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsUsbToDrive"),
1122 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsDriveToLocal"),
1123 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsDriveToUsb"),
1124 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsUsbToLocal")));
1126 // Slow tests are disabled on debug build. http://crbug.com/327719
1127 #if !defined(NDEBUG)
1128 #define MAYBE_ShowGridView DISABLED_ShowGridView
1130 #define MAYBE_ShowGridView ShowGridView
1132 WRAPPED_INSTANTIATE_TEST_CASE_P(
1134 FileManagerBrowserTest
,
1135 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "showGridViewDownloads"),
1136 TestParameter(IN_GUEST_MODE
, "showGridViewDownloads"),
1137 TestParameter(NOT_IN_GUEST_MODE
, "showGridViewDrive")));
1139 // Structure to describe an account info.
1140 struct TestAccountInfo
{
1141 const char* const email
;
1142 const char* const hash
;
1143 const char* const display_name
;
1147 DUMMY_ACCOUNT_INDEX
= 0,
1148 PRIMARY_ACCOUNT_INDEX
= 1,
1149 SECONDARY_ACCOUNT_INDEX_START
= 2,
1152 static const TestAccountInfo kTestAccounts
[] = {
1153 {"__dummy__@invalid.domain", "hashdummy", "Dummy Account"},
1154 {"alice@invalid.domain", "hashalice", "Alice"},
1155 {"bob@invalid.domain", "hashbob", "Bob"},
1156 {"charlie@invalid.domain", "hashcharlie", "Charlie"},
1159 // Test fixture class for testing multi-profile features.
1160 class MultiProfileFileManagerBrowserTest
: public FileManagerBrowserTestBase
{
1162 // Enables multi-profiles.
1163 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1164 FileManagerBrowserTestBase::SetUpCommandLine(command_line
);
1165 // Logs in to a dummy profile (For making MultiProfileWindowManager happy;
1166 // browser test creates a default window and the manager tries to assign a
1167 // user for it, and we need a profile connected to a user.)
1168 command_line
->AppendSwitchASCII(chromeos::switches::kLoginUser
,
1169 kTestAccounts
[DUMMY_ACCOUNT_INDEX
].email
);
1170 command_line
->AppendSwitchASCII(chromeos::switches::kLoginProfile
,
1171 kTestAccounts
[DUMMY_ACCOUNT_INDEX
].hash
);
1174 // Logs in to the primary profile of this test.
1175 void SetUpOnMainThread() override
{
1176 const TestAccountInfo
& info
= kTestAccounts
[PRIMARY_ACCOUNT_INDEX
];
1178 AddUser(info
, true);
1179 FileManagerBrowserTestBase::SetUpOnMainThread();
1182 // Loads all users to the current session and sets up necessary fields.
1183 // This is used for preparing all accounts in PRE_ test setup, and for testing
1184 // actual login behavior.
1185 void AddAllUsers() {
1186 for (size_t i
= 0; i
< arraysize(kTestAccounts
); ++i
)
1187 AddUser(kTestAccounts
[i
], i
>= SECONDARY_ACCOUNT_INDEX_START
);
1190 // Returns primary profile (if it is already created.)
1191 Profile
* profile() override
{
1192 Profile
* const profile
= chromeos::ProfileHelper::GetProfileByUserIdHash(
1193 kTestAccounts
[PRIMARY_ACCOUNT_INDEX
].hash
);
1194 return profile
? profile
: FileManagerBrowserTestBase::profile();
1197 // Sets the test case name (used as a function name in test_cases.js to call.)
1198 void set_test_case_name(const std::string
& name
) { test_case_name_
= name
; }
1200 // Adds a new user for testing to the current session.
1201 void AddUser(const TestAccountInfo
& info
, bool log_in
) {
1202 user_manager::UserManager
* const user_manager
=
1203 user_manager::UserManager::Get();
1205 user_manager
->UserLoggedIn(info
.email
, info
.hash
, false);
1206 user_manager
->SaveUserDisplayName(info
.email
,
1207 base::UTF8ToUTF16(info
.display_name
));
1208 SigninManagerFactory::GetForProfile(
1209 chromeos::ProfileHelper::GetProfileByUserIdHash(info
.hash
))->
1210 SetAuthenticatedUsername(info
.email
);
1214 GuestMode
GetGuestModeParam() const override
{ return NOT_IN_GUEST_MODE
; }
1216 const char* GetTestCaseNameParam() const override
{
1217 return test_case_name_
.c_str();
1220 std::string test_case_name_
;
1223 // Slow tests are disabled on debug build. http://crbug.com/327719
1224 // Fails on official build. http://crbug.com/429294
1225 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
1226 #define MAYBE_PRE_BasicDownloads DISABLED_PRE_BasicDownloads
1227 #define MAYBE_BasicDownloads DISABLED_BasicDownloads
1229 #define MAYBE_PRE_BasicDownloads PRE_BasicDownloads
1230 #define MAYBE_BasicDownloads BasicDownloads
1232 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1233 MAYBE_PRE_BasicDownloads
) {
1237 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1238 MAYBE_BasicDownloads
) {
1241 // Sanity check that normal operations work in multi-profile setting as well.
1242 set_test_case_name("keyboardCopyDownloads");
1246 // Slow tests are disabled on debug build. http://crbug.com/327719
1247 // Fails on official build. http://crbug.com/429294
1248 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
1249 #define MAYBE_PRE_BasicDrive DISABLED_PRE_BasicDrive
1250 #define MAYBE_BasicDrive DISABLED_BasicDrive
1252 #define MAYBE_PRE_BasicDrive PRE_BasicDrive
1253 #define MAYBE_BasicDrive BasicDrive
1255 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1256 MAYBE_PRE_BasicDrive
) {
1260 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
, MAYBE_BasicDrive
) {
1263 // Sanity check that normal operations work in multi-profile setting as well.
1264 set_test_case_name("keyboardCopyDrive");
1268 template<GuestMode M
>
1269 class GalleryBrowserTestBase
: public FileManagerBrowserTestBase
{
1271 virtual GuestMode
GetGuestModeParam() const override
{ return M
; }
1272 virtual const char* GetTestCaseNameParam() const override
{
1273 return test_case_name_
.c_str();
1277 virtual void SetUp() override
{
1278 AddScript("gallery/test_util.js");
1279 FileManagerBrowserTestBase::SetUp();
1282 virtual void OnMessage(const std::string
& name
,
1283 const base::DictionaryValue
& value
,
1284 std::string
* output
) override
;
1286 virtual const char* GetTestManifestName() const override
{
1287 return "gallery_test_manifest.json";
1290 void AddScript(const std::string
& name
) {
1291 scripts_
.AppendString(
1292 "chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn/" + name
);
1295 void set_test_case_name(const std::string
& name
) {
1296 test_case_name_
= name
;
1300 base::ListValue scripts_
;
1301 std::string test_case_name_
;
1304 template <GuestMode M
>
1305 void GalleryBrowserTestBase
<M
>::OnMessage(const std::string
& name
,
1306 const base::DictionaryValue
& value
,
1307 std::string
* output
) {
1308 if (name
== "getScripts") {
1309 std::string jsonString
;
1310 base::JSONWriter::Write(&scripts_
, output
);
1314 FileManagerBrowserTestBase::OnMessage(name
, value
, output
);
1317 typedef GalleryBrowserTestBase
<NOT_IN_GUEST_MODE
> GalleryBrowserTest
;
1318 typedef GalleryBrowserTestBase
<IN_GUEST_MODE
> GalleryBrowserTestInGuestMode
;
1320 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenSingleImageOnDownloads
) {
1321 AddScript("gallery/open_image_files.js");
1322 set_test_case_name("openSingleImageOnDownloads");
1326 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1327 OpenSingleImageOnDownloads
) {
1328 AddScript("gallery/open_image_files.js");
1329 set_test_case_name("openSingleImageOnDownloads");
1333 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenSingleImageOnDrive
) {
1334 AddScript("gallery/open_image_files.js");
1335 set_test_case_name("openSingleImageOnDrive");
1339 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenMultipleImagesOnDownloads
) {
1340 AddScript("gallery/open_image_files.js");
1341 set_test_case_name("openMultipleImagesOnDownloads");
1345 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1346 OpenMultipleImagesOnDownloads
) {
1347 AddScript("gallery/open_image_files.js");
1348 set_test_case_name("openMultipleImagesOnDownloads");
1352 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenMultipleImagesOnDrive
) {
1353 AddScript("gallery/open_image_files.js");
1354 set_test_case_name("openMultipleImagesOnDrive");
1358 // Disabled due to flakiness: crbug.com/437293
1359 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
,
1360 DISABLED_TraverseSlideImagesOnDownloads
) {
1361 AddScript("gallery/slide_mode.js");
1362 set_test_case_name("traverseSlideImagesOnDownloads");
1366 // Disabled due to flakiness: crbug.com/437293
1367 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1368 DISABLED_TraverseSlideImagesOnDownloads
) {
1369 AddScript("gallery/slide_mode.js");
1370 set_test_case_name("traverseSlideImagesOnDownloads");
1374 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, TraverseSlideImagesOnDrive
) {
1375 AddScript("gallery/slide_mode.js");
1376 set_test_case_name("traverseSlideImagesOnDrive");
1380 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RenameImageOnDownloads
) {
1381 AddScript("gallery/slide_mode.js");
1382 set_test_case_name("renameImageOnDownloads");
1386 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1387 RenameImageOnDownloads
) {
1388 AddScript("gallery/slide_mode.js");
1389 set_test_case_name("renameImageOnDownloads");
1393 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RenameImageOnDrive
) {
1394 AddScript("gallery/slide_mode.js");
1395 set_test_case_name("renameImageOnDrive");
1399 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, DeleteImageOnDownloads
) {
1400 AddScript("gallery/slide_mode.js");
1401 set_test_case_name("deleteImageOnDownloads");
1405 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1406 DeleteImageOnDownloads
) {
1407 AddScript("gallery/slide_mode.js");
1408 set_test_case_name("deleteImageOnDownloads");
1412 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, DeleteImageOnDrive
) {
1413 AddScript("gallery/slide_mode.js");
1414 set_test_case_name("deleteImageOnDrive");
1418 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RotateImageOnDownloads
) {
1419 AddScript("gallery/photo_editor.js");
1420 set_test_case_name("rotateImageOnDownloads");
1424 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1425 RotateImageOnDownloads
) {
1426 AddScript("gallery/photo_editor.js");
1427 set_test_case_name("rotateImageOnDownloads");
1431 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RotateImageOnDrive
) {
1432 AddScript("gallery/photo_editor.js");
1433 set_test_case_name("rotateImageOnDrive");
1437 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, CropImageOnDownloads
) {
1438 AddScript("gallery/photo_editor.js");
1439 set_test_case_name("cropImageOnDownloads");
1443 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1444 CropImageOnDownloads
) {
1445 AddScript("gallery/photo_editor.js");
1446 set_test_case_name("cropImageOnDownloads");
1450 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, CropImageOnDrive
) {
1451 AddScript("gallery/photo_editor.js");
1452 set_test_case_name("cropImageOnDrive");
1456 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, ExposureImageOnDownloads
) {
1457 AddScript("gallery/photo_editor.js");
1458 set_test_case_name("exposureImageOnDownloads");
1462 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1463 ExposureImageOnDownloads
) {
1464 AddScript("gallery/photo_editor.js");
1465 set_test_case_name("exposureImageOnDownloads");
1469 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, ExposureImageOnDrive
) {
1470 AddScript("gallery/photo_editor.js");
1471 set_test_case_name("exposureImageOnDrive");
1475 template<GuestMode M
>
1476 class VideoPlayerBrowserTestBase
: public FileManagerBrowserTestBase
{
1478 virtual GuestMode
GetGuestModeParam() const override
{ return M
; }
1479 virtual const char* GetTestCaseNameParam() const override
{
1480 return test_case_name_
.c_str();
1484 virtual void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1485 command_line
->AppendSwitch(
1486 chromeos::switches::kEnableVideoPlayerChromecastSupport
);
1487 FileManagerBrowserTestBase::SetUpCommandLine(command_line
);
1490 virtual const char* GetTestManifestName() const override
{
1491 return "video_player_test_manifest.json";
1494 void set_test_case_name(const std::string
& name
) {
1495 test_case_name_
= name
;
1499 std::string test_case_name_
;
1502 typedef VideoPlayerBrowserTestBase
<NOT_IN_GUEST_MODE
> VideoPlayerBrowserTest
;
1503 typedef VideoPlayerBrowserTestBase
<IN_GUEST_MODE
>
1504 VideoPlayerBrowserTestInGuestMode
;
1506 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest
, OpenSingleVideoOnDownloads
) {
1507 set_test_case_name("openSingleVideoOnDownloads");
1511 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest
, OpenSingleVideoOnDrive
) {
1512 set_test_case_name("openSingleVideoOnDrive");
1517 } // namespace file_manager