usb_gadget: Switch to official Google product IDs.
[chromium-blink-merge.git] / ash / test / ash_test_base.h
blobac667b7e1a1fb03ab3eee497042905f08b512a03
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 ui {
27 namespace test {
28 class EventGenerator;
32 namespace aura {
33 class RootWindow;
34 class Window;
35 class WindowDelegate;
36 } // namespace aura
38 namespace ash {
39 class DisplayManager;
41 namespace test {
43 class AshTestHelper;
44 class TestScreenshotDelegate;
45 class TestSystemTrayDelegate;
46 #if defined(OS_WIN)
47 class TestMetroViewerProcessHost;
48 #endif
50 class AshTestBase : public testing::Test {
51 public:
52 AshTestBase();
53 virtual ~AshTestBase();
55 // testing::Test:
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,
73 int id,
74 const gfx::Rect& bounds);
75 aura::Window* CreateTestWindowInShellWithDelegate(
76 aura::WindowDelegate* delegate,
77 int id,
78 const gfx::Rect& bounds);
79 aura::Window* CreateTestWindowInShellWithDelegateAndType(
80 aura::WindowDelegate* delegate,
81 ui::wm::WindowType type,
82 int id,
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();
93 protected:
94 enum UserSessionBlockReason {
95 FIRST_BLOCK_REASON,
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
126 // |block_reason|.
127 void BlockUserSession(UserSessionBlockReason block_reason);
128 void UnblockUserSession();
130 private:
131 bool setup_called_;
132 bool teardown_called_;
133 // |SetUp()| doesn't activate session if this is set to false.
134 bool start_session_;
135 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_;
136 scoped_ptr<AshTestHelper> ash_test_helper_;
137 scoped_ptr<ui::test::EventGenerator> event_generator_;
138 #if defined(OS_WIN)
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_;
144 #endif
146 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
149 class NoSessionAshTestBase : public AshTestBase {
150 public:
151 NoSessionAshTestBase() {
152 set_start_session(false);
154 virtual ~NoSessionAshTestBase() {}
156 private:
157 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
160 } // namespace test
161 } // namespace ash
163 #endif // ASH_TEST_ASH_TEST_BASE_H_