ash_test_base.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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
10#include "base/compiler_specific.h"
11#include "base/message_loop/message_loop.h"
12#include "base/threading/thread.h"
13#include "testing/gtest/include/gtest/gtest.h"
14#include "third_party/skia/include/core/SkColor.h"
15#include "ui/aura/client/window_types.h"
16#include "ui/views/test/test_views_delegate.h"
17
18#if defined(OS_WIN)
19#include "ui/base/win/scoped_ole_initializer.h"
20#endif
21
22namespace aura {
23class RootWindow;
24class Window;
25class WindowDelegate;
26
27namespace test {
28class EventGenerator;
29}  // namespace test
30}  // namespace aura
31
32namespace ash {
33namespace internal {
34class DisplayManager;
35}  // namespace internal
36
37namespace test {
38
39class AshTestHelper;
40#if defined(OS_WIN)
41class TestMetroViewerProcessHost;
42#endif
43
44class AshTestViewsDelegate : public views::TestViewsDelegate {
45 public:
46  // Overriden from TestViewsDelegate.
47  virtual content::WebContents* CreateWebContents(
48      content::BrowserContext* browser_context,
49      content::SiteInstance* site_instance) OVERRIDE;
50};
51
52class AshTestBase : public testing::Test {
53 public:
54  AshTestBase();
55  virtual ~AshTestBase();
56
57  base::MessageLoopForUI* message_loop() { return &message_loop_; }
58
59  // testing::Test:
60  virtual void SetUp() OVERRIDE;
61  virtual void TearDown() OVERRIDE;
62
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);
66
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();
71
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);
88
89  // Attach |window| to the current shell's root window.
90  void SetDefaultParentByPrimaryRootWindow(aura::Window* window);
91
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();
96
97 protected:
98  // True if the running environment supports multiple displays,
99  // or false otherwise (e.g. win8 bot).
100  static bool SupportsMultipleDisplays();
101
102  // True if the running environment supports host window resize,
103  // or false otherwise (e.g. win8 bot).
104  static bool SupportsHostWindowResize();
105
106  void RunAllPendingInMessageLoop();
107
108  // Utility methods to emulate user logged in or not, session started or not
109  // and user able to lock screen or not cases.
110  void SetSessionStarted(bool session_started);
111  void SetUserLoggedIn(bool user_logged_in);
112  void SetCanLockScreen(bool can_lock_screen);
113
114 private:
115  bool setup_called_;
116  bool teardown_called_;
117  base::MessageLoopForUI message_loop_;
118  scoped_ptr<AshTestHelper> ash_test_helper_;
119  scoped_ptr<aura::test::EventGenerator> event_generator_;
120#if defined(OS_WIN)
121  // Note that the order is important here as ipc_thread_ should be destroyed
122  // after metro_viewer_host_->channel_.
123  scoped_ptr<base::Thread> ipc_thread_;
124  scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_;
125  ui::ScopedOleInitializer ole_initializer_;
126#endif
127
128  DISALLOW_COPY_AND_ASSIGN(AshTestBase);
129};
130
131}  // namespace test
132}  // namespace ash
133
134#endif  // ASH_TEST_ASH_TEST_BASE_H_
135