| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "ash/test/ash_test_helper.h" | 5 #include "ash/test/ash_test_helper.h" | 
| 6 | 6 | 
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" | 
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" | 
| 9 #include "ash/test/display_manager_test_api.h" | 9 #include "ash/test/display_manager_test_api.h" | 
| 10 #include "ash/test/shell_test_api.h" | 10 #include "ash/test/shell_test_api.h" | 
| 11 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" | 
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" | 
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" | 
| 14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" | 
| 15 #include "ui/base/ime/text_input_test_support.h" | 15 #include "ui/base/ime/text_input_test_support.h" | 
| 16 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 16 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 
|  | 17 | 
|  | 18 | 
|  | 19 #if defined(ENABLE_MESSAGE_CENTER) | 
| 17 #include "ui/message_center/message_center.h" | 20 #include "ui/message_center/message_center.h" | 
|  | 21 #endif | 
| 18 | 22 | 
| 19 namespace ash { | 23 namespace ash { | 
| 20 namespace test { | 24 namespace test { | 
| 21 | 25 | 
| 22 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) | 26 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) | 
| 23     : message_loop_(message_loop), | 27     : message_loop_(message_loop), | 
| 24       test_shell_delegate_(NULL) { | 28       test_shell_delegate_(NULL) { | 
| 25   CHECK(message_loop_); | 29   CHECK(message_loop_); | 
| 26 } | 30 } | 
| 27 | 31 | 
| 28 AshTestHelper::~AshTestHelper() { | 32 AshTestHelper::~AshTestHelper() { | 
| 29 } | 33 } | 
| 30 | 34 | 
| 31 void AshTestHelper::SetUp() { | 35 void AshTestHelper::SetUp() { | 
| 32   // TODO(jennyz): Create mock or test AudioHandler so we can instantiate | 36   // TODO(jennyz): Create mock or test AudioHandler so we can instantiate | 
| 33   // an ash::Shell with the new CrasAudioHandler. crbug.com/233266 | 37   // an ash::Shell with the new CrasAudioHandler. crbug.com/233266 | 
| 34   CommandLine::ForCurrentProcess()->AppendSwitch( | 38   CommandLine::ForCurrentProcess()->AppendSwitch( | 
| 35       ash::switches::kAshDisableNewAudioHandler); | 39       ash::switches::kAshDisableNewAudioHandler); | 
| 36   // Disable animations during tests. | 40   // Disable animations during tests. | 
| 37   zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 41   zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 
| 38       ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 42       ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 
| 39   ui::TextInputTestSupport::Initialize(); | 43   ui::TextInputTestSupport::Initialize(); | 
| 40 | 44 | 
| 41   // Creates Shell and hook with Desktop. | 45   // Creates Shell and hook with Desktop. | 
| 42   test_shell_delegate_ = new TestShellDelegate; | 46   test_shell_delegate_ = new TestShellDelegate; | 
| 43 | 47 | 
|  | 48 #if defined(ENABLE_MESSAGE_CENTER) | 
| 44   // Creates MessageCenter since g_browser_process is not created in AshTestBase | 49   // Creates MessageCenter since g_browser_process is not created in AshTestBase | 
| 45   // tests. | 50   // tests. | 
| 46   message_center::MessageCenter::Initialize(); | 51   message_center::MessageCenter::Initialize(); | 
|  | 52 #endif | 
| 47   ash::Shell::CreateInstance(test_shell_delegate_); | 53   ash::Shell::CreateInstance(test_shell_delegate_); | 
| 48   Shell* shell = Shell::GetInstance(); | 54   Shell* shell = Shell::GetInstance(); | 
| 49   test::DisplayManagerTestApi(shell->display_manager()). | 55   test::DisplayManagerTestApi(shell->display_manager()). | 
| 50       DisableChangeDisplayUponHostResize(); | 56       DisableChangeDisplayUponHostResize(); | 
| 51   ShellTestApi(shell).DisableOutputConfiguratorAnimation(); | 57   ShellTestApi(shell).DisableOutputConfiguratorAnimation(); | 
| 52 | 58 | 
| 53 } | 59 } | 
| 54 | 60 | 
| 55 void AshTestHelper::TearDown() { | 61 void AshTestHelper::TearDown() { | 
| 56   // Tear down the shell. | 62   // Tear down the shell. | 
| 57   Shell::DeleteInstance(); | 63   Shell::DeleteInstance(); | 
| 58 | 64 | 
|  | 65 #if defined(ENABLE_MESSAGE_CENTER) | 
| 59   // Remove global message center state. | 66   // Remove global message center state. | 
| 60   message_center::MessageCenter::Shutdown(); | 67   message_center::MessageCenter::Shutdown(); | 
|  | 68 #endif | 
| 61 | 69 | 
| 62   aura::Env::DeleteInstance(); | 70   aura::Env::DeleteInstance(); | 
| 63   ui::TextInputTestSupport::Shutdown(); | 71   ui::TextInputTestSupport::Shutdown(); | 
| 64 | 72 | 
| 65   zero_duration_mode_.reset(); | 73   zero_duration_mode_.reset(); | 
| 66 } | 74 } | 
| 67 | 75 | 
| 68 void AshTestHelper::RunAllPendingInMessageLoop() { | 76 void AshTestHelper::RunAllPendingInMessageLoop() { | 
| 69 #if !defined(OS_MACOSX) | 77 #if !defined(OS_MACOSX) | 
| 70   DCHECK(MessageLoopForUI::current() == message_loop_); | 78   DCHECK(MessageLoopForUI::current() == message_loop_); | 
| 71   base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | 79   base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | 
| 72   run_loop.RunUntilIdle(); | 80   run_loop.RunUntilIdle(); | 
| 73 #endif | 81 #endif | 
| 74 } | 82 } | 
| 75 | 83 | 
| 76 aura::RootWindow* AshTestHelper::CurrentContext() { | 84 aura::RootWindow* AshTestHelper::CurrentContext() { | 
| 77   aura::RootWindow* root_window = Shell::GetActiveRootWindow(); | 85   aura::RootWindow* root_window = Shell::GetActiveRootWindow(); | 
| 78   if (!root_window) | 86   if (!root_window) | 
| 79     root_window = Shell::GetPrimaryRootWindow(); | 87     root_window = Shell::GetPrimaryRootWindow(); | 
| 80   DCHECK(root_window); | 88   DCHECK(root_window); | 
| 81   return root_window; | 89   return root_window; | 
| 82 } | 90 } | 
| 83 | 91 | 
| 84 }  // namespace test | 92 }  // namespace test | 
| 85 }  // namespace ash | 93 }  // namespace ash | 
| OLD | NEW | 
|---|