Commit d37f424f authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Don't bother showing an unused Browser* for FileManagerBrowserTestBase.

This affects file manager tests, gallery tests, and others. With a few
exceptions, these tests have no use for the browser() that
StartupBrowserCreator creates during startup. Not creating one leaves
more time for the tests to do things they really care about before
potentially timing out.

In fact, _not_ creating the Browser surfaces an existing bug more
prominently. That is, some tests have an iceberg dependency on the
existence of this Browser* that they should never have had in the
first place.

Bug: 736930
Change-Id: I1030e41800f3d2e0e5868ecd64d70c7d30f47c28
Reviewed-on: https://chromium-review.googlesource.com/1117977Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576427}
parent b04221bb
...@@ -391,15 +391,13 @@ class LocalFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { ...@@ -391,15 +391,13 @@ class LocalFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
// FileSystemExtensionApiTestBase override. // FileSystemExtensionApiTestBase override.
void AddTestMountPoint() override { void AddTestMountPoint() override {
EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) EXPECT_TRUE(
->RegisterFileSystem(kLocalMountPointName, content::BrowserContext::GetMountPoints(profile())->RegisterFileSystem(
storage::kFileSystemTypeNativeLocal, kLocalMountPointName, storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(), storage::FileSystemMountOption(), mount_point_dir_));
mount_point_dir_)); VolumeManager::Get(profile())->AddVolumeForTesting(
VolumeManager::Get(browser()->profile()) mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN,
->AddVolumeForTesting(mount_point_dir_, VOLUME_TYPE_TESTING, false /* read_only */);
chromeos::DEVICE_TYPE_UNKNOWN,
false /* read_only */);
} }
private: private:
...@@ -424,15 +422,13 @@ class RestrictedFileSystemExtensionApiTest ...@@ -424,15 +422,13 @@ class RestrictedFileSystemExtensionApiTest
// FileSystemExtensionApiTestBase override. // FileSystemExtensionApiTestBase override.
void AddTestMountPoint() override { void AddTestMountPoint() override {
EXPECT_TRUE( EXPECT_TRUE(
content::BrowserContext::GetMountPoints(browser()->profile()) content::BrowserContext::GetMountPoints(profile())->RegisterFileSystem(
->RegisterFileSystem(kRestrictedMountPointName, kRestrictedMountPointName,
storage::kFileSystemTypeRestrictedNativeLocal, storage::kFileSystemTypeRestrictedNativeLocal,
storage::FileSystemMountOption(), storage::FileSystemMountOption(), mount_point_dir_));
mount_point_dir_)); VolumeManager::Get(profile())->AddVolumeForTesting(
VolumeManager::Get(browser()->profile()) mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN,
->AddVolumeForTesting(mount_point_dir_, VOLUME_TYPE_TESTING, true /* read_only */);
chromeos::DEVICE_TYPE_UNKNOWN,
true /* read_only */);
} }
private: private:
...@@ -465,7 +461,7 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { ...@@ -465,7 +461,7 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
// FileSystemExtensionApiTestBase override. // FileSystemExtensionApiTestBase override.
void AddTestMountPoint() override { void AddTestMountPoint() override {
test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); test_util::WaitUntilDriveMountPointIsAdded(profile());
} }
// FileSystemExtensionApiTestBase override. // FileSystemExtensionApiTestBase override.
...@@ -550,7 +546,7 @@ class MultiProfileDriveFileSystemExtensionApiTest : ...@@ -550,7 +546,7 @@ class MultiProfileDriveFileSystemExtensionApiTest :
} }
void AddTestMountPoint() override { void AddTestMountPoint() override {
test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); test_util::WaitUntilDriveMountPointIsAdded(profile());
test_util::WaitUntilDriveMountPointIsAdded(second_profile_); test_util::WaitUntilDriveMountPointIsAdded(second_profile_);
} }
...@@ -571,7 +567,7 @@ class MultiProfileDriveFileSystemExtensionApiTest : ...@@ -571,7 +567,7 @@ class MultiProfileDriveFileSystemExtensionApiTest :
const char kResourceId[] = "unique-id-for-multiprofile-copy-test"; const char kResourceId[] = "unique-id-for-multiprofile-copy-test";
drive::FakeDriveService* const main_service = drive::FakeDriveService* const main_service =
static_cast<drive::FakeDriveService*>( static_cast<drive::FakeDriveService*>(
drive::util::GetDriveServiceByProfile(browser()->profile())); drive::util::GetDriveServiceByProfile(profile()));
drive::FakeDriveService* const sub_service = drive::FakeDriveService* const sub_service =
static_cast<drive::FakeDriveService*>( static_cast<drive::FakeDriveService*>(
drive::util::GetDriveServiceByProfile(second_profile_)); drive::util::GetDriveServiceByProfile(second_profile_));
...@@ -625,16 +621,14 @@ class LocalAndDriveFileSystemExtensionApiTest ...@@ -625,16 +621,14 @@ class LocalAndDriveFileSystemExtensionApiTest
// FileSystemExtensionApiTestBase override. // FileSystemExtensionApiTestBase override.
void AddTestMountPoint() override { void AddTestMountPoint() override {
EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) EXPECT_TRUE(
->RegisterFileSystem(kLocalMountPointName, content::BrowserContext::GetMountPoints(profile())->RegisterFileSystem(
storage::kFileSystemTypeNativeLocal, kLocalMountPointName, storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(), storage::FileSystemMountOption(), local_mount_point_dir_));
local_mount_point_dir_)); VolumeManager::Get(profile())->AddVolumeForTesting(
VolumeManager::Get(browser()->profile()) local_mount_point_dir_, VOLUME_TYPE_TESTING,
->AddVolumeForTesting(local_mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN, false /* read_only */);
chromeos::DEVICE_TYPE_UNKNOWN, test_util::WaitUntilDriveMountPointIsAdded(profile());
false /* read_only */);
test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
} }
protected: protected:
......
...@@ -42,11 +42,23 @@ struct TestCase { ...@@ -42,11 +42,23 @@ struct TestCase {
return *this; return *this;
} }
// Show the startup browser. Some tests invoke the file picker dialog during
// the test. Requesting a file picker from a background page is forbidden by
// the apps platform, and it's a bug that these tests do so.
// FindRuntimeContext() in select_file_dialog_extension.cc will use the last
// active browser in this case, which requires a Browser to be present. See
// https://crbug.com/736930.
TestCase& WithBrowser() {
with_browser = true;
return *this;
}
const char* test_case_name = nullptr; const char* test_case_name = nullptr;
GuestMode guest_mode = NOT_IN_GUEST_MODE; GuestMode guest_mode = NOT_IN_GUEST_MODE;
bool trusted_events = false; bool trusted_events = false;
bool tablet_mode = false; bool tablet_mode = false;
bool enable_drivefs = false; bool enable_drivefs = false;
bool with_browser = false;
}; };
// EventCase: FilesAppBrowserTest with trusted JS Events. // EventCase: FilesAppBrowserTest with trusted JS Events.
...@@ -81,6 +93,9 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase, ...@@ -81,6 +93,9 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase,
GuestMode GetGuestMode() const override { return GetParam().guest_mode; } GuestMode GetGuestMode() const override { return GetParam().guest_mode; }
bool GetEnableDriveFs() const override { return GetParam().enable_drivefs; } bool GetEnableDriveFs() const override { return GetParam().enable_drivefs; }
bool GetRequiresStartupBrowser() const override {
return GetParam().with_browser;
}
const char* GetTestCaseName() const override { const char* GetTestCaseName() const override {
return GetParam().test_case_name; return GetParam().test_case_name;
...@@ -407,33 +422,38 @@ WRAPPED_INSTANTIATE_TEST_CASE_P( ...@@ -407,33 +422,38 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
EventCase("tabindexFocusDownloads"), EventCase("tabindexFocusDownloads"),
EventCase("tabindexFocusDownloads").InGuestMode(), EventCase("tabindexFocusDownloads").InGuestMode(),
EventCase("tabindexFocusDirectorySelected"), EventCase("tabindexFocusDirectorySelected"),
EventCase("tabindexOpenDialogDrive"), EventCase("tabindexOpenDialogDrive").WithBrowser(),
EventCase("tabindexOpenDialogDrive").EnableDriveFs(), EventCase("tabindexOpenDialogDrive").WithBrowser().EnableDriveFs(),
EventCase("tabindexOpenDialogDownloads"), EventCase("tabindexOpenDialogDownloads").WithBrowser(),
EventCase("tabindexOpenDialogDownloads").InGuestMode(), EventCase("tabindexOpenDialogDownloads").WithBrowser().InGuestMode(),
EventCase("tabindexSaveFileDialogDrive"), EventCase("tabindexSaveFileDialogDrive").WithBrowser(),
EventCase("tabindexSaveFileDialogDrive").EnableDriveFs(), EventCase("tabindexSaveFileDialogDrive").WithBrowser().EnableDriveFs(),
EventCase("tabindexSaveFileDialogDownloads"), EventCase("tabindexSaveFileDialogDownloads").WithBrowser(),
EventCase("tabindexSaveFileDialogDownloads").InGuestMode())); EventCase("tabindexSaveFileDialogDownloads")
.WithBrowser()
.InGuestMode()));
WRAPPED_INSTANTIATE_TEST_CASE_P( WRAPPED_INSTANTIATE_TEST_CASE_P(
FileDialog, /* file_dialog.js */ FileDialog, /* file_dialog.js */
FilesAppBrowserTest, FilesAppBrowserTest,
::testing::Values( ::testing::Values(
TestCase("openFileDialogUnload"), TestCase("openFileDialogUnload").WithBrowser(),
TestCase("openFileDialogDownloads"), TestCase("openFileDialogDownloads").WithBrowser(),
TestCase("openFileDialogDownloads").InGuestMode(), TestCase("openFileDialogDownloads").WithBrowser().InGuestMode(),
TestCase("openFileDialogDownloads").InIncognito(), TestCase("openFileDialogDownloads").WithBrowser().InIncognito(),
TestCase("openFileDialogCancelDownloads"), TestCase("openFileDialogCancelDownloads").WithBrowser(),
TestCase("openFileDialogEscapeDownloads"), TestCase("openFileDialogEscapeDownloads").WithBrowser(),
TestCase("openFileDialogDrive"), TestCase("openFileDialogDrive").WithBrowser(),
TestCase("openFileDialogDrive").InIncognito(), TestCase("openFileDialogDrive").WithBrowser().InIncognito(),
TestCase("openFileDialogDrive").EnableDriveFs(), TestCase("openFileDialogDrive").WithBrowser().EnableDriveFs(),
TestCase("openFileDialogDrive").InIncognito().EnableDriveFs(), TestCase("openFileDialogDrive")
TestCase("openFileDialogCancelDrive"), .WithBrowser()
TestCase("openFileDialogCancelDrive").EnableDriveFs(), .InIncognito()
TestCase("openFileDialogEscapeDrive"), .EnableDriveFs(),
TestCase("openFileDialogEscapeDrive").EnableDriveFs())); TestCase("openFileDialogCancelDrive").WithBrowser(),
TestCase("openFileDialogCancelDrive").WithBrowser().EnableDriveFs(),
TestCase("openFileDialogEscapeDrive").WithBrowser(),
TestCase("openFileDialogEscapeDrive").WithBrowser().EnableDriveFs()));
WRAPPED_INSTANTIATE_TEST_CASE_P( WRAPPED_INSTANTIATE_TEST_CASE_P(
CopyBetweenWindows, /* copy_between_windows.js */ CopyBetweenWindows, /* copy_between_windows.js */
......
...@@ -890,6 +890,23 @@ void FileManagerBrowserTestBase::SetUpCommandLine( ...@@ -890,6 +890,23 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
// Use a fake audio stream crbug.com/835626 // Use a fake audio stream crbug.com/835626
command_line->AppendSwitch(switches::kDisableAudioOutput); command_line->AppendSwitch(switches::kDisableAudioOutput);
if (!GetRequiresStartupBrowser()) {
// Don't sink time into showing an unused browser window.
// InProcessBrowserTest::browser() will be null.
command_line->AppendSwitch(switches::kNoStartupWindow);
// Without a browser window, opening an app window, then closing it will
// trigger browser shutdown. Usually this is fine, except it also prevents
// any _new_ app window being created, should a test want to do that.
// (At the time of writing, exactly one does).
// Although in this path no browser is created (and so one can never
// close..), setting this to false prevents InProcessBrowserTest from adding
// the kDisableZeroBrowsersOpenForTests flag, which would prevent
// chrome_browser_main_chromeos from adding the keepalive that normally
// stops chromeos from shutting down unexpectedly.
set_exit_when_last_browser_closes(false);
}
if (IsGuestModeTest()) { if (IsGuestModeTest()) {
command_line->AppendSwitch(chromeos::switches::kGuestSession); command_line->AppendSwitch(chromeos::switches::kGuestSession);
command_line->AppendSwitchNative(chromeos::switches::kLoginUser, "$guest"); command_line->AppendSwitchNative(chromeos::switches::kLoginUser, "$guest");
...@@ -963,6 +980,7 @@ void FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() { ...@@ -963,6 +980,7 @@ void FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture() {
void FileManagerBrowserTestBase::SetUpOnMainThread() { void FileManagerBrowserTestBase::SetUpOnMainThread() {
extensions::ExtensionApiTest::SetUpOnMainThread(); extensions::ExtensionApiTest::SetUpOnMainThread();
CHECK(profile()); CHECK(profile());
CHECK_EQ(!!browser(), GetRequiresStartupBrowser());
CHECK(local_volume_->Mount(profile())); CHECK(local_volume_->Mount(profile()));
...@@ -979,8 +997,7 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() { ...@@ -979,8 +997,7 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() {
// CustomMountPointCallback. TODO(joelhockey): It would be better if the // CustomMountPointCallback. TODO(joelhockey): It would be better if the
// crostini interface allowed for testing without such tight coupling. // crostini interface allowed for testing without such tight coupling.
crostini_volume_ = std::make_unique<CrostiniTestVolume>(); crostini_volume_ = std::make_unique<CrostiniTestVolume>();
browser()->profile()->GetPrefs()->SetBoolean( profile()->GetPrefs()->SetBoolean(crostini::prefs::kCrostiniEnabled, true);
crostini::prefs::kCrostiniEnabled, true);
crostini::CrostiniManager::GetInstance()->set_skip_restart_for_testing(); crostini::CrostiniManager::GetInstance()->set_skip_restart_for_testing();
chromeos::DBusThreadManager* dbus_thread_manager = chromeos::DBusThreadManager* dbus_thread_manager =
chromeos::DBusThreadManager::Get(); chromeos::DBusThreadManager::Get();
...@@ -1018,6 +1035,10 @@ bool FileManagerBrowserTestBase::GetEnableDriveFs() const { ...@@ -1018,6 +1035,10 @@ bool FileManagerBrowserTestBase::GetEnableDriveFs() const {
return false; return false;
} }
bool FileManagerBrowserTestBase::GetRequiresStartupBrowser() const {
return false;
}
void FileManagerBrowserTestBase::StartTest() { void FileManagerBrowserTestBase::StartTest() {
LOG(INFO) << "FileManagerBrowserTest::StartTest " << GetTestCaseName(); LOG(INFO) << "FileManagerBrowserTest::StartTest " << GetTestCaseName();
static const base::FilePath test_extension_dir = static const base::FilePath test_extension_dir =
......
...@@ -41,6 +41,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -41,6 +41,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Overrides for each FileManagerBrowserTest test extension type. // Overrides for each FileManagerBrowserTest test extension type.
virtual GuestMode GetGuestMode() const = 0; virtual GuestMode GetGuestMode() const = 0;
virtual bool GetEnableDriveFs() const; virtual bool GetEnableDriveFs() const;
virtual bool GetRequiresStartupBrowser() const;
virtual const char* GetTestCaseName() const = 0; virtual const char* GetTestCaseName() const = 0;
virtual const char* GetTestExtensionManifestName() const = 0; virtual const char* GetTestExtensionManifestName() const = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment