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/views/test/views_test_base.h"
7 #include "base/run_loop.h"
8 #include "ui/base/clipboard/clipboard.h"
9 #include "ui/base/ime/input_method_initializer.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/aura/test/aura_test_helper.h"
13 #include "ui/views/corewm/capture_controller.h"
14 #include "ui/views/corewm/wm_state.h"
18 ViewsTestBase::ViewsTestBase()
19 : setup_called_(false),
20 teardown_called_(false) {
23 ViewsTestBase::~ViewsTestBase() {
25 << "You have overridden SetUp but never called super class's SetUp";
26 CHECK(teardown_called_)
27 << "You have overrideen TearDown but never called super class's TearDown";
30 void ViewsTestBase::SetUp() {
31 testing::Test::SetUp();
33 if (!views_delegate_.get())
34 views_delegate_.reset(new TestViewsDelegate());
35 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
36 bool allow_test_contexts = true;
37 aura_test_helper_->SetUp(allow_test_contexts);
38 wm_state_.reset(new views::corewm::WMState);
39 ui::InitializeInputMethodForTesting();
42 void ViewsTestBase::TearDown() {
43 ui::Clipboard::DestroyClipboardForCurrentThread();
45 // Flush the message loop because we have pending release tasks
46 // and these tasks if un-executed would upset Valgrind.
48 teardown_called_ = true;
49 views_delegate_.reset();
50 testing::Test::TearDown();
51 ui::ShutdownInputMethodForTesting();
52 aura_test_helper_->TearDown();
54 CHECK(!corewm::ScopedCaptureClient::IsActive());
57 void ViewsTestBase::RunPendingMessages() {
58 base::RunLoop run_loop;
59 run_loop.RunUntilIdle();
62 Widget::InitParams ViewsTestBase::CreateParams(
63 Widget::InitParams::Type type) {
64 Widget::InitParams params(type);
65 params.context = aura_test_helper_->root_window();
69 gfx::NativeView ViewsTestBase::GetContext() {
70 return aura_test_helper_->root_window();