Renames Setup to GlobalState
[chromium-blink-merge.git] / ash / test / ash_test_base.h
blobd45e21f0a935032358330b2041c847a211897b00
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_
8 #include <string>
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/gfx/display.h"
17 #include "ui/wm/public/window_types.h"
19 #if defined(OS_WIN)
20 #include "ui/base/win/scoped_ole_initializer.h"
21 #endif
23 namespace gfx {
24 class Rect;
27 namespace ui {
28 namespace test {
29 class EventGenerator;
33 namespace aura {
34 class RootWindow;
35 class Window;
36 class WindowDelegate;
37 } // namespace aura
39 namespace ash {
40 class DisplayManager;
42 namespace test {
44 class AshTestHelper;
45 class TestScreenshotDelegate;
46 class TestSystemTrayDelegate;
47 #if defined(OS_WIN)
48 class TestMetroViewerProcessHost;
49 #endif
51 class AshTestBase : public testing::Test {
52 public:
53 AshTestBase();
54 ~AshTestBase() override;
56 // testing::Test:
57 void SetUp() override;
58 void TearDown() override;
60 // Update the display configuration as given in |display_specs|.
61 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
62 void UpdateDisplay(const std::string& display_specs);
64 // Returns a root Window. Usually this is the active root Window, but that
65 // method can return NULL sometimes, and in those cases, we fall back on the
66 // primary root Window.
67 aura::Window* CurrentContext();
69 // Versions of the functions in aura::test:: that go through our shell
70 // StackingController instead of taking a parent.
71 aura::Window* CreateTestWindowInShellWithId(int id);
72 aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds);
73 aura::Window* CreateTestWindowInShell(SkColor color,
74 int id,
75 const gfx::Rect& bounds);
76 aura::Window* CreateTestWindowInShellWithDelegate(
77 aura::WindowDelegate* delegate,
78 int id,
79 const gfx::Rect& bounds);
80 aura::Window* CreateTestWindowInShellWithDelegateAndType(
81 aura::WindowDelegate* delegate,
82 ui::wm::WindowType type,
83 int id,
84 const gfx::Rect& bounds);
86 // Attach |window| to the current shell's root window.
87 void ParentWindowInPrimaryRootWindow(aura::Window* window);
89 // Returns the EventGenerator that uses screen coordinates and works
90 // across multiple displays. It createse a new generator if it
91 // hasn't been created yet.
92 ui::test::EventGenerator& GetEventGenerator();
94 protected:
95 enum UserSessionBlockReason {
96 FIRST_BLOCK_REASON,
97 BLOCKED_BY_LOCK_SCREEN = FIRST_BLOCK_REASON,
98 BLOCKED_BY_LOGIN_SCREEN,
99 BLOCKED_BY_USER_ADDING_SCREEN,
100 NUMBER_OF_BLOCK_REASONS
103 // Returns the rotation currentl active for the display |id|.
104 static gfx::Display::Rotation GetActiveDisplayRotation(int64 id);
106 // Returns the rotation currently active for the internal display.
107 static gfx::Display::Rotation GetCurrentInternalDisplayRotation();
109 // Proxy to AshTestHelper::SupportsMultipleDisplays().
110 static bool SupportsMultipleDisplays();
112 // Proxy to AshTestHelper::SupportsHostWindowResize().
113 static bool SupportsHostWindowResize();
115 void set_start_session(bool start_session) { start_session_ = start_session; }
117 AshTestHelper* ash_test_helper() { return ash_test_helper_.get(); }
119 void RunAllPendingInMessageLoop();
121 TestScreenshotDelegate* GetScreenshotDelegate();
122 TestSystemTrayDelegate* GetSystemTrayDelegate();
124 // Utility methods to emulate user logged in or not, session started or not
125 // and user able to lock screen or not cases.
126 void SetSessionStarted(bool session_started);
127 // Sets the SessionState to active, marking the begining of transitioning to
128 // a user session. The session is considered blocked until SetSessionStarted
129 // is called.
130 void SetSessionStarting();
131 void SetUserLoggedIn(bool user_logged_in);
132 void SetCanLockScreen(bool can_lock_screen);
133 void SetShouldLockScreenBeforeSuspending(bool should_lock);
134 void SetUserAddingScreenRunning(bool user_adding_screen_running);
136 // Methods to emulate blocking and unblocking user session with given
137 // |block_reason|.
138 void BlockUserSession(UserSessionBlockReason block_reason);
139 void UnblockUserSession();
141 void DisableIME();
143 private:
144 bool setup_called_;
145 bool teardown_called_;
146 // |SetUp()| doesn't activate session if this is set to false.
147 bool start_session_;
148 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_;
149 scoped_ptr<AshTestHelper> ash_test_helper_;
150 scoped_ptr<ui::test::EventGenerator> event_generator_;
151 #if defined(OS_WIN)
152 // Note that the order is important here as ipc_thread_ should be destroyed
153 // after metro_viewer_host_->channel_.
154 scoped_ptr<base::Thread> ipc_thread_;
155 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
156 ui::ScopedOleInitializer ole_initializer_;
157 #endif
159 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
162 class NoSessionAshTestBase : public AshTestBase {
163 public:
164 NoSessionAshTestBase() {
165 set_start_session(false);
167 ~NoSessionAshTestBase() override {}
169 private:
170 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
173 } // namespace test
174 } // namespace ash
176 #endif // ASH_TEST_ASH_TEST_BASE_H_