summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/ash/ash_keyboard_controller_proxy.h2
-rw-r--r--chrome/browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc156
-rw-r--r--chrome/chrome_tests_unit.gypi3
3 files changed, 161 insertions, 0 deletions
diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h
index 0bd26f4..5d84774 100644
--- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h
+++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h
@@ -39,6 +39,8 @@ class AshKeyboardControllerProxy
virtual ~AshKeyboardControllerProxy();
private:
+ friend class AshKeyboardControllerProxyTest;
+
void OnRequest(const ExtensionHostMsg_Request_Params& params);
// keyboard::KeyboardControllerProxy overrides
diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc b/chrome/browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc
new file mode 100644
index 0000000..4f4da62
--- /dev/null
+++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc
@@ -0,0 +1,156 @@
+// Copyright 2014 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 "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
+
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/window.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/input_method_factory.h"
+#include "ui/compositor/scoped_animation_duration_scale_mode.h"
+#include "ui/compositor/test/layer_animator_test_controller.h"
+#include "ui/keyboard/keyboard_controller.h"
+
+namespace {
+
+// Steps a layer animation until it is completed. Animations must be enabled.
+void RunAnimationForLayer(ui::Layer* layer) {
+ // Animations must be enabled for stepping to work.
+ ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
+ ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
+
+ ui::LayerAnimatorTestController controller(layer->GetAnimator());
+ gfx::AnimationContainerElement* element = layer->GetAnimator();
+ // Multiple steps are required to complete complex animations.
+ // TODO(vollick): This should not be necessary. crbug.com/154017
+ while (controller.animator()->is_animating()) {
+ controller.StartThreadedAnimationsIfNeeded();
+ base::TimeTicks step_time = controller.animator()->last_step_time();
+ element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
+ }
+}
+
+} // namespace
+
+class TestAshKeyboardControllerProxy : public AshKeyboardControllerProxy {
+ public:
+ TestAshKeyboardControllerProxy()
+ : window_(new aura::Window(&delegate_)),
+ input_method_(ui::CreateInputMethod(NULL,
+ gfx::kNullAcceleratedWidget)) {
+ window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ window_->set_owned_by_parent(false);
+ }
+
+ virtual ~TestAshKeyboardControllerProxy() {
+ window_.reset();
+ }
+
+ // Overridden from AshKeyboardControllerProxy:
+ virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); }
+ virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; }
+ virtual ui::InputMethod* GetInputMethod() OVERRIDE {
+ return input_method_.get();
+ }
+ virtual void RequestAudioInput(content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback) OVERRIDE {}
+
+ private:
+ scoped_ptr<aura::Window> window_;
+ aura::test::TestWindowDelegate delegate_;
+ scoped_ptr<ui::InputMethod> input_method_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAshKeyboardControllerProxy);
+};
+
+class AshKeyboardControllerProxyTest : public ash::test::AshTestBase {
+ public:
+ AshKeyboardControllerProxyTest() {}
+
+ virtual ~AshKeyboardControllerProxyTest() {}
+
+ // AshTestBase:
+ virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
+
+ TestAshKeyboardControllerProxy* proxy() { return proxy_; }
+ keyboard::KeyboardController* controller() { return controller_.get(); }
+
+ protected:
+ void ShowKeyboard(aura::Window* container);
+ void HideKeyboard(aura::Window* container);
+
+ TestAshKeyboardControllerProxy* proxy_;
+ scoped_ptr<keyboard::KeyboardController> controller_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerProxyTest);
+};
+
+void AshKeyboardControllerProxyTest::SetUp() {
+ ui::SetUpInputMethodFactoryForTesting();
+ AshTestBase::SetUp();
+ proxy_ = new TestAshKeyboardControllerProxy();
+ controller_.reset(new keyboard::KeyboardController(proxy_));
+
+ aura::Window* keyboard_container(controller_->GetContainerWindow());
+ keyboard_container->SetBounds(ash::Shell::GetPrimaryRootWindow()->bounds());
+ ash::Shell::GetPrimaryRootWindow()->AddChild(keyboard_container);
+ keyboard_container->AddChild(proxy_->GetKeyboardWindow());
+ ASSERT_NE(proxy_->GetKeyboardWindow()->bounds().height(), 0);
+}
+
+void AshKeyboardControllerProxyTest::TearDown() {
+ AshTestBase::TearDown();
+}
+
+void AshKeyboardControllerProxyTest::ShowKeyboard(aura::Window* container) {
+ proxy_->ShowKeyboardContainer(container);
+}
+
+void AshKeyboardControllerProxyTest::HideKeyboard(aura::Window* container) {
+ proxy_->HideKeyboardContainer(container);
+}
+
+TEST_F(AshKeyboardControllerProxyTest, VirtualKeyboardContainerAnimation) {
+ // We cannot short-circuit animations for this test.
+ ui::ScopedAnimationDurationScaleMode normal_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+
+ aura::Window* keyboard_container(controller()->GetContainerWindow());
+ ui::Layer* layer = keyboard_container->layer();
+
+ EXPECT_FALSE(keyboard_container->IsVisible());
+ ShowKeyboard(keyboard_container);
+
+ // Keyboard container and window should immediately become visible before
+ // animation starts.
+ EXPECT_TRUE(keyboard_container->IsVisible());
+ EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
+ EXPECT_EQ(0.0, layer->opacity());
+ gfx::Transform transform;
+ transform.Translate(0, proxy()->GetKeyboardWindow()->bounds().height());
+ EXPECT_EQ(transform, layer->transform());
+
+ RunAnimationForLayer(layer);
+ EXPECT_TRUE(keyboard_container->IsVisible());
+ EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
+ EXPECT_EQ(1.0, layer->opacity());
+ EXPECT_EQ(gfx::Transform(), layer->transform());
+
+ HideKeyboard(keyboard_container);
+ // Keyboard container and window should be visible before hide animation
+ // finishes.
+ EXPECT_TRUE(keyboard_container->IsVisible());
+ EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
+
+ RunAnimationForLayer(layer);
+ EXPECT_FALSE(keyboard_container->IsVisible());
+ EXPECT_FALSE(proxy()->GetKeyboardWindow()->IsVisible());
+ EXPECT_EQ(0.0, layer->opacity());
+ EXPECT_EQ(transform, layer->transform());
+}
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index e6844cc..b6b8c5b 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -542,6 +542,8 @@
'../extensions/common/url_pattern_set_unittest.cc',
'../extensions/common/url_pattern_unittest.cc',
'../extensions/common/user_script_unittest.cc',
+ '../ui/compositor/test/layer_animator_test_controller.cc',
+ '../ui/compositor/test/layer_animator_test_controller.h',
'app/chrome_dll.rc',
# All unittests in browser, common, renderer and service.
'browser/about_flags_unittest.cc',
@@ -1409,6 +1411,7 @@
'browser/translate/translate_prefs_unittest.cc',
'browser/translate/translate_script_unittest.cc',
'browser/ui/android/tab_model/tab_model_unittest.cc',
+ 'browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc',
'browser/ui/ash/event_rewriter_unittest.cc',
'browser/ui/ash/ime_controller_chromeos_unittest.cc',
'browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc',