OLD | NEW |
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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 10 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
12 #include "content/common/input_messages.h" | 12 #include "content/common/input_messages.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
16 #include "content/public/test/test_browser_context.h" | 16 #include "content/public/test/test_browser_context.h" |
17 #include "ipc/ipc_test_sink.h" | 17 #include "ipc/ipc_test_sink.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/client/screen_position_client.h" |
20 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
21 #include "ui/aura/layout_manager.h" | 22 #include "ui/aura/layout_manager.h" |
22 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/aura_test_helper.h" | 24 #include "ui/aura/test/aura_test_helper.h" |
24 #include "ui/aura/test/test_cursor_client.h" | 25 #include "ui/aura/test/test_cursor_client.h" |
25 #include "ui/aura/test/test_screen.h" | 26 #include "ui/aura/test/test_screen.h" |
26 #include "ui/aura/test/test_window_delegate.h" | 27 #include "ui/aura/test/test_window_delegate.h" |
27 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
28 #include "ui/aura/window_observer.h" | 29 #include "ui/aura/window_observer.h" |
29 #include "ui/base/events/event.h" | 30 #include "ui/base/events/event.h" |
30 #include "ui/base/events/event_utils.h" | 31 #include "ui/base/events/event_utils.h" |
31 #include "ui/base/ui_base_types.h" | 32 #include "ui/base/ui_base_types.h" |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 namespace { | 35 namespace { |
| 36 |
| 37 |
| 38 // Simple screen position client to test coordinate system conversion. |
| 39 class TestScreenPositionClient |
| 40 : public aura::client::ScreenPositionClient { |
| 41 public: |
| 42 TestScreenPositionClient() {} |
| 43 virtual ~TestScreenPositionClient() {} |
| 44 |
| 45 // aura::client::ScreenPositionClient overrides: |
| 46 virtual void ConvertPointToScreen(const aura::Window* window, |
| 47 gfx::Point* point) OVERRIDE { |
| 48 point->Offset(-1, -1); |
| 49 } |
| 50 |
| 51 virtual void ConvertPointFromScreen(const aura::Window* window, |
| 52 gfx::Point* point) OVERRIDE { |
| 53 point->Offset(1, 1); |
| 54 } |
| 55 |
| 56 virtual void ConvertHostPointToScreen(aura::RootWindow* window, |
| 57 gfx::Point* point) OVERRIDE { |
| 58 ConvertPointToScreen(window, point); |
| 59 } |
| 60 |
| 61 virtual void SetBounds(aura::Window* window, |
| 62 const gfx::Rect& bounds, |
| 63 const gfx::Display& display) OVERRIDE { |
| 64 } |
| 65 }; |
| 66 |
35 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 67 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
36 public: | 68 public: |
37 MockRenderWidgetHostDelegate() {} | 69 MockRenderWidgetHostDelegate() {} |
38 virtual ~MockRenderWidgetHostDelegate() {} | 70 virtual ~MockRenderWidgetHostDelegate() {} |
39 }; | 71 }; |
40 | 72 |
41 // Simple observer that keeps track of changes to a window for tests. | 73 // Simple observer that keeps track of changes to a window for tests. |
42 class TestWindowObserver : public aura::WindowObserver { | 74 class TestWindowObserver : public aura::WindowObserver { |
43 public: | 75 public: |
44 explicit TestWindowObserver(aura::Window* window_to_observe) | 76 explicit TestWindowObserver(aura::Window* window_to_observe) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 window->GetProperty(aura::client::kShowStateKey)); | 214 window->GetProperty(aura::client::kShowStateKey)); |
183 | 215 |
184 // Check that we requested and received the focus. | 216 // Check that we requested and received the focus. |
185 EXPECT_TRUE(window->HasFocus()); | 217 EXPECT_TRUE(window->HasFocus()); |
186 | 218 |
187 // Check that we'll also say it's okay to activate the window when there's an | 219 // Check that we'll also say it's okay to activate the window when there's an |
188 // ActivationClient defined. | 220 // ActivationClient defined. |
189 EXPECT_TRUE(view_->ShouldActivate()); | 221 EXPECT_TRUE(view_->ShouldActivate()); |
190 } | 222 } |
191 | 223 |
| 224 |
| 225 // Checks that a popup is positioned correctly relative to its parent using |
| 226 // screen coordinates. |
| 227 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { |
| 228 TestScreenPositionClient screen_position_client; |
| 229 |
| 230 aura::Window* window = parent_view_->GetNativeView(); |
| 231 aura::RootWindow* root = window->GetRootWindow(); |
| 232 aura::client::SetScreenPositionClient(root, &screen_position_client); |
| 233 |
| 234 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); |
| 235 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); |
| 236 int horiz = bounds_in_screen.width() / 4; |
| 237 int vert = bounds_in_screen.height() / 4; |
| 238 bounds_in_screen.Inset(horiz, vert); |
| 239 |
| 240 // Verify that when the popup is initialized for the first time, it correctly |
| 241 // treats the input bounds as screen coordinates. |
| 242 view_->InitAsPopup(parent_view_, bounds_in_screen); |
| 243 gfx::Rect final_bounds_in_screen = view_->GetViewBounds(); |
| 244 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString()); |
| 245 |
| 246 // Verify that directly setting the bounds via SetBounds() treats the input |
| 247 // as screen coordinates. |
| 248 bounds_in_screen = gfx::Rect(60, 60, 100, 100); |
| 249 view_->SetBounds(bounds_in_screen); |
| 250 final_bounds_in_screen = view_->GetViewBounds(); |
| 251 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString()); |
| 252 |
| 253 // Verify that setting the size does not alter the origin. |
| 254 gfx::Point original_origin = window->bounds().origin(); |
| 255 view_->SetSize(gfx::Size(120, 120)); |
| 256 gfx::Point new_origin = window->bounds().origin(); |
| 257 EXPECT_EQ(original_origin.ToString(), new_origin.ToString()); |
| 258 |
| 259 aura::client::SetScreenPositionClient(root, NULL); |
| 260 |
| 261 widget_host_ = NULL; |
| 262 view_ = NULL; |
| 263 } |
| 264 |
192 // Checks that a fullscreen view is destroyed when it loses the focus. | 265 // Checks that a fullscreen view is destroyed when it loses the focus. |
193 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) { | 266 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) { |
194 view_->InitAsFullscreen(parent_view_); | 267 view_->InitAsFullscreen(parent_view_); |
195 aura::Window* window = view_->GetNativeView(); | 268 aura::Window* window = view_->GetNativeView(); |
196 ASSERT_TRUE(window != NULL); | 269 ASSERT_TRUE(window != NULL); |
197 ASSERT_TRUE(window->HasFocus()); | 270 ASSERT_TRUE(window->HasFocus()); |
198 | 271 |
199 // After we create and focus another window, the RWHVA's window should be | 272 // After we create and focus another window, the RWHVA's window should be |
200 // destroyed. | 273 // destroyed. |
201 TestWindowObserver observer(window); | 274 TestWindowObserver observer(window); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 651 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
579 ViewMsg_Resize::Param params; | 652 ViewMsg_Resize::Param params; |
580 ViewMsg_Resize::Read(msg, ¶ms); | 653 ViewMsg_Resize::Read(msg, ¶ms); |
581 EXPECT_EQ("0,0 1600x1200", | 654 EXPECT_EQ("0,0 1600x1200", |
582 gfx::Rect(params.a.screen_info.availableRect).ToString()); | 655 gfx::Rect(params.a.screen_info.availableRect).ToString()); |
583 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); | 656 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); |
584 } | 657 } |
585 } | 658 } |
586 | 659 |
587 } // namespace content | 660 } // namespace content |
OLD | NEW |