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/aura/client/window_types.h"
17 #include "ui/views/test/test_views_delegate.h"
20 #include "ui/base/win/scoped_ole_initializer.h"
36 } // namespace internal
41 class TestScreenshotDelegate;
43 class TestMetroViewerProcessHost;
46 class AshTestViewsDelegate : public views::TestViewsDelegate {
48 // Overriden from TestViewsDelegate.
49 virtual content::WebContents* CreateWebContents(
50 content::BrowserContext* browser_context,
51 content::SiteInstance* site_instance) OVERRIDE;
54 class AshTestBase : public testing::Test {
57 virtual ~AshTestBase();
60 virtual void SetUp() OVERRIDE;
61 virtual void TearDown() OVERRIDE;
63 // Update the display configuration as given in |display_specs|.
64 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
65 void UpdateDisplay(const std::string& display_specs);
67 // Returns a root Window. Usually this is the active root Window, but that
68 // method can return NULL sometimes, and in those cases, we fall back on the
69 // primary root Window.
70 aura::Window* CurrentContext();
72 // Versions of the functions in aura::test:: that go through our shell
73 // StackingController instead of taking a parent.
74 aura::Window* CreateTestWindowInShellWithId(int id);
75 aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds);
76 aura::Window* CreateTestWindowInShell(SkColor color,
78 const gfx::Rect& bounds);
79 aura::Window* CreateTestWindowInShellWithDelegate(
80 aura::WindowDelegate* delegate,
82 const gfx::Rect& bounds);
83 aura::Window* CreateTestWindowInShellWithDelegateAndType(
84 aura::WindowDelegate* delegate,
85 aura::client::WindowType type,
87 const gfx::Rect& bounds);
89 // Attach |window| to the current shell's root window.
90 void ParentWindowInPrimaryRootWindow(aura::Window* window);
92 // Returns the EventGenerator that uses screen coordinates and works
93 // across multiple displays. It createse a new generator if it
94 // hasn't been created yet.
95 aura::test::EventGenerator& GetEventGenerator();
98 enum UserSessionBlockReason {
100 BLOCKED_BY_LOCK_SCREEN = FIRST_BLOCK_REASON,
101 BLOCKED_BY_LOGIN_SCREEN,
102 BLOCKED_BY_USER_ADDING_SCREEN,
103 NUMBER_OF_BLOCK_REASONS
106 // True if the running environment supports multiple displays,
107 // or false otherwise (e.g. win8 bot).
108 static bool SupportsMultipleDisplays();
110 // True if the running environment supports host window resize,
111 // or false otherwise (e.g. win8 bot).
112 static bool SupportsHostWindowResize();
114 void set_start_session(bool start_session) { start_session_ = start_session; }
116 void RunAllPendingInMessageLoop();
118 TestScreenshotDelegate* GetScreenshotDelegate();
120 // Utility methods to emulate user logged in or not, session started or not
121 // and user able to lock screen or not cases.
122 void SetSessionStarted(bool session_started);
123 void SetUserLoggedIn(bool user_logged_in);
124 void SetCanLockScreen(bool can_lock_screen);
125 void SetShouldLockScreenBeforeSuspending(bool should_lock);
126 void SetUserAddingScreenRunning(bool user_adding_screen_running);
128 // Methods to emulate blocking and unblocking user session with given
130 void BlockUserSession(UserSessionBlockReason block_reason);
131 void UnblockUserSession();
135 bool teardown_called_;
136 // |SetUp()| doesn't activate session if this is set to false.
138 content::TestBrowserThreadBundle thread_bundle_;
139 scoped_ptr<AshTestHelper> ash_test_helper_;
140 scoped_ptr<aura::test::EventGenerator> event_generator_;
142 // Note that the order is important here as ipc_thread_ should be destroyed
143 // after metro_viewer_host_->channel_.
144 scoped_ptr<base::Thread> ipc_thread_;
145 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
146 ui::ScopedOleInitializer ole_initializer_;
149 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
152 class NoSessionAshTestBase : public AshTestBase {
154 NoSessionAshTestBase() {
155 set_start_session(false);
157 virtual ~NoSessionAshTestBase() {}
160 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
166 #endif // ASH_TEST_ASH_TEST_BASE_H_