Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / views / test / views_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/views/test/views_test_base.h"
6
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"
15
16 namespace views {
17
18 ViewsTestBase::ViewsTestBase()
19     : setup_called_(false),
20       teardown_called_(false) {
21 }
22
23 ViewsTestBase::~ViewsTestBase() {
24   CHECK(setup_called_)
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";
28 }
29
30 void ViewsTestBase::SetUp() {
31   testing::Test::SetUp();
32   setup_called_ = true;
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();
40 }
41
42 void ViewsTestBase::TearDown() {
43   ui::Clipboard::DestroyClipboardForCurrentThread();
44
45   // Flush the message loop because we have pending release tasks
46   // and these tasks if un-executed would upset Valgrind.
47   RunPendingMessages();
48   teardown_called_ = true;
49   views_delegate_.reset();
50   testing::Test::TearDown();
51   ui::ShutdownInputMethodForTesting();
52   aura_test_helper_->TearDown();
53   wm_state_.reset();
54   CHECK(!corewm::ScopedCaptureClient::IsActive());
55 }
56
57 void ViewsTestBase::RunPendingMessages() {
58   base::RunLoop run_loop;
59   run_loop.RunUntilIdle();
60 }
61
62 Widget::InitParams ViewsTestBase::CreateParams(
63     Widget::InitParams::Type type) {
64   Widget::InitParams params(type);
65   params.context = aura_test_helper_->root_window();
66   return params;
67 }
68
69 gfx::NativeView ViewsTestBase::GetContext() {
70   return aura_test_helper_->root_window();
71 }
72
73 }  // namespace views