ash_test_base.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "ash/shell.h" 11#include "base/compiler_specific.h" 12#include "base/message_loop.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 "base/memory/scoped_ptr.h" 20#endif 21 22namespace aura { 23class Window; 24class WindowDelegate; 25 26namespace test { 27class EventGenerator; 28} // namespace test 29} // namespace aura 30 31namespace ui { 32class ScopedAnimationDurationScaleMode; 33} // namespace ui 34 35namespace ash { 36namespace internal { 37class DisplayManager; 38} // namespace internal 39 40namespace test { 41 42class TestMetroViewerProcessHost; 43class TestShellDelegate; 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 MessageLoopForUI* message_loop() { return &message_loop_; } 59 60 // testing::Test: 61 virtual void SetUp() OVERRIDE; 62 virtual void TearDown() OVERRIDE; 63 64 // Update the display configuration as given in |display_specs|. 65 // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. 66 void UpdateDisplay(const std::string& display_specs); 67 68 // Returns a RootWindow. Usually this is the active RootWindow, but that 69 // method can return NULL sometimes, and in those cases, we fall back on the 70 // primary RootWindow. 71 aura::RootWindow* CurrentContext(); 72 73 // Versions of the functions in aura::test:: that go through our shell 74 // StackingController instead of taking a parent. 75 aura::Window* CreateTestWindowInShellWithId(int id); 76 aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds); 77 aura::Window* CreateTestWindowInShell(SkColor color, 78 int id, 79 const gfx::Rect& bounds); 80 aura::Window* CreateTestWindowInShellWithDelegate( 81 aura::WindowDelegate* delegate, 82 int id, 83 const gfx::Rect& bounds); 84 aura::Window* CreateTestWindowInShellWithDelegateAndType( 85 aura::WindowDelegate* delegate, 86 aura::client::WindowType type, 87 int id, 88 const gfx::Rect& bounds); 89 90 // Attach |window| to the current shell's root window. 91 void SetDefaultParentByPrimaryRootWindow(aura::Window* window); 92 93 // Returns the EventGenerator that uses screen coordinates and works 94 // across multiple displays. It createse a new generator if it 95 // hasn't been created yet. 96 aura::test::EventGenerator& GetEventGenerator(); 97 98 protected: 99 void RunAllPendingInMessageLoop(); 100 101 // Utility methods to emulate user logged in or not, session started or not 102 // and user able to lock screen or not cases. 103 void SetSessionStarted(bool session_started); 104 void SetUserLoggedIn(bool user_logged_in); 105 void SetCanLockScreen(bool can_lock_screen); 106 107 private: 108 MessageLoopForUI message_loop_; 109 110 TestShellDelegate* test_shell_delegate_; 111 112 scoped_ptr<aura::test::EventGenerator> event_generator_; 113#if defined(OS_WIN) 114 scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 115#endif 116 117 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; 118 119 DISALLOW_COPY_AND_ASSIGN(AshTestBase); 120}; 121 122} // namespace test 123} // namespace ash 124 125#endif // ASH_TEST_ASH_TEST_BASE_H_ 126