| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/test/aura_test_helper.h" | 5 #include "ui/aura/test/aura_test_helper.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "ui/aura/client/default_capture_client.h" | 9 #include "ui/aura/client/default_capture_client.h" |
| 10 #include "ui/aura/client/focus_client.h" | 10 #include "ui/aura/client/focus_client.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #if defined(USE_X11) | 27 #if defined(USE_X11) |
| 28 #include "ui/aura/window_tree_host_x11.h" | 28 #include "ui/aura/window_tree_host_x11.h" |
| 29 #include "ui/base/x/x11_util.h" | 29 #include "ui/base/x/x11_util.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace aura { | 32 namespace aura { |
| 33 namespace test { | 33 namespace test { |
| 34 | 34 |
| 35 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop) | 35 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop) |
| 36 : setup_called_(false), | 36 : setup_called_(false), |
| 37 teardown_called_(false) { | 37 teardown_called_(false), |
| 38 env_created_(false) { |
| 38 DCHECK(message_loop); | 39 DCHECK(message_loop); |
| 39 message_loop_ = message_loop; | 40 message_loop_ = message_loop; |
| 40 // Disable animations during tests. | 41 // Disable animations during tests. |
| 41 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 42 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 42 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 43 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 43 #if defined(USE_X11) | 44 #if defined(USE_X11) |
| 44 test::SetUseOverrideRedirectWindowByDefault(true); | 45 test::SetUseOverrideRedirectWindowByDefault(true); |
| 45 #endif | 46 #endif |
| 46 InitializeAuraEventGeneratorDelegate(); | 47 InitializeAuraEventGeneratorDelegate(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 AuraTestHelper::~AuraTestHelper() { | 50 AuraTestHelper::~AuraTestHelper() { |
| 50 CHECK(setup_called_) | 51 CHECK(setup_called_) |
| 51 << "AuraTestHelper::SetUp() never called."; | 52 << "AuraTestHelper::SetUp() never called."; |
| 52 CHECK(teardown_called_) | 53 CHECK(teardown_called_) |
| 53 << "AuraTestHelper::TearDown() never called."; | 54 << "AuraTestHelper::TearDown() never called."; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { | 57 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { |
| 57 setup_called_ = true; | 58 setup_called_ = true; |
| 58 | 59 |
| 59 if (!Env::GetInstanceDontCreate()) | 60 if (!Env::GetInstanceDontCreate()) { |
| 60 env_ = aura::Env::CreateInstance(); | 61 env_created_ = true; |
| 62 Env::CreateInstance(true); |
| 63 } |
| 61 Env::GetInstance()->set_context_factory(context_factory); | 64 Env::GetInstance()->set_context_factory(context_factory); |
| 62 // Unit tests generally don't want to query the system, rather use the state | 65 // Unit tests generally don't want to query the system, rather use the state |
| 63 // from RootWindow. | 66 // from RootWindow. |
| 64 EnvTestHelper env_helper(Env::GetInstance()); | 67 EnvTestHelper env_helper(Env::GetInstance()); |
| 65 env_helper.SetInputStateLookup(nullptr); | 68 env_helper.SetInputStateLookup(nullptr); |
| 66 env_helper.ResetEventState(); | 69 env_helper.ResetEventState(); |
| 67 | 70 |
| 68 ui::InitializeInputMethodForTesting(); | 71 ui::InitializeInputMethodForTesting(); |
| 69 | 72 |
| 70 gfx::Size host_size(800, 600); | 73 gfx::Size host_size(800, 600); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 ui::GestureRecognizer::Reset(); | 95 ui::GestureRecognizer::Reset(); |
| 93 test_screen_.reset(); | 96 test_screen_.reset(); |
| 94 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | 97 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| 95 | 98 |
| 96 #if defined(USE_X11) | 99 #if defined(USE_X11) |
| 97 ui::test::ResetXCursorCache(); | 100 ui::test::ResetXCursorCache(); |
| 98 #endif | 101 #endif |
| 99 | 102 |
| 100 ui::ShutdownInputMethodForTesting(); | 103 ui::ShutdownInputMethodForTesting(); |
| 101 | 104 |
| 102 env_.reset(); | 105 if (env_created_) |
| 106 Env::DeleteInstance(); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void AuraTestHelper::RunAllPendingInMessageLoop() { | 109 void AuraTestHelper::RunAllPendingInMessageLoop() { |
| 106 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them | 110 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them |
| 107 // use run_loop.QuitClosure(). | 111 // use run_loop.QuitClosure(). |
| 108 base::RunLoop run_loop; | 112 base::RunLoop run_loop; |
| 109 run_loop.RunUntilIdle(); | 113 run_loop.RunUntilIdle(); |
| 110 } | 114 } |
| 111 | 115 |
| 112 } // namespace test | 116 } // namespace test |
| 113 } // namespace aura | 117 } // namespace aura |
| OLD | NEW |