Commit 844b16cb authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Update keyboard browser tests to use ChromeKeyboardControllerClient

This includes:
* keyboard_end_to_end_browsertest.cc
* keyboard_controller_browsertest.cc

Note: This renames the tests in keyboard_controller_browsertest from
VirtualKeyboard* to KeyboardController* to better match the file name
and the specific area of test focus.

This also contains some minor cleanup to keyboard::KeyboardController
that primarily impacts the in-progress SingleProcessMash implementation,
but should not affect the classic Ash implementation (except to clean
it up some). It is useful to isolate these changes from the larger CL
introducing AshKeyboardUI.

Bug: 876138
Change-Id: I8aa7e5da1f04f0d8b17a58e9582608e6159bee29
Reviewed-on: https://chromium-review.googlesource.com/c/1336250
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608638}
parent b5edc37e
......@@ -100,6 +100,12 @@ void ChromeKeyboardControllerClient::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void ChromeKeyboardControllerClient::NotifyKeyboardLoaded() {
is_keyboard_loaded_ = true;
for (auto& observer : observers_)
observer.OnKeyboardLoaded();
}
keyboard::mojom::KeyboardConfig
ChromeKeyboardControllerClient::GetKeyboardConfig() {
if (!cached_keyboard_config_) {
......
......@@ -37,7 +37,12 @@ class ChromeKeyboardControllerClient
// Forwards the 'OnKeyboardVisibilityChanged' mojo observer method.
// This is used by oobe and login to adjust the UI.
virtual void OnKeyboardVisibilityChanged(bool visible) = 0;
virtual void OnKeyboardVisibilityChanged(bool visible) {}
// Notifies observers when the keyboard content (i.e. the extension) has
// loaded. Note: if the content is already loaded when the observer is
// added, this will not be triggered, but see is_keyboard_loaded().
virtual void OnKeyboardLoaded() {}
};
// This class uses a static getter and only supports a single instance.
......@@ -54,6 +59,10 @@ class ChromeKeyboardControllerClient
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// In Classic Ash, notifies this that the contents have loaded, triggering
// OnKeyboardLoaded.
void NotifyKeyboardLoaded();
// Returns the cached KeyboardConfig value.
keyboard::mojom::KeyboardConfig GetKeyboardConfig();
......@@ -94,6 +103,7 @@ class ChromeKeyboardControllerClient
aura::Window* GetKeyboardWindow() const;
bool is_keyboard_enabled() { return is_keyboard_enabled_; }
bool is_keyboard_loaded() { return is_keyboard_loaded_; }
bool is_keyboard_visible() { return is_keyboard_visible_; }
void FlushForTesting();
......@@ -130,6 +140,9 @@ class ChromeKeyboardControllerClient
// Tracks the enabled state of the keyboard.
bool is_keyboard_enabled_ = false;
// Tracks when the keyboard content has loaded.
bool is_keyboard_loaded_ = false;
// Tracks the visible state of the keyboard.
bool is_keyboard_visible_ = false;
......
......@@ -46,7 +46,12 @@ aura::Window* ChromeKeyboardUI::LoadKeyboardWindow(LoadCallback callback) {
keyboard_contents_ = std::make_unique<ChromeKeyboardWebContents>(
browser_context_,
ChromeKeyboardControllerClient::Get()->GetVirtualKeyboardUrl(),
std::move(callback));
base::BindOnce(
[](LoadCallback callback) {
ChromeKeyboardControllerClient::Get()->NotifyKeyboardLoaded();
std::move(callback).Run();
},
std::move(callback)));
aura::Window* keyboard_window =
keyboard_contents_->web_contents()->GetNativeView();
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -17,24 +17,85 @@
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/dummy_text_input_client.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/test/event_generator.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_ui.h"
#include "ui/keyboard/public/keyboard_switches.h"
#include "ui/keyboard/resources/keyboard_resource_util.h"
#include "ui/keyboard/test/keyboard_test_util.h"
namespace {
const int kKeyboardHeightForTest = 100;
class KeyboardVisibleWaiter : public ChromeKeyboardControllerClient::Observer {
public:
explicit KeyboardVisibleWaiter(bool visible) : visible_(visible) {
ChromeKeyboardControllerClient::Get()->AddObserver(this);
}
~KeyboardVisibleWaiter() override {
ChromeKeyboardControllerClient::Get()->RemoveObserver(this);
}
void Wait() { run_loop_.Run(); }
// ChromeKeyboardControllerClient::Observer
void OnKeyboardVisibilityChanged(bool visible) override {
if (visible == visible_)
run_loop_.QuitWhenIdle();
}
private:
base::RunLoop run_loop_;
const bool visible_;
DISALLOW_COPY_AND_ASSIGN(KeyboardVisibleWaiter);
};
class KeyboardLoadedWaiter : public ChromeKeyboardControllerClient::Observer {
public:
KeyboardLoadedWaiter() {
ChromeKeyboardControllerClient::Get()->AddObserver(this);
}
~KeyboardLoadedWaiter() override {
ChromeKeyboardControllerClient::Get()->RemoveObserver(this);
}
void Wait() {
if (ChromeKeyboardControllerClient::Get()->is_keyboard_loaded())
return;
run_loop_.Run();
}
// ChromeKeyboardControllerClient::Observer
void OnKeyboardLoaded() override { run_loop_.QuitWhenIdle(); }
private:
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(KeyboardLoadedWaiter);
};
aura::Window* GetKeyboardRootWindow() {
return ChromeKeyboardControllerClient::Get()
->GetKeyboardWindow()
->GetRootWindow();
}
ui::InputMethod* GetInputMethod() {
aura::Window* root_window = GetKeyboardRootWindow();
return root_window ? root_window->GetHost()->GetInputMethod() : nullptr;
}
} // namespace
class VirtualKeyboardWebContentTest : public InProcessBrowserTest {
class KeyboardControllerWebContentTest : public InProcessBrowserTest {
public:
VirtualKeyboardWebContentTest() {}
~VirtualKeyboardWebContentTest() override {}
KeyboardControllerWebContentTest() {}
~KeyboardControllerWebContentTest() override {}
void SetUp() override {
ui::SetUpInputMethodFactoryForTesting();
......@@ -48,29 +109,22 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest {
command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
}
ui::InputMethod* GetInputMethod() {
return keyboard::KeyboardController::Get()->GetInputMethodForTest();
}
protected:
void FocusEditableNodeAndShowKeyboard(const gfx::Rect& init_bounds) {
client.reset(new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
auto* keyboard_controller = keyboard::KeyboardController::Get();
ui::InputMethod* input_method =
keyboard_controller->GetInputMethodForTest();
ui::InputMethod* input_method = GetInputMethod();
ASSERT_TRUE(input_method);
input_method->SetFocusedTextInputClient(client.get());
input_method->ShowVirtualKeyboardIfEnabled();
// Mock window.resizeTo that is expected to be called after navigate to a
// new virtual keyboard.
auto* keyboard_controller = ChromeKeyboardControllerClient::Get();
keyboard_controller->GetKeyboardWindow()->SetBounds(init_bounds);
ASSERT_TRUE(keyboard::WaitUntilShown());
}
void FocusNonEditableNode() {
client.reset(new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_NONE));
keyboard::KeyboardController::Get()
->GetInputMethodForTest()
->SetFocusedTextInputClient(client.get());
GetInputMethod()->SetFocusedTextInputClient(client.get());
}
void MockEnableIMEInDifferentExtension(const std::string& url,
......@@ -78,8 +132,8 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest {
DCHECK(!url.empty());
ChromeKeyboardControllerClient::Get()->set_virtual_keyboard_url_for_test(
GURL(url));
auto* keyboard_controller = keyboard::KeyboardController::Get();
keyboard_controller->Reload();
auto* keyboard_controller = ChromeKeyboardControllerClient::Get();
keyboard_controller->ReloadKeyboardIfNeeded();
// Mock window.resizeTo that is expected to be called after navigate to a
// new virtual keyboard.
keyboard_controller->GetKeyboardWindow()->SetBounds(init_bounds);
......@@ -88,56 +142,60 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest {
private:
std::unique_ptr<ui::DummyTextInputClient> client;
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardWebContentTest);
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerWebContentTest);
};
// Test for crbug.com/404340. After enabling an IME in a different extension,
// its virtual keyboard should not become visible if previous one is not.
IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest,
IN_PROC_BROWSER_TEST_F(KeyboardControllerWebContentTest,
EnableIMEInDifferentExtension) {
KeyboardLoadedWaiter().Wait();
gfx::Rect test_bounds(0, 0, 0, kKeyboardHeightForTest);
FocusEditableNodeAndShowKeyboard(test_bounds);
ASSERT_TRUE(keyboard::WaitUntilShown());
KeyboardVisibleWaiter(true).Wait();
FocusNonEditableNode();
ASSERT_TRUE(keyboard::WaitUntilHidden());
KeyboardVisibleWaiter(false).Wait();
MockEnableIMEInDifferentExtension("chrome-extension://domain-1", test_bounds);
// Keyboard should not become visible if previous keyboard is not.
EXPECT_FALSE(keyboard::IsKeyboardShowing());
EXPECT_FALSE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
FocusEditableNodeAndShowKeyboard(test_bounds);
// Keyboard should become visible after focus on an editable node.
ASSERT_TRUE(keyboard::WaitUntilShown());
KeyboardVisibleWaiter(true).Wait();
// Simulate hide keyboard by pressing hide key on the virtual keyboard.
keyboard::KeyboardController::Get()->HideKeyboardByUser();
ASSERT_TRUE(keyboard::WaitUntilHidden());
ChromeKeyboardControllerClient::Get()->HideKeyboard(
ash::mojom::HideReason::kUser);
KeyboardVisibleWaiter(false).Wait();
MockEnableIMEInDifferentExtension("chrome-extension://domain-2", test_bounds);
// Keyboard should not become visible if previous keyboard is not, even if it
// is currently focused on an editable node.
EXPECT_FALSE(keyboard::IsKeyboardShowing());
EXPECT_FALSE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest,
IN_PROC_BROWSER_TEST_F(KeyboardControllerWebContentTest,
CanDragFloatingKeyboardWithMouse) {
ChromeKeyboardControllerClient::Get()->SetContainerType(
keyboard::mojom::ContainerType::kFloating, base::nullopt,
base::DoNothing());
auto* controller = keyboard::KeyboardController::Get();
controller->ShowKeyboard(false);
ASSERT_TRUE(keyboard::WaitUntilShown());
auto* controller = ChromeKeyboardControllerClient::Get();
controller->ShowKeyboard();
KeyboardVisibleWaiter(true).Wait();
aura::Window* contents_window = controller->GetKeyboardWindow();
contents_window->SetBounds(gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(gfx::Point(0, 0), contents_window->bounds().origin());
controller->SetDraggableArea(contents_window->bounds());
controller->FlushForTesting();
// Drag the top left corner of the keyboard to move it.
ui::test::EventGenerator event_generator(ash::Shell::GetPrimaryRootWindow());
ui::test::EventGenerator event_generator(GetKeyboardRootWindow());
event_generator.MoveMouseTo(gfx::Point(0, 0));
event_generator.PressLeftButton();
event_generator.MoveMouseTo(gfx::Point(50, 50));
......@@ -147,29 +205,11 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest,
EXPECT_EQ(gfx::Point(50, 50), contents_window->bounds().origin());
}
// A test for crbug.com/734534
IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest,
DoesNotCrashWhenParentDoesNotExist) {
auto* controller = keyboard::KeyboardController::Get();
controller->LoadKeyboardWindowInBackground();
aura::Window* view = controller->GetKeyboardWindow();
EXPECT_TRUE(view);
// Remove the keyboard window parent.
EXPECT_TRUE(view->parent());
controller->DeactivateKeyboard();
EXPECT_FALSE(view->parent());
// Change window size to trigger OnWindowBoundsChanged.
view->SetBounds(gfx::Rect(0, 0, 1200, 800));
}
class VirtualKeyboardAppWindowTest : public extensions::PlatformAppBrowserTest {
class KeyboardControllerAppWindowTest
: public extensions::PlatformAppBrowserTest {
public:
VirtualKeyboardAppWindowTest() {}
~VirtualKeyboardAppWindowTest() override {}
KeyboardControllerAppWindowTest() {}
~KeyboardControllerAppWindowTest() override {}
// Ensure that the virtual keyboard is enabled.
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -177,11 +217,11 @@ class VirtualKeyboardAppWindowTest : public extensions::PlatformAppBrowserTest {
}
private:
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardAppWindowTest);
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAppWindowTest);
};
// Tests that ime window won't overscroll. See crbug.com/529880.
IN_PROC_BROWSER_TEST_F(VirtualKeyboardAppWindowTest,
IN_PROC_BROWSER_TEST_F(KeyboardControllerAppWindowTest,
DisableOverscrollForImeWindow) {
scoped_refptr<const extensions::Extension> extension =
extensions::ExtensionBuilder()
......@@ -221,12 +261,20 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardAppWindowTest,
ASSERT_EQ(non_ime_window_visible_height, ime_window_visible_height);
ASSERT_TRUE(ime_window_visible_height > 0);
int screen_height = ash::Shell::GetPrimaryRootWindow()->bounds().height();
// Make sure the keyboard has loaded before showing.
KeyboardLoadedWaiter().Wait();
auto* controller = ChromeKeyboardControllerClient::Get();
controller->ShowKeyboard();
KeyboardVisibleWaiter(true).Wait();
aura::Window* keyboard_window = GetKeyboardRootWindow();
ASSERT_TRUE(keyboard_window);
int screen_height = keyboard_window->bounds().height();
gfx::Rect test_bounds(0, 0, 0, screen_height - ime_window_visible_height + 1);
auto* controller = keyboard::KeyboardController::Get();
controller->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown());
controller->GetKeyboardWindow()->SetBounds(test_bounds);
// Allow actions triggered by window bounds observers to complete.
base::RunLoop().RunUntilIdle();
// Non ime window should have smaller visible view port due to overlap with
// virtual keyboard.
......@@ -243,10 +291,10 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardAppWindowTest,
ime_window_visible_height);
}
class VirtualKeyboardStateTest : public InProcessBrowserTest {
class KeyboardControllerStateTest : public InProcessBrowserTest {
public:
VirtualKeyboardStateTest() {}
~VirtualKeyboardStateTest() override {}
KeyboardControllerStateTest() {}
~KeyboardControllerStateTest() override {}
// Ensure that the virtual keyboard is enabled.
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -254,45 +302,66 @@ class VirtualKeyboardStateTest : public InProcessBrowserTest {
}
private:
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardStateTest);
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerStateTest);
};
IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest, OpenTwice) {
auto* controller = keyboard::KeyboardController::Get();
IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest, OpenTwice) {
auto* controller = ChromeKeyboardControllerClient::Get();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
// Call ShowKeyboard twice. The second call should has no effect.
controller->ShowKeyboard(false);
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
controller->ShowKeyboard(false);
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
EXPECT_FALSE(controller->is_keyboard_visible());
ASSERT_TRUE(keyboard::WaitUntilShown());
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::SHOWN);
// Call ShowKeyboard twice, the keyboard should become visible.
controller->ShowKeyboard();
controller->ShowKeyboard();
KeyboardVisibleWaiter(true).Wait();
EXPECT_TRUE(controller->is_keyboard_visible());
// Ensure the keyboard remains visible. Note: we call RunUntilIdle to at least
// ensure no other messages are pending instead of relying on a timeout that
// will slow down tests and potentially be flakey.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(controller->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest, StateResolvesAfterPreload) {
auto* controller = keyboard::KeyboardController::Get();
IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest, OpenAndCloseAndOpen) {
auto* controller = ChromeKeyboardControllerClient::Get();
controller->ShowKeyboard();
KeyboardVisibleWaiter(true).Wait();
controller->HideKeyboard(ash::mojom::HideReason::kSystem);
KeyboardVisibleWaiter(false).Wait();
controller->ShowKeyboard();
KeyboardVisibleWaiter(true).Wait();
}
// NOTE: The following tests test internal state of keyboard::KeyboardController
// and will not work in Multi Process Mash. TODO(stevenjb/shend): Determine
// whether this needs to be tested in a keyboard::KeyboardController unit test.
IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest, StateResolvesAfterPreload) {
if (::features::IsMultiProcessMash())
return;
auto* controller = keyboard::KeyboardController::Get();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
ASSERT_TRUE(keyboard::WaitUntilLoaded());
KeyboardLoadedWaiter().Wait();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::HIDDEN);
}
IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest, OpenAndCloseAndOpen) {
auto* controller = keyboard::KeyboardController::Get();
IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest,
OpenAndCloseAndOpenInternal) {
if (::features::IsMultiProcessMash())
return;
auto* controller = keyboard::KeyboardController::Get();
controller->ShowKeyboard(false);
// Need to wait the extension to be loaded. Hence LOADING_EXTENSION.
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
ASSERT_TRUE(keyboard::WaitUntilShown());
KeyboardVisibleWaiter(true).Wait();
controller->HideKeyboardExplicitlyBySystem();
EXPECT_EQ(controller->GetStateForTest(),
......@@ -305,7 +374,7 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest, OpenAndCloseAndOpen) {
}
// See crbug.com/755354.
IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest,
IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest,
DisablingKeyboardGoesToInitialState) {
auto* controller = keyboard::KeyboardController::Get();
......@@ -317,3 +386,24 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest,
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::INITIAL);
}
// A test for crbug.com/734534.
IN_PROC_BROWSER_TEST_F(KeyboardControllerWebContentTest,
DoesNotCrashWhenParentDoesNotExist) {
if (::features::IsMultiProcessMash())
return;
auto* controller = keyboard::KeyboardController::Get();
controller->LoadKeyboardWindowInBackground();
aura::Window* view = controller->GetKeyboardWindow();
EXPECT_TRUE(view);
// Remove the keyboard window parent.
EXPECT_TRUE(view->parent());
controller->DeactivateKeyboard();
EXPECT_FALSE(view->parent());
// Change window size to trigger OnWindowBoundsChanged.
view->SetBounds(gfx::Rect(0, 0, 1200, 800));
}
......@@ -5,7 +5,9 @@
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/files/file.h"
#include "base/run_loop.h"
#include "chrome/browser/chromeos/input_method/textinput_test_helper.h"
#include "chrome/browser/ui/ash/chrome_keyboard_controller_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
......@@ -15,18 +17,56 @@
#include "content/public/test/browser_test_utils.h"
#include "ui/aura/test/mus/change_completion_waiter.h"
#include "ui/aura/window_tree_host.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/public/keyboard_switches.h"
#include "ui/keyboard/resources/keyboard_resource_util.h"
#include "ui/keyboard/test/keyboard_test_util.h"
namespace keyboard {
namespace {
class KeyboardVisibleWaiter : public ChromeKeyboardControllerClient::Observer {
public:
explicit KeyboardVisibleWaiter(bool visible) : visible_(visible) {
ChromeKeyboardControllerClient::Get()->AddObserver(this);
}
~KeyboardVisibleWaiter() override {
ChromeKeyboardControllerClient::Get()->RemoveObserver(this);
}
void Wait() { run_loop_.Run(); }
// ChromeKeyboardControllerClient::Observer
void OnKeyboardVisibilityChanged(bool visible) override {
if (visible == visible_)
run_loop_.QuitWhenIdle();
}
private:
base::RunLoop run_loop_;
const bool visible_;
DISALLOW_COPY_AND_ASSIGN(KeyboardVisibleWaiter);
}; // namespace
bool WaitUntilShown() {
if (ChromeKeyboardControllerClient::Get()->is_keyboard_visible())
return true;
KeyboardVisibleWaiter(true).Wait();
return ChromeKeyboardControllerClient::Get()->is_keyboard_visible();
}
bool WaitUntilHidden() {
if (!ChromeKeyboardControllerClient::Get()->is_keyboard_visible())
return true;
KeyboardVisibleWaiter(false).Wait();
return !ChromeKeyboardControllerClient::Get()->is_keyboard_visible();
}
} // namespace
class KeyboardEndToEndTest : public InProcessBrowserTest {
public:
// Ensure that the virtual keyboard is enabled.
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kEnableVirtualKeyboard);
command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
}
void SetUpOnMainThread() override {
......@@ -36,17 +76,15 @@ class KeyboardEndToEndTest : public InProcessBrowserTest {
web_contents = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
ASSERT_TRUE(KeyboardController::Get());
ASSERT_TRUE(KeyboardController::Get()->IsEnabled());
EXPECT_FALSE(IsKeyboardVisible());
}
base::RunLoop().RunUntilIdle();
protected:
bool IsKeyboardVisible() {
auto* keyboard_controller = keyboard::KeyboardController::Get();
return keyboard_controller->IsKeyboardVisible();
auto* client = ChromeKeyboardControllerClient::Get();
ASSERT_TRUE(client);
ASSERT_TRUE(client->is_keyboard_enabled());
EXPECT_FALSE(client->is_keyboard_visible());
}
protected:
// Initialized in |SetUpOnMainThread|.
content::WebContents* web_contents;
......@@ -133,7 +171,8 @@ IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFormTest,
"document.getElementById('username').type = 'password'")
.error.empty());
EXPECT_FALSE(IsKeyboardHiding());
base::RunLoop().RunUntilIdle(); // Allow async operations to complete.
EXPECT_TRUE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFormTest,
......@@ -172,7 +211,8 @@ IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFormTest,
"setAttribute('inputmode', 'numeric')")
.error.empty());
EXPECT_FALSE(IsKeyboardHiding());
base::RunLoop().RunUntilIdle(); // Allow async operations to complete.
EXPECT_TRUE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFormTest,
......@@ -215,7 +255,8 @@ IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFocusTest,
content::EvalJs(web_contents, "document.getElementById('text').focus()")
.error.empty());
EXPECT_FALSE(IsKeyboardShowing());
base::RunLoop().RunUntilIdle(); // Allow async operations to complete.
EXPECT_FALSE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(KeyboardEndToEndFocusTest,
......@@ -230,7 +271,8 @@ IN_PROC_BROWSER_TEST_F(
TriggerAsyncInputFocusFromUserGestureDoesNotShowKeyboard) {
ClickElementWithId(web_contents, "async");
EXPECT_FALSE(IsKeyboardShowing());
base::RunLoop().RunUntilIdle(); // Allow async operations to complete.
EXPECT_FALSE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
IN_PROC_BROWSER_TEST_F(
......@@ -263,7 +305,8 @@ IN_PROC_BROWSER_TEST_F(
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(3501));
ClickElementWithId(web_contents, "async");
EXPECT_FALSE(IsKeyboardShowing());
base::RunLoop().RunUntilIdle(); // Allow async operations to complete.
EXPECT_FALSE(ChromeKeyboardControllerClient::Get()->is_keyboard_visible());
}
class KeyboardEndToEndOverscrollTest : public KeyboardEndToEndTest {
......@@ -274,7 +317,11 @@ class KeyboardEndToEndOverscrollTest : public KeyboardEndToEndTest {
void FocusAndShowKeyboard() { ClickElementWithId(web_contents, "username"); }
void HideKeyboard() { KeyboardController::Get()->HideKeyboardByUser(); }
void HideKeyboard() {
auto* controller = ChromeKeyboardControllerClient::Get();
controller->HideKeyboard(ash::mojom::HideReason::kUser);
controller->FlushForTesting();
}
protected:
int GetViewportHeight(content::WebContents* web_contents) {
......@@ -386,5 +433,3 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_EQ(browser()->window()->GetBounds(), old_browser_bounds);
EXPECT_EQ(GetViewportHeight(web_contents), old_height);
}
} // namespace keyboard
......@@ -193,13 +193,13 @@
# Virtual keyboard not supported.
-AccessibilityManagerLoginTest.ResumeSavedPref
-DefaultKeyboardExtensionBrowserTest.*
-KeyboardControllerAppWindowTest.*
-KeyboardControllerStateTest.*
-KeyboardControllerWebContentTest.*
-KeyboardEndToEndFocusTest.*
-KeyboardEndToEndFormTest.*
-KeyboardEndToEndOverscrollTest.*
-KioskVirtualKeyboardTest.*
-VirtualKeyboardAppWindowTest.*
-VirtualKeyboardStateTest.*
-VirtualKeyboardWebContentTest.*
-PolicyTest.VirtualKeyboardEnabled
# Also depends on keyboard. Test crashes in Mash. https://crbug.com/897012
......
......@@ -3,14 +3,14 @@
# Virtual keyboard not supported. https://crbug.com/646565
-DefaultKeyboardExtensionBrowserTest.*
-KeyboardControllerAppWindowTest.*
-KeyboardControllerStateTest.*
-KeyboardControllerWebContentTest.*
-KeyboardEndToEndFocusTest.*
-KeyboardEndToEndFormTest.*
-KeyboardEndToEndOverscrollTest.*
-KioskVirtualKeyboardTest.*
-PolicyTest.VirtualKeyboardEnabled
-VirtualKeyboardAppWindowTest.*
-VirtualKeyboardStateTest.*
-VirtualKeyboardWebContentTest.*
# Also depends on keyboard. Test hangs in single process mash crbug.com/897012
-SelectFileDialogExtensionBrowserTest.SelectFileVirtualKeyboard_TabletMode
......
......@@ -6,6 +6,7 @@
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/dummy_input_method.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_ui.h"
#include "ui/keyboard/keyboard_util.h"
......
......@@ -7,8 +7,6 @@
#include "base/run_loop.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/display/screen.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_controller_observer.h"
......@@ -53,20 +51,6 @@ bool WaitVisibilityChangesTo(bool wait_until) {
} // namespace
bool WaitUntilLoaded() {
auto* controller = KeyboardController::Get();
while (controller->GetStateForTest() == KeyboardControllerState::INITIAL ||
controller->GetStateForTest() ==
KeyboardControllerState::LOADING_EXTENSION) {
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(100));
run_loop.Run();
}
return true;
}
bool WaitUntilShown() {
// KeyboardController send a visibility update once the show animation
// finishes.
......
......@@ -6,9 +6,6 @@
#define UI_KEYBOARD_TEST_KEYBOARD_TEST_UTIL_H_
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/base/ime/dummy_input_method.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_ui.h"
namespace gfx {
......@@ -23,9 +20,6 @@ bool WaitUntilShown();
// Waits until the keyboard starts to hide, with possible pending animations.
bool WaitUntilHidden();
// Waits until the keyboard web contents has loaded.
bool WaitUntilLoaded();
// Returns true if the keyboard is about to show or already shown.
bool IsKeyboardShowing();
......
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