15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_TEST_ASH_TEST_BASE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_TEST_ASH_TEST_BASE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/message_loop/message_loop.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/threading/thread.h" 13a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "content/public/test/test_browser_thread_bundle.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/wm/public/window_types.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace gfx { 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class Rect; 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace ui { 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace test { 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass EventGenerator; 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace aura { 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class RootWindow; 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Window; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WindowDelegate; 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace aura 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DisplayManager; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test { 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class AshTestHelper; 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class TestScreenshotDelegate; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TestSystemTrayDelegate; 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestMetroViewerProcessHost; 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AshTestBase : public testing::Test { 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AshTestBase(); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~AshTestBase(); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // testing::Test: 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TearDown() OVERRIDE; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the display configuration as given in |display_specs|. 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateDisplay(const std::string& display_specs); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns a root Window. Usually this is the active root Window, but that 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // method can return NULL sometimes, and in those cases, we fall back on the 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // primary root Window. 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* CurrentContext(); 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Versions of the functions in aura::test:: that go through our shell 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // StackingController instead of taking a parent. 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithId(int id); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShell(SkColor color, 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithDelegate( 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithDelegateAndType( 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::wm::WindowType type, 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Attach |window| to the current shell's root window. 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ParentWindowInPrimaryRootWindow(aura::Window* window); 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the EventGenerator that uses screen coordinates and works 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // across multiple displays. It createse a new generator if it 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // hasn't been created yet. 91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::test::EventGenerator& GetEventGenerator(); 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 94bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch enum UserSessionBlockReason { 95bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch FIRST_BLOCK_REASON, 96bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_LOCK_SCREEN = FIRST_BLOCK_REASON, 97bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_LOGIN_SCREEN, 98bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_USER_ADDING_SCREEN, 99bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch NUMBER_OF_BLOCK_REASONS 100bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch }; 101bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 102c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Proxy to AshTestHelper::SupportsMultipleDisplays(). 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool SupportsMultipleDisplays(); 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 105c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Proxy to AshTestHelper::SupportsHostWindowResize(). 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static bool SupportsHostWindowResize(); 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 108bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch void set_start_session(bool start_session) { start_session_ = start_session; } 109bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AshTestHelper* ash_test_helper() { return ash_test_helper_.get(); } 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RunAllPendingInMessageLoop(); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestScreenshotDelegate* GetScreenshotDelegate(); 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestSystemTrayDelegate* GetSystemTrayDelegate(); 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Utility methods to emulate user logged in or not, session started or not 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and user able to lock screen or not cases. 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetSessionStarted(bool session_started); 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetUserLoggedIn(bool user_logged_in); 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetCanLockScreen(bool can_lock_screen); 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetShouldLockScreenBeforeSuspending(bool should_lock); 123bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void SetUserAddingScreenRunning(bool user_adding_screen_running); 124bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 125bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // Methods to emulate blocking and unblocking user session with given 126bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // |block_reason|. 127bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void BlockUserSession(UserSessionBlockReason block_reason); 128bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void UnblockUserSession(); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool setup_called_; 132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool teardown_called_; 133bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // |SetUp()| doesn't activate session if this is set to false. 134bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool start_session_; 13523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<AshTestHelper> ash_test_helper_; 137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<ui::test::EventGenerator> event_generator_; 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Note that the order is important here as ipc_thread_ should be destroyed 14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // after metro_viewer_host_->channel_. 14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<base::Thread> ipc_thread_; 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::ScopedOleInitializer ole_initializer_; 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AshTestBase); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 149bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass NoSessionAshTestBase : public AshTestBase { 150bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch public: 151bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NoSessionAshTestBase() { 152bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch set_start_session(false); 153bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch } 154bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch virtual ~NoSessionAshTestBase() {} 155bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 156bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch private: 157bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase); 158bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch}; 159bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace test 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // ASH_TEST_ASH_TEST_BASE_H_ 164