blob: 5e8fdd2adc66ce40873dd822b4139951a90268a8 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#ifndef ASH_TEST_ASH_TEST_BASE_H_
6#define ASH_TEST_ASH_TEST_BASE_H_
7
8#include <string>
9
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "base/compiler_specific.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010011#include "base/message_loop/message_loop.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010012#include "base/threading/thread.h"
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010013#include "content/public/test/test_browser_thread_bundle.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014#include "testing/gtest/include/gtest/gtest.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000015#include "third_party/skia/include/core/SkColor.h"
16#include "ui/aura/client/window_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "ui/views/test/test_views_delegate.h"
18
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000019#if defined(OS_WIN)
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010020#include "ui/base/win/scoped_ole_initializer.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000021#endif
22
23namespace aura {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010024class RootWindow;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000025class Window;
26class WindowDelegate;
27
28namespace test {
29class EventGenerator;
30} // namespace test
31} // namespace aura
32
Torne (Richard Coles)58218062012-11-14 11:43:16 +000033namespace ash {
34namespace internal {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000035class DisplayManager;
36} // namespace internal
Torne (Richard Coles)58218062012-11-14 11:43:16 +000037
38namespace test {
39
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010040class AshTestHelper;
41#if defined(OS_WIN)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000042class TestMetroViewerProcessHost;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010043#endif
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000044
Torne (Richard Coles)58218062012-11-14 11:43:16 +000045class AshTestViewsDelegate : public views::TestViewsDelegate {
46 public:
47 // Overriden from TestViewsDelegate.
48 virtual content::WebContents* CreateWebContents(
49 content::BrowserContext* browser_context,
50 content::SiteInstance* site_instance) OVERRIDE;
51};
52
53class AshTestBase : public testing::Test {
54 public:
55 AshTestBase();
56 virtual ~AshTestBase();
57
Torne (Richard Coles)58218062012-11-14 11:43:16 +000058 // testing::Test:
59 virtual void SetUp() OVERRIDE;
60 virtual void TearDown() OVERRIDE;
61
Torne (Richard Coles)58218062012-11-14 11:43:16 +000062 // Update the display configuration as given in |display_specs|.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000063 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000064 void UpdateDisplay(const std::string& display_specs);
65
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000066 // Returns a RootWindow. Usually this is the active RootWindow, but that
67 // method can return NULL sometimes, and in those cases, we fall back on the
68 // primary RootWindow.
69 aura::RootWindow* CurrentContext();
70
71 // Versions of the functions in aura::test:: that go through our shell
72 // StackingController instead of taking a parent.
73 aura::Window* CreateTestWindowInShellWithId(int id);
74 aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds);
75 aura::Window* CreateTestWindowInShell(SkColor color,
76 int id,
77 const gfx::Rect& bounds);
78 aura::Window* CreateTestWindowInShellWithDelegate(
79 aura::WindowDelegate* delegate,
80 int id,
81 const gfx::Rect& bounds);
82 aura::Window* CreateTestWindowInShellWithDelegateAndType(
83 aura::WindowDelegate* delegate,
84 aura::client::WindowType type,
85 int id,
86 const gfx::Rect& bounds);
87
88 // Attach |window| to the current shell's root window.
89 void SetDefaultParentByPrimaryRootWindow(aura::Window* window);
90
91 // Returns the EventGenerator that uses screen coordinates and works
92 // across multiple displays. It createse a new generator if it
93 // hasn't been created yet.
94 aura::test::EventGenerator& GetEventGenerator();
95
Torne (Richard Coles)58218062012-11-14 11:43:16 +000096 protected:
Ben Murdochbbcdd452013-07-25 10:06:34 +010097 enum UserSessionBlockReason {
98 FIRST_BLOCK_REASON,
99 BLOCKED_BY_LOCK_SCREEN = FIRST_BLOCK_REASON,
100 BLOCKED_BY_LOGIN_SCREEN,
101 BLOCKED_BY_USER_ADDING_SCREEN,
102 NUMBER_OF_BLOCK_REASONS
103 };
104
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100105 // True if the running environment supports multiple displays,
106 // or false otherwise (e.g. win8 bot).
107 static bool SupportsMultipleDisplays();
108
Ben Murdocheb525c52013-07-10 11:40:50 +0100109 // True if the running environment supports host window resize,
110 // or false otherwise (e.g. win8 bot).
111 static bool SupportsHostWindowResize();
112
Ben Murdochbb1529c2013-08-08 10:24:53 +0100113 void set_start_session(bool start_session) { start_session_ = start_session; }
114
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000115 void RunAllPendingInMessageLoop();
116
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000117 // 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);
Ben Murdochbbcdd452013-07-25 10:06:34 +0100122 void SetUserAddingScreenRunning(bool user_adding_screen_running);
123
124 // Methods to emulate blocking and unblocking user session with given
125 // |block_reason|.
126 void BlockUserSession(UserSessionBlockReason block_reason);
127 void UnblockUserSession();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000128
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000129 private:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100130 bool setup_called_;
131 bool teardown_called_;
Ben Murdochbb1529c2013-08-08 10:24:53 +0100132 // |SetUp()| doesn't activate session if this is set to false.
133 bool start_session_;
Ben Murdocha3f7b4e2013-07-24 10:36:34 +0100134 content::TestBrowserThreadBundle thread_bundle_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100135 scoped_ptr<AshTestHelper> ash_test_helper_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000136 scoped_ptr<aura::test::EventGenerator> event_generator_;
137#if defined(OS_WIN)
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100138 // Note that the order is important here as ipc_thread_ should be destroyed
139 // after metro_viewer_host_->channel_.
140 scoped_ptr<base::Thread> ipc_thread_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000141 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100142 ui::ScopedOleInitializer ole_initializer_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000143#endif
144
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000145 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
146};
147
Ben Murdochbb1529c2013-08-08 10:24:53 +0100148class NoSessionAshTestBase : public AshTestBase {
149 public:
150 NoSessionAshTestBase() {
151 set_start_session(false);
152 }
153 virtual ~NoSessionAshTestBase() {}
154
155 private:
156 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
157};
158
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000159} // namespace test
160} // namespace ash
161
162#endif // ASH_TEST_ASH_TEST_BASE_H_