dbus: Remove MockShillDeviceClient and MockShillIPConfigClient
[chromium-blink-merge.git] / ash / test / ash_test_base.h
blob281073e8b30ebb6b098ada7c4bba0e6f6f569494
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/aura/client/window_types.h"
17 #include "ui/views/test/test_views_delegate.h"
19 #if defined(OS_WIN)
20 #include "ui/base/win/scoped_ole_initializer.h"
21 #endif
23 namespace aura {
24 class RootWindow;
25 class Window;
26 class WindowDelegate;
28 namespace test {
29 class EventGenerator;
30 } // namespace test
31 } // namespace aura
33 namespace ash {
34 namespace internal {
35 class DisplayManager;
36 } // namespace internal
38 namespace test {
40 class AshTestHelper;
41 class TestScreenshotDelegate;
42 #if defined(OS_WIN)
43 class TestMetroViewerProcessHost;
44 #endif
46 class AshTestViewsDelegate : public views::TestViewsDelegate {
47 public:
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 {
55 public:
56 AshTestBase();
57 virtual ~AshTestBase();
59 // testing::Test:
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 RootWindow. Usually this is the active RootWindow, but that
68 // method can return NULL sometimes, and in those cases, we fall back on the
69 // primary RootWindow.
70 aura::RootWindow* 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,
77 int id,
78 const gfx::Rect& bounds);
79 aura::Window* CreateTestWindowInShellWithDelegate(
80 aura::WindowDelegate* delegate,
81 int id,
82 const gfx::Rect& bounds);
83 aura::Window* CreateTestWindowInShellWithDelegateAndType(
84 aura::WindowDelegate* delegate,
85 aura::client::WindowType type,
86 int id,
87 const gfx::Rect& bounds);
89 // Attach |window| to the current shell's root window.
90 void SetDefaultParentByPrimaryRootWindow(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();
97 protected:
98 enum UserSessionBlockReason {
99 FIRST_BLOCK_REASON,
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 SetUserAddingScreenRunning(bool user_adding_screen_running);
127 // Methods to emulate blocking and unblocking user session with given
128 // |block_reason|.
129 void BlockUserSession(UserSessionBlockReason block_reason);
130 void UnblockUserSession();
132 private:
133 bool setup_called_;
134 bool teardown_called_;
135 // |SetUp()| doesn't activate session if this is set to false.
136 bool start_session_;
137 content::TestBrowserThreadBundle thread_bundle_;
138 scoped_ptr<AshTestHelper> ash_test_helper_;
139 scoped_ptr<aura::test::EventGenerator> event_generator_;
140 #if defined(OS_WIN)
141 // Note that the order is important here as ipc_thread_ should be destroyed
142 // after metro_viewer_host_->channel_.
143 scoped_ptr<base::Thread> ipc_thread_;
144 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
145 ui::ScopedOleInitializer ole_initializer_;
146 #endif
148 DISALLOW_COPY_AND_ASSIGN(AshTestBase);
151 class NoSessionAshTestBase : public AshTestBase {
152 public:
153 NoSessionAshTestBase() {
154 set_start_session(false);
156 virtual ~NoSessionAshTestBase() {}
158 private:
159 DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase);
162 } // namespace test
163 } // namespace ash
165 #endif // ASH_TEST_ASH_TEST_BASE_H_