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/env/public/athena_env.h"
8 #include "athena/screen/public/screen_manager.h"
9 #include "athena/test/athena_test_helper.h"
10 #include "ui/aura/client/window_tree_client.h"
11 #include "ui/aura/test/event_generator_delegate_aura.h"
12 #include "ui/aura/window.h"
13 #include "ui/compositor/test/context_factories_for_test.h"
16 #include "ui/aura/window_tree_host_x11.h"
22 AthenaTestBase::AthenaTestBase()
23 : setup_called_(false), teardown_called_(false) {
26 AthenaTestBase::~AthenaTestBase() {
28 << "You have overridden SetUp but never called super class's SetUp";
29 CHECK(teardown_called_)
30 << "You have overridden TearDown but never called super class's TearDown";
33 void AthenaTestBase::SetUp() {
35 testing::Test::SetUp();
37 // The ContextFactory must exist before any Compositors are created.
38 bool enable_pixel_output = false;
39 ui::ContextFactory* context_factory =
40 ui::InitializeContextFactoryForTests(enable_pixel_output);
42 helper_.reset(new AthenaTestHelper(&message_loop_));
44 aura::test::SetUseOverrideRedirectWindowByDefault(true);
46 aura::test::InitializeAuraEventGeneratorDelegate();
47 helper_->SetUp(context_factory);
50 void AthenaTestBase::TearDown() {
51 AthenaEnv::Get()->OnTerminating();
53 teardown_called_ = true;
55 // Flush the message loop because we have pending release tasks
56 // and these tasks if un-executed would upset Valgrind.
57 RunAllPendingInMessageLoop();
60 ui::TerminateContextFactoryForTests();
61 testing::Test::TearDown();
64 void AthenaTestBase::RunAllPendingInMessageLoop() {
65 helper_->RunAllPendingInMessageLoop();
68 scoped_ptr<aura::Window> AthenaTestBase::CreateTestWindow(
69 aura::WindowDelegate* delegate,
70 const gfx::Rect& bounds) {
71 scoped_ptr<aura::Window> window(new aura::Window(delegate));
72 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
73 window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
74 aura::client::ParentWindowWithContext(
75 window.get(), ScreenManager::Get()->GetContext(), bounds);