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

Unified Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 1796773003: Implement NativeWidgetMac::ReorderNativeViews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement NativeWidgetMac::ReorderNativeViews Created 4 years, 9 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/widget/native_widget_mac_unittest.mm
diff --git a/ui/views/widget/native_widget_mac_unittest.mm b/ui/views/widget/native_widget_mac_unittest.mm
index e62394eeb9495cae774ef8a765be0f63bfeb9679..344fc93a9349013cbfe076f113d0cd0c24672965 100644
--- a/ui/views/widget/native_widget_mac_unittest.mm
+++ b/ui/views/widget/native_widget_mac_unittest.mm
@@ -27,6 +27,7 @@
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
+#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/native_cursor.h"
#include "ui/views/test/native_widget_factory.h"
#include "ui/views/test/test_widget_observer.h"
@@ -211,6 +212,43 @@ class WidgetChangeObserver : public TestWidgetObserver {
DISALLOW_COPY_AND_ASSIGN(WidgetChangeObserver);
};
+class NativeHostHolder {
+ public:
+ NativeHostHolder(NSView* view, NativeViewHost* host)
+ : view(view), host(host) {
+ host->set_owned_by_client();
+ }
+
+ void AttachNativeView() {
+ DCHECK(!host->native_view());
+ host->Attach(view.get());
+ }
+
+ void Detach() { host->Detach(); }
+
+ gfx::NativeView GetView() const { return view.get(); }
+ NativeViewHost* GetHost() const { return host.get(); }
+
+ private:
+ base::scoped_nsobject<NSView> view;
+ scoped_ptr<NativeViewHost> host;
+};
+
+void CheckViewsOrderEqual(NSArray* actual, NSArray* expected) {
+ if ([expected count] == 1) {
+ EXPECT_TRUE([actual containsObject:[expected firstObject]]);
+ return;
+ }
+
+ for (NSUInteger i = 0; i < [expected count] - 1; ++i) {
+ NSUInteger first = [actual indexOfObject:[expected objectAtIndex:i]];
+ NSUInteger second = [actual indexOfObject:[expected objectAtIndex:i + 1]];
+ EXPECT_LT(first, second);
+ EXPECT_NE(first, NSNotFound);
+ EXPECT_NE(second, NSNotFound);
+ }
+}
+
// Test visibility states triggered externally.
TEST_F(NativeWidgetMacTest, HideAndShowExternally) {
Widget* widget = CreateTopLevelPlatformWidget();
@@ -1336,6 +1374,37 @@ TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
widget->CloseNow();
}
+// Test that NativeViewHost::Attach/Detach method save NativeView z-order
+TEST_F(NativeWidgetMacTest, NativeViewsOrder) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+
+ const int native_views_count = 3;
+ std::vector<scoped_ptr<NativeHostHolder>> hosts;
+ for (int i = 0; i < native_views_count; ++i) {
+ scoped_ptr<NativeHostHolder> holder(
+ new NativeHostHolder([[NSView alloc] init], new NativeViewHost));
+ widget->GetRootView()->AddChildView(holder->GetHost());
+ holder->AttachNativeView();
+ hosts.push_back(std::move(holder));
+ }
+ CheckViewsOrderEqual(
+ [widget->GetNativeView() subviews],
+ [NSArray arrayWithObjects:hosts[0]->GetView(), hosts[1]->GetView(),
+ hosts[2]->GetView(), nil]);
+
+ hosts[1]->Detach();
+ CheckViewsOrderEqual(
+ [widget->GetNativeView() subviews],
+ [NSArray arrayWithObjects:hosts[0]->GetView(), hosts[2]->GetView(), nil]);
+
+ hosts[1]->AttachNativeView();
+ CheckViewsOrderEqual(
+ [widget->GetNativeView() subviews],
+ [NSArray arrayWithObjects:hosts[0]->GetView(), hosts[1]->GetView(),
+ hosts[2]->GetView(), nil]);
+ widget->CloseNow();
+}
+
} // namespace test
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698