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..e0019583603ddacbc25b29bee7a2dad7f2e7e21a 100644 |
--- a/ui/views/controls/native/native_view_host_aura_unittest.cc |
+++ b/ui/views/controls/native/native_view_host_aura_unittest.cc |
@@ -13,8 +13,41 @@ |
#include "ui/views/view_constants_aura.h" |
#include "ui/views/widget/widget.h" |
+namespace { |
+ |
+// Static class used to track if the NativeViewHostTesting has been destroyed. |
+class DestroyedCount { |
sky
2013/10/10 20:25:32
Why have this in a separate object rather than par
rharrison
2013/10/13 13:54:57
No good reason, Done.
|
+ public: |
+ static void Increment() { |
+ count_++; |
+ } |
+ |
+ static void Reset() { |
+ count_ = 0; |
+ } |
+ |
+ static int count() { |
+ return count_; |
+ } |
+ |
+ private: |
+ static int count_; |
+}; |
+int DestroyedCount::count_ = 0; |
+ |
+} // namespace |
+ |
namespace views { |
+// Testing wrapper of the NativeViewHost |
+class NativeViewHostTesting : public NativeViewHost { |
+ public: |
+ NativeViewHostTesting() {} |
+ virtual ~NativeViewHostTesting() { |
+ DestroyedCount::Increment(); |
+ } |
+}; |
+ |
class NativeViewHostAuraTest : public ViewsTestBase { |
public: |
NativeViewHostAuraTest() { |
@@ -32,6 +65,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); |
@@ -50,7 +91,7 @@ class NativeViewHostAuraTest : public ViewsTestBase { |
child_->SetContentsView(test_view); |
// Owned by |toplevel|. |
- host_.reset(new NativeViewHost); |
+ host_.reset(new NativeViewHostTesting); |
toplevel_->GetRootView()->AddChildView(host_.get()); |
host_->Attach(child_->GetNativeView()); |
} |
@@ -59,9 +100,22 @@ class NativeViewHostAuraTest : public ViewsTestBase { |
host_.reset(); |
} |
+ NativeViewHostTesting* ReleaseHost() { |
+ return host_.release(); |
+ } |
+ |
+ void DestroyTopLevel() { |
+ toplevel_.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_; |
+ scoped_ptr<NativeViewHostTesting> host_; |
scoped_ptr<Widget> child_; |
DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); |
@@ -95,4 +149,94 @@ 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), |
sky
2013/10/10 20:25:32
Comparing strinsg (ToString()) on all points (and
rharrison
2013/10/13 13:54:57
Done.
|
+ 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_CENTER); |
+ 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()); |
+ LOG(ERROR) << clipping_window()->layer()->bounds().ToString(); |
+ |
+ |
+ 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_gravity(NativeViewHost::GRAVITY_SOUTHEAST); |
+ 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(); |
+} |
+ |
+// Test that destroying the top level widget before destroying the attached |
+// NativeViewHost works correctly. Specifically the associated NVH should be |
+// destroyed and there shouldn't be any errors. |
+TEST_F(NativeViewHostAuraTest, DestroyWidget) { |
+ DestroyedCount::Reset(); |
+ CreateHost(); |
+ ReleaseHost(); |
+ EXPECT_EQ(0, DestroyedCount::count()); |
+ DestroyTopLevel(); |
+ EXPECT_EQ(1, DestroyedCount::count()); |
+} |
+ |
} // namespace views |