Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / views / test / views_test_base.cc
blobe508fd72096e7c8d0328a179fe87765a337f9fc5
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/compositor/test/context_factories_for_test.h"
11 #include "ui/views/test/views_test_helper.h"
13 namespace views {
15 ViewsTestBase::ViewsTestBase()
16 : setup_called_(false),
17 teardown_called_(false) {
20 ViewsTestBase::~ViewsTestBase() {
21 CHECK(setup_called_)
22 << "You have overridden SetUp but never called super class's SetUp";
23 CHECK(teardown_called_)
24 << "You have overridden TearDown but never called super class's TearDown";
27 void ViewsTestBase::SetUp() {
28 testing::Test::SetUp();
29 setup_called_ = true;
30 if (!views_delegate_.get())
31 views_delegate_.reset(new TestViewsDelegate());
33 // The ContextFactory must exist before any Compositors are created.
34 bool enable_pixel_output = false;
35 ui::ContextFactory* context_factory =
36 ui::InitializeContextFactoryForTests(enable_pixel_output);
37 views_delegate_->set_context_factory(context_factory);
39 test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory));
40 test_helper_->SetUp();
41 ui::InitializeInputMethodForTesting();
44 void ViewsTestBase::TearDown() {
45 ui::Clipboard::DestroyClipboardForCurrentThread();
47 // Flush the message loop because we have pending release tasks
48 // and these tasks if un-executed would upset Valgrind.
49 RunPendingMessages();
50 teardown_called_ = true;
51 views_delegate_.reset();
52 testing::Test::TearDown();
53 ui::ShutdownInputMethodForTesting();
54 test_helper_->TearDown();
55 ui::TerminateContextFactoryForTests();
58 void ViewsTestBase::RunPendingMessages() {
59 base::RunLoop run_loop;
60 run_loop.RunUntilIdle();
63 Widget::InitParams ViewsTestBase::CreateParams(
64 Widget::InitParams::Type type) {
65 Widget::InitParams params(type);
66 params.context = GetContext();
67 return params;
70 gfx::NativeWindow ViewsTestBase::GetContext() {
71 return test_helper_->GetContext();
74 } // namespace views