Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / aura / test / aura_test_base.cc
blob7cbe9ac9870c8e82c5e370c29537d05dc3e6ce3c
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.
5 #include "ui/aura/test/aura_test_base.h"
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/gesture_detection/gesture_configuration.h"
17 namespace aura {
18 namespace test {
20 AuraTestBase::AuraTestBase()
21 : setup_called_(false),
22 teardown_called_(false) {
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";
32 void AuraTestBase::SetUp() {
33 setup_called_ = true;
34 testing::Test::SetUp();
35 ui::InitializeInputMethodForTesting();
36 ui::GestureConfiguration* gesture_config =
37 ui::GestureConfiguration::GetInstance();
38 // Changing the parameters for gesture recognition shouldn't cause
39 // tests to fail, so we use a separate set of parameters for unit
40 // testing.
41 gesture_config->set_default_radius(0);
42 gesture_config->set_fling_max_cancel_to_down_time_in_ms(400);
43 gesture_config->set_fling_max_tap_gap_time_in_ms(200);
44 gesture_config->set_gesture_begin_end_types_enabled(true);
45 gesture_config->set_long_press_time_in_ms(1000);
46 gesture_config->set_max_distance_between_taps_for_double_tap(20);
47 gesture_config->set_max_distance_for_two_finger_tap_in_pixels(300);
48 gesture_config->set_max_fling_velocity(15000);
49 gesture_config->set_max_gesture_bounds_length(0);
50 gesture_config->set_max_separation_for_gesture_touches_in_pixels(150);
51 gesture_config->set_max_swipe_deviation_angle(20);
52 gesture_config->set_max_time_between_double_click_in_ms(700);
53 gesture_config->set_max_touch_down_duration_for_click_in_ms(800);
54 gesture_config->set_max_touch_move_in_pixels_for_click(5);
55 gesture_config->set_min_distance_for_pinch_scroll_in_pixels(20);
56 gesture_config->set_min_fling_velocity(30.0f);
57 gesture_config->set_min_pinch_update_span_delta(0);
58 gesture_config->set_min_scaling_span_in_pixels(125);
59 gesture_config->set_min_swipe_velocity(10);
60 gesture_config->set_scroll_debounce_interval_in_ms(0);
61 gesture_config->set_semi_long_press_time_in_ms(400);
62 gesture_config->set_show_press_delay_in_ms(5);
63 gesture_config->set_swipe_enabled(true);
64 gesture_config->set_tab_scrub_activation_delay_in_ms(200);
65 gesture_config->set_two_finger_tap_enabled(true);
66 gesture_config->set_velocity_tracker_strategy(
67 ui::VelocityTracker::Strategy::LSQ2_RESTRICTED);
69 // The ContextFactory must exist before any Compositors are created.
70 bool enable_pixel_output = false;
71 ui::ContextFactory* context_factory =
72 ui::InitializeContextFactoryForTests(enable_pixel_output);
74 helper_.reset(new AuraTestHelper(&message_loop_));
75 helper_->SetUp(context_factory);
78 void AuraTestBase::TearDown() {
79 teardown_called_ = true;
81 // Flush the message loop because we have pending release tasks
82 // and these tasks if un-executed would upset Valgrind.
83 RunAllPendingInMessageLoop();
85 helper_->TearDown();
86 ui::TerminateContextFactoryForTests();
87 ui::ShutdownInputMethodForTesting();
88 testing::Test::TearDown();
91 Window* AuraTestBase::CreateNormalWindow(int id, Window* parent,
92 WindowDelegate* delegate) {
93 Window* window = new Window(
94 delegate ? delegate :
95 test::TestWindowDelegate::CreateSelfDestroyingDelegate());
96 window->set_id(id);
97 window->Init(ui::LAYER_TEXTURED);
98 parent->AddChild(window);
99 window->SetBounds(gfx::Rect(0, 0, 100, 100));
100 window->Show();
101 return window;
104 void AuraTestBase::RunAllPendingInMessageLoop() {
105 helper_->RunAllPendingInMessageLoop();
108 void AuraTestBase::ParentWindow(Window* window) {
109 client::ParentWindowWithContext(window, root_window(), gfx::Rect());
112 bool AuraTestBase::DispatchEventUsingWindowDispatcher(ui::Event* event) {
113 ui::EventDispatchDetails details =
114 event_processor()->OnEventFromSource(event);
115 CHECK(!details.dispatcher_destroyed);
116 return event->handled();
119 } // namespace test
120 } // namespace aura