summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-26 07:31:28 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-26 07:31:28 +0000
commit09464c756f61675a1369bdc750a614d6689c76c9 (patch)
treececc3cca8a358a61f2262f1da58d6a140428694a
parenta4b5dd2d0eb8b1e7d4e09d8264fb535a82735c91 (diff)
downloadchromium_src-09464c756f61675a1369bdc750a614d6689c76c9.zip
chromium_src-09464c756f61675a1369bdc750a614d6689c76c9.tar.gz
chromium_src-09464c756f61675a1369bdc750a614d6689c76c9.tar.bz2
Add AshTestHelper to let unit tests create windows on Ash
BUG=235474,233374 TEST=ash_unittests, unit_tests Review URL: https://chromiumcodereview.appspot.com/14284017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196652 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/ash.gyp3
-rw-r--r--ash/shell.h2
-rw-r--r--ash/system/chromeos/network/network_state_notifier_unittest.cc1
-rw-r--r--ash/system/tray/system_tray_unittest.cc1
-rw-r--r--ash/system/web_notification/web_notification_tray_unittest.cc1
-rw-r--r--ash/test/ash_test_base.cc144
-rw-r--r--ash/test/ash_test_base.h30
-rw-r--r--ash/test/ash_test_helper.cc152
-rw-r--r--ash/test/ash_test_helper.h71
-rw-r--r--ash/test/ash_test_helper_unittest.cc57
10 files changed, 318 insertions, 144 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index c99f041..4080dce 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -537,6 +537,8 @@
'sources': [
'test/ash_test_base.cc',
'test/ash_test_base.h',
+ 'test/ash_test_helper.cc',
+ 'test/ash_test_helper.h',
'test/cursor_manager_test_api.cc',
'test/cursor_manager_test_api.h',
'test/launcher_view_test_api.cc',
@@ -662,6 +664,7 @@
'system/chromeos/network/network_state_notifier_unittest.cc',
'system/tray/system_tray_unittest.cc',
'system/web_notification/web_notification_tray_unittest.cc',
+ 'test/ash_test_helper_unittest.cc',
'test/ash_unittests.cc',
'tooltips/tooltip_controller_unittest.cc',
'touch/touch_observer_hud_unittest.cc',
diff --git a/ash/shell.h b/ash/shell.h
index 892b04a..67551c8 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -150,6 +150,7 @@ class ASH_EXPORT Shell
// A shell must be explicitly created so that it can call |Init()| with the
// delegate set. |delegate| can be NULL (if not required for initialization).
+ // Takes ownership of |delegate|.
static Shell* CreateInstance(ShellDelegate* delegate);
// Should never be called before |CreateInstance()|.
@@ -456,6 +457,7 @@ class ASH_EXPORT Shell
typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
+ // Takes ownership of |delegate|.
explicit Shell(ShellDelegate* delegate);
virtual ~Shell();
diff --git a/ash/system/chromeos/network/network_state_notifier_unittest.cc b/ash/system/chromeos/network/network_state_notifier_unittest.cc
index ff52d53..fde1ad0 100644
--- a/ash/system/chromeos/network/network_state_notifier_unittest.cc
+++ b/ash/system/chromeos/network/network_state_notifier_unittest.cc
@@ -6,6 +6,7 @@
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_widget.h"
+#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray.h"
#include "ash/test/ash_test_base.h"
diff --git a/ash/system/tray/system_tray_unittest.cc b/ash/system/tray/system_tray_unittest.cc
index 8ec6c9e..0e61a1e 100644
--- a/ash/system/tray/system_tray_unittest.cc
+++ b/ash/system/tray/system_tray_unittest.cc
@@ -8,6 +8,7 @@
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_widget.h"
+#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/test/ash_test_base.h"
diff --git a/ash/system/web_notification/web_notification_tray_unittest.cc b/ash/system/web_notification/web_notification_tray_unittest.cc
index 963601b..509e057 100644
--- a/ash/system/web_notification/web_notification_tray_unittest.cc
+++ b/ash/system/web_notification/web_notification_tray_unittest.cc
@@ -8,6 +8,7 @@
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_widget.h"
+#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/test/ash_test_base.h"
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 6c2e7fa..58227c6 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -7,47 +7,26 @@
#include <string>
#include <vector>
-#include "ash/ash_switches.h"
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
-#include "ash/screen_ash.h"
#include "ash/shell.h"
+#include "ash/test/ash_test_helper.h"
#include "ash/test/display_manager_test_api.h"
-#include "ash/test/shell_test_api.h"
#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/coordinate_conversion.h"
-#include "base/command_line.h"
-#include "base/run_loop.h"
#include "content/public/test/web_contents_tester.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
-#include "ui/base/ime/text_input_test_support.h"
-#include "ui/compositor/layer_animator.h"
-#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/display.h"
+#include "ui/gfx/point.h"
#include "ui/gfx/screen.h"
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "ui/message_center/message_center.h"
-#endif
-
-#if defined(OS_WIN)
-#include "ash/test/test_metro_viewer_process_host.h"
-#include "base/test/test_process_killer_win.h"
-#include "base/win/metro.h"
-#include "base/win/windows_version.h"
-#include "ui/aura/remote_root_window_host_win.h"
-#include "ui/aura/root_window_host_win.h"
-#include "ui/base/ime/win/tsf_bridge.h"
-#include "win8/test/test_registrar_constants.h"
-#endif
-
namespace ash {
namespace test {
namespace {
@@ -84,102 +63,33 @@ content::WebContents* AshTestViewsDelegate::CreateWebContents(
site_instance);
}
+/////////////////////////////////////////////////////////////////////////////
+
AshTestBase::AshTestBase()
- : test_shell_delegate_(NULL) {
+ : setup_called_(false),
+ teardown_called_(false) {
+ // Must initialize |ash_test_helper_| here because some tests rely on
+ // AshTestBase methods before they call AshTestBase::SetUp().
+ ash_test_helper_.reset(new AshTestHelper(&message_loop_));
}
AshTestBase::~AshTestBase() {
+ CHECK(setup_called_)
+ << "You have overridden SetUp but never called AshTestBase::SetUp";
+ CHECK(teardown_called_)
+ << "You have overridden TearDown but never called AshTestBase::TearDown";
}
void AshTestBase::SetUp() {
- // Use the origin (1,1) so that it doesn't over
- // lap with the native mouse cursor.
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAshHostWindowBounds, "1+1-800x600");
-#if defined(OS_WIN)
- aura::test::SetUsePopupAsRootWindowForTest(true);
- if (base::win::IsTSFAwareRequired())
- ui::TSFBridge::Initialize();
-#endif
- // Disable animations during tests.
- zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
- ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
- ui::TextInputTestSupport::Initialize();
-
- // Creates Shell and hook with Desktop.
- test_shell_delegate_ = new TestShellDelegate;
-
-#if defined(ENABLE_MESSAGE_CENTER)
- // Creates MessageCenter since g_browser_process is not created in AshTestBase
- // tests.
- message_center::MessageCenter::Initialize();
-#endif
- ash::Shell::CreateInstance(test_shell_delegate_);
- Shell* shell = Shell::GetInstance();
- test::DisplayManagerTestApi(shell->display_manager()).
- DisableChangeDisplayUponHostResize();
-
- Shell::GetPrimaryRootWindow()->Show();
- Shell::GetPrimaryRootWindow()->ShowRootWindow();
- // Move the mouse cursor to far away so that native events doesn't
- // interfere test expectations.
- Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000));
- shell->cursor_manager()->EnableMouseEvents();
- ShellTestApi(shell).DisableOutputConfiguratorAnimation();
-
-#if defined(OS_WIN)
- if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
- !CommandLine::ForCurrentProcess()->HasSwitch(
- ash::switches::kForceAshToDesktop)) {
- metro_viewer_host_.reset(new TestMetroViewerProcessHost("viewer"));
- ASSERT_TRUE(
- metro_viewer_host_->LaunchViewerAndWaitForConnection(
- win8::test::kDefaultTestAppUserModelId));
- aura::RemoteRootWindowHostWin* root_window_host =
- aura::RemoteRootWindowHostWin::Instance();
- ASSERT_TRUE(root_window_host != NULL);
- }
-#endif
+ setup_called_ = true;
+ ash_test_helper_->SetUp();
}
void AshTestBase::TearDown() {
+ teardown_called_ = true;
// Flush the message loop to finish pending release tasks.
RunAllPendingInMessageLoop();
-
-#if defined(OS_WIN)
- if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
- !CommandLine::ForCurrentProcess()->HasSwitch(
- ash::switches::kForceAshToDesktop)) {
- // Check that our viewer connection is still established.
- ASSERT_FALSE(metro_viewer_host_->closed_unexpectedly());
- }
-#endif
-
- // Tear down the shell.
- Shell::DeleteInstance();
-
-#if defined(ENABLE_MESSAGE_CENTER)
- // Remove global message center state.
- message_center::MessageCenter::Shutdown();
-#endif
-
- aura::Env::DeleteInstance();
- ui::TextInputTestSupport::Shutdown();
-
-#if defined(OS_WIN)
- aura::test::SetUsePopupAsRootWindowForTest(false);
- // Kill the viewer process if we spun one up.
- metro_viewer_host_.reset();
-
- // Clean up any dangling viewer processes as the metro APIs sometimes leave
- // zombies behind. A default browser process in metro will have the
- // following command line arg so use that to avoid killing all processes named
- // win8::test::kDefaultTestExePath.
- const wchar_t kViewerProcessArgument[] = L"DefaultBrowserServer";
- base::KillAllNamedProcessesWithArgument(win8::test::kDefaultTestExePath,
- kViewerProcessArgument);
-#endif
-
+ ash_test_helper_->TearDown();
event_generator_.reset();
// Some tests set an internal display id,
// reset it here, so other tests will continue in a clean environment.
@@ -201,11 +111,7 @@ void AshTestBase::UpdateDisplay(const std::string& display_specs) {
}
aura::RootWindow* AshTestBase::CurrentContext() {
- aura::RootWindow* root_window = Shell::GetActiveRootWindow();
- if (!root_window)
- root_window = Shell::GetPrimaryRootWindow();
- DCHECK(root_window);
- return root_window;
+ return ash_test_helper_->CurrentContext();
}
aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
@@ -268,25 +174,21 @@ void AshTestBase::SetDefaultParentByPrimaryRootWindow(aura::Window* window) {
}
void AshTestBase::RunAllPendingInMessageLoop() {
-#if !defined(OS_MACOSX)
- DCHECK(MessageLoopForUI::current() == &message_loop_);
- base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
- run_loop.RunUntilIdle();
-#endif
+ ash_test_helper_->RunAllPendingInMessageLoop();
}
void AshTestBase::SetSessionStarted(bool session_started) {
- test_shell_delegate_->test_session_state_delegate()->
+ ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
SetActiveUserSessionStarted(session_started);
}
void AshTestBase::SetUserLoggedIn(bool user_logged_in) {
- test_shell_delegate_->test_session_state_delegate()->
+ ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
SetHasActiveUser(user_logged_in);
}
void AshTestBase::SetCanLockScreen(bool can_lock_screen) {
- test_shell_delegate_->test_session_state_delegate()->
+ ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
SetCanLockScreen(can_lock_screen);
}
diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h
index 42b375f..eacdad6 100644
--- a/ash/test/ash_test_base.h
+++ b/ash/test/ash_test_base.h
@@ -7,7 +7,6 @@
#include <string>
-#include "ash/shell.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,12 +14,8 @@
#include "ui/aura/client/window_types.h"
#include "ui/views/test/test_views_delegate.h"
-#if defined(OS_WIN)
-#include "base/memory/scoped_ptr.h"
-#include "ui/base/win/scoped_ole_initializer.h"
-#endif
-
namespace aura {
+class RootWindow;
class Window;
class WindowDelegate;
@@ -29,10 +24,6 @@ class EventGenerator;
} // namespace test
} // namespace aura
-namespace ui {
-class ScopedAnimationDurationScaleMode;
-} // namespace ui
-
namespace ash {
namespace internal {
class DisplayManager;
@@ -40,8 +31,7 @@ class DisplayManager;
namespace test {
-class TestMetroViewerProcessHost;
-class TestShellDelegate;
+class AshTestHelper;
class AshTestViewsDelegate : public views::TestViewsDelegate {
public:
@@ -56,7 +46,7 @@ class AshTestBase : public testing::Test {
AshTestBase();
virtual ~AshTestBase();
- MessageLoopForUI* message_loop() { return &message_loop_; }
+ base::MessageLoopForUI* message_loop() { return &message_loop_; }
// testing::Test:
virtual void SetUp() OVERRIDE;
@@ -106,17 +96,11 @@ class AshTestBase : public testing::Test {
void SetCanLockScreen(bool can_lock_screen);
private:
- MessageLoopForUI message_loop_;
-
- TestShellDelegate* test_shell_delegate_;
-
+ bool setup_called_;
+ bool teardown_called_;
+ base::MessageLoopForUI message_loop_;
+ scoped_ptr<AshTestHelper> ash_test_helper_;
scoped_ptr<aura::test::EventGenerator> event_generator_;
-#if defined(OS_WIN)
- scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
- ui::ScopedOleInitializer ole_initializer_;
-#endif
-
- scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
DISALLOW_COPY_AND_ASSIGN(AshTestBase);
};
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
new file mode 100644
index 0000000..172a787
--- /dev/null
+++ b/ash/test/ash_test_helper.cc
@@ -0,0 +1,152 @@
+// Copyright 2013 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 "ash/test/ash_test_helper.h"
+
+#include "ash/ash_switches.h"
+#include "ash/shell.h"
+#include "ash/test/display_manager_test_api.h"
+#include "ash/test/shell_test_api.h"
+#include "ash/test/test_shell_delegate.h"
+#include "base/command_line.h"
+#include "base/run_loop.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/ime/text_input_test_support.h"
+#include "ui/compositor/layer_animator.h"
+#include "ui/compositor/scoped_animation_duration_scale_mode.h"
+
+#if defined(OS_WIN)
+#include "ash/test/test_metro_viewer_process_host.h"
+#include "base/test/test_process_killer_win.h"
+#include "base/win/metro.h"
+#include "base/win/windows_version.h"
+#include "ui/aura/remote_root_window_host_win.h"
+#include "ui/aura/root_window_host_win.h"
+#include "ui/base/ime/win/tsf_bridge.h"
+#include "win8/test/test_registrar_constants.h"
+#endif
+
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center.h"
+#endif
+
+namespace ash {
+namespace test {
+
+AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
+ : message_loop_(message_loop),
+ test_shell_delegate_(NULL) {
+ CHECK(message_loop_);
+}
+
+AshTestHelper::~AshTestHelper() {
+}
+
+void AshTestHelper::SetUp() {
+ // TODO(jamescook): Can we do this without changing command line?
+ // Use the origin (1,1) so that it doesn't over
+ // lap with the native mouse cursor.
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kAshHostWindowBounds, "1+1-800x600");
+#if defined(OS_WIN)
+ aura::test::SetUsePopupAsRootWindowForTest(true);
+ if (base::win::IsTSFAwareRequired())
+ ui::TSFBridge::Initialize();
+#endif
+ // Disable animations during tests.
+ zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
+ ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
+ ui::TextInputTestSupport::Initialize();
+
+ // Creates Shell and hook with Desktop.
+ test_shell_delegate_ = new TestShellDelegate;
+
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Creates MessageCenter since g_browser_process is not created in AshTestBase
+ // tests.
+ message_center::MessageCenter::Initialize();
+#endif
+ ash::Shell::CreateInstance(test_shell_delegate_);
+ Shell* shell = Shell::GetInstance();
+ test::DisplayManagerTestApi(shell->display_manager()).
+ DisableChangeDisplayUponHostResize();
+
+ Shell::GetPrimaryRootWindow()->Show();
+ Shell::GetPrimaryRootWindow()->ShowRootWindow();
+ // Move the mouse cursor to far away so that native events doesn't
+ // interfere test expectations.
+ Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000));
+ shell->cursor_manager()->EnableMouseEvents();
+ ShellTestApi(shell).DisableOutputConfiguratorAnimation();
+
+#if defined(OS_WIN)
+ if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kForceAshToDesktop)) {
+ metro_viewer_host_.reset(new TestMetroViewerProcessHost("viewer"));
+ CHECK(metro_viewer_host_->LaunchViewerAndWaitForConnection(
+ win8::test::kDefaultTestAppUserModelId));
+ aura::RemoteRootWindowHostWin* root_window_host =
+ aura::RemoteRootWindowHostWin::Instance();
+ CHECK(root_window_host != NULL);
+ }
+#endif
+}
+
+void AshTestHelper::TearDown() {
+#if defined(OS_WIN)
+ if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kForceAshToDesktop)) {
+ // Check that our viewer connection is still established.
+ CHECK(!metro_viewer_host_->closed_unexpectedly());
+ }
+#endif
+
+ // Tear down the shell.
+ Shell::DeleteInstance();
+
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Remove global message center state.
+ message_center::MessageCenter::Shutdown();
+#endif
+
+ aura::Env::DeleteInstance();
+ ui::TextInputTestSupport::Shutdown();
+
+#if defined(OS_WIN)
+ aura::test::SetUsePopupAsRootWindowForTest(false);
+ // Kill the viewer process if we spun one up.
+ metro_viewer_host_.reset();
+
+ // Clean up any dangling viewer processes as the metro APIs sometimes leave
+ // zombies behind. A default browser process in metro will have the
+ // following command line arg so use that to avoid killing all processes named
+ // win8::test::kDefaultTestExePath.
+ const wchar_t kViewerProcessArgument[] = L"DefaultBrowserServer";
+ base::KillAllNamedProcessesWithArgument(win8::test::kDefaultTestExePath,
+ kViewerProcessArgument);
+#endif
+ zero_duration_mode_.reset();
+}
+
+void AshTestHelper::RunAllPendingInMessageLoop() {
+#if !defined(OS_MACOSX)
+ DCHECK(MessageLoopForUI::current() == message_loop_);
+ base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
+ run_loop.RunUntilIdle();
+#endif
+}
+
+aura::RootWindow* AshTestHelper::CurrentContext() {
+ aura::RootWindow* root_window = Shell::GetActiveRootWindow();
+ if (!root_window)
+ root_window = Shell::GetPrimaryRootWindow();
+ DCHECK(root_window);
+ return root_window;
+}
+
+} // namespace test
+} // namespace ash
diff --git a/ash/test/ash_test_helper.h b/ash/test/ash_test_helper.h
new file mode 100644
index 0000000..9d3b25a
--- /dev/null
+++ b/ash/test/ash_test_helper.h
@@ -0,0 +1,71 @@
+// Copyright 2013 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.
+
+#ifndef ASH_TEST_ASH_TEST_HELPER_H_
+#define ASH_TEST_ASH_TEST_HELPER_H_
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+
+#if defined(OS_WIN)
+#include "ui/base/win/scoped_ole_initializer.h"
+#endif
+
+namespace aura {
+class RootWindow;
+} // namespace aura
+
+namespace base {
+class MessageLoopForUI;
+} // namespace base
+
+namespace ui {
+class ScopedAnimationDurationScaleMode;
+} // namespace ui
+
+namespace ash {
+namespace test {
+
+class TestMetroViewerProcessHost;
+class TestShellDelegate;
+
+// A helper class that does common initialization required for Ash. Creates a
+// root window and an ash::Shell instance with a test delegate.
+class AshTestHelper {
+ public:
+ explicit AshTestHelper(base::MessageLoopForUI* message_loop);
+ ~AshTestHelper();
+
+ // Creates the ash::Shell and performs associated initialization.
+ void SetUp();
+
+ // Destroys the ash::Shell and performs associated cleanup.
+ void TearDown();
+
+ // Returns a RootWindow. Usually this is the active RootWindow, but that
+ // method can return NULL sometimes, and in those cases, we fall back on the
+ // primary RootWindow.
+ aura::RootWindow* CurrentContext();
+
+ void RunAllPendingInMessageLoop();
+
+ base::MessageLoopForUI* message_loop() { return message_loop_; }
+ TestShellDelegate* test_shell_delegate() { return test_shell_delegate_; }
+
+ private:
+ base::MessageLoopForUI* message_loop_; // Not owned.
+ TestShellDelegate* test_shell_delegate_; // Owned by ash::Shell.
+ scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
+#if defined(OS_WIN)
+ scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
+ ui::ScopedOleInitializer ole_initializer_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(AshTestHelper);
+};
+
+} // namespace test
+} // namespace ash
+
+#endif // ASH_TEST_ASH_TEST_HELPER_H_
diff --git a/ash/test/ash_test_helper_unittest.cc b/ash/test/ash_test_helper_unittest.cc
new file mode 100644
index 0000000..fdb27f9
--- /dev/null
+++ b/ash/test/ash_test_helper_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright 2013 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 "ash/test/ash_test_helper.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/root_window.h"
+#include "ui/views/widget/widget.h"
+
+// Tests for AshTestHelper. Who will watch the watchers? And who will test
+// the tests?
+class AshTestHelperTest : public testing::Test {
+ public:
+ AshTestHelperTest() {}
+ virtual ~AshTestHelperTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ testing::Test::SetUp();
+ ash_test_helper_.reset(new ash::test::AshTestHelper(&message_loop_));
+ ash_test_helper_->SetUp();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ ash_test_helper_->TearDown();
+ testing::Test::TearDown();
+ }
+
+ ash::test::AshTestHelper* ash_test_helper() {
+ return ash_test_helper_.get();
+ }
+
+ private:
+ base::MessageLoopForUI message_loop_;
+ scoped_ptr<ash::test::AshTestHelper> ash_test_helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(AshTestHelperTest);
+};
+
+// Ensure that we have initialized enough of Ash to create and show a window.
+TEST_F(AshTestHelperTest, AshTestHelper) {
+ // Check initial state.
+ EXPECT_TRUE(ash_test_helper()->message_loop());
+ EXPECT_TRUE(ash_test_helper()->test_shell_delegate());
+ EXPECT_TRUE(ash_test_helper()->CurrentContext());
+
+ // Enough state is initialized to create a window.
+ using views::Widget;
+ scoped_ptr<Widget> w1(new Widget);
+ Widget::InitParams params;
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.context = ash_test_helper()->CurrentContext();
+ w1->Init(params);
+ w1->Show();
+ EXPECT_TRUE(w1->IsActive());
+ EXPECT_TRUE(w1->IsVisible());
+}