ash_test_base.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 "testing/gtest/include/gtest/gtest.h" 13#include "third_party/skia/include/core/SkColor.h" 14#include "ui/aura/client/window_types.h" 15#include "ui/views/test/test_views_delegate.h" 16 17#if defined(OS_WIN) 18#include "ui/base/win/scoped_ole_initializer.h" 19#endif 20 21namespace aura { 22class RootWindow; 23class Window; 24class WindowDelegate; 25 26namespace test { 27class EventGenerator; 28} // namespace test 29} // namespace aura 30 31namespace ash { 32namespace internal { 33class DisplayManager; 34} // namespace internal 35 36namespace test { 37 38class AshTestHelper; 39#if defined(OS_WIN) 40class TestMetroViewerProcessHost; 41#endif 42 43class AshTestViewsDelegate : public views::TestViewsDelegate { 44 public: 45 // Overriden from TestViewsDelegate. 46 virtual content::WebContents* CreateWebContents( 47 content::BrowserContext* browser_context, 48 content::SiteInstance* site_instance) OVERRIDE; 49}; 50 51class AshTestBase : public testing::Test { 52 public: 53 AshTestBase(); 54 virtual ~AshTestBase(); 55 56 base::MessageLoopForUI* message_loop() { return &message_loop_; } 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 void RunAllPendingInMessageLoop(); 98 99 // Utility methods to emulate user logged in or not, session started or not 100 // and user able to lock screen or not cases. 101 void SetSessionStarted(bool session_started); 102 void SetUserLoggedIn(bool user_logged_in); 103 void SetCanLockScreen(bool can_lock_screen); 104 105 private: 106 bool setup_called_; 107 bool teardown_called_; 108 base::MessageLoopForUI message_loop_; 109 scoped_ptr<AshTestHelper> ash_test_helper_; 110 scoped_ptr<aura::test::EventGenerator> event_generator_; 111#if defined(OS_WIN) 112 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 113 ui::ScopedOleInitializer ole_initializer_; 114#endif 115 116 DISALLOW_COPY_AND_ASSIGN(AshTestBase); 117}; 118 119} // namespace test 120} // namespace ash 121 122#endif // ASH_TEST_ASH_TEST_BASE_H_ 123