NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / file_manager_browsertest.cc
blob9f990ebaf092dbbf981a5ab8458a96100e0e414a
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
7 // folder.
8 // - Selecting a file and copy-pasting it with the keyboard copies the file.
9 // - Selecting a file and pressing delete deletes it.
11 #include <deque>
12 #include <string>
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 {
64 namespace {
66 enum EntryType {
67 FILE,
68 DIRECTORY,
71 enum TargetVolume { LOCAL_VOLUME, DRIVE_VOLUME, USB_VOLUME, };
73 enum SharedOption {
74 NONE,
75 SHARED,
78 enum GuestMode {
79 NOT_IN_GUEST_MODE,
80 IN_GUEST_MODE,
81 IN_INCOGNITO
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) {
92 if (value == "file")
93 *output = FILE;
94 else if (value == "directory")
95 *output = DIRECTORY;
96 else
97 return false;
98 return true;
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")
105 *output = SHARED;
106 else if (value == "none")
107 *output = NONE;
108 else
109 return false;
110 return true;
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;
122 else
123 return false;
124 return true;
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) :
142 type(type),
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) {
150 EntryType type;
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);
162 // static
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,
177 &MapStringToTime);
180 // Message from JavaScript to add entries.
181 struct AddEntriesMessage {
182 // Target volume to be added the |entries|.
183 TargetVolume volume;
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);
193 // static
194 void AddEntriesMessage::RegisterJSONConverter(
195 base::JSONValueConverter<AddEntriesMessage>* converter) {
196 converter->RegisterCustomField("volume",
197 &AddEntriesMessage::volume,
198 &MapStringToTargetVolume);
199 converter->RegisterRepeatedMessage<TestEntryInfo>(
200 "entries",
201 &AddEntriesMessage::entries);
204 // Test volume.
205 class TestVolume {
206 protected:
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(); }
218 private:
219 std::string name_;
220 base::ScopedTempDir root_;
223 // The local volume class for test.
224 // This class provides the operations for a test volume that simulates local
225 // drive.
226 class LocalTestVolume : public TestVolume {
227 public:
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
232 // success.
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) {
241 case FILE: {
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.";
248 break;
250 case DIRECTORY:
251 ASSERT_TRUE(base::CreateDirectory(target_path)) <<
252 "Failed to create a directory: " << target_path.value();
253 break;
255 ASSERT_TRUE(UpdateModifiedTime(entry));
258 private:
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))
265 return false;
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())
273 return false;
274 return UpdateModifiedTime(it->second);
276 return true;
279 std::map<base::FilePath, const TestEntryInfo> entries_;
282 class DownloadsTestVolume : public LocalTestVolume {
283 public:
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 {
296 public:
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))
308 return false;
309 // Must be in sync with BASIC_FAKE_ENTRY_SET in the JS test code.
310 CreateEntry(
311 TestEntryInfo(FILE, "text.txt", "hello.txt", "text/plain", NONE,
312 base::Time::Now()));
313 CreateEntry(
314 TestEntryInfo(DIRECTORY, std::string(), "A", std::string(), NONE,
315 base::Time::Now()));
316 return true;
319 bool Mount(Profile* profile) override {
320 if (!CreateRootDirectory(profile))
321 return false;
322 storage::ExternalMountPoints* const mount_points =
323 storage::ExternalMountPoints::GetSystemInstance();
325 // First revoke the existing mount point (if any).
326 mount_points->RevokeFileSystem(name());
327 const bool result =
328 mount_points->RegisterFileSystem(name(),
329 storage::kFileSystemTypeNativeLocal,
330 storage::FileSystemMountOption(),
331 root_path());
332 if (!result)
333 return false;
335 VolumeManager::Get(profile)->AddVolumeInfoForTesting(
336 root_path(), volume_type_, device_type_);
337 return true;
340 private:
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
347 // drive.
348 class DriveTestVolume : public TestVolume {
349 public:
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) {
370 case FILE:
371 CreateFile(entry.source_file_name,
372 parent_entry->resource_id(),
373 target_name,
374 entry.mime_type,
375 entry.shared_option == SHARED,
376 entry.last_modified_time);
377 break;
378 case DIRECTORY:
379 CreateDirectory(
380 parent_entry->resource_id(), target_name, entry.last_modified_time);
381 break;
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,
393 target_name,
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);
398 ASSERT_TRUE(entry);
400 fake_drive_service_->SetLastModifiedTime(
401 entry->file_id(),
402 modification_time,
403 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
404 base::MessageLoop::current()->RunUntilIdle();
405 ASSERT_TRUE(error == google_apis::HTTP_SUCCESS);
406 ASSERT_TRUE(entry);
407 CheckForUpdates();
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,
416 bool shared_with_me,
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(
430 mime_type,
431 content_data,
432 parent_id,
433 target_name,
434 shared_with_me,
435 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
436 base::MessageLoop::current()->RunUntilIdle();
437 ASSERT_EQ(google_apis::HTTP_CREATED, error);
438 ASSERT_TRUE(entry);
440 fake_drive_service_->SetLastModifiedTime(
441 entry->file_id(),
442 modification_time,
443 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
444 base::MessageLoop::current()->RunUntilIdle();
445 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
446 ASSERT_TRUE(entry);
448 CheckForUpdates();
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(
466 Profile* profile) {
467 profile_ = profile;
468 fake_drive_service_ = new drive::FakeDriveService;
469 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
471 if (!CreateRootDirectory(profile))
472 return NULL;
473 integration_service_ = new drive::DriveIntegrationService(
474 profile, NULL, fake_drive_service_, std::string(), root_path(), NULL);
475 return integration_service_;
478 private:
479 Profile* profile_;
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 {
486 public:
487 struct Message {
488 int type;
489 std::string message;
490 scoped_refptr<extensions::TestSendMessageFunction> function;
493 FileManagerTestListener() {
494 registrar_.Add(this,
495 extensions::NOTIFICATION_EXTENSION_TEST_PASSED,
496 content::NotificationService::AllSources());
497 registrar_.Add(this,
498 extensions::NOTIFICATION_EXTENSION_TEST_FAILED,
499 content::NotificationService::AllSources());
500 registrar_.Add(this,
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();
510 return entry;
513 void Observe(int type,
514 const content::NotificationSource& source,
515 const content::NotificationDetails& details) override {
516 Message entry;
517 entry.type = type;
518 entry.message = type != extensions::NOTIFICATION_EXTENSION_TEST_PASSED
519 ? *content::Details<std::string>(details).ptr()
520 : std::string();
521 entry.function =
522 type == extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
523 ? content::Source<extensions::TestSendMessageFunction>(source).ptr()
524 : NULL;
525 messages_.push_back(entry);
526 base::MessageLoopForUI::current()->Quit();
529 private:
530 std::deque<Message> messages_;
531 content::NotificationRegistrar registrar_;
534 // The base test class.
535 class FileManagerBrowserTestBase : public ExtensionApiTest {
536 protected:
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
545 // test.
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_;
565 private:
566 drive::DriveIntegrationService* CreateDriveIntegrationService(
567 Profile* profile);
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;
637 while (true) {
638 FileManagerTestListener::Message entry = listener.GetNextMessage();
639 if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED) {
640 // Test succeed.
641 break;
642 } else if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) {
643 // Test failed.
644 ADD_FAILURE() << entry.message;
645 break;
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;
654 std::string name;
655 if (!value || !value->GetAsDictionary(&message_dictionary) ||
656 !message_dictionary->GetString("name", &name))
657 continue;
659 std::string output;
660 OnMessage(name, *message_dictionary, &output);
661 if (HasFatalFailure())
662 break;
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();
674 return;
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);
686 return;
689 if (name == "isInGuestMode") {
690 // Obtain whether the test is in guest mode or not.
691 *output = GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false";
692 return;
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);
709 return;
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) {
720 case LOCAL_VOLUME:
721 local_volume_->CreateEntry(*message.entries[i]);
722 break;
723 case DRIVE_VOLUME:
724 if (drive_volume_.get())
725 drive_volume_->CreateEntry(*message.entries[i]);
726 break;
727 case USB_VOLUME:
728 if (usb_volume_)
729 usb_volume_->CreateEntry(*message.entries[i]);
730 break;
731 default:
732 NOTREACHED();
733 break;
737 return;
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());
745 return;
748 if (name == "mountFakeMtp") {
749 mtp_volume_.reset(new FakeTestVolume("fake-mtp",
750 VOLUME_TYPE_MTP,
751 chromeos::DEVICE_TYPE_UNKNOWN));
752 ASSERT_TRUE(mtp_volume_->PrepareTestEntries(profile()));
754 mtp_volume_->Mount(profile());
755 return;
758 if (name == "useCellularNetwork") {
759 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
760 net::NetworkChangeNotifier::CONNECTION_3G);
761 return;
764 if (name == "clickNotificationButton") {
765 std::string extension_id;
766 std::string notification_id;
767 int index;
768 ASSERT_TRUE(value.GetString("extensionId", &extension_id));
769 ASSERT_TRUE(value.GetString("notificationId", &notification_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);
778 return;
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) {
808 StartTest();
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
825 #else
826 #define MAYBE_FileDisplay FileDisplay
827 #endif
828 WRAPPED_INSTANTIATE_TEST_CASE_P(
829 MAYBE_FileDisplay,
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
840 #else
841 #define MAYBE_OpenVideoFiles OpenVideoFiles
842 #endif
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
854 #else
855 #define MAYBE_OpenAudioFiles OpenAudioFiles
856 #endif
857 WRAPPED_INSTANTIATE_TEST_CASE_P(
858 MAYBE_OpenAudioFiles,
859 FileManagerBrowserTest,
860 ::testing::Values(
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
873 #else
874 #define MAYBE_CreateNewFolder CreateNewFolder
875 #endif
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
892 #else
893 #define MAYBE_KeyboardOperations KeyboardOperations
894 #endif
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
919 #else
920 #define MAYBE_DriveSpecific DriveSpecific
921 #endif
922 WRAPPED_INSTANTIATE_TEST_CASE_P(
923 MAYBE_DriveSpecific,
924 FileManagerBrowserTest,
925 ::testing::Values(
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
936 #else
937 #define MAYBE_Transfer Transfer
938 #endif
939 WRAPPED_INSTANTIATE_TEST_CASE_P(
940 MAYBE_Transfer,
941 FileManagerBrowserTest,
942 ::testing::Values(
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
956 #else
957 #define MAYBE_RestorePrefs RestorePrefs
958 #endif
959 WRAPPED_INSTANTIATE_TEST_CASE_P(
960 MAYBE_RestorePrefs,
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
968 #if !defined(NDEBUG)
969 #define MAYBE_ShareDialog DISABLED_ShareDialog
970 #else
971 #define MAYBE_ShareDialog ShareDialog
972 #endif
973 WRAPPED_INSTANTIATE_TEST_CASE_P(
974 MAYBE_ShareDialog,
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
980 #if !defined(NDEBUG)
981 #define MAYBE_RestoreGeometry DISABLED_RestoreGeometry
982 #else
983 #define MAYBE_RestoreGeometry RestoreGeometry
984 #endif
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
993 #if !defined(NDEBUG)
994 #define MAYBE_Traverse DISABLED_Traverse
995 #else
996 #define MAYBE_Traverse Traverse
997 #endif
998 WRAPPED_INSTANTIATE_TEST_CASE_P(
999 MAYBE_Traverse,
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
1008 #else
1009 #define MAYBE_SuggestAppDialog SuggestAppDialog
1010 #endif
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
1020 #else
1021 #define MAYBE_ExecuteDefaultTaskOnDownloads ExecuteDefaultTaskOnDownloads
1022 #endif
1023 WRAPPED_INSTANTIATE_TEST_CASE_P(
1024 MAYBE_ExecuteDefaultTaskOnDownloads,
1025 FileManagerBrowserTest,
1026 ::testing::Values(
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
1033 #else
1034 #define MAYBE_ExecuteDefaultTaskOnDrive ExecuteDefaultTaskOnDrive
1035 #endif
1036 INSTANTIATE_TEST_CASE_P(
1037 MAYBE_ExecuteDefaultTaskOnDrive,
1038 FileManagerBrowserTest,
1039 ::testing::Values(
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
1045 #else
1046 #define MAYBE_DefaultActionDialog DefaultActionDialog
1047 #endif
1048 WRAPPED_INSTANTIATE_TEST_CASE_P(
1049 MAYBE_DefaultActionDialog,
1050 FileManagerBrowserTest,
1051 ::testing::Values(
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
1059 #else
1060 #define MAYBE_GenericTask GenericTask
1061 #endif
1062 WRAPPED_INSTANTIATE_TEST_CASE_P(
1063 MAYBE_GenericTask,
1064 FileManagerBrowserTest,
1065 ::testing::Values(
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
1072 #else
1073 #define MAYBE_FolderShortcuts FolderShortcuts
1074 #endif
1075 WRAPPED_INSTANTIATE_TEST_CASE_P(
1076 MAYBE_FolderShortcuts,
1077 FileManagerBrowserTest,
1078 ::testing::Values(
1079 TestParameter(NOT_IN_GUEST_MODE, "traverseFolderShortcuts"),
1080 TestParameter(NOT_IN_GUEST_MODE, "addRemoveFolderShortcuts")));
1082 INSTANTIATE_TEST_CASE_P(
1083 TabIndex,
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
1090 #else
1091 #define MAYBE_OpenFileDialog OpenFileDialog
1092 #endif
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
1112 #else
1113 #define MAYBE_CopyBetweenWindows CopyBetweenWindows
1114 #endif
1115 WRAPPED_INSTANTIATE_TEST_CASE_P(
1116 MAYBE_CopyBetweenWindows,
1117 FileManagerBrowserTest,
1118 ::testing::Values(
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
1129 #else
1130 #define MAYBE_ShowGridView ShowGridView
1131 #endif
1132 WRAPPED_INSTANTIATE_TEST_CASE_P(
1133 MAYBE_ShowGridView,
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;
1146 enum {
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 {
1161 protected:
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();
1204 if (log_in)
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);
1213 private:
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
1228 #else
1229 #define MAYBE_PRE_BasicDownloads PRE_BasicDownloads
1230 #define MAYBE_BasicDownloads BasicDownloads
1231 #endif
1232 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
1233 MAYBE_PRE_BasicDownloads) {
1234 AddAllUsers();
1237 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
1238 MAYBE_BasicDownloads) {
1239 AddAllUsers();
1241 // Sanity check that normal operations work in multi-profile setting as well.
1242 set_test_case_name("keyboardCopyDownloads");
1243 StartTest();
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
1251 #else
1252 #define MAYBE_PRE_BasicDrive PRE_BasicDrive
1253 #define MAYBE_BasicDrive BasicDrive
1254 #endif
1255 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
1256 MAYBE_PRE_BasicDrive) {
1257 AddAllUsers();
1260 IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest, MAYBE_BasicDrive) {
1261 AddAllUsers();
1263 // Sanity check that normal operations work in multi-profile setting as well.
1264 set_test_case_name("keyboardCopyDrive");
1265 StartTest();
1268 template<GuestMode M>
1269 class GalleryBrowserTestBase : public FileManagerBrowserTestBase {
1270 public:
1271 virtual GuestMode GetGuestModeParam() const override { return M; }
1272 virtual const char* GetTestCaseNameParam() const override {
1273 return test_case_name_.c_str();
1276 protected:
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;
1299 private:
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);
1311 return;
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");
1323 StartTest();
1326 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1327 OpenSingleImageOnDownloads) {
1328 AddScript("gallery/open_image_files.js");
1329 set_test_case_name("openSingleImageOnDownloads");
1330 StartTest();
1333 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDrive) {
1334 AddScript("gallery/open_image_files.js");
1335 set_test_case_name("openSingleImageOnDrive");
1336 StartTest();
1339 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenMultipleImagesOnDownloads) {
1340 AddScript("gallery/open_image_files.js");
1341 set_test_case_name("openMultipleImagesOnDownloads");
1342 StartTest();
1345 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1346 OpenMultipleImagesOnDownloads) {
1347 AddScript("gallery/open_image_files.js");
1348 set_test_case_name("openMultipleImagesOnDownloads");
1349 StartTest();
1352 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenMultipleImagesOnDrive) {
1353 AddScript("gallery/open_image_files.js");
1354 set_test_case_name("openMultipleImagesOnDrive");
1355 StartTest();
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");
1363 StartTest();
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");
1371 StartTest();
1374 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, TraverseSlideImagesOnDrive) {
1375 AddScript("gallery/slide_mode.js");
1376 set_test_case_name("traverseSlideImagesOnDrive");
1377 StartTest();
1380 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RenameImageOnDownloads) {
1381 AddScript("gallery/slide_mode.js");
1382 set_test_case_name("renameImageOnDownloads");
1383 StartTest();
1386 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1387 RenameImageOnDownloads) {
1388 AddScript("gallery/slide_mode.js");
1389 set_test_case_name("renameImageOnDownloads");
1390 StartTest();
1393 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RenameImageOnDrive) {
1394 AddScript("gallery/slide_mode.js");
1395 set_test_case_name("renameImageOnDrive");
1396 StartTest();
1399 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, DeleteImageOnDownloads) {
1400 AddScript("gallery/slide_mode.js");
1401 set_test_case_name("deleteImageOnDownloads");
1402 StartTest();
1405 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1406 DeleteImageOnDownloads) {
1407 AddScript("gallery/slide_mode.js");
1408 set_test_case_name("deleteImageOnDownloads");
1409 StartTest();
1412 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, DeleteImageOnDrive) {
1413 AddScript("gallery/slide_mode.js");
1414 set_test_case_name("deleteImageOnDrive");
1415 StartTest();
1418 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RotateImageOnDownloads) {
1419 AddScript("gallery/photo_editor.js");
1420 set_test_case_name("rotateImageOnDownloads");
1421 StartTest();
1424 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1425 RotateImageOnDownloads) {
1426 AddScript("gallery/photo_editor.js");
1427 set_test_case_name("rotateImageOnDownloads");
1428 StartTest();
1431 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RotateImageOnDrive) {
1432 AddScript("gallery/photo_editor.js");
1433 set_test_case_name("rotateImageOnDrive");
1434 StartTest();
1437 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, CropImageOnDownloads) {
1438 AddScript("gallery/photo_editor.js");
1439 set_test_case_name("cropImageOnDownloads");
1440 StartTest();
1443 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1444 CropImageOnDownloads) {
1445 AddScript("gallery/photo_editor.js");
1446 set_test_case_name("cropImageOnDownloads");
1447 StartTest();
1450 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, CropImageOnDrive) {
1451 AddScript("gallery/photo_editor.js");
1452 set_test_case_name("cropImageOnDrive");
1453 StartTest();
1456 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, ExposureImageOnDownloads) {
1457 AddScript("gallery/photo_editor.js");
1458 set_test_case_name("exposureImageOnDownloads");
1459 StartTest();
1462 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
1463 ExposureImageOnDownloads) {
1464 AddScript("gallery/photo_editor.js");
1465 set_test_case_name("exposureImageOnDownloads");
1466 StartTest();
1469 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, ExposureImageOnDrive) {
1470 AddScript("gallery/photo_editor.js");
1471 set_test_case_name("exposureImageOnDrive");
1472 StartTest();
1475 template<GuestMode M>
1476 class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
1477 public:
1478 virtual GuestMode GetGuestModeParam() const override { return M; }
1479 virtual const char* GetTestCaseNameParam() const override {
1480 return test_case_name_.c_str();
1483 protected:
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;
1498 private:
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");
1508 StartTest();
1511 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDrive) {
1512 set_test_case_name("openSingleVideoOnDrive");
1513 StartTest();
1516 } // namespace
1517 } // namespace file_manager