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