Commit 13eec553 authored by Chrome Cunningham's avatar Chrome Cunningham Committed by Commit Bot

Revert "Add TestKeyboardControllerObserver for ash keyboard unit tests"

This reverts commit 79faeacd.

Reason for revert: broke linux-chromeos-dbg
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-chromeos-dbg/9171

Original change's description:
> Add TestKeyboardControllerObserver for ash keyboard unit tests
> 
> This also includes some cleanup of the BUILD.gn files.
> 
> Currently TestKeyboardControllerObserver is only needed by
> AshKeyboardControllerUnitTests, but will be required by any tests
> affecting the keyboard with SingleProcessMash once enabled.
> 
> Bug: 843332
> Change-Id: I3c321cfaefe55bb61bb11f2232f524714f6453f5
> Reviewed-on: https://chromium-review.googlesource.com/c/1343524
> Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
> Reviewed-by: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#610881}

TBR=stevenjb@chromium.org,sky@chromium.org

Change-Id: Ib7827c5a036c84e4486cb4ce8c32fd94a9c8f14a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 843332
Reviewed-on: https://chromium-review.googlesource.com/c/1351453Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610893}
parent e46111ec
......@@ -1911,7 +1911,6 @@ test("ash_unittests") {
"//ash/components/tap_visualizer:unit_tests",
"//ash/keyboard/arc",
"//ash/public/cpp",
"//ash/public/cpp:test_support",
"//ash/public/cpp:unit_tests",
"//ash/public/cpp/vector_icons",
"//ash/resources/vector_icons",
......@@ -2105,8 +2104,6 @@ static_library("test_support_common") {
"app_list/test/app_list_test_helper.h",
"app_list/test/test_app_list_client.cc",
"app_list/test/test_app_list_client.h",
"app_menu/notification_menu_view_test_api.cc",
"app_menu/notification_menu_view_test_api.h",
"display/display_configuration_controller_test_api.cc",
"display/display_configuration_controller_test_api.h",
"display/mirror_window_test_api.cc",
......@@ -2136,6 +2133,12 @@ static_library("test_support_common") {
"metrics/user_metrics_recorder_test_api.h",
"mojo_test_interface_factory.cc",
"mojo_test_interface_factory.h",
# TODO(jamescook): Consider adding a //ash/public/cpp:test_support target.
"app_menu/notification_menu_view_test_api.cc",
"app_menu/notification_menu_view_test_api.h",
"public/cpp/immersive/immersive_fullscreen_controller_test_api.cc",
"public/cpp/immersive/immersive_fullscreen_controller_test_api.h",
"rotator/screen_rotation_animator_test_api.cc",
"rotator/screen_rotation_animator_test_api.h",
"session/test_session_controller_client.cc",
......@@ -2224,7 +2227,6 @@ static_library("test_support_common") {
"//ash/app_menu",
"//ash/components/fast_ink",
"//ash/public/cpp",
"//ash/public/cpp:test_support",
"//ash/public/interfaces:test_interfaces",
"//base",
"//base:i18n",
......
......@@ -7,11 +7,9 @@
#include <memory>
#include <vector>
#include "ash/public/cpp/test/test_keyboard_controller_observer.h"
#include "ash/public/interfaces/keyboard_controller.mojom.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/test/scoped_task_environment.h"
......@@ -30,10 +28,55 @@ namespace ash {
namespace {
class TestObserver : public mojom::KeyboardControllerObserver {
public:
explicit TestObserver(mojom::KeyboardController* controller) {
mojom::KeyboardControllerObserverAssociatedPtrInfo ptr_info;
keyboard_controller_observer_binding_.Bind(mojo::MakeRequest(&ptr_info));
controller->AddObserver(std::move(ptr_info));
}
~TestObserver() override = default;
// mojom::KeyboardControllerObserver:
void OnKeyboardEnableFlagsChanged(
const std::vector<keyboard::mojom::KeyboardEnableFlag>& flags) override {
enable_flags_ = flags;
}
void OnKeyboardEnabledChanged(bool enabled) override {
if (!enabled)
++destroyed_count_;
}
void OnKeyboardVisibilityChanged(bool visible) override {}
void OnKeyboardVisibleBoundsChanged(const gfx::Rect& bounds) override {}
void OnKeyboardOccludedBoundsChanged(const gfx::Rect& bounds) override {}
void OnKeyboardConfigChanged(KeyboardConfigPtr config) override {
config_ = *config;
}
const KeyboardConfig& config() const { return config_; }
void set_config(const KeyboardConfig& config) { config_ = config; }
const std::vector<keyboard::mojom::KeyboardEnableFlag>& enable_flags() const {
return enable_flags_;
}
int destroyed_count() const { return destroyed_count_; }
private:
std::vector<keyboard::mojom::KeyboardEnableFlag> enable_flags_;
KeyboardConfig config_;
int destroyed_count_ = 0;
mojo::AssociatedBinding<mojom::KeyboardControllerObserver>
keyboard_controller_observer_binding_{this};
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
class TestClient {
public:
explicit TestClient(service_manager::Connector* connector) {
connector->BindInterface("test", &keyboard_controller_ptr_);
test_observer_ =
std::make_unique<TestObserver>(keyboard_controller_ptr_.get());
}
~TestClient() = default;
......@@ -139,6 +182,7 @@ class TestClient {
keyboard_controller_ptr_.FlushForTesting();
}
TestObserver* test_observer() const { return test_observer_.get(); }
int got_keyboard_config_count() const { return got_keyboard_config_count_; }
const KeyboardConfig& keyboard_config() const { return keyboard_config_; }
......@@ -156,6 +200,7 @@ class TestClient {
int got_keyboard_config_count_ = 0;
KeyboardConfig keyboard_config_;
mojom::KeyboardControllerPtr keyboard_controller_ptr_;
std::unique_ptr<TestObserver> test_observer_;
};
class TestContainerBehavior : public keyboard::ContainerBehavior {
......@@ -252,7 +297,7 @@ class AshKeyboardControllerTest : public AshTestBase {
test_client_ = std::make_unique<TestClient>(connector_.get());
// Set the initial observer config to the client (default) config.
test_observer()->set_config(test_client()->keyboard_config());
test_client_->test_observer()->set_config(test_client()->keyboard_config());
}
void TearDown() override {
......@@ -269,9 +314,6 @@ class AshKeyboardControllerTest : public AshTestBase {
return Shell::Get()->ash_keyboard_controller()->keyboard_controller();
}
TestClient* test_client() { return test_client_.get(); }
TestKeyboardControllerObserver* test_observer() {
return ash_test_helper()->test_keyboard_controller_observer();
}
private:
std::unique_ptr<service_manager::Connector> connector_;
......@@ -296,7 +338,7 @@ TEST_F(AshKeyboardControllerTest, SetKeyboardConfig) {
KeyboardConfigPtr config =
KeyboardConfig::New(test_client()->keyboard_config());
// Set the observer config to the client (default) config.
test_observer()->set_config(*config);
test_client()->test_observer()->set_config(*config);
// Change the keyboard config.
bool old_auto_complete = config->auto_complete;
......@@ -308,7 +350,8 @@ TEST_F(AshKeyboardControllerTest, SetKeyboardConfig) {
EXPECT_NE(old_auto_complete, test_client()->keyboard_config().auto_complete);
// Test that the test observer received the change.
EXPECT_NE(old_auto_complete, test_observer()->config().auto_complete);
EXPECT_NE(old_auto_complete,
test_client()->test_observer()->config().auto_complete);
}
TEST_F(AshKeyboardControllerTest, EnableFlags) {
......@@ -319,7 +362,7 @@ TEST_F(AshKeyboardControllerTest, EnableFlags) {
test_client()->GetEnableFlags();
EXPECT_TRUE(
base::ContainsValue(enable_flags, KeyboardEnableFlag::kExtensionEnabled));
EXPECT_EQ(enable_flags, test_observer()->enable_flags());
EXPECT_EQ(enable_flags, test_client()->test_observer()->enable_flags());
EXPECT_TRUE(test_client()->IsKeyboardEnabled());
// Set the enable override to disable the keyboard.
......@@ -329,7 +372,7 @@ TEST_F(AshKeyboardControllerTest, EnableFlags) {
base::ContainsValue(enable_flags, KeyboardEnableFlag::kExtensionEnabled));
EXPECT_TRUE(
base::ContainsValue(enable_flags, KeyboardEnableFlag::kPolicyDisabled));
EXPECT_EQ(enable_flags, test_observer()->enable_flags());
EXPECT_EQ(enable_flags, test_client()->test_observer()->enable_flags());
EXPECT_FALSE(test_client()->IsKeyboardEnabled());
// Clear the enable override; should enable the keyboard.
......@@ -339,28 +382,28 @@ TEST_F(AshKeyboardControllerTest, EnableFlags) {
base::ContainsValue(enable_flags, KeyboardEnableFlag::kExtensionEnabled));
EXPECT_FALSE(
base::ContainsValue(enable_flags, KeyboardEnableFlag::kPolicyDisabled));
EXPECT_EQ(enable_flags, test_observer()->enable_flags());
EXPECT_EQ(enable_flags, test_client()->test_observer()->enable_flags());
EXPECT_TRUE(test_client()->IsKeyboardEnabled());
}
TEST_F(AshKeyboardControllerTest, RebuildKeyboardIfEnabled) {
EXPECT_EQ(0, test_observer()->destroyed_count());
EXPECT_EQ(0, test_client()->test_observer()->destroyed_count());
// Enable the keyboard.
test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_EQ(0, test_observer()->destroyed_count());
EXPECT_EQ(0, test_client()->test_observer()->destroyed_count());
// Enable the keyboard again; this should not reload the keyboard.
test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_EQ(0, test_observer()->destroyed_count());
EXPECT_EQ(0, test_client()->test_observer()->destroyed_count());
// Rebuild the keyboard. This should destroy the previous keyboard window.
test_client()->RebuildKeyboardIfEnabled();
EXPECT_EQ(1, test_observer()->destroyed_count());
EXPECT_EQ(1, test_client()->test_observer()->destroyed_count());
// Disable the keyboard. The keyboard window should be destroyed.
test_client()->ClearEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
EXPECT_EQ(2, test_observer()->destroyed_count());
EXPECT_EQ(2, test_client()->test_observer()->destroyed_count());
}
TEST_F(AshKeyboardControllerTest, ShowAndHideKeyboard) {
......@@ -375,8 +418,8 @@ TEST_F(AshKeyboardControllerTest, ShowAndHideKeyboard) {
test_client()->HideKeyboard();
EXPECT_FALSE(keyboard_controller()->GetKeyboardWindow()->IsVisible());
// TODO(stevenjb): Also use TestKeyboardControllerObserver and
// IsKeyboardVisible to test visibility changes. https://crbug.com/849995.
// TODO(stevenjb): Also use TestObserver and IsKeyboardVisible to test
// visibility changes. https://crbug.com/849995.
}
TEST_F(AshKeyboardControllerTest, SetContainerType) {
......
......@@ -187,21 +187,3 @@ source_set("unit_tests") {
"//ui/gfx:test_support",
]
}
source_set("test_support") {
sources = [
"immersive/immersive_fullscreen_controller_test_api.cc",
"immersive/immersive_fullscreen_controller_test_api.h",
"test/test_keyboard_controller_observer.cc",
"test/test_keyboard_controller_observer.h",
]
deps = [
":cpp",
"//base",
"//services/service_manager/public/cpp",
"//ui/aura",
"//ui/gfx",
"//ui/views",
]
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/test/test_keyboard_controller_observer.h"
#include "base/run_loop.h"
namespace ash {
TestKeyboardControllerObserver::TestKeyboardControllerObserver(
mojom::KeyboardController* controller)
: controller_(controller) {
keyboard_controller_observer_binding_.Bind(
mojo::MakeRequestAssociatedWithDedicatedPipe(&ptr_));
controller_->AddObserver(ptr_.PassInterface());
}
TestKeyboardControllerObserver::~TestKeyboardControllerObserver() = default;
void TestKeyboardControllerObserver::OnKeyboardEnableFlagsChanged(
const std::vector<keyboard::mojom::KeyboardEnableFlag>& flags) {
enable_flags_ = flags;
}
void TestKeyboardControllerObserver::OnKeyboardEnabledChanged(bool enabled) {
if (!enabled)
++destroyed_count_;
}
void TestKeyboardControllerObserver::OnKeyboardConfigChanged(
keyboard::mojom::KeyboardConfigPtr config) {
config_ = *config;
}
void TestKeyboardControllerObserver::OnKeyboardVisibilityChanged(bool visible) {
}
void TestKeyboardControllerObserver::OnKeyboardVisibleBoundsChanged(
const gfx::Rect& bounds) {}
void TestKeyboardControllerObserver::OnKeyboardOccludedBoundsChanged(
const gfx::Rect& bounds) {}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_TEST_TEST_KEYBOARD_CONTROLLER_OBSERVER_H_
#define ASH_PUBLIC_CPP_TEST_TEST_KEYBOARD_CONTROLLER_OBSERVER_H_
#include "ash/public/interfaces/keyboard_controller.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
namespace ash {
// mojom::KeyboardControllerObserver implementation for tests. This class
// implements a test client observer for tests running with the Window Service.
class TestKeyboardControllerObserver
: public mojom::KeyboardControllerObserver {
public:
explicit TestKeyboardControllerObserver(
mojom::KeyboardController* controller);
~TestKeyboardControllerObserver() override;
// mojom::KeyboardControllerObserver
void OnKeyboardEnableFlagsChanged(
const std::vector<keyboard::mojom::KeyboardEnableFlag>& flags) override;
void OnKeyboardEnabledChanged(bool enabled) override;
void OnKeyboardConfigChanged(
keyboard::mojom::KeyboardConfigPtr config) override;
void OnKeyboardVisibilityChanged(bool visible) override;
void OnKeyboardVisibleBoundsChanged(const gfx::Rect& bounds) override;
void OnKeyboardOccludedBoundsChanged(const gfx::Rect& bounds) override;
const keyboard::mojom::KeyboardConfig& config() const { return config_; }
void set_config(const keyboard::mojom::KeyboardConfig& config) {
config_ = config;
}
const std::vector<keyboard::mojom::KeyboardEnableFlag>& enable_flags() const {
return enable_flags_;
}
int destroyed_count() const { return destroyed_count_; }
private:
mojom::KeyboardController* controller_;
mojom::KeyboardControllerObserverAssociatedPtr ptr_;
std::vector<keyboard::mojom::KeyboardEnableFlag> enable_flags_;
keyboard::mojom::KeyboardConfig config_;
int destroyed_count_ = 0;
mojo::AssociatedBinding<mojom::KeyboardControllerObserver>
keyboard_controller_observer_binding_{this};
DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerObserver);
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_TEST_TEST_KEYBOARD_CONTROLLER_OBSERVER_H_
......@@ -687,11 +687,12 @@ class VirtualKeyboardRootWindowControllerTest
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
SetTouchKeyboardEnabled(true);
keyboard::SetTouchKeyboardEnabled(true);
Shell::Get()->EnableKeyboard();
}
void TearDown() override {
SetTouchKeyboardEnabled(false);
keyboard::SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
}
......
......@@ -15,7 +15,6 @@
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/display/unified_mouse_warp_controller.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
......@@ -470,17 +469,6 @@ void AshTestBase::UnblockUserSession() {
GetSessionControllerClient()->UnlockScreen();
}
void AshTestBase::SetTouchKeyboardEnabled(bool enabled) {
auto flag = keyboard::mojom::KeyboardEnableFlag::kTouchEnabled;
if (enabled)
Shell::Get()->ash_keyboard_controller()->SetEnableFlag(flag);
else
Shell::Get()->ash_keyboard_controller()->ClearEnableFlag(flag);
// Ensure that observer methods and mojo calls between AshKeyboardController,
// keyboard::KeyboardController, and AshKeyboardUI complete.
base::RunLoop().RunUntilIdle();
}
void AshTestBase::DisableIME() {
aura::test::DisableIME(Shell::GetPrimaryRootWindow()->GetHost());
}
......
......@@ -226,10 +226,6 @@ class AshTestBase : public testing::Test {
void BlockUserSession(UserSessionBlockReason block_reason);
void UnblockUserSession();
// Enable or disable the keyboard for touch and run the message loop to
// allow observer operations to complete.
void SetTouchKeyboardEnabled(bool enabled);
void DisableIME();
// Swap the primary display with the secondary.
......
......@@ -12,10 +12,8 @@
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/display/display_configuration_controller_test_api.h"
#include "ash/display/screen_ash.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/mojo_test_interface_factory.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/test/test_keyboard_controller_observer.h"
#include "ash/session/test_session_controller_client.h"
#include "ash/shell.h"
#include "ash/shell_init_params.h"
......@@ -240,19 +238,9 @@ void AshTestHelper::SetUp(bool start_session, bool provide_local_state) {
app_list_test_helper_ = std::make_unique<AppListTestHelper>();
CreateWindowService();
// Create the test keyboard controller observer to respond to
// OnKeyboardLoadContents() and enable the virtual keyboard. Note: enabling
// the keyboard just makes it available, it does not show it or otherwise
// affect behavior.
test_keyboard_controller_observer_ =
std::make_unique<TestKeyboardControllerObserver>(
shell->ash_keyboard_controller());
shell->ash_keyboard_controller()->EnableKeyboard();
}
void AshTestHelper::TearDown() {
test_keyboard_controller_observer_.reset();
app_list_test_helper_.reset();
aura::test::SetEnvForTestWindows(nullptr);
......
......@@ -51,7 +51,6 @@ namespace ash {
class AppListTestHelper;
class AshTestEnvironment;
class AshTestViewsDelegate;
class TestKeyboardControllerObserver;
class TestShellDelegate;
// A helper class that does common initialization required for Ash. Creates a
......@@ -107,10 +106,6 @@ class AshTestHelper {
return app_list_test_helper_.get();
}
TestKeyboardControllerObserver* test_keyboard_controller_observer() {
return test_keyboard_controller_observer_.get();
}
void reset_commandline() { command_line_.reset(); }
// Gets a Connector that talks directly to the WindowService.
......@@ -149,9 +144,6 @@ class AshTestHelper {
std::unique_ptr<AppListTestHelper> app_list_test_helper_;
std::unique_ptr<TestKeyboardControllerObserver>
test_keyboard_controller_observer_;
service_manager::TestConnectorFactory test_connector_factory_;
std::unique_ptr<service_manager::Connector> window_service_connector_;
......
......@@ -18,6 +18,7 @@
#include "ui/aura/window.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/keyboard/public/keyboard_switches.h"
#include "ui/keyboard/test/keyboard_test_util.h"
......@@ -57,7 +58,7 @@ class PipPositionerTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
SetTouchKeyboardEnabled(true);
keyboard::SetTouchKeyboardEnabled(true);
Shell::Get()->EnableKeyboard();
UpdateWorkArea("400x400");
......@@ -69,7 +70,7 @@ class PipPositionerTest : public AshTestBase {
}
void TearDown() override {
SetTouchKeyboardEnabled(false);
keyboard::SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
}
......
......@@ -19,6 +19,7 @@
#include "ui/base/hit_test.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/keyboard/public/keyboard_switches.h"
#include "ui/keyboard/test/keyboard_test_util.h"
#include "ui/views/widget/widget.h"
......@@ -71,7 +72,8 @@ class PipWindowResizerTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
SetTouchKeyboardEnabled(true);
keyboard::SetTouchKeyboardEnabled(true);
Shell::Get()->EnableKeyboard();
widget_ = CreateWidgetForTest(gfx::Rect(200, 200, 100, 100));
window_ = widget_->GetNativeWindow();
......@@ -82,7 +84,7 @@ class PipWindowResizerTest : public AshTestBase {
}
void TearDown() override {
SetTouchKeyboardEnabled(false);
keyboard::SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
}
......
......@@ -127,9 +127,15 @@ class ScopedStickyKeyboardEnabler {
: accessibility_controller_(Shell::Get()->accessibility_controller()),
enabled_(accessibility_controller_->IsVirtualKeyboardEnabled()) {
accessibility_controller_->SetVirtualKeyboardEnabled(true);
keyboard::KeyboardController::Get()->EnableKeyboard(
std::make_unique<keyboard::TestKeyboardUI>(
Shell::Get()->window_tree_host_manager()->input_method()),
nullptr);
keyboard::KeyboardController::Get()->set_keyboard_locked(true);
}
~ScopedStickyKeyboardEnabler() {
keyboard::KeyboardController::Get()->set_keyboard_locked(false);
accessibility_controller_->SetVirtualKeyboardEnabled(enabled_);
}
......@@ -1864,7 +1870,8 @@ class WorkspaceLayoutManagerSystemUiAreaTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
SetTouchKeyboardEnabled(true);
keyboard::SetTouchKeyboardEnabled(true);
Shell::Get()->EnableKeyboard();
window_ = CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
wm::WindowState* window_state = wm::GetWindowState(window_);
......@@ -1874,7 +1881,7 @@ class WorkspaceLayoutManagerSystemUiAreaTest : public AshTestBase {
}
void TearDown() override {
SetTouchKeyboardEnabled(false);
keyboard::SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
}
......
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