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

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: sync 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
« no previous file with comments | « ash/system/tray_display.cc ('k') | ash/wm/system_gesture_event_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Move the mouse cursor to far away so that native events doesn't
63 // interfere test expectations.
64 Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000));
65 UpdateDisplay("800x600");
62 Shell::GetInstance()->cursor_manager()->ShowCursor(true); 66 Shell::GetInstance()->cursor_manager()->ShowCursor(true);
63 67
64 // Disable animations during tests. 68 // Disable animations during tests.
65 ui::LayerAnimator::set_disable_animations_for_test(true); 69 ui::LayerAnimator::set_disable_animations_for_test(true);
66 } 70 }
67 71
68 void AshTestBase::TearDown() { 72 void AshTestBase::TearDown() {
69 // Flush the message loop to finish pending release tasks. 73 // Flush the message loop to finish pending release tasks.
70 RunAllPendingInMessageLoop(); 74 RunAllPendingInMessageLoop();
71 75
72 // Tear down the shell. 76 // Tear down the shell.
73 Shell::DeleteInstance(); 77 Shell::DeleteInstance();
74 aura::Env::DeleteInstance(); 78 aura::Env::DeleteInstance();
75 ui::TextInputTestSupport::Shutdown(); 79 ui::TextInputTestSupport::Shutdown();
76 } 80 }
77 81
78 void AshTestBase::ChangeDisplayConfig(float scale, 82 void AshTestBase::ChangeDisplayConfig(float scale,
79 const gfx::Rect& bounds_in_pixel) { 83 const gfx::Rect& bounds_in_pixel) {
80 gfx::Display display = gfx::Display(gfx::Screen::GetPrimaryDisplay().id()); 84 gfx::Display display = gfx::Display(gfx::Screen::GetPrimaryDisplay().id());
81 display.SetScaleAndBounds(scale, bounds_in_pixel); 85 display.SetScaleAndBounds(scale, bounds_in_pixel);
82 std::vector<gfx::Display> displays; 86 std::vector<gfx::Display> displays;
83 displays.push_back(display); 87 displays.push_back(display);
84 aura::Env::GetInstance()->display_manager()->OnNativeDisplaysChanged( 88 aura::Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(
85 displays); 89 displays);
86 } 90 }
87 91
88 void AshTestBase::UpdateDisplay(const std::string& display_specs) { 92 void AshTestBase::UpdateDisplay(const std::string& display_specs) {
89 std::vector<gfx::Display> displays = CreateDisplaysFromString(display_specs); 93 std::vector<gfx::Display> displays = CreateDisplaysFromString(display_specs);
90 aura::Env::GetInstance()->display_manager()-> 94 internal::MultiDisplayManager* display_manager =
91 OnNativeDisplaysChanged(displays); 95 static_cast<internal::MultiDisplayManager*>(
96 aura::Env::GetInstance()->display_manager());
97 display_manager->SetDisplayIdsForTest(&displays);
98 display_manager->OnNativeDisplaysChanged(displays);
92 99
93 // On non-testing environment, when a secondary display is connected, a new 100 // 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 101 // 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. 102 // one for GPU performance reasons. Try to emulate the behavior.
96 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 103 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
97 DCHECK_EQ(displays.size(), root_windows.size()); 104 DCHECK_EQ(displays.size(), root_windows.size());
98 size_t next_y = 0; 105 size_t next_y = 0;
99 for (size_t i = 0; i < root_windows.size(); ++i) { 106 for (size_t i = 0; i < root_windows.size(); ++i) {
100 const gfx::Size size = root_windows[i]->GetHostSize(); 107 const gfx::Size size = root_windows[i]->GetHostSize();
101 root_windows[i]->SetHostBounds(gfx::Rect(gfx::Point(0, next_y), size)); 108 root_windows[i]->SetHostBounds(gfx::Rect(gfx::Point(0, next_y), size));
102 next_y += size.height(); 109 next_y += size.height();
103 } 110 }
104 } 111 }
105 112
106 void AshTestBase::RunAllPendingInMessageLoop() { 113 void AshTestBase::RunAllPendingInMessageLoop() {
107 #if !defined(OS_MACOSX) 114 #if !defined(OS_MACOSX)
108 DCHECK(MessageLoopForUI::current() == &message_loop_); 115 DCHECK(MessageLoopForUI::current() == &message_loop_);
109 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); 116 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
110 run_loop.RunUntilIdle(); 117 run_loop.RunUntilIdle();
111 #endif 118 #endif
112 } 119 }
113 120
114 } // namespace test 121 } // namespace test
115 } // namespace ash 122 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_display.cc ('k') | ash/wm/system_gesture_event_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698