Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / test / athena_test_base.cc
blobcbe812ccc900e23fe757cbdfebcaa834277b88c8
1 // Copyright 2014 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 "athena/test/athena_test_base.h"
7 #include "athena/screen/public/screen_manager.h"
8 #include "athena/test/athena_test_helper.h"
9 #include "ui/aura/client/window_tree_client.h"
10 #include "ui/aura/test/event_generator_delegate_aura.h"
11 #include "ui/aura/window.h"
12 #include "ui/compositor/test/context_factories_for_test.h"
14 #if defined(USE_X11)
15 #include "ui/aura/window_tree_host_x11.h"
16 #endif
18 namespace athena {
19 namespace test {
21 AthenaTestBase::AthenaTestBase()
22 : setup_called_(false), teardown_called_(false) {
25 AthenaTestBase::~AthenaTestBase() {
26 CHECK(setup_called_)
27 << "You have overridden SetUp but never called super class's SetUp";
28 CHECK(teardown_called_)
29 << "You have overridden TearDown but never called super class's TearDown";
32 void AthenaTestBase::SetUp() {
33 setup_called_ = true;
34 testing::Test::SetUp();
36 // The ContextFactory must exist before any Compositors are created.
37 bool enable_pixel_output = false;
38 ui::ContextFactory* context_factory =
39 ui::InitializeContextFactoryForTests(enable_pixel_output);
41 helper_.reset(new AthenaTestHelper(&message_loop_));
42 #if defined(USE_X11)
43 aura::test::SetUseOverrideRedirectWindowByDefault(true);
44 #endif
45 aura::test::InitializeAuraEventGeneratorDelegate();
46 helper_->SetUp(context_factory);
49 void AthenaTestBase::TearDown() {
50 teardown_called_ = true;
52 // Flush the message loop because we have pending release tasks
53 // and these tasks if un-executed would upset Valgrind.
54 RunAllPendingInMessageLoop();
56 helper_->TearDown();
57 ui::TerminateContextFactoryForTests();
58 testing::Test::TearDown();
61 void AthenaTestBase::RunAllPendingInMessageLoop() {
62 helper_->RunAllPendingInMessageLoop();
65 scoped_ptr<aura::Window> AthenaTestBase::CreateTestWindow(
66 aura::WindowDelegate* delegate,
67 const gfx::Rect& bounds) {
68 scoped_ptr<aura::Window> window(new aura::Window(delegate));
69 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
70 window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
71 aura::client::ParentWindowWithContext(
72 window.get(), ScreenManager::Get()->GetContext(), bounds);
73 return window.Pass();
76 } // namespace test
77 } // namespace athena