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"
12 ViewsTestBase::ViewsTestBase()
13 : setup_called_(false),
14 teardown_called_(false) {
17 ViewsTestBase::~ViewsTestBase() {
19 << "You have overridden SetUp but never called super class's SetUp";
20 CHECK(teardown_called_
)
21 << "You have overridden TearDown but never called super class's TearDown";
24 void ViewsTestBase::SetUp() {
25 testing::Test::SetUp();
27 if (!views_delegate_for_setup_
)
28 views_delegate_for_setup_
.reset(new TestViewsDelegate());
31 new ScopedViewsTestHelper(views_delegate_for_setup_
.Pass()));
34 void ViewsTestBase::TearDown() {
35 ui::Clipboard::DestroyClipboardForCurrentThread();
37 // Flush the message loop because we have pending release tasks
38 // and these tasks if un-executed would upset Valgrind.
40 teardown_called_
= true;
41 testing::Test::TearDown();
45 void ViewsTestBase::RunPendingMessages() {
46 base::RunLoop run_loop
;
47 run_loop
.RunUntilIdle();
50 Widget::InitParams
ViewsTestBase::CreateParams(
51 Widget::InitParams::Type type
) {
52 Widget::InitParams
params(type
);
53 params
.context
= GetContext();
57 gfx::NativeWindow
ViewsTestBase::GetContext() {
58 return test_helper_
->GetContext();