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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 19681003: Fix issue where window bounds were being passed with wrong coordinates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adds unit test to catch coordinate system related errors in the RWHVA. Created 7 years, 4 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 | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | 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 "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
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 scoped_ptr<TestScreenPositionClient> screen_position_client;
229 screen_position_client.reset(new TestScreenPositionClient());
sky 2013/07/26 15:37:59 Any reason to use a scoped_ptr here rather than on
230
231 aura::Window* window = parent_view_->GetNativeView();
232 aura::RootWindow* root = window->GetRootWindow();
233 aura::client::SetScreenPositionClient(root, screen_position_client.get());
234
235 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
236 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
237 int horiz = bounds_in_screen.width() / 4;
238 int vert = bounds_in_screen.height() / 4;
239 bounds_in_screen.Inset(horiz, vert);
240
241 // Verify that when the popup is initialized for the first time, it correctly
242 // treats the input bounds as screen coordinates.
243 view_->InitAsPopup(parent_view_, bounds_in_screen);
244 gfx::Rect final_bounds_in_screen = view_->GetViewBounds();
245 EXPECT_EQ(final_bounds_in_screen, bounds_in_screen);
sky 2013/07/26 15:37:59 nit: if you compare strings (rect has a ToString()
246
247 // Verify that directly setting the bounds via SetBounds() treats the input
248 // as screen coordinates.
249 bounds_in_screen = gfx::Rect(60, 60, 100, 100);
250 view_->SetBounds(bounds_in_screen);
251 final_bounds_in_screen = view_->GetViewBounds();
252 EXPECT_EQ(final_bounds_in_screen, bounds_in_screen);
253
254 // Verify that setting the size does not alter the origin.
255 gfx::Point original_origin = window->bounds().origin();
256 view_->SetSize(gfx::Size(120, 120));
257 gfx::Point new_origin = window->bounds().origin();
258 EXPECT_EQ(original_origin, new_origin);
259
260 aura::client::SetScreenPositionClient(root, NULL);
261
262 widget_host_ = NULL;
263 view_ = NULL;
264 }
265
192 // Checks that a fullscreen view is destroyed when it loses the focus. 266 // Checks that a fullscreen view is destroyed when it loses the focus.
193 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) { 267 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) {
194 view_->InitAsFullscreen(parent_view_); 268 view_->InitAsFullscreen(parent_view_);
195 aura::Window* window = view_->GetNativeView(); 269 aura::Window* window = view_->GetNativeView();
196 ASSERT_TRUE(window != NULL); 270 ASSERT_TRUE(window != NULL);
197 ASSERT_TRUE(window->HasFocus()); 271 ASSERT_TRUE(window->HasFocus());
198 272
199 // After we create and focus another window, the RWHVA's window should be 273 // After we create and focus another window, the RWHVA's window should be
200 // destroyed. 274 // destroyed.
201 TestWindowObserver observer(window); 275 TestWindowObserver observer(window);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); 652 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
579 ViewMsg_Resize::Param params; 653 ViewMsg_Resize::Param params;
580 ViewMsg_Resize::Read(msg, &params); 654 ViewMsg_Resize::Read(msg, &params);
581 EXPECT_EQ("0,0 1600x1200", 655 EXPECT_EQ("0,0 1600x1200",
582 gfx::Rect(params.a.screen_info.availableRect).ToString()); 656 gfx::Rect(params.a.screen_info.availableRect).ToString());
583 EXPECT_EQ("1600x1200", params.a.new_size.ToString()); 657 EXPECT_EQ("1600x1200", params.a.new_size.ToString());
584 } 658 }
585 } 659 }
586 660
587 } // namespace content 661 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698