Probably broke Win7 Tests (dbg)(6). http://build.chromium.org/p/chromium.win/builders...
[chromium-blink-merge.git] / ash / test / ash_test_base.h
blob6ef1591edae0aa25bec582ccf5996ce97f51a34b
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/wm/public/window_types.h"
18 #if defined(OS_WIN)
19 #include "ui/base/win/scoped_ole_initializer.h"
20 #endif
22 namespace gfx {
23 class Rect;
26 namespace aura {
27 class RootWindow;
28 class Window;
29 class WindowDelegate;
31 namespace test {
32 class EventGenerator;
33 } // namespace test
34 } // namespace aura
36 namespace ash {
37 class DisplayManager;
39 namespace test {
41 class AshTestHelper;
42 class TestScreenshotDelegate;
43 class TestSystemTrayDelegate;
44 #if defined(OS_WIN)
45 class TestMetroViewerProcessHost;
46 #endif
48 class AshTestBase : public testing::Test {
49 public:
50 AshTestBase();
51 virtual ~AshTestBase();
53 // testing::Test:
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,
71 int id,
72 const gfx::Rect& bounds);
73 aura::Window* CreateTestWindowInShellWithDelegate(
74 aura::WindowDelegate* delegate,
75 int id,
76 const gfx::Rect& bounds);
77 aura::Window* CreateTestWindowInShellWithDelegateAndType(
78 aura::WindowDelegate* delegate,
79 ui::wm::WindowType type,
80 int id,
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();
91 protected:
92 enum UserSessionBlockReason {
93 FIRST_BLOCK_REASON,
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
124 // |block_reason|.
125 void BlockUserSession(UserSessionBlockReason block_reason);
126 void UnblockUserSession();
128 private:
129 bool setup_called_;
130 bool teardown_called_;
131 // |SetUp()| doesn't activate session if this is set to false.
132 bool start_session_;
133 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_;
134 scoped_ptr<AshTestHelper> ash_test_helper_;
135 scoped_ptr<aura::test::EventGenerator> event_generator_;
136 #if defined(OS_WIN)
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_;
142 #endif
144 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
147 class NoSessionAshTestBase : public AshTestBase {
148 public:
149 NoSessionAshTestBase() {
150 set_start_session(false);
152 virtual ~NoSessionAshTestBase() {}
154 private:
155 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
158 } // namespace test
159 } // namespace ash
161 #endif // ASH_TEST_ASH_TEST_BASE_H_