1 // Copyright (c) 2012 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 #ifndef ASH_TEST_ASH_TEST_BASE_H_
6 #define ASH_TEST_ASH_TEST_BASE_H_
10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/threading/thread.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/wm/public/window_types.h"
19 #include "ui/base/win/scoped_ole_initializer.h"
44 class TestScreenshotDelegate
;
45 class TestSystemTrayDelegate
;
47 class TestMetroViewerProcessHost
;
50 class AshTestBase
: public testing::Test
{
53 virtual ~AshTestBase();
56 virtual void SetUp() OVERRIDE
;
57 virtual void TearDown() OVERRIDE
;
59 // Update the display configuration as given in |display_specs|.
60 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
61 void UpdateDisplay(const std::string
& display_specs
);
63 // Returns a root Window. Usually this is the active root Window, but that
64 // method can return NULL sometimes, and in those cases, we fall back on the
65 // primary root Window.
66 aura::Window
* CurrentContext();
68 // Versions of the functions in aura::test:: that go through our shell
69 // StackingController instead of taking a parent.
70 aura::Window
* CreateTestWindowInShellWithId(int id
);
71 aura::Window
* CreateTestWindowInShellWithBounds(const gfx::Rect
& bounds
);
72 aura::Window
* CreateTestWindowInShell(SkColor color
,
74 const gfx::Rect
& bounds
);
75 aura::Window
* CreateTestWindowInShellWithDelegate(
76 aura::WindowDelegate
* delegate
,
78 const gfx::Rect
& bounds
);
79 aura::Window
* CreateTestWindowInShellWithDelegateAndType(
80 aura::WindowDelegate
* delegate
,
81 ui::wm::WindowType type
,
83 const gfx::Rect
& bounds
);
85 // Attach |window| to the current shell's root window.
86 void ParentWindowInPrimaryRootWindow(aura::Window
* window
);
88 // Returns the EventGenerator that uses screen coordinates and works
89 // across multiple displays. It createse a new generator if it
90 // hasn't been created yet.
91 ui::test::EventGenerator
& GetEventGenerator();
94 enum UserSessionBlockReason
{
96 BLOCKED_BY_LOCK_SCREEN
= FIRST_BLOCK_REASON
,
97 BLOCKED_BY_LOGIN_SCREEN
,
98 BLOCKED_BY_USER_ADDING_SCREEN
,
99 NUMBER_OF_BLOCK_REASONS
102 // Proxy to AshTestHelper::SupportsMultipleDisplays().
103 static bool SupportsMultipleDisplays();
105 // Proxy to AshTestHelper::SupportsHostWindowResize().
106 static bool SupportsHostWindowResize();
108 void set_start_session(bool start_session
) { start_session_
= start_session
; }
110 AshTestHelper
* ash_test_helper() { return ash_test_helper_
.get(); }
112 void RunAllPendingInMessageLoop();
114 TestScreenshotDelegate
* GetScreenshotDelegate();
115 TestSystemTrayDelegate
* GetSystemTrayDelegate();
117 // Utility methods to emulate user logged in or not, session started or not
118 // and user able to lock screen or not cases.
119 void SetSessionStarted(bool session_started
);
120 void SetUserLoggedIn(bool user_logged_in
);
121 void SetCanLockScreen(bool can_lock_screen
);
122 void SetShouldLockScreenBeforeSuspending(bool should_lock
);
123 void SetUserAddingScreenRunning(bool user_adding_screen_running
);
125 // Methods to emulate blocking and unblocking user session with given
127 void BlockUserSession(UserSessionBlockReason block_reason
);
128 void UnblockUserSession();
132 bool teardown_called_
;
133 // |SetUp()| doesn't activate session if this is set to false.
135 scoped_ptr
<content::TestBrowserThreadBundle
> thread_bundle_
;
136 scoped_ptr
<AshTestHelper
> ash_test_helper_
;
137 scoped_ptr
<ui::test::EventGenerator
> event_generator_
;
139 // Note that the order is important here as ipc_thread_ should be destroyed
140 // after metro_viewer_host_->channel_.
141 scoped_ptr
<base::Thread
> ipc_thread_
;
142 scoped_ptr
<TestMetroViewerProcessHost
> metro_viewer_host_
;
143 ui::ScopedOleInitializer ole_initializer_
;
146 DISALLOW_COPY_AND_ASSIGN(AshTestBase
);
149 class NoSessionAshTestBase
: public AshTestBase
{
151 NoSessionAshTestBase() {
152 set_start_session(false);
154 virtual ~NoSessionAshTestBase() {}
157 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase
);
163 #endif // ASH_TEST_ASH_TEST_BASE_H_