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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
index 03f7d5c591f2b3279fc742bd52b60997753ff066..fb4bcba1f100b4426be9b995d20a75db4d569055 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
@@ -17,6 +17,7 @@
#include "ipc/ipc_test_sink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window.h"
@@ -32,6 +33,37 @@
namespace content {
namespace {
+
+
+// Simple screen position client to test coordinate system conversion.
+class TestScreenPositionClient
+ : public aura::client::ScreenPositionClient {
+ public:
+ TestScreenPositionClient() {}
+ virtual ~TestScreenPositionClient() {}
+
+ // aura::client::ScreenPositionClient overrides:
+ virtual void ConvertPointToScreen(const aura::Window* window,
+ gfx::Point* point) OVERRIDE {
+ point->Offset(-1, -1);
+ }
+
+ virtual void ConvertPointFromScreen(const aura::Window* window,
+ gfx::Point* point) OVERRIDE {
+ point->Offset(1, 1);
+ }
+
+ virtual void ConvertHostPointToScreen(aura::RootWindow* window,
+ gfx::Point* point) OVERRIDE {
+ ConvertPointToScreen(window, point);
+ }
+
+ virtual void SetBounds(aura::Window* window,
+ const gfx::Rect& bounds,
+ const gfx::Display& display) OVERRIDE {
+ }
+};
+
class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
public:
MockRenderWidgetHostDelegate() {}
@@ -189,6 +221,48 @@ TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
EXPECT_TRUE(view_->ShouldActivate());
}
+
+// Checks that a popup is positioned correctly relative to its parent using
+// screen coordinates.
+TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
+ scoped_ptr<TestScreenPositionClient> screen_position_client;
+ screen_position_client.reset(new TestScreenPositionClient());
sky 2013/07/26 15:37:59 Any reason to use a scoped_ptr here rather than on
+
+ aura::Window* window = parent_view_->GetNativeView();
+ aura::RootWindow* root = window->GetRootWindow();
+ aura::client::SetScreenPositionClient(root, screen_position_client.get());
+
+ parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
+ gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
+ int horiz = bounds_in_screen.width() / 4;
+ int vert = bounds_in_screen.height() / 4;
+ bounds_in_screen.Inset(horiz, vert);
+
+ // Verify that when the popup is initialized for the first time, it correctly
+ // treats the input bounds as screen coordinates.
+ view_->InitAsPopup(parent_view_, bounds_in_screen);
+ gfx::Rect final_bounds_in_screen = view_->GetViewBounds();
+ 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()
+
+ // Verify that directly setting the bounds via SetBounds() treats the input
+ // as screen coordinates.
+ bounds_in_screen = gfx::Rect(60, 60, 100, 100);
+ view_->SetBounds(bounds_in_screen);
+ final_bounds_in_screen = view_->GetViewBounds();
+ EXPECT_EQ(final_bounds_in_screen, bounds_in_screen);
+
+ // Verify that setting the size does not alter the origin.
+ gfx::Point original_origin = window->bounds().origin();
+ view_->SetSize(gfx::Size(120, 120));
+ gfx::Point new_origin = window->bounds().origin();
+ EXPECT_EQ(original_origin, new_origin);
+
+ aura::client::SetScreenPositionClient(root, NULL);
+
+ widget_host_ = NULL;
+ view_ = NULL;
+}
+
// Checks that a fullscreen view is destroyed when it loses the focus.
TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) {
view_->InitAsFullscreen(parent_view_);
« 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