Commit 9b8749da authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Add SelectFileDialogExtensionBrowserTest virtual keyboard test

FilesApp provides the innards of the extension file dialog. For tablet
mode tests, always enable the Ash virtual keyboard and add a test that
clicks dialog filename <input> element and checks that the Ash virtual
keyboard appears.

The virtual keyboard test and enable-features=SingleProcessMash do not
play nice at this time: exclude this test from single process mash.

Bug: 879434, 897012
Change-Id: Ia5a72abd3fcdbd12282c36b27cc1213fd7e6672b
Reviewed-on: https://chromium-review.googlesource.com/c/1290571
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601078}
parent 06450f8b
......@@ -6,6 +6,8 @@
#include <memory>
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/shell_test_api.mojom.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
......@@ -28,15 +30,17 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/test/extension_test_message_listener.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/test/keyboard_test_util.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_policy.h"
#include "ui/shell_dialogs/selected_file_info.h"
using content::BrowserContext;
// Mock listener used by test below.
class MockSelectFileDialogListener : public ui::SelectFileDialog::Listener {
public:
MockSelectFileDialogListener()
......@@ -50,7 +54,7 @@ class MockSelectFileDialogListener : public ui::SelectFileDialog::Listener {
base::FilePath path() const { return path_; }
void* params() const { return params_; }
// ui::SelectFileDialog::Listener implementation.
// ui::SelectFileDialog::Listener:
void FileSelected(const base::FilePath& path,
int index,
void* params) override {
......@@ -119,6 +123,17 @@ class SelectFileDialogExtensionBrowserTest
extensions::ExtensionBrowserTest::SetUp();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Ash tablet mode does not automatically enable the virtual keyboard, so
// force the virtual keyboard via the command line for tablet mode tests.
const char* test_name =
::testing::UnitTest::GetInstance()->current_test_info()->name();
if (base::StringPiece(test_name).ends_with("_TabletMode"))
command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
}
void SetUpOnMainThread() override {
extensions::ExtensionBrowserTest::SetUpOnMainThread();
CHECK(profile());
......@@ -154,6 +169,36 @@ class SelectFileDialogExtensionBrowserTest
ASSERT_EQ(0, js_error_count);
}
void ClickElement(const std::string& selector) {
content::RenderFrameHost* frame_host =
dialog_->GetRenderViewHost()->GetMainFrame();
auto* web_contents = content::WebContents::FromRenderFrameHost(frame_host);
CHECK(web_contents);
int x;
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
web_contents,
"var bounds = document.querySelector('" + selector +
"').getBoundingClientRect();"
"domAutomationController.send("
" Math.floor(bounds.left + bounds.width / 2));",
&x));
int y;
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
web_contents,
"var bounds = document.querySelector('" + selector +
"').getBoundingClientRect();"
"domAutomationController.send("
" Math.floor(bounds.top + bounds.height / 2));",
&y));
LOG(INFO) << "ClickElement " << selector << " (" << x << "," << y << ")";
constexpr auto kButton = blink::WebMouseEvent::Button::kLeft;
content::SimulateMouseClickAt(web_contents, 0, kButton, gfx::Point(x, y));
}
void OpenDialog(ui::SelectFileDialog::Type dialog_type,
const base::FilePath& file_path,
const gfx::NativeWindow& owning_window,
......@@ -362,6 +407,37 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
ASSERT_EQ(this, listener_->params());
}
IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
SelectFileVirtualKeyboard_TabletMode) {
gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow();
// Setup tablet mode.
test::SetAndWaitForTabletMode(true);
// Enable the virtual keyboard.
ash::mojom::ShellTestApiPtr shell_test_api;
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &shell_test_api);
ash::mojom::ShellTestApiAsyncWaiter waiter(shell_test_api.get());
waiter.EnableVirtualKeyboard();
// Open the file dialog to save a file, providing a suggested file path.
// Ensure the "Save" button is enabled by waiting for notification from
// chrome.test.sendMessage().
const base::FilePath test_file =
downloads_dir_.AppendASCII("file_manager_save.html");
ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_SAVEAS_FILE,
test_file, owning_window, "dialog-ready"));
// Click the dialog's filename input element.
ASSERT_NO_FATAL_FAILURE(ClickElement("#filename-input-textbox"));
// The virtual keyboard should be shown.
keyboard::WaitUntilShown();
ASSERT_TRUE(keyboard::IsKeyboardShowing());
}
IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
OpenSingletonTabAndCancel) {
gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow();
......
......@@ -223,3 +223,6 @@
# ContentScriptApiTests are flaky: crbug.com/895110 and crbug.com/895070
-ContentScriptApiTest.ContentScriptExtensionAPIs
-ContentScriptApiTest.ContentScriptBlockingScriptsDontRunTwice
# Test hangs in single process mash crbug.com/897012
-SelectFileDialogExtensionBrowserTest.SelectFileVirtualKeyboard_TabletMode
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