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

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

Issue 489763002: MacViews: Gets a webview working in views_examples_with_content_exe Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to master Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/native/native_view_host_mac.mm ('k') | ui/views/controls/webview/webview.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/native/native_view_host_unittest.cc
diff --git a/ui/views/controls/native/native_view_host_unittest.cc b/ui/views/controls/native/native_view_host_unittest.cc
index e77fd358bf5827b987f1649eb50e93d9143ffd80..cf043e10c825c305106722f663ce5a1d400c7061 100644
--- a/ui/views/controls/native/native_view_host_unittest.cc
+++ b/ui/views/controls/native/native_view_host_unittest.cc
@@ -6,10 +6,13 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/aura/window.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
+#if defined(USE_AURA)
+#include "ui/aura/window.h"
+#endif
+
namespace views {
class NativeViewHostTest : public ViewsTestBase {
@@ -53,9 +56,10 @@ class NativeViewHostTest : public ViewsTestBase {
return toplevel_.get();
}
- private:
+ protected:
scoped_ptr<Widget> toplevel_;
+ private:
DISALLOW_COPY_AND_ASSIGN(NativeViewHostTest);
};
@@ -68,10 +72,28 @@ class NativeViewHierarchyChangedTestView : public View {
NativeViewHierarchyChangedTestView() : notification_count_(0) {
}
+ virtual ~NativeViewHierarchyChangedTestView() {
+ if (g_expect_destroy)
+ EXPECT_EQ(g_expect_destroy_object, this);
+ g_expect_destroy_object = NULL;
+ }
+
void ResetCount() {
notification_count_ = 0;
}
+ void ExpectDestroy() {
+ DCHECK(!g_expect_destroy);
+ g_expect_destroy = true;
+ g_expect_destroy_object = this;
+ }
+
+ static bool PopExpectDestroy() {
+ DCHECK(g_expect_destroy);
+ g_expect_destroy = false;
+ return g_expect_destroy_object == NULL;
+ }
+
int notification_count() const { return notification_count_; }
// Overriden from View:
@@ -81,14 +103,28 @@ class NativeViewHierarchyChangedTestView : public View {
}
private:
+ static bool g_expect_destroy;
+ static NativeViewHierarchyChangedTestView* g_expect_destroy_object;
+
int notification_count_;
DISALLOW_COPY_AND_ASSIGN(NativeViewHierarchyChangedTestView);
};
+bool NativeViewHierarchyChangedTestView::g_expect_destroy = false;
+NativeViewHierarchyChangedTestView*
+ NativeViewHierarchyChangedTestView::g_expect_destroy_object = NULL;
+
+#if defined(USE_AURA)
aura::Window* GetNativeParent(aura::Window* window) {
return window->parent();
}
+#else
+gfx::NativeView GetNativeParent(gfx::NativeView native_view) {
+ Widget* widget = Widget::GetWidgetForNativeView(native_view);
+ return widget ? widget->GetNativeView() : NULL;
+}
+#endif
class ViewHierarchyChangedTestHost : public NativeViewHost {
public:
@@ -126,23 +162,33 @@ class ViewHierarchyChangedTestHost : public NativeViewHost {
// Verifies NativeViewHierarchyChanged is sent.
TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) {
+ // Put a test view in the parent widget to track changes.
+ views::View* parent_view = toplevel()->GetRootView();
+ NativeViewHierarchyChangedTestView* test_view_in_parent =
+ new NativeViewHierarchyChangedTestView;
+ parent_view->AddChildView(test_view_in_parent);
+
// Create a child widget.
- NativeViewHierarchyChangedTestView* test_view =
+ NativeViewHierarchyChangedTestView* test_view_in_child =
new NativeViewHierarchyChangedTestView;
+
NativeViewHost* host = new NativeViewHost;
- scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(),
- toplevel()->GetRootView(),
- test_view,
- host));
+ scoped_ptr<Widget> child(CreateChildForHost(
+ toplevel()->GetNativeView(), parent_view, test_view_in_child, host));
#if defined(USE_AURA)
// Two notifications are generated from inserting the native view into the
// clipping window and then inserting the clipping window into the root
// window.
- EXPECT_EQ(2, test_view->notification_count());
+ EXPECT_EQ(2, test_view_in_child->notification_count());
#else
- EXPECT_EQ(0, test_view->notification_count());
+ // One notification results from inserting the native contents view of the
+ // Widget created in CreateChildForHost() into the toplevel Widget's native
+ // hierarchy.
+ EXPECT_EQ(1, test_view_in_child->notification_count());
+ EXPECT_EQ(1, test_view_in_parent->notification_count());
#endif
- test_view->ResetCount();
+ test_view_in_child->ResetCount();
+ test_view_in_parent->ResetCount();
// Detaching should send a NativeViewHierarchyChanged() notification and
// change the parent.
@@ -150,13 +196,17 @@ TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) {
#if defined(USE_AURA)
// Two notifications are generated from removing the native view from the
// clipping window and then reparenting it to the root window.
- EXPECT_EQ(2, test_view->notification_count());
+ EXPECT_EQ(2, test_view_in_child->notification_count());
#else
- EXPECT_EQ(1, test_view->notification_count());
+ // There are no notifications in the child view because it is not associated
+ // with a Widget after being detached. The parent gets one change.
+ EXPECT_EQ(0, test_view_in_child->notification_count());
+ EXPECT_EQ(1, test_view_in_parent->notification_count());
#endif
EXPECT_NE(toplevel()->GetNativeView(),
GetNativeParent(child->GetNativeView()));
- test_view->ResetCount();
+ test_view_in_child->ResetCount();
+ test_view_in_parent->ResetCount();
// Attaching should send a NativeViewHierarchyChanged() notification and
// reset the parent.
@@ -164,14 +214,24 @@ TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) {
#if defined(USE_AURA)
// There is a clipping window inserted above the native view that needs to be
// accounted for when looking at the relationship between the native views.
- EXPECT_EQ(2, test_view->notification_count());
+ EXPECT_EQ(2, test_view_in_child->notification_count());
EXPECT_EQ(toplevel()->GetNativeView(),
GetNativeParent(GetNativeParent(child->GetNativeView())));
#else
- EXPECT_EQ(1, test_view->notification_count());
+ EXPECT_EQ(0, test_view_in_child->notification_count());
+ EXPECT_EQ(1, test_view_in_parent->notification_count());
EXPECT_EQ(toplevel()->GetNativeView(),
GetNativeParent(child->GetNativeView()));
#endif
+
+ // Ownership of the views should still rest with the original Widgets.
+ test_view_in_child->ExpectDestroy();
+ child.reset();
+ EXPECT_TRUE(NativeViewHierarchyChangedTestView::PopExpectDestroy());
+
+ test_view_in_parent->ExpectDestroy();
+ toplevel_.reset();
+ EXPECT_TRUE(NativeViewHierarchyChangedTestView::PopExpectDestroy());
}
// Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move
« no previous file with comments | « ui/views/controls/native/native_view_host_mac.mm ('k') | ui/views/controls/webview/webview.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698