Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_manager / file_manager_browsertest.cc
index 771e13f..2a0357e 100644 (file)
 #include <string>
 
 #include "base/bind.h"
-#include "base/callback.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/json/json_reader.h"
 #include "base/json/json_value_converter.h"
 #include "base/json/json_writer.h"
+#include "base/prefs/pref_service.h"
 #include "base/strings/string_piece.h"
+#include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/browser_process.h"
 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
 #include "chrome/browser/chromeos/drive/file_system_interface.h"
 #include "chrome/browser/chromeos/drive/test_util.h"
+#include "chrome/browser/chromeos/file_manager/app_id.h"
 #include "chrome/browser/chromeos/file_manager/drive_test_util.h"
 #include "chrome/browser/chromeos/file_manager/path_util.h"
+#include "chrome/browser/chromeos/file_manager/volume_manager.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
 #include "chrome/browser/drive/fake_drive_service.h"
-#include "chrome/browser/extensions/api/test/test_api.h"
 #include "chrome/browser/extensions/component_loader.h"
 #include "chrome/browser/extensions/extension_apitest.h"
-#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
 #include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
+#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
 #include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
 #include "chromeos/chromeos_switches.h"
-#include "content/public/browser/browser_context.h"
+#include "components/user_manager/user_manager.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/test/test_utils.h"
+#include "extensions/browser/api/test/test_api.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/notification_types.h"
 #include "extensions/common/extension.h"
-#include "google_apis/drive/gdata_wapi_parser.h"
+#include "extensions/test/extension_test_message_listener.h"
+#include "google_apis/drive/drive_api_parser.h"
 #include "google_apis/drive/test_util.h"
 #include "net/test/embedded_test_server/embedded_test_server.h"
-#include "webkit/browser/fileapi/external_mount_points.h"
+#include "storage/browser/fileapi/external_mount_points.h"
 
 using drive::DriveIntegrationServiceFactory;
 
@@ -53,10 +65,7 @@ enum EntryType {
   DIRECTORY,
 };
 
