1 // Copyright (c) 2012 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 "ui/aura/test/aura_test_base.h"
6
7 #include "ui/aura/client/window_tree_client.h"
8 #include "ui/aura/root_window.h"
9 #include "ui/aura/test/aura_test_helper.h"
10 #include "ui/aura/test/test_window_delegate.h"
11 #include "ui/aura/window.h"
12 #include "ui/base/ime/input_method_initializer.h"
13 #include "ui/events/gestures/gesture_configuration.h"
14
15 namespace aura {
16 namespace test {
17
AuraTestBase()18 AuraTestBase::AuraTestBase()
19 : setup_called_(false),
20 teardown_called_(false) {
21 }
22
~AuraTestBase()23 AuraTestBase::~AuraTestBase() {
24 CHECK(setup_called_)
25 << "You have overridden SetUp but never called super class's SetUp";
26 CHECK(teardown_called_)
27 << "You have overridden TearDown but never called super class's TearDown";
28 }
29
SetUp()30 void AuraTestBase::SetUp() {
31 setup_called_ = true;
32 testing::Test::SetUp();
33 ui::InitializeInputMethodForTesting();
34
35 // Changing the parameters for gesture recognition shouldn't cause
36 // tests to fail, so we use a separate set of parameters for unit
37 // testing.
38 ui::GestureConfiguration::set_long_press_time_in_seconds(1.0);
39 ui::GestureConfiguration::set_semi_long_press_time_in_seconds(0.4);
40 ui::GestureConfiguration::set_show_press_delay_in_ms(5);
41 ui::GestureConfiguration::set_max_distance_for_two_finger_tap_in_pixels(300);
42 ui::GestureConfiguration::set_max_seconds_between_double_click(0.7);
43 ui::GestureConfiguration::
44 set_max_separation_for_gesture_touches_in_pixels(150);
45 ui::GestureConfiguration::
46 set_max_touch_down_duration_in_seconds_for_click(0.8);
47 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(5);
48 ui::GestureConfiguration::set_max_distance_between_taps_for_double_tap(20);
49 ui::GestureConfiguration::set_min_distance_for_pinch_scroll_in_pixels(20);
50 ui::GestureConfiguration::set_min_flick_speed_squared(550.f * 550.f);
51 ui::GestureConfiguration::set_min_pinch_update_distance_in_pixels(5);
52 ui::GestureConfiguration::set_min_rail_break_velocity(200);
53 ui::GestureConfiguration::set_min_scroll_delta_squared(5 * 5);
54 ui::GestureConfiguration::
55 set_min_touch_down_duration_in_seconds_for_click(0.01);
56 ui::GestureConfiguration::set_points_buffered_for_velocity(10);
57 ui::GestureConfiguration::set_rail_break_proportion(15);
58 ui::GestureConfiguration::set_rail_start_proportion(2);
59 ui::GestureConfiguration::set_scroll_prediction_seconds(0);
60 ui::GestureConfiguration::set_default_radius(0);
61 ui::GestureConfiguration::set_fling_acceleration_curve_coefficients(
62 0, 0.0166667f);
63 ui::GestureConfiguration::set_fling_acceleration_curve_coefficients(
64 1, -0.0238095f);
65 ui::GestureConfiguration::set_fling_acceleration_curve_coefficients(
66 2, 0.0452381f);
67 ui::GestureConfiguration::set_fling_acceleration_curve_coefficients(
68 3, 0.8f);
69 ui::GestureConfiguration::set_fling_velocity_cap(15000.0f);
70
71 helper_.reset(new AuraTestHelper(&message_loop_));
72 helper_->SetUp();
73 }
74
TearDown()75 void AuraTestBase::TearDown() {
76 teardown_called_ = true;
77
78 // Flush the message loop because we have pending release tasks
79 // and these tasks if un-executed would upset Valgrind.
80 RunAllPendingInMessageLoop();
81
82 helper_->TearDown();
83 ui::ShutdownInputMethodForTesting();
84 testing::Test::TearDown();
85 }
86
CreateNormalWindow(int id,Window * parent,WindowDelegate * delegate)87 Window* AuraTestBase::CreateNormalWindow(int id, Window* parent,
88 WindowDelegate* delegate) {
89 Window* window = new Window(
90 delegate ? delegate :
91 test::TestWindowDelegate::CreateSelfDestroyingDelegate());
92 window->set_id(id);
93 window->Init(ui::LAYER_TEXTURED);
94 parent->AddChild(window);
95 window->SetBounds(gfx::Rect(0, 0, 100, 100));
96 window->Show();
97 return window;
98 }
99
CreateTransientChild(int id,Window * parent)100 Window* AuraTestBase::CreateTransientChild(int id, Window* parent) {
101 Window* window = new Window(NULL);
102 window->set_id(id);
103 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
104 window->Init(ui::LAYER_TEXTURED);
105 aura::client::ParentWindowWithContext(window, root_window(), gfx::Rect());
106 parent->AddTransientChild(window);
107 return window;
108 }
109
RunAllPendingInMessageLoop()110 void AuraTestBase::RunAllPendingInMessageLoop() {
111 helper_->RunAllPendingInMessageLoop();
112 }
113
ParentWindow(Window * window)114 void AuraTestBase::ParentWindow(Window* window) {
115 client::ParentWindowWithContext(window, root_window(), gfx::Rect());
116 }
117
118 } // namespace test
119 } // namespace aura
120