Index: ui/aura/aura_test_base.cc |
diff --git a/ui/aura/aura_test_base.cc b/ui/aura/aura_test_base.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf1c8209980771fa25ef071cdad6ea477ee0a3fa |
--- /dev/null |
+++ b/ui/aura/aura_test_base.cc |
@@ -0,0 +1,57 @@ |
+// 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/aura_test_base.h" |
+ |
+#if defined(OS_WIN) |
+#include <ole2.h> |
+#endif |
+ |
+#include "ui/aura/desktop.h" |
+#include "ui/gfx/compositor/test_compositor.h" |
+ |
+namespace aura { |
+ |
+static ui::Compositor* TestCreateCompositor() { |
+ return new ui::TestCompositor(); |
+} |
+ |
+AuraTestBase::AuraTestBase() |
+ : setup_called_(false), |
+ teardown_called_(false) { |
+#if defined(OS_WIN) |
+ OleInitialize(NULL); |
+#endif |
+} |
+ |
+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 overrideen TearDown but never called super class's TearDown"; |
+} |
+ |
+void AuraTestBase::SetUp() { |
+ testing::Test::SetUp(); |
+ setup_called_ = true; |
+ aura::Desktop::set_compositor_factory_for_testing(&TestCreateCompositor); |
+ if (!aura::Desktop::GetInstance()->default_parent()) |
+ aura::Desktop::GetInstance()->CreateDefaultParentForTesting(); |
+ Desktop::GetInstance()->Show(); |
+ Desktop::GetInstance()->SetSize(gfx::Size(500, 500)); |
+} |
+ |
+void AuraTestBase::TearDown() { |
+ // Flush the message loop because we have pending release tasks |
+ // and these tasks if un-executed would upset Valgrind. |
+ RunPendingMessages(); |
+ teardown_called_ = true; |
+ testing::Test::TearDown(); |
+ aura::Desktop::set_compositor_factory_for_testing(NULL); |
+} |
+ |
+} // namespace aura |