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"
42 class TestScreenshotDelegate
;
43 class TestSystemTrayDelegate
;
45 class TestMetroViewerProcessHost
;
48 class AshTestBase
: public testing::Test
{
51 virtual ~AshTestBase();
54 virtual void SetUp() OVERRIDE
;
55 virtual void TearDown() OVERRIDE
;
57 // Update the display configuration as given in |display_specs|.
58 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
59 void UpdateDisplay(const std::string
& display_specs
);
61 // Returns a root Window. Usually this is the active root Window, but that
62 // method can return NULL sometimes, and in those cases, we fall back on the
63 // primary root Window.
64 aura::Window
* CurrentContext();
66 // Versions of the functions in aura::test:: that go through our shell
67 // StackingController instead of taking a parent.
68 aura::Window
* CreateTestWindowInShellWithId(int id
);
69 aura::Window
* CreateTestWindowInShellWithBounds(const gfx::Rect
& bounds
);
70 aura::Window
* CreateTestWindowInShell(SkColor color
,
72 const gfx::Rect
& bounds
);
73 aura::Window
* CreateTestWindowInShellWithDelegate(
74 aura::WindowDelegate
* delegate
,
76 const gfx::Rect
& bounds
);
77 aura::Window
* CreateTestWindowInShellWithDelegateAndType(
78 aura::WindowDelegate
* delegate
,
79 ui::wm::WindowType type
,
81 const gfx::Rect
& bounds
);
83 // Attach |window| to the current shell's root window.
84 void ParentWindowInPrimaryRootWindow(aura::Window
* window
);
86 // Returns the EventGenerator that uses screen coordinates and works
87 // across multiple displays. It createse a new generator if it
88 // hasn't been created yet.
89 aura::test::EventGenerator
& GetEventGenerator();
92 enum UserSessionBlockReason
{
94 BLOCKED_BY_LOCK_SCREEN
= FIRST_BLOCK_REASON
,
95 BLOCKED_BY_LOGIN_SCREEN
,
96 BLOCKED_BY_USER_ADDING_SCREEN
,
97 NUMBER_OF_BLOCK_REASONS
100 // Proxy to AshTestHelper::SupportsMultipleDisplays().
101 static bool SupportsMultipleDisplays();
103 // Proxy to AshTestHelper::SupportsHostWindowResize().
104 static bool SupportsHostWindowResize();
106 void set_start_session(bool start_session
) { start_session_
= start_session
; }
108 AshTestHelper
* ash_test_helper() { return ash_test_helper_
.get(); }
110 void RunAllPendingInMessageLoop();
112 TestScreenshotDelegate
* GetScreenshotDelegate();
113 TestSystemTrayDelegate
* GetSystemTrayDelegate();
115 // Utility methods to emulate user logged in or not, session started or not
116 // and user able to lock screen or not cases.
117 void SetSessionStarted(bool session_started
);
118 void SetUserLoggedIn(bool user_logged_in
);
119 void SetCanLockScreen(bool can_lock_screen
);
120 void SetShouldLockScreenBeforeSuspending(bool should_lock
);
121 void SetUserAddingScreenRunning(bool user_adding_screen_running
);
123 // Methods to emulate blocking and unblocking user session with given
125 void BlockUserSession(UserSessionBlockReason block_reason
);
126 void UnblockUserSession();
130 bool teardown_called_
;
131 // |SetUp()| doesn't activate session if this is set to false.
133 scoped_ptr
<content::TestBrowserThreadBundle
> thread_bundle_
;
134 scoped_ptr
<AshTestHelper
> ash_test_helper_
;
135 scoped_ptr
<aura::test::EventGenerator
> event_generator_
;
137 // Note that the order is important here as ipc_thread_ should be destroyed
138 // after metro_viewer_host_->channel_.
139 scoped_ptr
<base::Thread
> ipc_thread_
;
140 scoped_ptr
<TestMetroViewerProcessHost
> metro_viewer_host_
;
141 ui::ScopedOleInitializer ole_initializer_
;
144 DISALLOW_COPY_AND_ASSIGN(AshTestBase
);
147 class NoSessionAshTestBase
: public AshTestBase
{
149 NoSessionAshTestBase() {
150 set_start_session(false);
152 virtual ~NoSessionAshTestBase() {}
155 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase
);
161 #endif // ASH_TEST_ASH_TEST_BASE_H_