ash_test_base.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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.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 void RunAllPendingInMessageLoop(); 99 100 // Utility methods to emulate user logged in or not, session started or not 101 // and user able to lock screen or not cases. 102 void SetSessionStarted(bool session_started); 103 void SetUserLoggedIn(bool user_logged_in); 104 void SetCanLockScreen(bool can_lock_screen); 105 106 private: 107 bool setup_called_; 108 bool teardown_called_; 109 base::MessageLoopForUI message_loop_; 110 scoped_ptr<AshTestHelper> ash_test_helper_; 111 scoped_ptr<aura::test::EventGenerator> event_generator_; 112#if defined(OS_WIN) 113 // Note that the order is important here as ipc_thread_ should be destroyed 114 // after metro_viewer_host_->channel_. 115 scoped_ptr<base::Thread> ipc_thread_; 116 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 117 ui::ScopedOleInitializer ole_initializer_; 118#endif 119 120 DISALLOW_COPY_AND_ASSIGN(AshTestBase); 121}; 122 123} // namespace test 124} // namespace ash 125 126#endif // ASH_TEST_ASH_TEST_BASE_H_ 127