Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: chrome/browser/ui/ash/ash_keyboard_controller_proxy_unittest.cc

Issue 139293009: Move keyboard test from unit test to browser test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
6
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ui/aura/test/test_window_delegate.h"
10 #include "ui/aura/window.h"
11 #include "ui/base/ime/input_method.h"
12 #include "ui/base/ime/input_method_factory.h"
13 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
14 #include "ui/compositor/test/layer_animator_test_controller.h"
15 #include "ui/keyboard/keyboard_controller.h"
16
17 namespace {
18
19 // Steps a layer animation until it is completed. Animations must be enabled.
20 void RunAnimationForLayer(ui::Layer* layer) {
21 // Animations must be enabled for stepping to work.
22 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
23 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
24
25 ui::LayerAnimatorTestController controller(layer->GetAnimator());
26 gfx::AnimationContainerElement* element = layer->GetAnimator();
27 // Multiple steps are required to complete complex animations.
28 // TODO(vollick): This should not be necessary. crbug.com/154017
29 while (controller.animator()->is_animating()) {
30 controller.StartThreadedAnimationsIfNeeded();
31 base::TimeTicks step_time = controller.animator()->last_step_time();
32 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
33 }
34 }
35
36 } // namespace
37
38 class TestAshKeyboardControllerProxy : public AshKeyboardControllerProxy {
39 public:
40 TestAshKeyboardControllerProxy()
41 : window_(new aura::Window(&delegate_)),
42 input_method_(ui::CreateInputMethod(NULL,
43 gfx::kNullAcceleratedWidget)) {
44 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
45 window_->set_owned_by_parent(false);
46 }
47
48 virtual ~TestAshKeyboardControllerProxy() {
49 window_.reset();
50 }
51
52 // Overridden from AshKeyboardControllerProxy:
53 virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); }
54 virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; }
55 virtual ui::InputMethod* GetInputMethod() OVERRIDE {
56 return input_method_.get();
57 }
58 virtual void RequestAudioInput(content::WebContents* web_contents,
59 const content::MediaStreamRequest& request,
60 const content::MediaResponseCallback& callback) OVERRIDE {}
61
62 private:
63 scoped_ptr<aura::Window> window_;
64 aura::test::TestWindowDelegate delegate_;
65 scoped_ptr<ui::InputMethod> input_method_;
66
67 DISALLOW_COPY_AND_ASSIGN(TestAshKeyboardControllerProxy);
68 };
69
70 class AshKeyboardControllerProxyTest : public ash::test::AshTestBase {
71 public:
72 AshKeyboardControllerProxyTest() {}
73
74 virtual ~AshKeyboardControllerProxyTest() {}
75
76 // AshTestBase:
77 virtual void SetUp() OVERRIDE;
78 virtual void TearDown() OVERRIDE;
79
80 TestAshKeyboardControllerProxy* proxy() { return proxy_; }
81 keyboard::KeyboardController* controller() { return controller_.get(); }
82
83 protected:
84 void ShowKeyboard(aura::Window* container);
85 void HideKeyboard(aura::Window* container);
86
87 TestAshKeyboardControllerProxy* proxy_;
88 scoped_ptr<keyboard::KeyboardController> controller_;
89
90 private:
91 DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerProxyTest);
92 };
93
94 void AshKeyboardControllerProxyTest::SetUp() {
95 ui::SetUpInputMethodFactoryForTesting();
96 AshTestBase::SetUp();
97 proxy_ = new TestAshKeyboardControllerProxy();
98 controller_.reset(new keyboard::KeyboardController(proxy_));
99
100 aura::Window* keyboard_container(controller_->GetContainerWindow());
101 keyboard_container->SetBounds(ash::Shell::GetPrimaryRootWindow()->bounds());
102 ash::Shell::GetPrimaryRootWindow()->AddChild(keyboard_container);
103 keyboard_container->AddChild(proxy_->GetKeyboardWindow());
104 ASSERT_NE(proxy_->GetKeyboardWindow()->bounds().height(), 0);
105 }
106
107 void AshKeyboardControllerProxyTest::TearDown() {
108 AshTestBase::TearDown();
109 }
110
111 void AshKeyboardControllerProxyTest::ShowKeyboard(aura::Window* container) {
112 proxy_->ShowKeyboardContainer(container);
113 }
114
115 void AshKeyboardControllerProxyTest::HideKeyboard(aura::Window* container) {
116 proxy_->HideKeyboardContainer(container);
117 }
118
119 TEST_F(AshKeyboardControllerProxyTest, VirtualKeyboardContainerAnimation) {
120 // We cannot short-circuit animations for this test.
121 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
122 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
123
124 aura::Window* keyboard_container(controller()->GetContainerWindow());
125 ui::Layer* layer = keyboard_container->layer();
126
127 EXPECT_FALSE(keyboard_container->IsVisible());
128 ShowKeyboard(keyboard_container);
129
130 // Keyboard container and window should immediately become visible before
131 // animation starts.
132 EXPECT_TRUE(keyboard_container->IsVisible());
133 EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
134 EXPECT_EQ(0.0, layer->opacity());
135 gfx::Transform transform;
136 transform.Translate(0, proxy()->GetKeyboardWindow()->bounds().height());
137 EXPECT_EQ(transform, layer->transform());
138
139 RunAnimationForLayer(layer);
140 EXPECT_TRUE(keyboard_container->IsVisible());
141 EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
142 EXPECT_EQ(1.0, layer->opacity());
143 EXPECT_EQ(gfx::Transform(), layer->transform());
144
145 HideKeyboard(keyboard_container);
146 // Keyboard container and window should be visible before hide animation
147 // finishes.
148 EXPECT_TRUE(keyboard_container->IsVisible());
149 EXPECT_TRUE(proxy()->GetKeyboardWindow()->IsVisible());
150
151 RunAnimationForLayer(layer);
152 EXPECT_FALSE(keyboard_container->IsVisible());
153 EXPECT_FALSE(proxy()->GetKeyboardWindow()->IsVisible());
154 EXPECT_EQ(0.0, layer->opacity());
155 EXPECT_EQ(transform, layer->transform());
156 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/ash_keyboard_controller_proxy_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698