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 "base/memory/scoped_nsobject.h" | 5 #import "base/memory/scoped_nsobject.h" |
| 6 #include "base/message_loop.h" |
6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
7 #import "chrome/browser/ui/cocoa/intents/web_intent_view_controller_message.h" | 8 #import "chrome/browser/ui/cocoa/intents/web_intent_view_controller_Progress.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
10 | 11 |
11 class WebIntentViewControllerMessageTest : public CocoaTest { | 12 class WebIntentViewControllerProgressTest : public CocoaTest { |
12 public: | 13 public: |
13 WebIntentViewControllerMessageTest() { | 14 WebIntentViewControllerProgressTest() { |
14 view_controller_.reset([[WebIntentViewControllerMessage alloc] init]); | 15 view_controller_.reset([[WebIntentViewControllerProgress alloc] init]); |
15 view_.reset([[view_controller_ view] retain]); | 16 view_.reset([[view_controller_ view] retain]); |
16 [[test_window() contentView] addSubview:view_]; | 17 [[test_window() contentView] addSubview:view_]; |
17 } | 18 } |
18 | 19 |
19 protected: | 20 protected: |
20 scoped_nsobject<WebIntentViewControllerMessage> view_controller_; | 21 scoped_nsobject<WebIntentViewControllerProgress> view_controller_; |
21 scoped_nsobject<NSView> view_; | 22 scoped_nsobject<NSView> view_; |
| 23 MessageLoop message_loop_; |
22 }; | 24 }; |
23 | 25 |
24 TEST_VIEW(WebIntentViewControllerMessageTest, view_) | 26 TEST_VIEW(WebIntentViewControllerProgressTest, view_) |
25 | 27 |
26 TEST_F(WebIntentViewControllerMessageTest, Layout) { | 28 TEST_F(WebIntentViewControllerProgressTest, Layout) { |
27 const CGFloat margin = 10; | 29 const CGFloat margin = 10; |
28 NSRect inner_frame = NSMakeRect(margin, margin, 100, 50); | 30 NSRect inner_frame = NSMakeRect(margin, margin, 100, 50); |
29 | 31 |
30 // Layout with empty title and message. | 32 // Layout with empty title and message. |
31 NSSize empty_size = | 33 NSSize empty_size = |
32 [view_controller_ minimumSizeForInnerWidth:NSWidth(inner_frame)]; | 34 [view_controller_ minimumSizeForInnerWidth:NSWidth(inner_frame)]; |
33 EXPECT_LE(empty_size.width, NSWidth(inner_frame)); | 35 EXPECT_LE(empty_size.width, NSWidth(inner_frame)); |
34 [view_ setFrame:NSInsetRect(inner_frame, -margin, -margin)]; | 36 [view_ setFrame:NSInsetRect(inner_frame, -margin, -margin)]; |
35 [view_controller_ layoutWithInnerFrame:inner_frame]; | 37 [view_controller_ layoutWithInnerFrame:inner_frame]; |
36 | 38 |
37 // Layout with a long string that wraps. | 39 // Layout with a long string that wraps. |
38 NSString* string = @"A quick brown fox jumps over the lazy dog."; | 40 NSString* string = @"A quick brown fox jumps over the lazy dog."; |
39 [view_controller_ setTitle:string]; | 41 [view_controller_ setTitle:string]; |
40 [view_controller_ setMessage:string]; | 42 [view_controller_ setMessage:string]; |
41 NSSize new_size = | 43 NSSize new_size = |
42 [view_controller_ minimumSizeForInnerWidth:NSWidth(inner_frame)]; | 44 [view_controller_ minimumSizeForInnerWidth:NSWidth(inner_frame)]; |
43 EXPECT_GE(new_size.width, empty_size.width); | 45 EXPECT_GE(new_size.width, empty_size.width); |
44 EXPECT_GT(new_size.height, empty_size.height); | 46 EXPECT_GT(new_size.height, empty_size.height); |
45 EXPECT_EQ(NSWidth(inner_frame), new_size.width); | 47 EXPECT_EQ(NSWidth(inner_frame), new_size.width); |
46 inner_frame.size.height = new_size.height; | 48 inner_frame.size.height = new_size.height; |
47 [view_ setFrame:NSInsetRect(inner_frame, -margin, -margin)]; | 49 [view_ setFrame:NSInsetRect(inner_frame, -margin, -margin)]; |
48 [view_controller_ layoutWithInnerFrame:inner_frame]; | 50 [view_controller_ layoutWithInnerFrame:inner_frame]; |
49 | 51 |
50 // Verify that all controls are inside the inner frame. | 52 // Verify that all controls are inside the inner frame. |
51 for (NSView* child in [view_ subviews]) | 53 for (NSView* child in [view_ subviews]) |
52 EXPECT_TRUE(NSContainsRect(inner_frame, [child frame])); | 54 EXPECT_TRUE(NSContainsRect(inner_frame, [child frame])); |
53 } | 55 } |
| 56 |
| 57 TEST_F(WebIntentViewControllerProgressTest, Progress) { |
| 58 [view_controller_ setPercentDone:-1]; |
| 59 [view_ display]; |
| 60 [view_controller_ setPercentDone:50]; |
| 61 [view_ display]; |
| 62 } |
OLD | NEW |