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
)->AddVolumeForTesting(
336 root_path(), volume_type_
, device_type_
, false /* read_only */);
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(
392 parent_id
, target_name
, drive::AddNewDirectoryOptions(),
393 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
394 base::MessageLoop::current()->RunUntilIdle();
395 ASSERT_EQ(google_apis::HTTP_CREATED
, error
);
398 fake_drive_service_
->SetLastModifiedTime(
401 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
402 base::MessageLoop::current()->RunUntilIdle();
403 ASSERT_TRUE(error
== google_apis::HTTP_SUCCESS
);
408 // Creates a test file with the given spec.
409 // Serves |test_file_name| file. Pass an empty string for an empty file.
410 void CreateFile(const std::string
& source_file_name
,
411 const std::string
& parent_id
,
412 const std::string
& target_name
,
413 const std::string
& mime_type
,
415 const base::Time
& modification_time
) {
416 google_apis::DriveApiErrorCode error
= google_apis::DRIVE_OTHER_ERROR
;
418 std::string content_data
;
419 if (!source_file_name
.empty()) {
420 base::FilePath source_file_path
=
421 google_apis::test_util::GetTestFilePath("chromeos/file_manager").
422 AppendASCII(source_file_name
);
423 ASSERT_TRUE(base::ReadFileToString(source_file_path
, &content_data
));
426 scoped_ptr
<google_apis::FileResource
> entry
;
427 fake_drive_service_
->AddNewFile(
433 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
434 base::MessageLoop::current()->RunUntilIdle();
435 ASSERT_EQ(google_apis::HTTP_CREATED
, error
);
438 fake_drive_service_
->SetLastModifiedTime(
441 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
442 base::MessageLoop::current()->RunUntilIdle();
443 ASSERT_EQ(google_apis::HTTP_SUCCESS
, error
);
449 // Notifies FileSystem that the contents in FakeDriveService are
450 // changed, hence the new contents should be fetched.
451 void CheckForUpdates() {
452 if (integration_service_
&& integration_service_
->file_system()) {
453 integration_service_
->file_system()->CheckForUpdates();
457 // Sets the url base for the test server to be used to generate share urls
458 // on the files and directories.
459 void ConfigureShareUrlBase(const GURL
& share_url_base
) {
460 fake_drive_service_
->set_share_url_base(share_url_base
);
463 drive::DriveIntegrationService
* CreateDriveIntegrationService(
466 fake_drive_service_
= new drive::FakeDriveService
;
467 fake_drive_service_
->LoadAppListForDriveApi("drive/applist.json");
469 if (!CreateRootDirectory(profile
))
471 integration_service_
= new drive::DriveIntegrationService(
472 profile
, NULL
, fake_drive_service_
, std::string(), root_path(), NULL
);
473 return integration_service_
;
478 drive::FakeDriveService
* fake_drive_service_
;
479 drive::DriveIntegrationService
* integration_service_
;
482 // Listener to obtain the test relative messages synchronously.
483 class FileManagerTestListener
: public content::NotificationObserver
{
488 scoped_refptr
<extensions::TestSendMessageFunction
> function
;
491 FileManagerTestListener() {
493 extensions::NOTIFICATION_EXTENSION_TEST_PASSED
,
494 content::NotificationService::AllSources());
496 extensions::NOTIFICATION_EXTENSION_TEST_FAILED
,
497 content::NotificationService::AllSources());
499 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
,
500 content::NotificationService::AllSources());
503 Message
GetNextMessage() {
504 if (messages_
.empty())
505 content::RunMessageLoop();
506 const Message entry
= messages_
.front();
507 messages_
.pop_front();
511 void Observe(int type
,
512 const content::NotificationSource
& source
,
513 const content::NotificationDetails
& details
) override
{
516 entry
.message
= type
!= extensions::NOTIFICATION_EXTENSION_TEST_PASSED
517 ? *content::Details
<std::string
>(details
).ptr()
520 type
== extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
521 ? content::Source
<extensions::TestSendMessageFunction
>(source
).ptr()
523 messages_
.push_back(entry
);
524 base::MessageLoopForUI::current()->Quit();
528 std::deque
<Message
> messages_
;
529 content::NotificationRegistrar registrar_
;
532 // The base test class.
533 class FileManagerBrowserTestBase
: public ExtensionApiTest
{
535 void SetUpInProcessBrowserTestFixture() override
;
537 void SetUpOnMainThread() override
;
539 // Adds an incognito and guest-mode flags for tests in the guest mode.
540 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
542 // Loads our testing extension and sends it a string identifying the current
544 virtual void StartTest();
545 void RunTestMessageLoop();
547 // Overriding point for test configurations.
548 virtual const char* GetTestManifestName() const {
549 return "file_manager_test_manifest.json";
551 virtual GuestMode
GetGuestModeParam() const = 0;
552 virtual const char* GetTestCaseNameParam() const = 0;
553 virtual void OnMessage(const std::string
& name
,
554 const base::DictionaryValue
& value
,
555 std::string
* output
);
557 scoped_ptr
<LocalTestVolume
> local_volume_
;
558 linked_ptr
<DriveTestVolume
> drive_volume_
;
559 std::map
<Profile
*, linked_ptr
<DriveTestVolume
> > drive_volumes_
;
560 scoped_ptr
<FakeTestVolume
> usb_volume_
;
561 scoped_ptr
<FakeTestVolume
> mtp_volume_
;
564 drive::DriveIntegrationService
* CreateDriveIntegrationService(
566 DriveIntegrationServiceFactory::FactoryCallback
567 create_drive_integration_service_
;
568 scoped_ptr
<DriveIntegrationServiceFactory::ScopedFactoryForTest
>
569 service_factory_for_test_
;
572 void FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() {
573 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
574 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
576 local_volume_
.reset(new DownloadsTestVolume
);
577 if (GetGuestModeParam() != IN_GUEST_MODE
) {
578 create_drive_integration_service_
=
579 base::Bind(&FileManagerBrowserTestBase::CreateDriveIntegrationService
,
580 base::Unretained(this));
581 service_factory_for_test_
.reset(
582 new DriveIntegrationServiceFactory::ScopedFactoryForTest(
583 &create_drive_integration_service_
));
587 void FileManagerBrowserTestBase::SetUpOnMainThread() {
588 ExtensionApiTest::SetUpOnMainThread();
589 ASSERT_TRUE(local_volume_
->Mount(profile()));
591 if (GetGuestModeParam() != IN_GUEST_MODE
) {
592 // Install the web server to serve the mocked share dialog.
593 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
594 const GURL
share_url_base(embedded_test_server()->GetURL(
595 "/chromeos/file_manager/share_dialog_mock/index.html"));
596 drive_volume_
= drive_volumes_
[profile()->GetOriginalProfile()];
597 drive_volume_
->ConfigureShareUrlBase(share_url_base
);
598 test_util::WaitUntilDriveMountPointIsAdded(profile());
601 net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
604 void FileManagerBrowserTestBase::SetUpCommandLine(
605 base::CommandLine
* command_line
) {
606 if (GetGuestModeParam() == IN_GUEST_MODE
) {
607 command_line
->AppendSwitch(chromeos::switches::kGuestSession
);
608 command_line
->AppendSwitchNative(chromeos::switches::kLoginUser
, "");
609 command_line
->AppendSwitch(switches::kIncognito
);
611 if (GetGuestModeParam() == IN_INCOGNITO
) {
612 command_line
->AppendSwitch(switches::kIncognito
);
614 ExtensionApiTest::SetUpCommandLine(command_line
);
617 void FileManagerBrowserTestBase::StartTest() {
618 base::FilePath root_path
;
619 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT
, &root_path
));
621 // Launch the extension.
622 const base::FilePath path
=
623 root_path
.Append(FILE_PATH_LITERAL("ui/file_manager/integration_tests"));
624 const extensions::Extension
* const extension
=
625 LoadExtensionAsComponentWithManifest(path
, GetTestManifestName());
626 ASSERT_TRUE(extension
);
628 RunTestMessageLoop();
631 void FileManagerBrowserTestBase::RunTestMessageLoop() {
632 // Handle the messages from JavaScript.
633 // The while loop is break when the test is passed or failed.
634 FileManagerTestListener listener
;
636 FileManagerTestListener::Message entry
= listener
.GetNextMessage();
637 if (entry
.type
== extensions::NOTIFICATION_EXTENSION_TEST_PASSED
) {
640 } else if (entry
.type
== extensions::NOTIFICATION_EXTENSION_TEST_FAILED
) {
642 ADD_FAILURE() << entry
.message
;
646 // Parse the message value as JSON.
647 const scoped_ptr
<const base::Value
> value(
648 base::JSONReader::Read(entry
.message
));
650 // If the message is not the expected format, just ignore it.
651 const base::DictionaryValue
* message_dictionary
= NULL
;
653 if (!value
|| !value
->GetAsDictionary(&message_dictionary
) ||
654 !message_dictionary
->GetString("name", &name
))
658 OnMessage(name
, *message_dictionary
, &output
);
659 if (HasFatalFailure())
662 entry
.function
->Reply(output
);
666 void FileManagerBrowserTestBase::OnMessage(const std::string
& name
,
667 const base::DictionaryValue
& value
,
668 std::string
* output
) {
669 if (name
== "getTestName") {
670 // Pass the test case name.
671 *output
= GetTestCaseNameParam();
675 if (name
== "getRootPaths") {
676 // Pass the root paths.
677 const scoped_ptr
<base::DictionaryValue
> res(new base::DictionaryValue());
678 res
->SetString("downloads",
679 "/" + util::GetDownloadsMountPointName(profile()));
680 res
->SetString("drive",
681 "/" + drive::util::GetDriveMountPointPath(profile()
682 ).BaseName().AsUTF8Unsafe() + "/root");
683 base::JSONWriter::Write(res
.get(), output
);
687 if (name
== "isInGuestMode") {
688 // Obtain whether the test is in guest mode or not.
689 *output
= GetGuestModeParam() != NOT_IN_GUEST_MODE
? "true" : "false";
693 if (name
== "getCwsWidgetContainerMockUrl") {
694 // Obtain whether the test is in guest mode or not.
695 const GURL url
= embedded_test_server()->GetURL(
696 "/chromeos/file_manager/cws_container_mock/index.html");
697 std::string origin
= url
.GetOrigin().spec();
699 // Removes trailing a slash.
700 if (*origin
.rbegin() == '/')
701 origin
.resize(origin
.length() - 1);
703 const scoped_ptr
<base::DictionaryValue
> res(new base::DictionaryValue());
704 res
->SetString("url", url
.spec());
705 res
->SetString("origin", origin
);
706 base::JSONWriter::Write(res
.get(), output
);
710 if (name
== "addEntries") {
711 // Add entries to the specified volume.
712 base::JSONValueConverter
<AddEntriesMessage
> add_entries_message_converter
;
713 AddEntriesMessage message
;
714 ASSERT_TRUE(add_entries_message_converter
.Convert(value
, &message
));
716 for (size_t i
= 0; i
< message
.entries
.size(); ++i
) {
717 switch (message
.volume
) {
719 local_volume_
->CreateEntry(*message
.entries
[i
]);
722 if (drive_volume_
.get())
723 drive_volume_
->CreateEntry(*message
.entries
[i
]);
727 usb_volume_
->CreateEntry(*message
.entries
[i
]);
738 if (name
== "mountFakeUsb") {
739 usb_volume_
.reset(new FakeTestVolume("fake-usb",
740 VOLUME_TYPE_REMOVABLE_DISK_PARTITION
,
741 chromeos::DEVICE_TYPE_USB
));
742 usb_volume_
->Mount(profile());
746 if (name
== "mountFakeMtp") {
747 mtp_volume_
.reset(new FakeTestVolume("fake-mtp",
749 chromeos::DEVICE_TYPE_UNKNOWN
));
750 ASSERT_TRUE(mtp_volume_
->PrepareTestEntries(profile()));
752 mtp_volume_
->Mount(profile());
756 if (name
== "useCellularNetwork") {
757 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
758 net::NetworkChangeNotifier::CONNECTION_3G
);
762 if (name
== "clickNotificationButton") {
763 std::string extension_id
;
764 std::string notification_id
;
766 ASSERT_TRUE(value
.GetString("extensionId", &extension_id
));
767 ASSERT_TRUE(value
.GetString("notificationId", ¬ification_id
));
768 ASSERT_TRUE(value
.GetInteger("index", &index
));
770 const std::string delegate_id
= extension_id
+ "-" + notification_id
;
771 const Notification
* notification
= g_browser_process
->
772 notification_ui_manager()->FindById(delegate_id
, profile());
773 ASSERT_TRUE(notification
);
775 notification
->delegate()->ButtonClick(index
);
779 FAIL() << "Unknown test message: " << name
;
782 drive::DriveIntegrationService
*
783 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile
* profile
) {
784 drive_volumes_
[profile
->GetOriginalProfile()].reset(new DriveTestVolume());
785 return drive_volumes_
[profile
->GetOriginalProfile()]->
786 CreateDriveIntegrationService(profile
);
789 // Parameter of FileManagerBrowserTest.
790 // The second value is the case name of JavaScript.
791 typedef std::tr1::tuple
<GuestMode
, const char*> TestParameter
;
793 // Test fixture class for normal (not multi-profile related) tests.
794 class FileManagerBrowserTest
:
795 public FileManagerBrowserTestBase
,
796 public ::testing::WithParamInterface
<TestParameter
> {
797 GuestMode
GetGuestModeParam() const override
{
798 return std::tr1::get
<0>(GetParam());
800 const char* GetTestCaseNameParam() const override
{
801 return std::tr1::get
<1>(GetParam());
805 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest
, Test
) {
809 // Unlike TEST/TEST_F, which are macros that expand to further macros,
810 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
811 // stringizes the arguments. As a result, macros passed as parameters (such as
812 // prefix or test_case_name) will not be expanded by the preprocessor. To work
813 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
814 // pre-processor will expand macros such as MAYBE_test_name before
815 // instantiating the test.
816 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
817 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
819 // Slow tests are disabled on debug build. http://crbug.com/327719
820 // Fails on official build. http://crbug.com/429294
821 // Disabled under MSAN as well. http://crbug.com/468980.
822 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
823 #define MAYBE_FileDisplay DISABLED_FileDisplay
825 #define MAYBE_FileDisplay FileDisplay
827 WRAPPED_INSTANTIATE_TEST_CASE_P(
829 FileManagerBrowserTest
,
830 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayDownloads"),
831 TestParameter(IN_GUEST_MODE
, "fileDisplayDownloads"),
832 TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayDrive"),
833 TestParameter(NOT_IN_GUEST_MODE
, "fileDisplayMtp")));
835 // Slow tests are disabled on debug build. http://crbug.com/327719
836 // Fails on official build. http://crbug.com/429294
837 // Disabled under MSAN as well. http://crbug.com/468980.
838 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
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 // Disabled under MSAN, ASAN, and LSAN as well. http://crbug.com/468980.
853 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || \
854 defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
855 defined(LEAK_SANITIZER)
856 #define MAYBE_OpenAudioFiles DISABLED_OpenAudioFiles
858 #define MAYBE_OpenAudioFiles OpenAudioFiles
860 WRAPPED_INSTANTIATE_TEST_CASE_P(
861 MAYBE_OpenAudioFiles
,
862 FileManagerBrowserTest
,
864 TestParameter(IN_GUEST_MODE
, "audioOpenDownloads"),
865 TestParameter(NOT_IN_GUEST_MODE
, "audioOpenDownloads"),
866 TestParameter(NOT_IN_GUEST_MODE
, "audioOpenDrive"),
867 TestParameter(NOT_IN_GUEST_MODE
, "audioAutoAdvanceDrive"),
868 TestParameter(NOT_IN_GUEST_MODE
, "audioRepeatSingleFileDrive"),
869 TestParameter(NOT_IN_GUEST_MODE
, "audioNoRepeatSingleFileDrive"),
870 TestParameter(NOT_IN_GUEST_MODE
, "audioRepeatMultipleFileDrive"),
871 TestParameter(NOT_IN_GUEST_MODE
, "audioNoRepeatMultipleFileDrive")));
873 // Slow tests are disabled on debug build. http://crbug.com/327719
874 // Fails on official build. http://crbug.com/429294
875 // Disabled under MSAN, ASAN, and LSAN as well. http://crbug.com/468980.
876 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || \
877 defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
878 defined(LEAK_SANITIZER)
879 #define MAYBE_OpenImageFiles DISABLED_OpenImageFiles
881 #define MAYBE_OpenImageFiles OpenImageFiles
883 WRAPPED_INSTANTIATE_TEST_CASE_P(
884 MAYBE_OpenImageFiles
,
885 FileManagerBrowserTest
,
886 ::testing::Values(TestParameter(IN_GUEST_MODE
, "imageOpenDownloads"),
887 TestParameter(NOT_IN_GUEST_MODE
, "imageOpenDownloads"),
888 TestParameter(NOT_IN_GUEST_MODE
, "imageOpenDrive")));
890 // Slow tests are disabled on debug build. http://crbug.com/327719
891 // Disabled under MSAN as well. http://crbug.com/468980.
892 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
893 #define MAYBE_CreateNewFolder DISABLED_CreateNewFolder
895 #define MAYBE_CreateNewFolder CreateNewFolder
897 WRAPPED_INSTANTIATE_TEST_CASE_P(
898 MAYBE_CreateNewFolder
,
899 FileManagerBrowserTest
,
900 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
901 "createNewFolderAfterSelectFile"),
902 TestParameter(IN_GUEST_MODE
,
903 "createNewFolderDownloads"),
904 TestParameter(NOT_IN_GUEST_MODE
,
905 "createNewFolderDownloads"),
906 TestParameter(NOT_IN_GUEST_MODE
,
907 "createNewFolderDrive")));
909 // Slow tests are disabled on debug build. http://crbug.com/327719
910 // Fails on official build. http://crbug.com/429294
911 // Disabled under MSAN as well. http://crbug.com/468980.
912 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
913 #define MAYBE_KeyboardOperations DISABLED_KeyboardOperations
915 #define MAYBE_KeyboardOperations KeyboardOperations
917 WRAPPED_INSTANTIATE_TEST_CASE_P(
918 MAYBE_KeyboardOperations
,
919 FileManagerBrowserTest
,
920 ::testing::Values(TestParameter(IN_GUEST_MODE
, "keyboardDeleteDownloads"),
921 TestParameter(NOT_IN_GUEST_MODE
,
922 "keyboardDeleteDownloads"),
923 TestParameter(NOT_IN_GUEST_MODE
, "keyboardDeleteDrive"),
924 TestParameter(IN_GUEST_MODE
, "keyboardCopyDownloads"),
925 TestParameter(NOT_IN_GUEST_MODE
, "keyboardCopyDownloads"),
926 TestParameter(NOT_IN_GUEST_MODE
, "keyboardCopyDrive"),
927 TestParameter(IN_GUEST_MODE
, "renameFileDownloads"),
928 TestParameter(NOT_IN_GUEST_MODE
, "renameFileDownloads"),
929 TestParameter(NOT_IN_GUEST_MODE
, "renameFileDrive"),
930 TestParameter(IN_GUEST_MODE
,
931 "renameNewDirectoryDownloads"),
932 TestParameter(NOT_IN_GUEST_MODE
,
933 "renameNewDirectoryDownloads"),
934 TestParameter(NOT_IN_GUEST_MODE
,
935 "renameNewDirectoryDrive")));
937 // Slow tests are disabled on debug build. http://crbug.com/327719
938 // Fails on official build. http://crbug.com/429294
939 // Disabled under MSAN, ASAN, and LSAN as well. http://crbug.com/468980.
940 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || \
941 defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
942 defined(LEAK_SANITIZER)
943 #define MAYBE_DriveSpecific DISABLED_DriveSpecific
945 #define MAYBE_DriveSpecific DriveSpecific
947 WRAPPED_INSTANTIATE_TEST_CASE_P(
949 FileManagerBrowserTest
,
951 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarRecent"),
952 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarOffline"),
953 TestParameter(NOT_IN_GUEST_MODE
, "openSidebarSharedWithMe"),
954 TestParameter(NOT_IN_GUEST_MODE
, "autocomplete"),
955 TestParameter(NOT_IN_GUEST_MODE
, "pinFileOnMobileNetwork"),
956 TestParameter(NOT_IN_GUEST_MODE
, "clickFirstSearchResult"),
957 TestParameter(NOT_IN_GUEST_MODE
, "pressEnterToSearch")));
959 // Slow tests are disabled on debug build. http://crbug.com/327719
960 // Fails on official build. http://crbug.com/429294
961 // Disabled under MSAN, ASAN, and LSAN as well. http://crbug.com/468980.
962 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || \
963 defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
964 defined(LEAK_SANITIZER)
965 #define MAYBE_Transfer DISABLED_Transfer
967 #define MAYBE_Transfer Transfer
969 WRAPPED_INSTANTIATE_TEST_CASE_P(
971 FileManagerBrowserTest
,
973 TestParameter(NOT_IN_GUEST_MODE
, "transferFromDriveToDownloads"),
974 TestParameter(NOT_IN_GUEST_MODE
, "transferFromDownloadsToDrive"),
975 TestParameter(NOT_IN_GUEST_MODE
, "transferFromSharedToDownloads"),
976 TestParameter(NOT_IN_GUEST_MODE
, "transferFromSharedToDrive"),
977 TestParameter(NOT_IN_GUEST_MODE
, "transferFromRecentToDownloads"),
978 TestParameter(NOT_IN_GUEST_MODE
, "transferFromRecentToDrive"),
979 TestParameter(NOT_IN_GUEST_MODE
, "transferFromOfflineToDownloads"),
980 TestParameter(NOT_IN_GUEST_MODE
, "transferFromOfflineToDrive")));
982 // Slow tests are disabled on debug build. http://crbug.com/327719
983 // Fails on official build. http://crbug.com/429294
984 // Disabled under MSAN as well. http://crbug.com/468980.
985 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
986 #define MAYBE_RestorePrefs DISABLED_RestorePrefs
988 #define MAYBE_RestorePrefs RestorePrefs
990 WRAPPED_INSTANTIATE_TEST_CASE_P(
992 FileManagerBrowserTest
,
993 ::testing::Values(TestParameter(IN_GUEST_MODE
, "restoreSortColumn"),
994 TestParameter(NOT_IN_GUEST_MODE
, "restoreSortColumn"),
995 TestParameter(IN_GUEST_MODE
, "restoreCurrentView"),
996 TestParameter(NOT_IN_GUEST_MODE
, "restoreCurrentView")));
998 // Slow tests are disabled on debug build. http://crbug.com/327719
999 // Disabled under MSAN, ASAN, and LSAN as well. http://crbug.com/468980.
1000 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER) || \
1001 defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER)
1002 #define MAYBE_ShareDialog DISABLED_ShareDialog
1004 #define MAYBE_ShareDialog ShareDialog
1006 WRAPPED_INSTANTIATE_TEST_CASE_P(
1008 FileManagerBrowserTest
,
1009 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "shareFile"),
1010 TestParameter(NOT_IN_GUEST_MODE
, "shareDirectory")));
1012 // Slow tests are disabled on debug build. http://crbug.com/327719
1013 // Disabled under MSAN as well. http://crbug.com/468980.
1014 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1015 #define MAYBE_RestoreGeometry DISABLED_RestoreGeometry
1017 #define MAYBE_RestoreGeometry RestoreGeometry
1019 WRAPPED_INSTANTIATE_TEST_CASE_P(
1020 MAYBE_RestoreGeometry
,
1021 FileManagerBrowserTest
,
1022 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "restoreGeometry"),
1023 TestParameter(IN_GUEST_MODE
, "restoreGeometry")));
1025 // Slow tests are disabled on debug build. http://crbug.com/327719
1026 // Disabled under MSAN as well. http://crbug.com/468980.
1027 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1028 #define MAYBE_Traverse DISABLED_Traverse
1030 #define MAYBE_Traverse Traverse
1032 WRAPPED_INSTANTIATE_TEST_CASE_P(
1034 FileManagerBrowserTest
,
1035 ::testing::Values(TestParameter(IN_GUEST_MODE
, "traverseDownloads"),
1036 TestParameter(NOT_IN_GUEST_MODE
, "traverseDownloads"),
1037 TestParameter(NOT_IN_GUEST_MODE
, "traverseDrive")));
1039 // Slow tests are disabled on debug build. http://crbug.com/327719
1040 // Disabled under MSAN as well. http://crbug.com/468980.
1041 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1042 #define MAYBE_SuggestAppDialog DISABLED_SuggestAppDialog
1044 #define MAYBE_SuggestAppDialog SuggestAppDialog
1046 WRAPPED_INSTANTIATE_TEST_CASE_P(
1047 MAYBE_SuggestAppDialog
,
1048 FileManagerBrowserTest
,
1049 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "suggestAppDialog")));
1051 // Slow tests are disabled on debug build. http://crbug.com/327719
1052 // Disabled under MSAN as well. http://crbug.com/468980.
1053 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1054 #define MAYBE_ExecuteDefaultTaskOnDownloads \
1055 DISABLED_ExecuteDefaultTaskOnDownloads
1057 #define MAYBE_ExecuteDefaultTaskOnDownloads ExecuteDefaultTaskOnDownloads
1059 WRAPPED_INSTANTIATE_TEST_CASE_P(
1060 MAYBE_ExecuteDefaultTaskOnDownloads
,
1061 FileManagerBrowserTest
,
1063 TestParameter(NOT_IN_GUEST_MODE
, "executeDefaultTaskOnDownloads"),
1064 TestParameter(IN_GUEST_MODE
, "executeDefaultTaskOnDownloads")));
1066 // Slow tests are disabled on debug build. http://crbug.com/327719
1067 // Disabled under MSAN as well. http://crbug.com/468980.
1068 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1069 #define MAYBE_ExecuteDefaultTaskOnDrive DISABLED_ExecuteDefaultTaskOnDrive
1071 #define MAYBE_ExecuteDefaultTaskOnDrive ExecuteDefaultTaskOnDrive
1073 INSTANTIATE_TEST_CASE_P(
1074 MAYBE_ExecuteDefaultTaskOnDrive
,
1075 FileManagerBrowserTest
,
1077 TestParameter(NOT_IN_GUEST_MODE
, "executeDefaultTaskOnDrive")));
1079 // Slow tests are disabled on debug build. http://crbug.com/327719
1080 // Disabled under MSAN as well. http://crbug.com/468980.
1081 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1082 #define MAYBE_DefaultActionDialog DISABLED_DefaultActionDialog
1084 #define MAYBE_DefaultActionDialog DefaultActionDialog
1086 WRAPPED_INSTANTIATE_TEST_CASE_P(
1087 MAYBE_DefaultActionDialog
,
1088 FileManagerBrowserTest
,
1090 TestParameter(NOT_IN_GUEST_MODE
, "defaultActionDialogOnDownloads"),
1091 TestParameter(IN_GUEST_MODE
, "defaultActionDialogOnDownloads"),
1092 TestParameter(NOT_IN_GUEST_MODE
, "defaultActionDialogOnDrive")));
1094 // Slow tests are disabled on debug build. http://crbug.com/327719
1095 // Disabled under MSAN as well. http://crbug.com/468980.
1096 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1097 #define MAYBE_GenericTask DISABLED_GenericTask
1099 #define MAYBE_GenericTask GenericTask
1101 WRAPPED_INSTANTIATE_TEST_CASE_P(
1103 FileManagerBrowserTest
,
1105 TestParameter(NOT_IN_GUEST_MODE
, "genericTaskIsNotExecuted"),
1106 TestParameter(NOT_IN_GUEST_MODE
, "genericAndNonGenericTasksAreMixed")));
1108 // Slow tests are disabled on debug build. http://crbug.com/327719
1109 // Disabled under MSAN as well. http://crbug.com/468980.
1110 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1111 #define MAYBE_FolderShortcuts DISABLED_FolderShortcuts
1113 #define MAYBE_FolderShortcuts FolderShortcuts
1115 WRAPPED_INSTANTIATE_TEST_CASE_P(
1116 MAYBE_FolderShortcuts
,
1117 FileManagerBrowserTest
,
1119 TestParameter(NOT_IN_GUEST_MODE
, "traverseFolderShortcuts"),
1120 TestParameter(NOT_IN_GUEST_MODE
, "addRemoveFolderShortcuts")));
1122 INSTANTIATE_TEST_CASE_P(
1124 FileManagerBrowserTest
,
1125 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "searchBoxFocus")));
1127 INSTANTIATE_TEST_CASE_P(TabindexFocus
,
1128 FileManagerBrowserTest
,
1129 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
1132 INSTANTIATE_TEST_CASE_P(
1133 TabindexFocusDownloads
,
1134 FileManagerBrowserTest
,
1135 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
1136 "tabindexFocusDownloads"),
1137 TestParameter(IN_GUEST_MODE
, "tabindexFocusDownloads")));
1139 INSTANTIATE_TEST_CASE_P(
1140 TabindexFocusDirectorySelected
,
1141 FileManagerBrowserTest
,
1142 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
1143 "tabindexFocusDirectorySelected")));
1145 // Fails on official build. http://crbug.com/429294
1146 // Disabled under MSAN as well. http://crbug.com/468980.
1147 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
1148 #define MAYBE_OpenFileDialog DISABLED_OpenFileDialog
1150 #define MAYBE_OpenFileDialog OpenFileDialog
1152 WRAPPED_INSTANTIATE_TEST_CASE_P(
1153 MAYBE_OpenFileDialog
,
1154 FileManagerBrowserTest
,
1155 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
,
1156 "openFileDialogOnDownloads"),
1157 TestParameter(IN_GUEST_MODE
,
1158 "openFileDialogOnDownloads"),
1159 TestParameter(NOT_IN_GUEST_MODE
,
1160 "openFileDialogOnDrive"),
1161 TestParameter(IN_INCOGNITO
,
1162 "openFileDialogOnDownloads"),
1163 TestParameter(IN_INCOGNITO
,
1164 "openFileDialogOnDrive"),
1165 TestParameter(NOT_IN_GUEST_MODE
,
1166 "unloadFileDialog")));
1168 // Slow tests are disabled on debug build. http://crbug.com/327719
1169 // Disabled under MSAN as well. http://crbug.com/468980.
1170 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1171 #define MAYBE_CopyBetweenWindows DISABLED_CopyBetweenWindows
1173 #define MAYBE_CopyBetweenWindows CopyBetweenWindows
1175 WRAPPED_INSTANTIATE_TEST_CASE_P(
1176 MAYBE_CopyBetweenWindows
,
1177 FileManagerBrowserTest
,
1179 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsLocalToDrive"),
1180 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsLocalToUsb"),
1181 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsUsbToDrive"),
1182 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsDriveToLocal"),
1183 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsDriveToUsb"),
1184 TestParameter(NOT_IN_GUEST_MODE
, "copyBetweenWindowsUsbToLocal")));
1186 // Slow tests are disabled on debug build. http://crbug.com/327719
1187 // Disabled under MSAN as well. http://crbug.com/468980.
1188 #if !defined(NDEBUG) || defined(MEMORY_SANITIZER)
1189 #define MAYBE_ShowGridView DISABLED_ShowGridView
1191 #define MAYBE_ShowGridView ShowGridView
1193 WRAPPED_INSTANTIATE_TEST_CASE_P(
1195 FileManagerBrowserTest
,
1196 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE
, "showGridViewDownloads"),
1197 TestParameter(IN_GUEST_MODE
, "showGridViewDownloads"),
1198 TestParameter(NOT_IN_GUEST_MODE
, "showGridViewDrive")));
1200 // Structure to describe an account info.
1201 struct TestAccountInfo
{
1202 const char* const email
;
1203 const char* const hash
;
1204 const char* const display_name
;
1208 DUMMY_ACCOUNT_INDEX
= 0,
1209 PRIMARY_ACCOUNT_INDEX
= 1,
1210 SECONDARY_ACCOUNT_INDEX_START
= 2,
1213 static const TestAccountInfo kTestAccounts
[] = {
1214 {"__dummy__@invalid.domain", "hashdummy", "Dummy Account"},
1215 {"alice@invalid.domain", "hashalice", "Alice"},
1216 {"bob@invalid.domain", "hashbob", "Bob"},
1217 {"charlie@invalid.domain", "hashcharlie", "Charlie"},
1220 // Test fixture class for testing multi-profile features.
1221 class MultiProfileFileManagerBrowserTest
: public FileManagerBrowserTestBase
{
1223 // Enables multi-profiles.
1224 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1225 FileManagerBrowserTestBase::SetUpCommandLine(command_line
);
1226 // Logs in to a dummy profile (For making MultiProfileWindowManager happy;
1227 // browser test creates a default window and the manager tries to assign a
1228 // user for it, and we need a profile connected to a user.)
1229 command_line
->AppendSwitchASCII(chromeos::switches::kLoginUser
,
1230 kTestAccounts
[DUMMY_ACCOUNT_INDEX
].email
);
1231 command_line
->AppendSwitchASCII(chromeos::switches::kLoginProfile
,
1232 kTestAccounts
[DUMMY_ACCOUNT_INDEX
].hash
);
1235 // Logs in to the primary profile of this test.
1236 void SetUpOnMainThread() override
{
1237 const TestAccountInfo
& info
= kTestAccounts
[PRIMARY_ACCOUNT_INDEX
];
1239 AddUser(info
, true);
1240 FileManagerBrowserTestBase::SetUpOnMainThread();
1243 // Loads all users to the current session and sets up necessary fields.
1244 // This is used for preparing all accounts in PRE_ test setup, and for testing
1245 // actual login behavior.
1246 void AddAllUsers() {
1247 for (size_t i
= 0; i
< arraysize(kTestAccounts
); ++i
)
1248 AddUser(kTestAccounts
[i
], i
>= SECONDARY_ACCOUNT_INDEX_START
);
1251 // Returns primary profile (if it is already created.)
1252 Profile
* profile() override
{
1253 Profile
* const profile
= chromeos::ProfileHelper::GetProfileByUserIdHash(
1254 kTestAccounts
[PRIMARY_ACCOUNT_INDEX
].hash
);
1255 return profile
? profile
: FileManagerBrowserTestBase::profile();
1258 // Sets the test case name (used as a function name in test_cases.js to call.)
1259 void set_test_case_name(const std::string
& name
) { test_case_name_
= name
; }
1261 // Adds a new user for testing to the current session.
1262 void AddUser(const TestAccountInfo
& info
, bool log_in
) {
1263 user_manager::UserManager
* const user_manager
=
1264 user_manager::UserManager::Get();
1266 user_manager
->UserLoggedIn(info
.email
, info
.hash
, false);
1267 user_manager
->SaveUserDisplayName(info
.email
,
1268 base::UTF8ToUTF16(info
.display_name
));
1269 SigninManagerFactory::GetForProfile(
1270 chromeos::ProfileHelper::GetProfileByUserIdHash(info
.hash
))->
1271 SetAuthenticatedUsername(info
.email
);
1275 GuestMode
GetGuestModeParam() const override
{ return NOT_IN_GUEST_MODE
; }
1277 const char* GetTestCaseNameParam() const override
{
1278 return test_case_name_
.c_str();
1281 std::string test_case_name_
;
1284 // Slow tests are disabled on debug build. http://crbug.com/327719
1285 // Fails on official build. http://crbug.com/429294
1286 // Disabled under MSAN as well. http://crbug.com/468980.
1287 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
1288 #define MAYBE_PRE_BasicDownloads DISABLED_PRE_BasicDownloads
1289 #define MAYBE_BasicDownloads DISABLED_BasicDownloads
1291 #define MAYBE_PRE_BasicDownloads PRE_BasicDownloads
1292 #define MAYBE_BasicDownloads BasicDownloads
1294 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1295 MAYBE_PRE_BasicDownloads
) {
1299 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1300 MAYBE_BasicDownloads
) {
1303 // Sanity check that normal operations work in multi-profile setting as well.
1304 set_test_case_name("keyboardCopyDownloads");
1308 // Slow tests are disabled on debug build. http://crbug.com/327719
1309 // Fails on official build. http://crbug.com/429294
1310 // Disabled under MSAN as well. http://crbug.com/468980.
1311 #if !defined(NDEBUG) || defined(OFFICIAL_BUILD) || defined(MEMORY_SANITIZER)
1312 #define MAYBE_PRE_BasicDrive DISABLED_PRE_BasicDrive
1313 #define MAYBE_BasicDrive DISABLED_BasicDrive
1315 #define MAYBE_PRE_BasicDrive PRE_BasicDrive
1316 #define MAYBE_BasicDrive BasicDrive
1318 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
,
1319 MAYBE_PRE_BasicDrive
) {
1323 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest
, MAYBE_BasicDrive
) {
1326 // Sanity check that normal operations work in multi-profile setting as well.
1327 set_test_case_name("keyboardCopyDrive");
1331 template<GuestMode M
>
1332 class GalleryBrowserTestBase
: public FileManagerBrowserTestBase
{
1334 virtual GuestMode
GetGuestModeParam() const override
{ return M
; }
1335 virtual const char* GetTestCaseNameParam() const override
{
1336 return test_case_name_
.c_str();
1340 virtual const char* GetTestManifestName() const override
{
1341 return "gallery_test_manifest.json";
1344 void set_test_case_name(const std::string
& name
) {
1345 test_case_name_
= name
;
1349 base::ListValue scripts_
;
1350 std::string test_case_name_
;
1353 typedef GalleryBrowserTestBase
<NOT_IN_GUEST_MODE
> GalleryBrowserTest
;
1354 typedef GalleryBrowserTestBase
<IN_GUEST_MODE
> GalleryBrowserTestInGuestMode
;
1356 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenSingleImageOnDownloads
) {
1357 set_test_case_name("openSingleImageOnDownloads");
1361 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1362 OpenSingleImageOnDownloads
) {
1363 set_test_case_name("openSingleImageOnDownloads");
1367 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenSingleImageOnDrive
) {
1368 set_test_case_name("openSingleImageOnDrive");
1372 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenMultipleImagesOnDownloads
) {
1373 set_test_case_name("openMultipleImagesOnDownloads");
1377 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1378 OpenMultipleImagesOnDownloads
) {
1379 set_test_case_name("openMultipleImagesOnDownloads");
1383 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, OpenMultipleImagesOnDrive
) {
1384 set_test_case_name("openMultipleImagesOnDrive");
1388 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, TraverseSlideImagesOnDownloads
) {
1389 set_test_case_name("traverseSlideImagesOnDownloads");
1393 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1394 TraverseSlideImagesOnDownloads
) {
1395 set_test_case_name("traverseSlideImagesOnDownloads");
1399 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, TraverseSlideImagesOnDrive
) {
1400 set_test_case_name("traverseSlideImagesOnDrive");
1404 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RenameImageOnDownloads
) {
1405 set_test_case_name("renameImageOnDownloads");
1409 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1410 RenameImageOnDownloads
) {
1411 set_test_case_name("renameImageOnDownloads");
1415 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RenameImageOnDrive
) {
1416 set_test_case_name("renameImageOnDrive");
1420 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, DeleteImageOnDownloads
) {
1421 set_test_case_name("deleteImageOnDownloads");
1425 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1426 DeleteImageOnDownloads
) {
1427 set_test_case_name("deleteImageOnDownloads");
1431 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, DeleteImageOnDrive
) {
1432 set_test_case_name("deleteImageOnDrive");
1436 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RotateImageOnDownloads
) {
1437 set_test_case_name("rotateImageOnDownloads");
1441 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1442 RotateImageOnDownloads
) {
1443 set_test_case_name("rotateImageOnDownloads");
1447 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, RotateImageOnDrive
) {
1448 set_test_case_name("rotateImageOnDrive");
1452 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, CropImageOnDownloads
) {
1453 set_test_case_name("cropImageOnDownloads");
1457 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1458 CropImageOnDownloads
) {
1459 set_test_case_name("cropImageOnDownloads");
1463 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, CropImageOnDrive
) {
1464 set_test_case_name("cropImageOnDrive");
1468 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, ExposureImageOnDownloads
) {
1469 set_test_case_name("exposureImageOnDownloads");
1473 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode
,
1474 ExposureImageOnDownloads
) {
1475 set_test_case_name("exposureImageOnDownloads");
1479 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest
, ExposureImageOnDrive
) {
1480 set_test_case_name("exposureImageOnDrive");
1484 template<GuestMode M
>
1485 class VideoPlayerBrowserTestBase
: public FileManagerBrowserTestBase
{
1487 virtual GuestMode
GetGuestModeParam() const override
{ return M
; }
1488 virtual const char* GetTestCaseNameParam() const override
{
1489 return test_case_name_
.c_str();
1493 virtual void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1494 command_line
->AppendSwitch(
1495 chromeos::switches::kEnableVideoPlayerChromecastSupport
);
1496 FileManagerBrowserTestBase::SetUpCommandLine(command_line
);
1499 virtual const char* GetTestManifestName() const override
{
1500 return "video_player_test_manifest.json";
1503 void set_test_case_name(const std::string
& name
) {
1504 test_case_name_
= name
;
1508 std::string test_case_name_
;
1511 typedef VideoPlayerBrowserTestBase
<NOT_IN_GUEST_MODE
> VideoPlayerBrowserTest
;
1512 typedef VideoPlayerBrowserTestBase
<IN_GUEST_MODE
>
1513 VideoPlayerBrowserTestInGuestMode
;
1515 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest
, OpenSingleVideoOnDownloads
) {
1516 set_test_case_name("openSingleVideoOnDownloads");
1520 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest
, OpenSingleVideoOnDrive
) {
1521 set_test_case_name("openSingleVideoOnDrive");
1526 } // namespace file_manager