Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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. |
| 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 12 | #include "base/threading/thread.h" |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 13 | #include "content/public/test/test_browser_thread_bundle.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "third_party/skia/include/core/SkColor.h" |
| 16 | #include "ui/aura/client/window_types.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | #include "ui/views/test/test_views_delegate.h" |
| 18 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 19 | #if defined(OS_WIN) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 20 | #include "ui/base/win/scoped_ole_initializer.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | namespace aura { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 24 | class RootWindow; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | class Window; |
| 26 | class WindowDelegate; |
| 27 | |
| 28 | namespace test { |
| 29 | class EventGenerator; |
| 30 | } // namespace test |
| 31 | } // namespace aura |
| 32 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 33 | namespace ash { |
| 34 | namespace internal { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 35 | class DisplayManager; |
| 36 | } // namespace internal |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 37 | |
| 38 | namespace test { |
| 39 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 40 | class AshTestHelper; |
| 41 | #if defined(OS_WIN) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 42 | class TestMetroViewerProcessHost; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 43 | #endif |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 44 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | class 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 | |
| 53 | class AshTestBase : public testing::Test { |
| 54 | public: |
| 55 | AshTestBase(); |
| 56 | virtual ~AshTestBase(); |
| 57 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 58 | // testing::Test: |
| 59 | virtual void SetUp() OVERRIDE; |
| 60 | virtual void TearDown() OVERRIDE; |
| 61 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 62 | // Update the display configuration as given in |display_specs|. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 63 | // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 64 | void UpdateDisplay(const std::string& display_specs); |
| 65 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 66 | // 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 96 | protected: |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 97 | 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 105 | // True if the running environment supports multiple displays, |
| 106 | // or false otherwise (e.g. win8 bot). |
| 107 | static bool SupportsMultipleDisplays(); |
| 108 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 109 | // True if the running environment supports host window resize, |
| 110 | // or false otherwise (e.g. win8 bot). |
| 111 | static bool SupportsHostWindowResize(); |
| 112 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 113 | void set_start_session(bool start_session) { start_session_ = start_session; } |
| 114 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 115 | void RunAllPendingInMessageLoop(); |
| 116 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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); |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 122 | 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 128 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 129 | private: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 130 | bool setup_called_; |
| 131 | bool teardown_called_; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 132 | // |SetUp()| doesn't activate session if this is set to false. |
| 133 | bool start_session_; |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 134 | content::TestBrowserThreadBundle thread_bundle_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 135 | scoped_ptr<AshTestHelper> ash_test_helper_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 136 | scoped_ptr<aura::test::EventGenerator> event_generator_; |
| 137 | #if defined(OS_WIN) |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 138 | // 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 141 | scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 142 | ui::ScopedOleInitializer ole_initializer_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 143 | #endif |
| 144 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 145 | DISALLOW_COPY_AND_ASSIGN(AshTestBase); |
| 146 | }; |
| 147 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 148 | class 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 159 | } // namespace test |
| 160 | } // namespace ash |
| 161 | |
| 162 | #endif // ASH_TEST_ASH_TEST_BASE_H_ |