Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / test / views_test_base.cc
blob1e18266ce361372c667dd326e40b95a864478710
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"
10 namespace views {
12 ViewsTestBase::ViewsTestBase()
13 : setup_called_(false),
14 teardown_called_(false) {
17 ViewsTestBase::~ViewsTestBase() {
18 CHECK(setup_called_)
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();
26 setup_called_ = true;
27 if (!views_delegate_for_setup_)
28 views_delegate_for_setup_.reset(new TestViewsDelegate());
30 test_helper_.reset(
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.
39 RunPendingMessages();
40 teardown_called_ = true;
41 testing::Test::TearDown();
42 test_helper_.reset();
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();
54 return params;
57 gfx::NativeWindow ViewsTestBase::GetContext() {
58 return test_helper_->GetContext();
61 } // namespace views