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

Unified Diff: ui/views/controls/native/native_view_host_aura_unittest.cc

Issue 24299004: Implement features in NativeViewHostAura for scroll end effect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responsed to sky's comments and finished tests Created 7 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/native/native_view_host_aura_unittest.cc
diff --git a/ui/views/controls/native/native_view_host_aura_unittest.cc b/ui/views/controls/native/native_view_host_aura_unittest.cc
index 7653cc905c31ba106fc6e6d4b920b754f9a4289b..58cfd02bec32be8882cc5a7db3eca084070f5473 100644
--- a/ui/views/controls/native/native_view_host_aura_unittest.cc
+++ b/ui/views/controls/native/native_view_host_aura_unittest.cc
@@ -32,6 +32,14 @@ class NativeViewHostAuraTest : public ViewsTestBase {
return child_.get();
}
+ aura::Window* clipping_window() {
+ return native_host()->clipping_window_;
+ }
+
+ Widget* toplevel() {
+ return toplevel_.get();
+ }
+
void CreateHost() {
// Create the top level widget.
toplevel_.reset(new Widget);
@@ -59,6 +67,11 @@ class NativeViewHostAuraTest : public ViewsTestBase {
host_.reset();
}
+ gfx::Point CalculateNativeViewOrigin(gfx::Rect input_rect,
+ gfx::Rect native_rect) {
+ return native_host()->CalculateNativeViewOrigin(input_rect, native_rect);
+ }
+
private:
scoped_ptr<Widget> toplevel_;
scoped_ptr<NativeViewHost> host_;
@@ -95,4 +108,83 @@ TEST_F(NativeViewHostAuraTest, HostViewPropertyKey) {
EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
}
+// Tests that the values being calculated by CalculateNativeViewOrigin are
+// correct.
+TEST_F(NativeViewHostAuraTest, CalculateNewNativeViewOrigin) {
+ CreateHost();
+
+ gfx::Rect clip_rect(0, 0, 50, 50);
+ gfx::Rect contents_rect(50, 50, 100, 100);
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
+ EXPECT_EQ(gfx::Point(0, 0),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTH);
+ EXPECT_EQ(gfx::Point(-25, 0),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHEAST);
+ EXPECT_EQ(gfx::Point(-50, 0),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_EAST);
+ EXPECT_EQ(gfx::Point(-50, -25),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
+ EXPECT_EQ(gfx::Point(-50, -50),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTH);
+ EXPECT_EQ(gfx::Point(-25, -50),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHWEST);
+ EXPECT_EQ(gfx::Point(0, -50),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_WEST);
+ EXPECT_EQ(gfx::Point(0, -25),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_CENTER);
+ EXPECT_EQ(gfx::Point(-25, -25),
+ CalculateNativeViewOrigin(clip_rect, contents_rect));
+
+ DestroyHost();
+}
+
+// Test that the fast resize path places the clipping and content windows were
+// they are supposed to be.
+TEST_F(NativeViewHostAuraTest, FastResizePath) {
+ CreateHost();
+ host()->set_fast_resize(false);
+ toplevel()->SetBounds(gfx::Rect(0, 0, 100, 100));
+ native_host()->ShowWidget(0, 0, 100, 100);
+ host()->set_fast_resize(true);
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
+ native_host()->ShowWidget(0, 0, 50, 50);
+ EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
+ host()->native_view()->layer()->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 50, 50), clipping_window()->layer()->bounds());
+
+ host()->set_fast_resize(false);
+ native_host()->ShowWidget(0, 0, 100, 100);
+ host()->set_fast_resize(true);
+
+ host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
+ EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
+ host()->native_view()->layer()->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 100, 100), clipping_window()->layer()->bounds());
+
+ native_host()->ShowWidget(0, 0, 50, 50);
+ EXPECT_EQ(gfx::Rect(-50, -50, 100, 100),
+ host()->native_view()->layer()->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 50, 50), clipping_window()->layer()->bounds());
+
+ DestroyHost();
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698