ash_test_base.h revision a3f7b4e666c476898878fa745f637129375cd889
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 "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" 18 19#if defined(OS_WIN) 20#include "ui/base/win/scoped_ole_initializer.h" 21#endif 22 23namespace aura { 24class RootWindow; 25class Window; 26class WindowDelegate; 27 28namespace test { 29class EventGenerator; 30} // namespace test 31} // namespace aura 32 33namespace ash { 34namespace internal { 35class DisplayManager; 36} // namespace internal 37 38namespace test { 39 40class AshTestHelper; 41#if defined(OS_WIN) 42class TestMetroViewerProcessHost; 43#endif 44 45class 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 58 // testing::Test: 59 virtual void SetUp() OVERRIDE; 60 virtual void TearDown() OVERRIDE; 61 62 // Update the display configuration as given in |display_specs|. 63 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. 64 void UpdateDisplay(const std::string& display_specs); 65 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 96 protected: 97 // True if the running environment supports multiple displays, 98 // or false otherwise (e.g. win8 bot). 99 static bool SupportsMultipleDisplays(); 100 101 // True if the running environment supports host window resize, 102 // or false otherwise (e.g. win8 bot). 103 static bool SupportsHostWindowResize(); 104 105 void RunAllPendingInMessageLoop(); 106 107 // Utility methods to emulate user logged in or not, session started or not 108 // and user able to lock screen or not cases. 109 void SetSessionStarted(bool session_started); 110 void SetUserLoggedIn(bool user_logged_in); 111 void SetCanLockScreen(bool can_lock_screen); 112 113 private: 114 bool setup_called_; 115 bool teardown_called_; 116 content::TestBrowserThreadBundle thread_bundle_; 117 scoped_ptr<AshTestHelper> ash_test_helper_; 118 scoped_ptr<aura::test::EventGenerator> event_generator_; 119#if defined(OS_WIN) 120 // Note that the order is important here as ipc_thread_ should be destroyed 121 // after metro_viewer_host_->channel_. 122 scoped_ptr<base::Thread> ipc_thread_; 123 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 124 ui::ScopedOleInitializer ole_initializer_; 125#endif 126 127 DISALLOW_COPY_AND_ASSIGN(AshTestBase); 128}; 129 130} // namespace test 131} // namespace ash 132 133#endif // ASH_TEST_ASH_TEST_BASE_H_ 134