Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: ash/test/ash_test_base.cc

Issue 10905288: Switch primary display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comment Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_base.h" 5 #include "ash/test/ash_test_base.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
11 #include "ash/display/multi_display_manager.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/test/test_shell_delegate.h" 13 #include "ash/test/test_shell_delegate.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/string_split.h" 15 #include "base/string_split.h"
15 #include "content/public/test/web_contents_tester.h" 16 #include "content/public/test/web_contents_tester.h"
16 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
17 #include "ui/aura/display_manager.h" 18 #include "ui/aura/display_manager.h"
18 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
19 #include "ui/base/ime/text_input_test_support.h" 20 #include "ui/base/ime/text_input_test_support.h"
20 #include "ui/compositor/layer_animator.h" 21 #include "ui/compositor/layer_animator.h"
(...skipping 30 matching lines...) Expand all
51 52
52 AshTestBase::~AshTestBase() { 53 AshTestBase::~AshTestBase() {
53 } 54 }
54 55
55 void AshTestBase::SetUp() { 56 void AshTestBase::SetUp() {
56 ui::TextInputTestSupport::Initilaize(); 57 ui::TextInputTestSupport::Initilaize();
57 // Creates Shell and hook with Desktop. 58 // Creates Shell and hook with Desktop.
58 TestShellDelegate* delegate = new TestShellDelegate; 59 TestShellDelegate* delegate = new TestShellDelegate;
59 ash::Shell::CreateInstance(delegate); 60 ash::Shell::CreateInstance(delegate);
60 Shell::GetPrimaryRootWindow()->Show(); 61 Shell::GetPrimaryRootWindow()->Show();
61 Shell::GetPrimaryRootWindow()->SetHostSize(gfx::Size(800, 600)); 62 UpdateDisplay("800x600");
62 Shell::GetInstance()->cursor_manager()->ShowCursor(true); 63 Shell::GetInstance()->cursor_manager()->ShowCursor(true);
63 64
64 // Disable animations during tests. 65 // Disable animations during tests.
65 ui::LayerAnimator::set_disable_animations_for_test(true); 66 ui::LayerAnimator::set_disable_animations_for_test(true);
66 } 67 }
67 68
68 void AshTestBase::TearDown() { 69 void AshTestBase::TearDown() {
69 // Flush the message loop to finish pending release tasks. 70 // Flush the message loop to finish pending release tasks.
70 RunAllPendingInMessageLoop(); 71 RunAllPendingInMessageLoop();
71 72
72 // Tear down the shell. 73 // Tear down the shell.
73 Shell::DeleteInstance(); 74 Shell::DeleteInstance();
74 aura::Env::DeleteInstance(); 75 aura::Env::DeleteInstance();
75 ui::TextInputTestSupport::Shutdown(); 76 ui::TextInputTestSupport::Shutdown();
76 } 77 }
77 78
78 void AshTestBase::ChangeDisplayConfig(float scale, 79 void AshTestBase::ChangeDisplayConfig(float scale,
79 const gfx::Rect& bounds_in_pixel) { 80 const gfx::Rect& bounds_in_pixel) {
80 gfx::Display display = gfx::Display(gfx::Screen::GetPrimaryDisplay().id()); 81 gfx::Display display = gfx::Display(gfx::Screen::GetPrimaryDisplay().id());
81 display.SetScaleAndBounds(scale, bounds_in_pixel); 82 display.SetScaleAndBounds(scale, bounds_in_pixel);
82 std::vector<gfx::Display> displays; 83 std::vector<gfx::Display> displays;
83 displays.push_back(display); 84 displays.push_back(display);
84 aura::Env::GetInstance()->display_manager()->OnNativeDisplaysChanged( 85 aura::Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(
85 displays); 86 displays);
86 } 87 }
87 88
88 void AshTestBase::UpdateDisplay(const std::string& display_specs) { 89 void AshTestBase::UpdateDisplay(const std::string& display_specs) {
89 std::vector<gfx::Display> displays = CreateDisplaysFromString(display_specs); 90 std::vector<gfx::Display> displays = CreateDisplaysFromString(display_specs);
90 aura::Env::GetInstance()->display_manager()-> 91 internal::MultiDisplayManager* display_manager =
91 OnNativeDisplaysChanged(displays); 92 static_cast<internal::MultiDisplayManager*>(
93 aura::Env::GetInstance()->display_manager());
94 display_manager->SetDisplayIdsForTest(&displays);
95 display_manager->OnNativeDisplaysChanged(displays);
92 96
93 // On non-testing environment, when a secondary display is connected, a new 97 // On non-testing environment, when a secondary display is connected, a new
94 // native (i.e. X) window for the display is always created below the previous 98 // native (i.e. X) window for the display is always created below the previous
95 // one for GPU performance reasons. Try to emulate the behavior. 99 // one for GPU performance reasons. Try to emulate the behavior.
96 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 100 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
97 DCHECK_EQ(displays.size(), root_windows.size()); 101 DCHECK_EQ(displays.size(), root_windows.size());
98 size_t next_y = 0; 102 size_t next_y = 0;
99 for (size_t i = 0; i < root_windows.size(); ++i) { 103 for (size_t i = 0; i < root_windows.size(); ++i) {
100 const gfx::Size size = root_windows[i]->GetHostSize(); 104 const gfx::Size size = root_windows[i]->GetHostSize();
101 root_windows[i]->SetHostBounds(gfx::Rect(gfx::Point(0, next_y), size)); 105 root_windows[i]->SetHostBounds(gfx::Rect(gfx::Point(0, next_y), size));
102 next_y += size.height(); 106 next_y += size.height();
103 } 107 }
104 } 108 }
105 109
106 void AshTestBase::RunAllPendingInMessageLoop() { 110 void AshTestBase::RunAllPendingInMessageLoop() {
107 #if !defined(OS_MACOSX) 111 #if !defined(OS_MACOSX)
108 DCHECK(MessageLoopForUI::current() == &message_loop_); 112 DCHECK(MessageLoopForUI::current() == &message_loop_);
109 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); 113 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
110 run_loop.RunUntilIdle(); 114 run_loop.RunUntilIdle();
111 #endif 115 #endif
112 } 116 }
113 117
114 } // namespace test 118 } // namespace test
115 } // namespace ash 119 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698