OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
7 #import "testing/gtest_mac.h" | 7 #import "testing/gtest_mac.h" |
8 | 8 |
9 class ConstrainedWindowAlertTest : public CocoaTest { | 9 class ConstrainedWindowAlertTest : public CocoaTest { |
10 }; | 10 }; |
11 | 11 |
12 // Test showing the alert. | 12 // Test showing the alert. |
13 TEST_F(ConstrainedWindowAlertTest, Show) { | 13 TEST_F(ConstrainedWindowAlertTest, Show) { |
14 scoped_nsobject<ConstrainedWindowAlert> alert( | 14 base::scoped_nsobject<ConstrainedWindowAlert> alert( |
15 [[ConstrainedWindowAlert alloc] init]); | 15 [[ConstrainedWindowAlert alloc] init]); |
16 EXPECT_TRUE([alert window]); | 16 EXPECT_TRUE([alert window]); |
17 EXPECT_TRUE([alert closeButton]); | 17 EXPECT_TRUE([alert closeButton]); |
18 | 18 |
19 [alert setMessageText:@"Message text"]; | 19 [alert setMessageText:@"Message text"]; |
20 [alert setInformativeText:@"Informative text"]; | 20 [alert setInformativeText:@"Informative text"]; |
21 [alert addButtonWithTitle:@"OK" keyEquivalent:@"" target:nil action:NULL]; | 21 [alert addButtonWithTitle:@"OK" keyEquivalent:@"" target:nil action:NULL]; |
22 [alert addButtonWithTitle:@"Cancel" keyEquivalent:@"" target:nil action:NULL]; | 22 [alert addButtonWithTitle:@"Cancel" keyEquivalent:@"" target:nil action:NULL]; |
23 | 23 |
24 [alert layout]; | 24 [alert layout]; |
25 [[alert window] makeKeyAndOrderFront:nil]; | 25 [[alert window] makeKeyAndOrderFront:nil]; |
26 } | 26 } |
27 | 27 |
28 // Test showing the alert with no buttons. | 28 // Test showing the alert with no buttons. |
29 TEST_F(ConstrainedWindowAlertTest, NoButtons) { | 29 TEST_F(ConstrainedWindowAlertTest, NoButtons) { |
30 scoped_nsobject<ConstrainedWindowAlert> alert( | 30 base::scoped_nsobject<ConstrainedWindowAlert> alert( |
31 [[ConstrainedWindowAlert alloc] init]); | 31 [[ConstrainedWindowAlert alloc] init]); |
32 [alert layout]; | 32 [alert layout]; |
33 [[alert window] makeKeyAndOrderFront:nil]; | 33 [[alert window] makeKeyAndOrderFront:nil]; |
34 } | 34 } |
35 | 35 |
36 // Test adding an accessory view to an alert. | 36 // Test adding an accessory view to an alert. |
37 TEST_F(ConstrainedWindowAlertTest, AccessoryView) { | 37 TEST_F(ConstrainedWindowAlertTest, AccessoryView) { |
38 scoped_nsobject<ConstrainedWindowAlert> alert( | 38 base::scoped_nsobject<ConstrainedWindowAlert> alert( |
39 [[ConstrainedWindowAlert alloc] init]); | 39 [[ConstrainedWindowAlert alloc] init]); |
40 [alert addButtonWithTitle:@"OK" keyEquivalent:@"" target:nil action:NULL]; | 40 [alert addButtonWithTitle:@"OK" keyEquivalent:@"" target:nil action:NULL]; |
41 [alert addButtonWithTitle:@"Cancel" keyEquivalent:@"" target:nil action:NULL]; | 41 [alert addButtonWithTitle:@"Cancel" keyEquivalent:@"" target:nil action:NULL]; |
42 | 42 |
43 NSRect view_rect = NSMakeRect(0, 0, 700, 300); | 43 NSRect view_rect = NSMakeRect(0, 0, 700, 300); |
44 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:view_rect]); | 44 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:view_rect]); |
45 EXPECT_FALSE([alert accessoryView]); | 45 EXPECT_FALSE([alert accessoryView]); |
46 [alert setAccessoryView:view]; | 46 [alert setAccessoryView:view]; |
47 EXPECT_NSEQ([alert accessoryView], view); | 47 EXPECT_NSEQ([alert accessoryView], view); |
48 | 48 |
49 [alert layout]; | 49 [alert layout]; |
50 NSRect window_rect = [[alert window] frame]; | 50 NSRect window_rect = [[alert window] frame]; |
51 EXPECT_GT(NSWidth(window_rect), NSWidth(view_rect)); | 51 EXPECT_GT(NSWidth(window_rect), NSWidth(view_rect)); |
52 EXPECT_GT(NSHeight(window_rect), NSHeight(view_rect)); | 52 EXPECT_GT(NSHeight(window_rect), NSHeight(view_rect)); |
53 | 53 |
54 [[alert window] makeKeyAndOrderFront:nil]; | 54 [[alert window] makeKeyAndOrderFront:nil]; |
55 } | 55 } |
OLD | NEW |