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 f6dc561f2f04fdaffb166e61141631d07b5dafce..ba0591ead5e6ff8ac8b7d1308982e00591030d95 100644 |
--- a/ui/views/controls/native/native_view_host_aura_unittest.cc |
+++ b/ui/views/controls/native/native_view_host_aura_unittest.cc |
@@ -16,6 +16,21 @@ |
namespace views { |
+// Testing wrapper of the NativeViewHost |
+class NativeViewHostTesting : public NativeViewHost { |
+ public: |
+ NativeViewHostTesting() {} |
+ virtual ~NativeViewHostTesting() { destroyed_count_++; } |
+ |
+ static void ResetDestroyedCount() { destroyed_count_ = 0; } |
+ |
+ static int destroyed_count() { return destroyed_count_; } |
+ |
+ private: |
+ static int destroyed_count_; |
+}; |
sky
2014/06/05 15:49:01
DISALLOW_...
calamity
2014/06/06 08:13:44
Done.
|
+int NativeViewHostTesting::destroyed_count_ = 0; |
+ |
class NativeViewHostAuraTest : public ViewsTestBase { |
public: |
NativeViewHostAuraTest() { |
@@ -37,6 +52,8 @@ class NativeViewHostAuraTest : public ViewsTestBase { |
return child_.get(); |
} |
+ aura::Window* clipping_window() { return &(native_host()->clipping_window_); } |
+ |
void CreateHost() { |
// Create the top level widget. |
toplevel_.reset(new Widget); |
@@ -55,7 +72,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()); |
} |
@@ -64,9 +81,13 @@ class NativeViewHostAuraTest : public ViewsTestBase { |
host_.reset(); |
} |
+ NativeViewHostTesting* ReleaseHost() { return host_.release(); } |
+ |
+ void DestroyTopLevel() { toplevel_.reset(); } |
+ |
private: |
scoped_ptr<Widget> toplevel_; |
- scoped_ptr<NativeViewHost> host_; |
+ scoped_ptr<NativeViewHostTesting> host_; |
scoped_ptr<Widget> child_; |
DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); |
@@ -114,4 +135,37 @@ TEST_F(NativeViewHostAuraTest, CursorForNativeView) { |
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(20, 20, 100, 100)); |
+ native_host()->ShowWidget(0, 0, 100, 100); |
+ EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
+ host()->native_view()->layer()->bounds().ToString()); |
+ |
+ host()->set_fast_resize(true); |
+ native_host()->ShowWidget(10, 25, 50, 50); |
+ EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
+ host()->native_view()->layer()->bounds().ToString()); |
+ EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), |
+ clipping_window()->layer()->bounds().ToString()); |
+ |
+ 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) { |
+ NativeViewHostTesting::ResetDestroyedCount(); |
+ CreateHost(); |
+ ReleaseHost(); |
+ EXPECT_EQ(0, NativeViewHostTesting::destroyed_count()); |
+ DestroyTopLevel(); |
+ EXPECT_EQ(1, NativeViewHostTesting::destroyed_count()); |
+} |
+ |
} // namespace views |