Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / ui / aura / test / aura_test_helper.cc
blob2cc8b0dade4853a79fb4e3a50ceba5b8167efab7
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_helper.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/input_state_lookup.h"
13 #include "ui/aura/test/env_test_helper.h"
14 #include "ui/aura/test/event_generator_delegate_aura.h"
15 #include "ui/aura/test/test_focus_client.h"
16 #include "ui/aura/test/test_screen.h"
17 #include "ui/aura/test/test_window_tree_client.h"
18 #include "ui/aura/window.h"
19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/base/ime/input_method_factory.h"
21 #include "ui/base/ime/input_method_initializer.h"
22 #include "ui/compositor/compositor.h"
23 #include "ui/compositor/layer_animator.h"
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
25 #include "ui/gfx/screen.h"
27 #if defined(USE_X11)
28 #include "ui/aura/window_tree_host_x11.h"
29 #include "ui/base/x/x11_util.h"
30 #endif
32 namespace aura {
33 namespace test {
35 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop)
36 : setup_called_(false),
37 teardown_called_(false) {
38 DCHECK(message_loop);
39 message_loop_ = message_loop;
40 // Disable animations during tests.
41 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
42 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
43 #if defined(USE_X11)
44 test::SetUseOverrideRedirectWindowByDefault(true);
45 #endif
46 InitializeAuraEventGeneratorDelegate();
49 AuraTestHelper::~AuraTestHelper() {
50 CHECK(setup_called_)
51 << "AuraTestHelper::SetUp() never called.";
52 CHECK(teardown_called_)
53 << "AuraTestHelper::TearDown() never called.";
56 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
57 setup_called_ = true;
59 Env::CreateInstance(true);
60 Env::GetInstance()->set_context_factory(context_factory);
61 // Unit tests generally don't want to query the system, rather use the state
62 // from RootWindow.
63 EnvTestHelper(Env::GetInstance()).SetInputStateLookup(nullptr);
65 ui::SetUpInputMethodFactoryForTesting();
66 ui::InitializeInputMethodForTesting();
68 gfx::Size host_size(800, 600);
69 test_screen_.reset(TestScreen::Create(host_size));
70 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
71 host_.reset(test_screen_->CreateHostForPrimaryDisplay());
73 focus_client_.reset(new TestFocusClient);
74 client::SetFocusClient(root_window(), focus_client_.get());
75 stacking_client_.reset(new TestWindowTreeClient(root_window()));
76 capture_client_.reset(new client::DefaultCaptureClient(root_window()));
78 root_window()->Show();
79 // Ensure width != height so tests won't confuse them.
80 host()->SetBounds(gfx::Rect(host_size));
83 void AuraTestHelper::TearDown() {
84 teardown_called_ = true;
85 stacking_client_.reset();
86 capture_client_.reset();
87 focus_client_.reset();
88 client::SetFocusClient(root_window(), NULL);
89 host_.reset();
90 ui::GestureRecognizer::Reset();
91 test_screen_.reset();
92 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
94 #if defined(USE_X11)
95 ui::test::ResetXCursorCache();
96 #endif
98 ui::ShutdownInputMethodForTesting();
100 Env::DeleteInstance();
103 void AuraTestHelper::RunAllPendingInMessageLoop() {
104 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
105 // use run_loop.QuitClosure().
106 base::RunLoop run_loop;
107 run_loop.RunUntilIdle();
110 } // namespace test
111 } // namespace aura