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

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

Issue 1689483002: MacViews: Implement NativeWidgetMac::SchedulePaintInRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac.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_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 @end 47 @end
48 48
49 // Test NSWindow that provides hooks via method overrides to verify behavior. 49 // Test NSWindow that provides hooks via method overrides to verify behavior.
50 @interface NativeWidgetMacTestWindow : NativeWidgetMacNSWindow { 50 @interface NativeWidgetMacTestWindow : NativeWidgetMacNSWindow {
51 @private 51 @private
52 int invalidateShadowCount_; 52 int invalidateShadowCount_;
53 } 53 }
54 @property(readonly, nonatomic) int invalidateShadowCount; 54 @property(readonly, nonatomic) int invalidateShadowCount;
55 @end 55 @end
56 56
57 // Used to mock BridgedContentView so that calls to drawRect: can be
58 // intercepted.
59 @interface MockBridgedView : NSView {
60 @private
61 // Number of times -[NSView drawRect:] has been called.
62 NSUInteger drawRectCount_;
63
64 // The dirtyRect parameter passed to last invocation of drawRect:.
65 NSRect lastDirtyRect_;
66 }
67
68 @property(assign, nonatomic) NSUInteger drawRectCount;
69 @property(assign, nonatomic) NSRect lastDirtyRect;
70 @end
71
57 namespace views { 72 namespace views {
58 namespace test { 73 namespace test {
59 74
60 // BridgedNativeWidget friend to access private members. 75 // BridgedNativeWidget friend to access private members.
61 class BridgedNativeWidgetTestApi { 76 class BridgedNativeWidgetTestApi {
62 public: 77 public:
63 explicit BridgedNativeWidgetTestApi(NSWindow* window) { 78 explicit BridgedNativeWidgetTestApi(NSWindow* window) {
64 bridge_ = NativeWidgetMac::GetBridgeForNativeWindow(window); 79 bridge_ = NativeWidgetMac::GetBridgeForNativeWindow(window);
65 } 80 }
66 81
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 NSWindow* ns_window = widget->GetNativeWindow(); 1213 NSWindow* ns_window = widget->GetNativeWindow();
1199 1214
1200 CGFloat old_opacity = [ns_window alphaValue]; 1215 CGFloat old_opacity = [ns_window alphaValue];
1201 widget->SetOpacity(0xAA); 1216 widget->SetOpacity(0xAA);
1202 EXPECT_NE(old_opacity, [ns_window alphaValue]); 1217 EXPECT_NE(old_opacity, [ns_window alphaValue]);
1203 EXPECT_DOUBLE_EQ(0xAA / 255.0, [ns_window alphaValue]); 1218 EXPECT_DOUBLE_EQ(0xAA / 255.0, [ns_window alphaValue]);
1204 1219
1205 widget->CloseNow(); 1220 widget->CloseNow();
1206 } 1221 }
1207 1222
1223 // Test that NativeWidgetMac::SchedulePaintInRect correctly passes the dirtyRect
1224 // parameter to BridgedContentView::drawRect, for a titled window (window with a
1225 // toolbar).
1226 TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Titled) {
1227 Widget* widget = CreateTopLevelPlatformWidget();
1228
1229 gfx::Rect screen_rect(50, 50, 100, 100);
1230 widget->SetBounds(screen_rect);
1231
1232 // Setup the mock content view for the NSWindow, so that we can intercept
1233 // drawRect.
1234 NSWindow* window = widget->GetNativeWindow();
1235 base::scoped_nsobject<MockBridgedView> mock_bridged_view(
1236 [[MockBridgedView alloc] init]);
1237 [window setContentView:mock_bridged_view];
1238
1239 // Ensure the initial draw of the window is done.
1240 base::RunLoop().RunUntilIdle();
1241
1242 // Add a dummy view to the widget. This will cause SchedulePaint to be called
1243 // on the dummy view.
1244 View* dummy_view = new View();
1245 gfx::Rect dummy_bounds(25, 30, 10, 15);
1246 dummy_view->SetBoundsRect(dummy_bounds);
1247 // Reset drawRect count.
1248 [mock_bridged_view setDrawRectCount:0];
1249 widget->GetContentsView()->AddChildView(dummy_view);
1250
1251 // SchedulePaint is asyncronous. Wait for drawRect: to be called.
1252 base::RunLoop().RunUntilIdle();
1253
1254 EXPECT_EQ(1u, [mock_bridged_view drawRectCount]);
1255 int client_area_height = widget->GetClientAreaBoundsInScreen().height();
1256 // These are expected dummy_view bounds in AppKit coordinate system. The y
1257 // coordinate of rect origin is calculated as:
1258 // client_area_height - 30 (dummy_view's y coordinate) - 15 (dummy view's
1259 // height).
1260 gfx::Rect expected_appkit_bounds(25, client_area_height - 45, 10, 15);
1261 EXPECT_NSEQ(expected_appkit_bounds.ToCGRect(),
1262 [mock_bridged_view lastDirtyRect]);
1263 widget->CloseNow();
1264 }
1265
1266 // Test that NativeWidgetMac::SchedulePaintInRect correctly passes the dirtyRect
1267 // parameter to BridgedContentView::drawRect, for a borderless window.
1268 TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Borderless) {
1269 Widget* widget = CreateTopLevelFramelessPlatformWidget();
1270
1271 gfx::Rect screen_rect(50, 50, 100, 100);
1272 widget->SetBounds(screen_rect);
1273
1274 // Setup the mock content view for the NSWindow, so that we can intercept
1275 // drawRect.
1276 NSWindow* window = widget->GetNativeWindow();
1277 base::scoped_nsobject<MockBridgedView> mock_bridged_view(
1278 [[MockBridgedView alloc] init]);
1279 [window setContentView:mock_bridged_view];
1280
1281 // Ensure the initial draw of the window is done.
1282 base::RunLoop().RunUntilIdle();
1283
1284 // Add a dummy view to the widget. This will cause SchedulePaint to be called
1285 // on the dummy view.
1286 View* dummy_view = new View();
1287 gfx::Rect dummy_bounds(25, 30, 10, 15);
1288 dummy_view->SetBoundsRect(dummy_bounds);
1289 // Reset drawRect count.
1290 [mock_bridged_view setDrawRectCount:0];
1291 widget->GetRootView()->AddChildView(dummy_view);
1292
1293 // SchedulePaint is asyncronous. Wait for drawRect: to be called.
1294 base::RunLoop().RunUntilIdle();
1295
1296 EXPECT_EQ(1u, [mock_bridged_view drawRectCount]);
1297 // These are expected dummy_view bounds in AppKit coordinate system. The y
1298 // coordinate of rect origin is calculated as:
1299 // 100(client area height) - 30 (dummy_view's y coordinate) - 15 (dummy view's
1300 // height).
1301 gfx::Rect expected_appkit_bounds(25, 55, 10, 15);
1302 EXPECT_NSEQ(expected_appkit_bounds.ToCGRect(),
1303 [mock_bridged_view lastDirtyRect]);
1304 widget->CloseNow();
1305 }
1306
1208 } // namespace test 1307 } // namespace test
1209 } // namespace views 1308 } // namespace views
1210 1309
1211 @implementation TestStopAnimationWaiter 1310 @implementation TestStopAnimationWaiter
1212 - (void)setWindowStateForEnd { 1311 - (void)setWindowStateForEnd {
1213 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); 1312 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd);
1214 } 1313 }
1215 @end 1314 @end
1216 1315
1217 @implementation NativeWidgetMacTestWindow 1316 @implementation NativeWidgetMacTestWindow
1218 1317
1219 @synthesize invalidateShadowCount = invalidateShadowCount_; 1318 @synthesize invalidateShadowCount = invalidateShadowCount_;
1220 1319
1221 - (void)invalidateShadow { 1320 - (void)invalidateShadow {
1222 ++invalidateShadowCount_; 1321 ++invalidateShadowCount_;
1223 [super invalidateShadow]; 1322 [super invalidateShadow];
1224 } 1323 }
1225 1324
1226 @end 1325 @end
1326
1327 @implementation MockBridgedView
1328
1329 @synthesize drawRectCount = drawRectCount_;
1330 @synthesize lastDirtyRect = lastDirtyRect_;
1331
1332 - (void)drawRect:(NSRect)dirtyRect {
1333 ++drawRectCount_;
1334 lastDirtyRect_ = dirtyRect;
1335 }
1336
1337 @end
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698