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"
15 #include "ui/aura/window_tree_host_x11.h"
21 AthenaTestBase::AthenaTestBase()
22 : setup_called_(false), teardown_called_(false) {
25 AthenaTestBase::~AthenaTestBase() {
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() {
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_
));
43 aura::test::SetUseOverrideRedirectWindowByDefault(true);
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();
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
);