summaryrefslogtreecommitdiffstats
path: root/ui/aura/test/aura_test_base.cc
blob: 6ffbfb972ffabbc3791ea17c0501ab221b6c300a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/aura/test/aura_test_base.h"

#if defined(OS_WIN)
#include <ole2.h>
#endif

#include "ui/aura/root_window.h"
#include "ui/aura/test/test_stacking_client.h"

namespace aura {
namespace test {

AuraTestBase::AuraTestBase()
    : setup_called_(false),
      teardown_called_(false) {
#if defined(OS_WIN)
  OleInitialize(NULL);
#endif

  // TestStackingClient is owned by the root window.
  new TestStackingClient();
  RootWindow::GetInstance()->Show();
  RootWindow::GetInstance()->SetHostSize(gfx::Size(600, 600));
}

AuraTestBase::~AuraTestBase() {
#if defined(OS_WIN)
  OleUninitialize();
#endif
  CHECK(setup_called_)
      << "You have overridden SetUp but never called super class's SetUp";
  CHECK(teardown_called_)
      << "You have overridden TearDown but never called super class's TearDown";

  // Flush the message loop because we have pending release tasks
  // and these tasks if un-executed would upset Valgrind.
  RunAllPendingInMessageLoop();

  // Ensure that we don't use the previously-allocated static RootWindow object
  // later -- on Linux, it holds a reference to our message loop's X connection.
  aura::RootWindow::DeleteInstance();
}

TestStackingClient* AuraTestBase::GetTestStackingClient() {
  return static_cast<TestStackingClient*>(
      aura::RootWindow::GetInstance()->stacking_client());
}

void AuraTestBase::SetUp() {
  testing::Test::SetUp();
  setup_called_ = true;
}

void AuraTestBase::TearDown() {
  teardown_called_ = true;
  testing::Test::TearDown();
}

void AuraTestBase::RunAllPendingInMessageLoop() {
  message_loop_.RunAllPendingWithDispatcher(
      RootWindow::GetInstance()->GetDispatcher());
}

}  // namespace test
}  // namespace aura