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

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 2454283002: MacViews: Hide windows before closing. (Closed)
Patch Set: Fix tests. Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/widget/native_widget_mac.h" 5 #import "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #import "base/mac/scoped_nsautorelease_pool.h" 10 #import "base/mac/scoped_nsautorelease_pool.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 EXPECT_FALSE([ns_window isVisible]); 358 EXPECT_FALSE([ns_window isVisible]);
359 EXPECT_EQ(5, observer.gained_visible_count()); 359 EXPECT_EQ(5, observer.gained_visible_count());
360 EXPECT_EQ(5, observer.lost_visible_count()); 360 EXPECT_EQ(5, observer.lost_visible_count());
361 361
362 [ns_window makeKeyAndOrderFront:nil]; 362 [ns_window makeKeyAndOrderFront:nil];
363 EXPECT_TRUE(widget->IsVisible()); 363 EXPECT_TRUE(widget->IsVisible());
364 EXPECT_TRUE([ns_window isVisible]); 364 EXPECT_TRUE([ns_window isVisible]);
365 EXPECT_EQ(6, observer.gained_visible_count()); 365 EXPECT_EQ(6, observer.gained_visible_count());
366 EXPECT_EQ(5, observer.lost_visible_count()); 366 EXPECT_EQ(5, observer.lost_visible_count());
367 367
368 // No change when closing. 368 // Closing the widget also hides it.
369 widget->CloseNow(); 369 widget->CloseNow();
370 EXPECT_EQ(5, observer.lost_visible_count()); 370 EXPECT_EQ(6, observer.lost_visible_count());
371 EXPECT_EQ(6, observer.gained_visible_count()); 371 EXPECT_EQ(6, observer.gained_visible_count());
372 } 372 }
373 373
374 // A view that counts calls to OnPaint(). 374 // A view that counts calls to OnPaint().
375 class PaintCountView : public View { 375 class PaintCountView : public View {
376 public: 376 public:
377 PaintCountView() { SetBounds(0, 0, 100, 100); } 377 PaintCountView() { SetBounds(0, 0, 100, 100); }
378 378
379 // View: 379 // View:
380 void OnPaint(gfx::Canvas* canvas) override { 380 void OnPaint(gfx::Canvas* canvas) override {
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 parent_nswindow_.reset([[child->GetNativeWindow() parentWindow] retain]); 1147 parent_nswindow_.reset([[child->GetNativeWindow() parentWindow] retain]);
1148 EXPECT_TRUE(parent_nswindow_); 1148 EXPECT_TRUE(parent_nswindow_);
1149 EXPECT_TRUE([parent_nswindow_ delegate]); 1149 EXPECT_TRUE([parent_nswindow_ delegate]);
1150 } 1150 }
1151 1151
1152 ~ParentCloseMonitor() override { 1152 ~ParentCloseMonitor() override {
1153 EXPECT_TRUE(child_closed_); // Otherwise the observer wasn't removed. 1153 EXPECT_TRUE(child_closed_); // Otherwise the observer wasn't removed.
1154 } 1154 }
1155 1155
1156 void OnWidgetDestroying(Widget* child) override { 1156 void OnWidgetDestroying(Widget* child) override {
1157 // Upon a parent-triggered close, the NSWindow relationship will still exist 1157 // Closing the parent should hide it first, which will destroy the parent-
1158 // (it's removed just after OnWidgetDestroying() returns). The parent should 1158 // child relationship. The parent should still be open (children are always
1159 // still be open (children are always closed first), but not have a delegate 1159 // closed first), but not have a delegate (since it is being torn down).
1160 // (since it is being torn down). 1160 EXPECT_FALSE([child->GetNativeWindow() parentWindow]);
1161 EXPECT_TRUE([child->GetNativeWindow() parentWindow]); 1161 EXPECT_FALSE([parent_nswindow_ isVisible]);
1162 EXPECT_TRUE([parent_nswindow_ isVisible]);
1163 EXPECT_FALSE([parent_nswindow_ delegate]); 1162 EXPECT_FALSE([parent_nswindow_ delegate]);
1164 1163
1165 EXPECT_FALSE(child_closed_); 1164 EXPECT_FALSE(child_closed_);
1166 } 1165 }
tapted 2016/10/28 05:13:17 huh - there's not much difference between these no
1167 1166
1168 void OnWidgetDestroyed(Widget* child) override { 1167 void OnWidgetDestroyed(Widget* child) override {
1169 EXPECT_FALSE([child->GetNativeWindow() parentWindow]);
1170 EXPECT_TRUE([parent_nswindow_ isVisible]);
1171 EXPECT_FALSE([parent_nswindow_ delegate]);
1172
1173 EXPECT_FALSE(child_closed_); 1168 EXPECT_FALSE(child_closed_);
1174 child->RemoveObserver(this); 1169 child->RemoveObserver(this);
1175 child_closed_ = true; 1170 child_closed_ = true;
1176 } 1171 }
1177 1172
1178 bool child_closed() const { return child_closed_; } 1173 bool child_closed() const { return child_closed_; }
1179 1174
1180 private: 1175 private:
1181 base::scoped_nsobject<NSWindow> parent_nswindow_; 1176 base::scoped_nsobject<NSWindow> parent_nswindow_;
1182 bool child_closed_ = false; 1177 bool child_closed_ = false;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 1797
1803 - (void)dealloc { 1798 - (void)dealloc {
1804 if (deallocFlag_) { 1799 if (deallocFlag_) {
1805 DCHECK(!*deallocFlag_); 1800 DCHECK(!*deallocFlag_);
1806 *deallocFlag_ = true; 1801 *deallocFlag_ = true;
1807 } 1802 }
1808 [super dealloc]; 1803 [super dealloc];
1809 } 1804 }
1810 1805
1811 @end 1806 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698