Commit 14bd4f1a authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

Stop browser_tests leaving an open Explorer window

This change stops browser_tests from leaving a file explorer window
open after it completes.

Currently, browser test `DownloadExtensionTest.DownloadsShowFunction`
tests the "Show in Folder" functionality by opening a file explorer
window, but has no way to close this window after it completes. This
results in a stray file-explorer window. At times, the stray window
may also come with an error popup if the temp directory it points to
has already been deleted.

With this change, the call to open the file explorer is skipped if
shell operations have been disabled for testing. The call is skipped
as late as possible, in order to exercise as much of the code as
possible.

Change-Id: If015143d98a3e7e5d4a6bce958780fce6fa63f32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339599Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#796626}
parent f6b74dad
...@@ -1200,6 +1200,7 @@ IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, FileExistenceCheckAfterSearch) { ...@@ -1200,6 +1200,7 @@ IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, FileExistenceCheckAfterSearch) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
DownloadsShowFunction) { DownloadsShowFunction) {
platform_util::internal::DisableShellOperationsForTesting();
ScopedCancellingItem item(CreateFirstSlowTestDownload()); ScopedCancellingItem item(CreateFirstSlowTestDownload());
ASSERT_TRUE(item.get()); ASSERT_TRUE(item.get());
......
...@@ -55,6 +55,10 @@ void DisableShellOperationsForTesting() { ...@@ -55,6 +55,10 @@ void DisableShellOperationsForTesting() {
shell_operations_allowed = false; shell_operations_allowed = false;
} }
bool AreShellOperationsAllowed() {
return shell_operations_allowed;
}
} // namespace internal } // namespace internal
void OpenItem(Profile* profile, void OpenItem(Profile* profile,
......
...@@ -24,6 +24,9 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type); ...@@ -24,6 +24,9 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type);
// Prevent shell or external applications from being invoked during testing. // Prevent shell or external applications from being invoked during testing.
void DisableShellOperationsForTesting(); void DisableShellOperationsForTesting();
// Returns false if DisableShellOperationsForTesting() has been called.
bool AreShellOperationsAllowed();
} // namespace internal } // namespace internal
} // namespace platform_util } // namespace platform_util
......
...@@ -85,6 +85,11 @@ class ShowItemHelper : public content::NotificationObserver { ...@@ -85,6 +85,11 @@ class ShowItemHelper : public content::NotificationObserver {
{"file://" + full_path.value()}); // List of file(s) to highlight. {"file://" + full_path.value()}); // List of file(s) to highlight.
writer.AppendString({}); // startup-id writer.AppendString({}); // startup-id
// Skip opening the folder during browser tests, to avoid leaving an open
// file explorer window behind.
if (!internal::AreShellOperationsAllowed())
return;
filemanager_proxy_->CallMethod( filemanager_proxy_->CallMethod(
&show_items_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &show_items_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&ShowItemHelper::ShowItemInFolderResponse, base::BindOnce(&ShowItemHelper::ShowItemInFolderResponse,
......
...@@ -66,6 +66,11 @@ void ShowItemInFolderOnWorkerThread(const base::FilePath& full_path) { ...@@ -66,6 +66,11 @@ void ShowItemInFolderOnWorkerThread(const base::FilePath& full_path) {
const ITEMIDLIST* highlight[] = {file_item}; const ITEMIDLIST* highlight[] = {file_item};
// Skip opening the folder during browser tests, to avoid leaving an open
// file explorer window behind.
if (!platform_util::internal::AreShellOperationsAllowed())
return;
hr = hr =
SHOpenFolderAndSelectItems(dir_item, base::size(highlight), highlight, 0); SHOpenFolderAndSelectItems(dir_item, base::size(highlight), highlight, 0);
if (FAILED(hr)) { if (FAILED(hr)) {
......
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