-enum TargetVolume {
-  LOCAL_VOLUME,
-  DRIVE_VOLUME,
-};
+enum TargetVolume { LOCAL_VOLUME, DRIVE_VOLUME, USB_VOLUME, };
 
 enum SharedOption {
   NONE,
@@ -66,6 +75,7 @@ enum SharedOption {
 enum GuestMode {
   NOT_IN_GUEST_MODE,
   IN_GUEST_MODE,
+  IN_INCOGNITO
 };
 
 // This global operator is used from Google Test to format error messages.
@@ -104,6 +114,8 @@ bool MapStringToTargetVolume(const base::StringPiece& value,
     *output = DRIVE_VOLUME;
   else if (value == "local")
     *output = LOCAL_VOLUME;
+  else if (value == "usb")
+    *output = USB_VOLUME;
   else
     return false;
   return true;
@@ -175,7 +187,6 @@ struct AddEntriesMessage {
       base::JSONValueConverter<AddEntriesMessage>* converter);
 };
 
-
 // static
 void AddEntriesMessage::RegisterJSONConverter(
     base::JSONValueConverter<AddEntriesMessage>* converter) {
@@ -187,27 +198,40 @@ void AddEntriesMessage::RegisterJSONConverter(
       &AddEntriesMessage::entries);
 }
 
+// Test volume.
+class TestVolume {
+ protected:
+  explicit TestVolume(const std::string& name) : name_(name) {}
+  virtual ~TestVolume() {}
+
+  bool CreateRootDirectory(const Profile* profile) {
+    const base::FilePath path = profile->GetPath().Append(name_);
+    return root_.path() == path || root_.Set(path);
+  }
+
+  const std::string& name() { return name_; }
+  const base::FilePath root_path() { return root_.path(); }
+
+ private:
+  std::string name_;
+  base::ScopedTempDir root_;
+};
+
 // The local volume class for test.
 // This class provides the operations for a test volume that simulates local
 // drive.
-class LocalTestVolume {
+class LocalTestVolume : public TestVolume {
  public:
+  explicit LocalTestVolume(const std::string& name) : TestVolume(name) {}
+  virtual ~LocalTestVolume() {}
+
   // Adds this volume to the file system as a local volume. Returns true on
   // success.
-  bool Mount(Profile* profile) {
-    if (local_path_.empty()) {
-      if (!tmp_dir_.CreateUniqueTempDir())
-        return false;
-      local_path_ = tmp_dir_.path().Append("Downloads");
-    }
-
-    return util::RegisterDownloadsMountPoint(profile, local_path_) &&
-        base::CreateDirectory(local_path_);
-  }
+  virtual bool Mount(Profile* profile) = 0;
 
   void CreateEntry(const TestEntryInfo& entry) {
     const base::FilePath target_path =
-        local_path_.AppendASCII(entry.target_path);
+        root_path().AppendASCII(entry.target_path);
 
     entries_.insert(std::make_pair(target_path, entry));
     switch (entry.type) {
@@ -232,14 +256,14 @@ class LocalTestVolume {
   // Updates ModifiedTime of the entry and its parents by referring
   // TestEntryInfo. Returns true on success.
   bool UpdateModifiedTime(const TestEntryInfo& entry) {
-    const base::FilePath path = local_path_.AppendASCII(entry.target_path);
+    const base::FilePath path = root_path().AppendASCII(entry.target_path);
     if (!base::TouchFile(path, entry.last_modified_time,
                          entry.last_modified_time))
       return false;
 
     // Update the modified time of parent directories because it may be also
     // affected by the update of child items.
-    if (path.DirName() != local_path_) {
+    if (path.DirName() != root_path()) {
       const std::map<base::FilePath, const TestEntryInfo>::iterator it =
           entries_.find(path.DirName());
       if (it == entries_.end())
@@ -249,35 +273,80 @@ class LocalTestVolume {
     return true;
   }
 
-  base::FilePath local_path_;
-  base::ScopedTempDir tmp_dir_;
   std::map<base::FilePath, const TestEntryInfo> entries_;
 };
 
-// The drive volume class for test.
-// This class provides the operations for a test volume that simulates Google
-// drive.
-class DriveTestVolume {
+class DownloadsTestVolume : public LocalTestVolume {
  public:
-  DriveTestVolume() : fake_drive_service_(NULL),
-                      integration_service_(NULL) {
+  DownloadsTestVolume() : LocalTestVolume("Downloads") {}
+  virtual ~DownloadsTestVolume() {}
+
+  virtual bool Mount(Profile* profile) override {
+    return CreateRootDirectory(profile) &&
+           VolumeManager::Get(profile)
+               ->RegisterDownloadsDirectoryForTesting(root_path());
   }
+};
 
-  // Sends request to add this volume to the file system as Google drive.
-  // This method must be called at SetUp method of FileManagerBrowserTestBase.
-  // Returns true on success.
-  bool SetUp() {
-    if (!test_cache_root_.CreateUniqueTempDir())
+// Test volume for mimicing a specified type of volumes by a local folder.
+class FakeTestVolume : public LocalTestVolume {
+ public:
+  FakeTestVolume(const std::string& name,
+                 VolumeType volume_type,
+                 chromeos::DeviceType device_type)
+      : LocalTestVolume(name),
+        volume_type_(volume_type),
+        device_type_(device_type) {}
+  virtual ~FakeTestVolume() {}
+
+  // Simple test entries used for testing, e.g., read-only volumes.
+  bool PrepareTestEntries(Profile* profile) {
+    if (!CreateRootDirectory(profile))
       return false;
-    create_drive_integration_service_ =
-        base::Bind(&DriveTestVolume::CreateDriveIntegrationService,
-                   base::Unretained(this));
-    service_factory_for_test_.reset(
-        new DriveIntegrationServiceFactory::ScopedFactoryForTest(
-            &create_drive_integration_service_));
+    // Must be in sync with BASIC_FAKE_ENTRY_SET in the JS test code.
+    CreateEntry(
+        TestEntryInfo(FILE, "text.txt", "hello.txt", "text/plain", NONE,
+                      base::Time::Now()));
+    CreateEntry(
+        TestEntryInfo(DIRECTORY, std::string(), "A", std::string(), NONE,
+                      base::Time::Now()));
+    return true;
+  }
+
+  virtual bool Mount(Profile* profile) override {
+    if (!CreateRootDirectory(profile))
+      return false;
+    storage::ExternalMountPoints* const mount_points =
+        storage::ExternalMountPoints::GetSystemInstance();
+
+    // First revoke the existing mount point (if any).
+    mount_points->RevokeFileSystem(name());
+    const bool result =
+        mount_points->RegisterFileSystem(name(),
+                                         storage::kFileSystemTypeNativeLocal,
+                                         storage::FileSystemMountOption(),
+                                         root_path());
+    if (!result)
+      return false;
+
+    VolumeManager::Get(profile)->AddVolumeInfoForTesting(
+        root_path(), volume_type_, device_type_);
     return true;
   }
 
+ private:
+  const VolumeType volume_type_;
+  const chromeos::DeviceType device_type_;
+};
+
+// The drive volume class for test.
+// This class provides the operations for a test volume that simulates Google
+// drive.
+class DriveTestVolume : public TestVolume {
+ public:
+  DriveTestVolume() : TestVolume("drive"), integration_service_(NULL) {}
+  virtual ~DriveTestVolume() {}
+
   void CreateEntry(const TestEntryInfo& entry) {
     const base::FilePath path =
         base::FilePath::FromUTF8Unsafe(entry.target_path);
@@ -290,7 +359,7 @@ class DriveTestVolume {
         drive::util::GetDriveMyDriveRootPath().Append(path).DirName(),
         google_apis::test_util::CreateCopyResultCallback(
             &error, &parent_entry));
-    drive::test_util::RunBlockingPoolTask();
+    content::RunAllBlockingPoolTasksUntilIdle();
     ASSERT_EQ(drive::FILE_ERROR_OK, error);
     ASSERT_TRUE(parent_entry);
 
@@ -304,9 +373,8 @@ class DriveTestVolume {
                    entry.last_modified_time);
         break;
       case DIRECTORY:
-        CreateDirectory(parent_entry->resource_id(),
-                        target_name,
-                        entry.last_modified_time);
+        CreateDirectory(
+            parent_entry->resource_id(), target_name, entry.last_modified_time);
         break;
     }
   }
@@ -316,24 +384,23 @@ class DriveTestVolume {
                        const std::string& target_name,
                        const base::Time& modification_time) {
     google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
-    scoped_ptr<google_apis::ResourceEntry> resource_entry;
+    scoped_ptr<google_apis::FileResource> entry;
     fake_drive_service_->AddNewDirectory(
         parent_id,
         target_name,
-        google_apis::test_util::CreateCopyResultCallback(&error,
-                                                         &resource_entry));
+        drive::DriveServiceInterface::AddNewDirectoryOptions(),
+        google_apis::test_util::CreateCopyResultCallback(&error, &entry));
     base::MessageLoop::current()->RunUntilIdle();
     ASSERT_EQ(google_apis::HTTP_CREATED, error);
-    ASSERT_TRUE(resource_entry);
+    ASSERT_TRUE(entry);
 
     fake_drive_service_->SetLastModifiedTime(
-        resource_entry->resource_id(),
+        entry->file_id(),
         modification_time,
-        google_apis::test_util::CreateCopyResultCallback(&error,
-                                                         &resource_entry));
+        google_apis::test_util::CreateCopyResultCallback(&error, &entry));
     base::MessageLoop::current()->RunUntilIdle();
     ASSERT_TRUE(error == google_apis::HTTP_SUCCESS);
-    ASSERT_TRUE(resource_entry);
+    ASSERT_TRUE(entry);
     CheckForUpdates();
   }
 
@@ -355,27 +422,25 @@ class DriveTestVolume {
       ASSERT_TRUE(base::ReadFileToString(source_file_path, &content_data));
     }
 
-    scoped_ptr<google_apis::ResourceEntry> resource_entry;
+    scoped_ptr<google_apis::FileResource> entry;
     fake_drive_service_->AddNewFile(
         mime_type,
         content_data,
         parent_id,
         target_name,
         shared_with_me,
-        google_apis::test_util::CreateCopyResultCallback(&error,
-                                                         &resource_entry));
+        google_apis::test_util::CreateCopyResultCallback(&error, &entry));
     base::MessageLoop::current()->RunUntilIdle();
     ASSERT_EQ(google_apis::HTTP_CREATED, error);
-    ASSERT_TRUE(resource_entry);
+    ASSERT_TRUE(entry);
 
     fake_drive_service_->SetLastModifiedTime(
-        resource_entry->resource_id(),
+        entry->file_id(),
         modification_time,
-        google_apis::test_util::CreateCopyResultCallback(&error,
-                                                         &resource_entry));
+        google_apis::test_util::CreateCopyResultCallback(&error, &entry));
     base::MessageLoop::current()->RunUntilIdle();
     ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
-    ASSERT_TRUE(resource_entry);
+    ASSERT_TRUE(entry);
 
     CheckForUpdates();
   }
@@ -396,25 +461,21 @@ class DriveTestVolume {
 
   drive::DriveIntegrationService* CreateDriveIntegrationService(
       Profile* profile) {
+    profile_ = profile;
     fake_drive_service_ = new drive::FakeDriveService;
-    fake_drive_service_->LoadResourceListForWapi(
-        "gdata/empty_feed.json");
-    fake_drive_service_->LoadAccountMetadataForWapi(
-        "gdata/account_metadata.json");
     fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
+
+    if (!CreateRootDirectory(profile))
+      return NULL;
     integration_service_ = new drive::DriveIntegrationService(
-        profile, NULL, fake_drive_service_, test_cache_root_.path(), NULL);
+        profile, NULL, fake_drive_service_, std::string(), root_path(), NULL);
     return integration_service_;
   }
 
  private:
-  base::ScopedTempDir test_cache_root_;
+  Profile* profile_;
   drive::FakeDriveService* fake_drive_service_;
   drive::DriveIntegrationService* integration_service_;
-  DriveIntegrationServiceFactory::FactoryCallback
-      create_drive_integration_service_;
-  scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
-      service_factory_for_test_;
 };
 
 // Listener to obtain the test relative messages synchronously.
@@ -428,13 +489,13 @@ class FileManagerTestListener : public content::NotificationObserver {
 
   FileManagerTestListener() {
     registrar_.Add(this,
-                   chrome::NOTIFICATION_EXTENSION_TEST_PASSED,
+                   extensions::NOTIFICATION_EXTENSION_TEST_PASSED,
                    content::NotificationService::AllSources());
     registrar_.Add(this,
-                   chrome::NOTIFICATION_EXTENSION_TEST_FAILED,
+                   extensions::NOTIFICATION_EXTENSION_TEST_FAILED,
                    content::NotificationService::AllSources());
     registrar_.Add(this,
-                   chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
+                   extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE,
                    content::NotificationService::AllSources());
   }
 
@@ -448,15 +509,16 @@ class FileManagerTestListener : public content::NotificationObserver {
 
   virtual void Observe(int type,
                        const content::NotificationSource& source,
-                       const content::NotificationDetails& details) OVERRIDE {
+                       const content::NotificationDetails& details) override {
     Message entry;
     entry.type = type;
-    entry.message = type != chrome::NOTIFICATION_EXTENSION_TEST_PASSED ?
-        *content::Details<std::string>(details).ptr() :
-        std::string();
-    entry.function = type == chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE ?
-        content::Source<extensions::TestSendMessageFunction>(source).ptr() :
-        NULL;
+    entry.message = type != extensions::NOTIFICATION_EXTENSION_TEST_PASSED
+                        ? *content::Details<std::string>(details).ptr()
+                        : std::string();
+    entry.function =
+        type == extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
+            ? content::Source<extensions::TestSendMessageFunction>(source).ptr()
+            : NULL;
     messages_.push_back(entry);
     base::MessageLoopForUI::current()->Quit();
   }
@@ -466,86 +528,111 @@ class FileManagerTestListener : public content::NotificationObserver {
   content::NotificationRegistrar registrar_;
 };
 
-// Parameter of FileManagerBrowserTest.
-// The second value is the case name of JavaScript.
-typedef std::tr1::tuple<GuestMode, const char*> TestParameter;
-
 // The base test class.
-class FileManagerBrowserTest :
-      public ExtensionApiTest,
-      public ::testing::WithParamInterface<TestParameter> {
+class FileManagerBrowserTestBase : public ExtensionApiTest {
  protected:
-  FileManagerBrowserTest() :
-      local_volume_(new LocalTestVolume),
-      drive_volume_(std::tr1::get<0>(GetParam()) != IN_GUEST_MODE ?
-                    new DriveTestVolume() : NULL) {}
-
-  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
+  virtual void SetUpInProcessBrowserTestFixture() override;
 
-  virtual void SetUpOnMainThread() OVERRIDE;
+  virtual void SetUpOnMainThread() override;
 
   // Adds an incognito and guest-mode flags for tests in the guest mode.
-  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
+  virtual void SetUpCommandLine(CommandLine* command_line) override;
 
   // Loads our testing extension and sends it a string identifying the current
   // test.
-  void StartTest();
+  virtual void StartTest();
+  void RunTestMessageLoop();
 
-  const scoped_ptr<LocalTestVolume> local_volume_;
-  const scoped_ptr<DriveTestVolume> drive_volume_;
+  // Overriding point for test configurations.
+  virtual const char* GetTestManifestName() const {
+    return "file_manager_test_manifest.json";
+  }
+  virtual GuestMode GetGuestModeParam() const = 0;
+  virtual const char* GetTestCaseNameParam() const = 0;
+  virtual void OnMessage(const std::string& name,
+                         const base::DictionaryValue& value,
+                         std::string* output);
+
+  scoped_ptr<LocalTestVolume> local_volume_;
+  linked_ptr<DriveTestVolume> drive_volume_;
+  std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_;
+  scoped_ptr<FakeTestVolume> usb_volume_;
+  scoped_ptr<FakeTestVolume> mtp_volume_;
+
+ private:
+  drive::DriveIntegrationService* CreateDriveIntegrationService(
+      Profile* profile);
+  DriveIntegrationServiceFactory::FactoryCallback
+      create_drive_integration_service_;
+  scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
+      service_factory_for_test_;
 };
 
-void FileManagerBrowserTest::SetUpInProcessBrowserTestFixture() {
+void FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() {
   ExtensionApiTest::SetUpInProcessBrowserTestFixture();
   extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
-  if (drive_volume_)
-    ASSERT_TRUE(drive_volume_->SetUp());
+
+  local_volume_.reset(new DownloadsTestVolume);
+  if (GetGuestModeParam() != IN_GUEST_MODE) {
+    create_drive_integration_service_ =
+        base::Bind(&FileManagerBrowserTestBase::CreateDriveIntegrationService,
+                   base::Unretained(this));
+    service_factory_for_test_.reset(
+        new DriveIntegrationServiceFactory::ScopedFactoryForTest(
+            &create_drive_integration_service_));
+  }
 }
 
-void FileManagerBrowserTest::SetUpOnMainThread() {
+void FileManagerBrowserTestBase::SetUpOnMainThread() {
   ExtensionApiTest::SetUpOnMainThread();
-  ASSERT_TRUE(local_volume_->Mount(browser()->profile()));
+  ASSERT_TRUE(local_volume_->Mount(profile()));
 
-  if (drive_volume_) {
+  if (GetGuestModeParam() != IN_GUEST_MODE) {
     // Install the web server to serve the mocked share dialog.
     ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
     const GURL share_url_base(embedded_test_server()->GetURL(
         "/chromeos/file_manager/share_dialog_mock/index.html"));
+    drive_volume_ = drive_volumes_[profile()->GetOriginalProfile()];
     drive_volume_->ConfigureShareUrlBase(share_url_base);
-    test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
+    test_util::WaitUntilDriveMountPointIsAdded(profile());
   }
+
+  net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
 }
 
-void FileManagerBrowserTest::SetUpCommandLine(CommandLine* command_line) {
-  if (std::tr1::get<0>(GetParam()) == IN_GUEST_MODE) {
+void FileManagerBrowserTestBase::SetUpCommandLine(CommandLine* command_line) {
+  if (GetGuestModeParam() == IN_GUEST_MODE) {
     command_line->AppendSwitch(chromeos::switches::kGuestSession);
     command_line->AppendSwitchNative(chromeos::switches::kLoginUser, "");
     command_line->AppendSwitch(switches::kIncognito);
   }
-  // TODO(yoshiki): Remove the flag when the feature is launched.
-  if (std::tr1::get<1>(GetParam()) == std::string("suggestAppDialog")) {
-    command_line->AppendSwitch(
-        chromeos::switches::kFileManagerEnableWebstoreIntegration);
+  if (GetGuestModeParam() == IN_INCOGNITO) {
+    command_line->AppendSwitch(switches::kIncognito);
   }
   ExtensionApiTest::SetUpCommandLine(command_line);
 }
 
-IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) {
+void FileManagerBrowserTestBase::StartTest() {
   // Launch the extension.
-  base::FilePath path = test_data_dir_.AppendASCII("file_manager_browsertest");
-  const extensions::Extension* extension = LoadExtensionAsComponent(path);
+  const base::FilePath path =
+      test_data_dir_.AppendASCII("file_manager_browsertest");
+  const extensions::Extension* const extension =
+      LoadExtensionAsComponentWithManifest(path, GetTestManifestName());
   ASSERT_TRUE(extension);
 
+  RunTestMessageLoop();
+}
+
+void FileManagerBrowserTestBase::RunTestMessageLoop() {
   // Handle the messages from JavaScript.
   // The while loop is break when the test is passed or failed.
   FileManagerTestListener listener;
-  base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter;
   while (true) {
     FileManagerTestListener::Message entry = listener.GetNextMessage();
-    if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_PASSED) {
+    if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED) {
       // Test succeed.
       break;
-    } else if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_FAILED) {
+    } else if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) {
       // Test failed.
       ADD_FAILURE() << entry.message;
       break;
@@ -562,86 +649,247 @@ IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) {
         !message_dictionary->GetString("name", &name))
       continue;
 
-    if (name == "getTestName") {
-      // Pass the test case name.
-      entry.function->Reply(std::tr1::get<1>(GetParam()));
-    } else if (name == "getRootPaths") {
-      // Pass the root paths.
-      const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
-      res->SetString("downloads",
-          "/" + util::GetDownloadsMountPointName(browser()->profile()));
-      res->SetString("drive", "/drive/root");
-      std::string jsonString;
-      base::JSONWriter::Write(res.get(), &jsonString);
-      entry.function->Reply(jsonString);
-    } else if (name == "isInGuestMode") {
-      // Obtain whether the test is in guest mode or not.
-      entry.function->Reply(std::tr1::get<0>(GetParam()) ? "true" : "false");
-    } else if (name == "getCwsWidgetContainerMockUrl") {
-      // Obtain whether the test is in guest mode or not.
-      const GURL url = embedded_test_server()->GetURL(
-            "/chromeos/file_manager/cws_container_mock/index.html");
-      std::string origin = url.GetOrigin().spec();
-
-      // Removes trailing a slash.
-      if (*origin.rbegin() == '/')
-        origin.resize(origin.length() - 1);
-
-      const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
-      res->SetString("url", url.spec());
-      res->SetString("origin", origin);
-      std::string jsonString;
-      base::JSONWriter::Write(res.get(), &jsonString);
-      entry.function->Reply(jsonString);
-    } else if (name == "addEntries") {
-      // Add entries to the specified volume.
-      AddEntriesMessage message;
-      if (!add_entries_message_converter.Convert(*value.get(), &message)) {
-        entry.function->Reply("onError");
-        continue;
-      }
-      for (size_t i = 0; i < message.entries.size(); ++i) {
-        switch (message.volume) {
-          case LOCAL_VOLUME:
-            local_volume_->CreateEntry(*message.entries[i]);
-            break;
-          case DRIVE_VOLUME:
-            if (drive_volume_)
-              drive_volume_->CreateEntry(*message.entries[i]);
-            break;
-          default:
-            NOTREACHED();
-            break;
-        }
+    std::string output;
+    OnMessage(name, *message_dictionary, &output);
+    if (HasFatalFailure())
+      break;
+
+    entry.function->Reply(output);
+  }
+}
+
+void FileManagerBrowserTestBase::OnMessage(const std::string& name,
+                                           const base::DictionaryValue& value,
+                                           std::string* output) {
+  if (name == "getTestName") {
+    // Pass the test case name.
+    *output = GetTestCaseNameParam();
+    return;
+  }
+
+  if (name == "getRootPaths") {
+    // Pass the root paths.
+    const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
+    res->SetString("downloads",
+        "/" + util::GetDownloadsMountPointName(profile()));
+    res->SetString("drive",
+        "/" + drive::util::GetDriveMountPointPath(profile()
+            ).BaseName().AsUTF8Unsafe() + "/root");
+    base::JSONWriter::Write(res.get(), output);
+    return;
+  }
+
+  if (name == "isInGuestMode") {
+    // Obtain whether the test is in guest mode or not.
+    *output = GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false";
+    return;
+  }
+
+  if (name == "getCwsWidgetContainerMockUrl") {
+    // Obtain whether the test is in guest mode or not.
+    const GURL url = embedded_test_server()->GetURL(
+          "/chromeos/file_manager/cws_container_mock/index.html");
+    std::string origin = url.GetOrigin().spec();
+
+    // Removes trailing a slash.
+    if (*origin.rbegin() == '/')
+      origin.resize(origin.length() - 1);
+
+    const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
+    res->SetString("url", url.spec());
+    res->SetString("origin", origin);
+    base::JSONWriter::Write(res.get(), output);
+    return;
+  }
+
+  if (name == "addEntries") {
+    // Add entries to the specified volume.
+    base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter;
+    AddEntriesMessage message;
+    ASSERT_TRUE(add_entries_message_converter.Convert(value, &message));
+
+    for (size_t i = 0; i < message.entries.size(); ++i) {
+      switch (message.volume) {
+        case LOCAL_VOLUME:
+          local_volume_->CreateEntry(*message.entries[i]);
+          break;
+        case DRIVE_VOLUME:
+          if (drive_volume_.get())
+            drive_volume_->CreateEntry(*message.entries[i]);
+          break;
+        case USB_VOLUME:
+          if (usb_volume_)
+            usb_volume_->CreateEntry(*message.entries[i]);
+          break;
+        default:
+          NOTREACHED();
+          break;
       }
-      entry.function->Reply("onEntryAdded");
     }
+
+    return;
+  }
+
+  if (name == "mountFakeUsb") {
+    usb_volume_.reset(new FakeTestVolume("fake-usb",
+                                         VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
+                                         chromeos::DEVICE_TYPE_USB));
+    usb_volume_->Mount(profile());
+    return;
+  }
+
+  if (name == "mountFakeMtp") {
+    mtp_volume_.reset(new FakeTestVolume("fake-mtp",
+                                         VOLUME_TYPE_MTP,
+                                         chromeos::DEVICE_TYPE_UNKNOWN));
+    ASSERT_TRUE(mtp_volume_->PrepareTestEntries(profile()));
+
+    mtp_volume_->Mount(profile());
+    return;
   }
+
+  if (name == "useCellularNetwork") {
+    net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
+        net::NetworkChangeNotifier::CONNECTION_3G);
+    return;
+  }
+
+  if (name == "clickNotificationButton") {
+    std::string extension_id;
+    std::string notification_id;
+    int index;
+    ASSERT_TRUE(value.GetString("extensionId", &extension_id));
+    ASSERT_TRUE(value.GetString("notificationId", &notification_id));
+    ASSERT_TRUE(value.GetInteger("index", &index));
+
+    const std::string delegate_id = extension_id + "-" + notification_id;
+    const Notification* notification = g_browser_process->
+        notification_ui_manager()->FindById(delegate_id, profile());
+    ASSERT_TRUE(notification);
+
+    notification->delegate()->ButtonClick(index);
+    return;
+  }
+
+  FAIL() << "Unknown test message: " << name;
 }
 
-INSTANTIATE_TEST_CASE_P(
-    FileDisplay,
+drive::DriveIntegrationService*
+FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile* profile) {
+  drive_volumes_[profile->GetOriginalProfile()].reset(new DriveTestVolume());
+  return drive_volumes_[profile->GetOriginalProfile()]->
+      CreateDriveIntegrationService(profile);
+}
+
+// Parameter of FileManagerBrowserTest.
+// The second value is the case name of JavaScript.
+typedef std::tr1::tuple<GuestMode, const char*> TestParameter;
+
+// Test fixture class for normal (not multi-profile related) tests.
+class FileManagerBrowserTest :
+      public FileManagerBrowserTestBase,
+      public ::testing::WithParamInterface<TestParameter> {
+  virtual GuestMode GetGuestModeParam() const override {
+    return std::tr1::get<0>(GetParam());
+  }
+  virtual const char* GetTestCaseNameParam() const override {
+    return std::tr1::get<1>(GetParam());
+  }
+};
+
+IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) {
+  StartTest();
+}
+
+// Unlike TEST/TEST_F, which are macros that expand to further macros,
+// INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
+// stringizes the arguments. As a result, macros passed as parameters (such as
+// prefix or test_case_name) will not be expanded by the preprocessor. To work
+// around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
+// pre-processor will expand macros such as MAYBE_test_name before
+// instantiating the test.
+#define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
+  INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_FileDisplay DISABLED_FileDisplay
+#else
+#define MAYBE_FileDisplay FileDisplay
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_FileDisplay,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDownloads"),
                       TestParameter(IN_GUEST_MODE, "fileDisplayDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDrive")));
+                      TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDrive"),
+                      TestParameter(NOT_IN_GUEST_MODE, "fileDisplayMtp")));
 
-INSTANTIATE_TEST_CASE_P(
-    OpenSpecialTypes,
+// http://crbug.com/327719
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    DISABLED_OpenZipFiles,
+    FileManagerBrowserTest,
+    ::testing::Values(TestParameter(IN_GUEST_MODE, "zipOpenDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "zipOpenDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "zipOpenDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_OpenVideoFiles DISABLED_OpenVideoFiles
+#else
+#define MAYBE_OpenVideoFiles OpenVideoFiles
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_OpenVideoFiles,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(IN_GUEST_MODE, "videoOpenDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE, "videoOpenDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "videoOpenDrive"),
-                      TestParameter(IN_GUEST_MODE, "audioOpenDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "audioOpenDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "audioOpenDrive"),
-                      TestParameter(IN_GUEST_MODE, "galleryOpenDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "videoOpenDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_OpenAudioFiles DISABLED_OpenAudioFiles
+#else
+#define MAYBE_OpenAudioFiles OpenAudioFiles
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_OpenAudioFiles,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(IN_GUEST_MODE, "audioOpenDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioOpenDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioOpenDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioAutoAdvanceDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioRepeatSingleFileDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioNoRepeatSingleFileDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioRepeatMultipleFileDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "audioNoRepeatMultipleFileDrive")));
+
+// Flaky http://crbug.com/327719
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    DISABLED_CreateNewFolder,
+    FileManagerBrowserTest,
+    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
+                                    "createNewFolderAfterSelectFile"),
+                      TestParameter(IN_GUEST_MODE,
+                                    "createNewFolderDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE,
-                                    "galleryOpenDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "galleryOpenDrive")));
-
-INSTANTIATE_TEST_CASE_P(
-    KeyboardOperations,
+                                    "createNewFolderDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE,
+                                    "createNewFolderDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_KeyboardOperations DISABLED_KeyboardOperations
+#else
+#define MAYBE_KeyboardOperations KeyboardOperations
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_KeyboardOperations,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(IN_GUEST_MODE, "keyboardDeleteDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE,
@@ -649,104 +897,659 @@ INSTANTIATE_TEST_CASE_P(
                       TestParameter(NOT_IN_GUEST_MODE, "keyboardDeleteDrive"),
                       TestParameter(IN_GUEST_MODE, "keyboardCopyDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE, "keyboardCopyDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE, "keyboardCopyDrive")));
-
-INSTANTIATE_TEST_CASE_P(
-    DriveSpecific,
-    FileManagerBrowserTest,
-    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "openSidebarRecent"),
-                      TestParameter(NOT_IN_GUEST_MODE, "openSidebarOffline"),
+                      TestParameter(NOT_IN_GUEST_MODE, "keyboardCopyDrive"),
+                      TestParameter(IN_GUEST_MODE, "renameFileDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "renameFileDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "renameFileDrive"),
+                      TestParameter(IN_GUEST_MODE,
+                                    "renameNewDirectoryDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE,
-                                    "openSidebarSharedWithMe"),
-                      TestParameter(NOT_IN_GUEST_MODE, "autocomplete")));
-
-INSTANTIATE_TEST_CASE_P(
-    Transfer,
-    FileManagerBrowserTest,
-    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromDriveToDownloads"),
+                                    "renameNewDirectoryDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromDownloadsToDrive"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromSharedToDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromSharedToDrive"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromRecentToDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromRecentToDrive"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromOfflineToDownloads"),
-                      TestParameter(NOT_IN_GUEST_MODE,
-                                    "transferFromOfflineToDrive")));
-
-INSTANTIATE_TEST_CASE_P(
-     HideSearchBox,
-     FileManagerBrowserTest,
-     ::testing::Values(TestParameter(IN_GUEST_MODE, "hideSearchBox"),
-                       TestParameter(NOT_IN_GUEST_MODE, "hideSearchBox")));
-
-INSTANTIATE_TEST_CASE_P(
-    RestorePrefs,
+                                    "renameNewDirectoryDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_DriveSpecific DISABLED_DriveSpecific
+#else
+#define MAYBE_DriveSpecific DriveSpecific
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_DriveSpecific,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "openSidebarRecent"),
+        TestParameter(NOT_IN_GUEST_MODE, "openSidebarOffline"),
+        TestParameter(NOT_IN_GUEST_MODE, "openSidebarSharedWithMe"),
+        TestParameter(NOT_IN_GUEST_MODE, "autocomplete"),
+        TestParameter(NOT_IN_GUEST_MODE, "pinFileOnMobileNetwork")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_Transfer DISABLED_Transfer
+#else
+#define MAYBE_Transfer Transfer
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_Transfer,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromDriveToDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromDownloadsToDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromSharedToDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromSharedToDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromRecentToDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromRecentToDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromOfflineToDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "transferFromOfflineToDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_RestorePrefs DISABLED_RestorePrefs
+#else
+#define MAYBE_RestorePrefs RestorePrefs
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_RestorePrefs,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(IN_GUEST_MODE, "restoreSortColumn"),
                       TestParameter(NOT_IN_GUEST_MODE, "restoreSortColumn"),
                       TestParameter(IN_GUEST_MODE, "restoreCurrentView"),
                       TestParameter(NOT_IN_GUEST_MODE, "restoreCurrentView")));
 
-INSTANTIATE_TEST_CASE_P(
-    ShareDialog,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_ShareDialog DISABLED_ShareDialog
+#else
+#define MAYBE_ShareDialog ShareDialog
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_ShareDialog,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "shareFile"),
                       TestParameter(NOT_IN_GUEST_MODE, "shareDirectory")));
 
-INSTANTIATE_TEST_CASE_P(
-    RestoreGeometry,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_RestoreGeometry DISABLED_RestoreGeometry
+#else
+#define MAYBE_RestoreGeometry RestoreGeometry
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_RestoreGeometry,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "restoreGeometry"),
                       TestParameter(IN_GUEST_MODE, "restoreGeometry")));
 
-INSTANTIATE_TEST_CASE_P(
-    Traverse,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_Traverse DISABLED_Traverse
+#else
+#define MAYBE_Traverse Traverse
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_Traverse,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(IN_GUEST_MODE, "traverseDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE, "traverseDownloads"),
                       TestParameter(NOT_IN_GUEST_MODE, "traverseDrive")));
 
-INSTANTIATE_TEST_CASE_P(
-    SuggestAppDialog,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_SuggestAppDialog DISABLED_SuggestAppDialog
+#else
+#define MAYBE_SuggestAppDialog SuggestAppDialog
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_SuggestAppDialog,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "suggestAppDialog")));
 
-INSTANTIATE_TEST_CASE_P(
-    ExecuteDefaultTaskOnDownloads,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_ExecuteDefaultTaskOnDownloads \
+  DISABLED_ExecuteDefaultTaskOnDownloads
+#else
+#define MAYBE_ExecuteDefaultTaskOnDownloads ExecuteDefaultTaskOnDownloads
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_ExecuteDefaultTaskOnDownloads,
     FileManagerBrowserTest,
     ::testing::Values(
         TestParameter(NOT_IN_GUEST_MODE, "executeDefaultTaskOnDownloads"),
         TestParameter(IN_GUEST_MODE, "executeDefaultTaskOnDownloads")));
 
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_ExecuteDefaultTaskOnDrive DISABLED_ExecuteDefaultTaskOnDrive
+#else
+#define MAYBE_ExecuteDefaultTaskOnDrive ExecuteDefaultTaskOnDrive
+#endif
 INSTANTIATE_TEST_CASE_P(
-    ExecuteDefaultTaskOnDrive,
+    MAYBE_ExecuteDefaultTaskOnDrive,
     FileManagerBrowserTest,
     ::testing::Values(
         TestParameter(NOT_IN_GUEST_MODE, "executeDefaultTaskOnDrive")));
 
-INSTANTIATE_TEST_CASE_P(
-    NavigationList,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_DefaultActionDialog DISABLED_DefaultActionDialog
+#else
+#define MAYBE_DefaultActionDialog DefaultActionDialog
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_DefaultActionDialog,
     FileManagerBrowserTest,
-    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
-                                    "traverseNavigationList")));
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "defaultActionDialogOnDownloads"),
+        TestParameter(IN_GUEST_MODE, "defaultActionDialogOnDownloads"),
+        TestParameter(NOT_IN_GUEST_MODE, "defaultActionDialogOnDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_GenericTask DISABLED_GenericTask
+#else
+#define MAYBE_GenericTask GenericTask
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_GenericTask,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "genericTaskIsNotExecuted"),
+        TestParameter(NOT_IN_GUEST_MODE, "genericAndNonGenericTasksAreMixed")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_FolderShortcuts DISABLED_FolderShortcuts
+#else
+#define MAYBE_FolderShortcuts FolderShortcuts
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_FolderShortcuts,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "traverseFolderShortcuts"),
+        TestParameter(NOT_IN_GUEST_MODE, "addRemoveFolderShortcuts")));
 
 INSTANTIATE_TEST_CASE_P(
     TabIndex,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "searchBoxFocus")));
 
-INSTANTIATE_TEST_CASE_P(
-    Thumbnails,
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_Thumbnails DISABLED_Thumbnails
+#else
+#define MAYBE_Thumbnails Thumbnails
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_Thumbnails,
     FileManagerBrowserTest,
     ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "thumbnailsDownloads"),
                       TestParameter(IN_GUEST_MODE, "thumbnailsDownloads")));
 
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_OpenFileDialog DISABLED_OpenFileDialog
+#else
+#define MAYBE_OpenFileDialog OpenFileDialog
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_OpenFileDialog,
+    FileManagerBrowserTest,
+    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
+                                    "openFileDialogOnDownloads"),
+                      TestParameter(IN_GUEST_MODE,
+                                    "openFileDialogOnDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE,
+                                    "openFileDialogOnDrive"),
+                      TestParameter(IN_INCOGNITO,
+                                    "openFileDialogOnDownloads"),
+                      TestParameter(IN_INCOGNITO,
+                                    "openFileDialogOnDrive"),
+                      TestParameter(NOT_IN_GUEST_MODE,
+                                    "unloadFileDialog")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_CopyBetweenWindows DISABLED_CopyBetweenWindows
+#else
+#define MAYBE_CopyBetweenWindows CopyBetweenWindows
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_CopyBetweenWindows,
+    FileManagerBrowserTest,
+    ::testing::Values(
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsLocalToDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsLocalToUsb"),
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsUsbToDrive"),
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsDriveToLocal"),
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsDriveToUsb"),
+        TestParameter(NOT_IN_GUEST_MODE, "copyBetweenWindowsUsbToLocal")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_ShowGridView DISABLED_ShowGridView
+#else
+#define MAYBE_ShowGridView ShowGridView
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+    MAYBE_ShowGridView,
+    FileManagerBrowserTest,
+    ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "showGridViewDownloads"),
+                      TestParameter(IN_GUEST_MODE, "showGridViewDownloads"),
+                      TestParameter(NOT_IN_GUEST_MODE, "showGridViewDrive")));
+
+// Structure to describe an account info.
+struct TestAccountInfo {
+  const char* const email;
+  const char* const hash;
+  const char* const display_name;
+};
+
+enum {
+  DUMMY_ACCOUNT_INDEX = 0,
+  PRIMARY_ACCOUNT_INDEX = 1,
+  SECONDARY_ACCOUNT_INDEX_START = 2,
+};
+
+static const TestAccountInfo kTestAccounts[] = {
+  {"__dummy__@invalid.domain", "hashdummy", "Dummy Account"},
+  {"alice@invalid.domain", "hashalice", "Alice"},
+  {"bob@invalid.domain", "hashbob", "Bob"},
+  {"charlie@invalid.domain", "hashcharlie", "Charlie"},
+};
+
+// Test fixture class for testing multi-profile features.
+class MultiProfileFileManagerBrowserTest : public FileManagerBrowserTestBase {
+ protected:
+  // Enables multi-profiles.
+  virtual void SetUpCommandLine(CommandLine* command_line) override {
+    FileManagerBrowserTestBase::SetUpCommandLine(command_line);
+    // Logs in to a dummy profile (For making MultiProfileWindowManager happy;
+    // browser test creates a default window and the manager tries to assign a
+    // user for it, and we need a profile connected to a user.)
+    command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
+                                    kTestAccounts[DUMMY_ACCOUNT_INDEX].email);
+    command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
+                                    kTestAccounts[DUMMY_ACCOUNT_INDEX].hash);
+  }
+
+  // Logs in to the primary profile of this test.
+  virtual void SetUpOnMainThread() override {
+    const TestAccountInfo& info = kTestAccounts[PRIMARY_ACCOUNT_INDEX];
+
+    AddUser(info, true);
+    FileManagerBrowserTestBase::SetUpOnMainThread();
+  }
+
+  // Loads all users to the current session and sets up necessary fields.
+  // This is used for preparing all accounts in PRE_ test setup, and for testing
+  // actual login behavior.
+  void AddAllUsers() {
+    for (size_t i = 0; i < arraysize(kTestAccounts); ++i)
+      AddUser(kTestAccounts[i], i >= SECONDARY_ACCOUNT_INDEX_START);
+  }
+
+  // Returns primary profile (if it is already created.)
+  virtual Profile* profile() override {
+    Profile* const profile = chromeos::ProfileHelper::GetProfileByUserIdHash(
+        kTestAccounts[PRIMARY_ACCOUNT_INDEX].hash);
+    return profile ? profile : FileManagerBrowserTestBase::profile();
+  }
+
+  // Sets the test case name (used as a function name in test_cases.js to call.)
+  void set_test_case_name(const std::string& name) { test_case_name_ = name; }
+
+  // Adds a new user for testing to the current session.
+  void AddUser(const TestAccountInfo& info, bool log_in) {
+    user_manager::UserManager* const user_manager =
+        user_manager::UserManager::Get();
+    if (log_in)
+      user_manager->UserLoggedIn(info.email, info.hash, false);
+    user_manager->SaveUserDisplayName(info.email,
+                                      base::UTF8ToUTF16(info.display_name));
+    chromeos::ProfileHelper::GetProfileByUserIdHash(info.hash)->GetPrefs()->
+        SetString(prefs::kGoogleServicesUsername, info.email);
+  }
+
+ private:
+  virtual GuestMode GetGuestModeParam() const override {
+    return NOT_IN_GUEST_MODE;
+  }
+
+  virtual const char* GetTestCaseNameParam() const override {
+    return test_case_name_.c_str();
+  }
+
+  std::string test_case_name_;
+};
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_PRE_BasicDownloads DISABLED_PRE_BasicDownloads
+#define MAYBE_BasicDownloads DISABLED_BasicDownloads
+#else
+#define MAYBE_PRE_BasicDownloads PRE_BasicDownloads
+#define MAYBE_BasicDownloads BasicDownloads
+#endif
+IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
+                       MAYBE_PRE_BasicDownloads) {
+  AddAllUsers();
+}
+
+IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
+                       MAYBE_BasicDownloads) {
+  AddAllUsers();
+
+  // Sanity check that normal operations work in multi-profile setting as well.
+  set_test_case_name("keyboardCopyDownloads");
+  StartTest();
+}
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+// Fails on official build. http://crbug.com/429294
+#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
+#define MAYBE_PRE_BasicDrive DISABLED_PRE_BasicDrive
+#define MAYBE_BasicDrive DISABLED_BasicDrive
+#else
+#define MAYBE_PRE_BasicDrive PRE_BasicDrive
+#define MAYBE_BasicDrive BasicDrive
+#endif
+IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
+                       MAYBE_PRE_BasicDrive) {
+  AddAllUsers();
+}
+
+IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest, MAYBE_BasicDrive) {
+  AddAllUsers();
+
+  // Sanity check that normal operations work in multi-profile setting as well.
+  set_test_case_name("keyboardCopyDrive");
+  StartTest();
+}
+
+template<GuestMode M>
+class GalleryBrowserTestBase : public FileManagerBrowserTestBase {
+ public:
+  virtual GuestMode GetGuestModeParam() const override { return M; }
+  virtual const char* GetTestCaseNameParam() const override {
+    return test_case_name_.c_str();
+  }
+
+ protected:
+  virtual void SetUp() override {
+    AddScript("common/test_util_common.js");
+    AddScript("gallery/test_util.js");
+    FileManagerBrowserTestBase::SetUp();
+  }
+
+  virtual void OnMessage(const std::string& name,
+                         const base::DictionaryValue& value,
+                         std::string* output) override;
+
+  virtual const char* GetTestManifestName() const override {
+    return "gallery_test_manifest.json";
+  }
+
+  void AddScript(const std::string& name) {
+    scripts_.AppendString(
+        "chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn/" + name);
+  }
+
+  void set_test_case_name(const std::string& name) {
+    test_case_name_ = name;
+  }
+
+ private:
+  base::ListValue scripts_;
+  std::string test_case_name_;
+};
+
+template <GuestMode M>
+void GalleryBrowserTestBase<M>::OnMessage(const std::string& name,
+                                          const base::DictionaryValue& value,
+                                          std::string* output) {
+  if (name == "getScripts") {
+    std::string jsonString;
+    base::JSONWriter::Write(&scripts_, output);
+    return;
+  }
+
+  FileManagerBrowserTestBase::OnMessage(name, value, output);
+}
+
+typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest;
+typedef GalleryBrowserTestBase<IN_GUEST_MODE> GalleryBrowserTestInGuestMode;
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDownloads) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openSingleImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       OpenSingleImageOnDownloads) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openSingleImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDrive) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openSingleImageOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenMultipleImagesOnDownloads) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openMultipleImagesOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       OpenMultipleImagesOnDownloads) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openMultipleImagesOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenMultipleImagesOnDrive) {
+  AddScript("gallery/open_image_files.js");
+  set_test_case_name("openMultipleImagesOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, TraverseSlideImagesOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("traverseSlideImagesOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       TraverseSlideImagesOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("traverseSlideImagesOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, TraverseSlideImagesOnDrive) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("traverseSlideImagesOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RenameImageOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("renameImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       RenameImageOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("renameImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RenameImageOnDrive) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("renameImageOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, DeleteImageOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("deleteImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       DeleteImageOnDownloads) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("deleteImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, DeleteImageOnDrive) {
+  AddScript("gallery/slide_mode.js");
+  set_test_case_name("deleteImageOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RotateImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("rotateImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       RotateImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("rotateImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, RotateImageOnDrive) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("rotateImageOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, CropImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("cropImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       CropImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("cropImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, CropImageOnDrive) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("cropImageOnDrive");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, ExposureImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("exposureImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode,
+                       ExposureImageOnDownloads) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("exposureImageOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, ExposureImageOnDrive) {
+  AddScript("gallery/photo_editor.js");
+  set_test_case_name("exposureImageOnDrive");
+  StartTest();
+}
+
+template<GuestMode M>
+class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
+ public:
+  virtual GuestMode GetGuestModeParam() const override { return M; }
+  virtual const char* GetTestCaseNameParam() const override {
+    return test_case_name_.c_str();
+  }
+
+ protected:
+  virtual void SetUp() override {
+    AddScript("common/test_util_common.js");
+    AddScript("video_player/test_util.js");
+    FileManagerBrowserTestBase::SetUp();
+  }
+
+  virtual void SetUpCommandLine(CommandLine* command_line) override {
+    command_line->AppendSwitch(
+        chromeos::switches::kEnableVideoPlayerChromecastSupport);
+    FileManagerBrowserTestBase::SetUpCommandLine(command_line);
+  }
+
+  virtual void OnMessage(const std::string& name,
+                         const base::DictionaryValue& value,
+                         std::string* output) override;
+
+  virtual const char* GetTestManifestName() const override {
+    return "video_player_test_manifest.json";
+  }
+
+  void AddScript(const std::string& name) {
+    scripts_.AppendString(
+        "chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/" + name);
+  }
+
+  void set_test_case_name(const std::string& name) {
+    test_case_name_ = name;
+  }
+
+ private:
+  base::ListValue scripts_;
+  std::string test_case_name_;
+};
+
+template <GuestMode M>
+void VideoPlayerBrowserTestBase<M>::OnMessage(
+    const std::string& name,
+    const base::DictionaryValue& value,
+    std::string* output) {
+  if (name == "getScripts") {
+    std::string jsonString;
+    base::JSONWriter::Write(&scripts_, output);
+    return;
+  }
+
+  FileManagerBrowserTestBase::OnMessage(name, value, output);
+}
+
+typedef VideoPlayerBrowserTestBase<NOT_IN_GUEST_MODE> VideoPlayerBrowserTest;
+typedef VideoPlayerBrowserTestBase<IN_GUEST_MODE>
+    VideoPlayerBrowserTestInGuestMode;
+
+IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDownloads) {
+  AddScript("video_player/open_video_files.js");
+  set_test_case_name("openSingleVideoOnDownloads");
+  StartTest();
+}
+
+IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDrive) {
+  AddScript("video_player/open_video_files.js");
+  set_test_case_name("openSingleVideoOnDrive");
+  StartTest();
+}
+
 }  // namespace
 }  // namespace file_manager