OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/nsview_additions.h" | 5 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #import "testing/gtest_mac.h" | 10 #import "testing/gtest_mac.h" |
11 | 11 |
12 typedef CocoaTest NSViewChromeAdditionsTest; | 12 typedef CocoaTest NSViewChromeAdditionsTest; |
13 | 13 |
14 @interface ParentView : NSView { | 14 @interface ParentView : NSView { |
15 @private | 15 @private |
16 int removeCount_; | 16 int removeCount_; |
17 int addCount_; | 17 int addCount_; |
(...skipping 13 matching lines...) Expand all Loading... |
31 ++removeCount_; | 31 ++removeCount_; |
32 } | 32 } |
33 | 33 |
34 - (void)didAddSubview:(NSView*)view { | 34 - (void)didAddSubview:(NSView*)view { |
35 ++addCount_; | 35 ++addCount_; |
36 } | 36 } |
37 | 37 |
38 @end | 38 @end |
39 | 39 |
40 TEST_F(NSViewChromeAdditionsTest, BelowAboveView) { | 40 TEST_F(NSViewChromeAdditionsTest, BelowAboveView) { |
41 scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]); | 41 base::scoped_nsobject<NSView> parent( |
42 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]); | 42 [[NSView alloc] initWithFrame:NSZeroRect]); |
43 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]); | 43 base::scoped_nsobject<NSView> child1( |
| 44 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 45 base::scoped_nsobject<NSView> child2( |
| 46 [[NSView alloc] initWithFrame:NSZeroRect]); |
44 | 47 |
45 [parent addSubview:child1]; | 48 [parent addSubview:child1]; |
46 [parent addSubview:child2]; | 49 [parent addSubview:child2]; |
47 EXPECT_TRUE([child1 cr_isBelowView:child2]); | 50 EXPECT_TRUE([child1 cr_isBelowView:child2]); |
48 EXPECT_FALSE([child1 cr_isAboveView:child2]); | 51 EXPECT_FALSE([child1 cr_isAboveView:child2]); |
49 EXPECT_FALSE([child2 cr_isBelowView:child1]); | 52 EXPECT_FALSE([child2 cr_isBelowView:child1]); |
50 EXPECT_TRUE([child2 cr_isAboveView:child1]); | 53 EXPECT_TRUE([child2 cr_isAboveView:child1]); |
51 | 54 |
52 [child1 removeFromSuperview]; | 55 [child1 removeFromSuperview]; |
53 [child2 removeFromSuperview]; | 56 [child2 removeFromSuperview]; |
54 [parent addSubview:child2]; | 57 [parent addSubview:child2]; |
55 [parent addSubview:child1]; | 58 [parent addSubview:child1]; |
56 EXPECT_FALSE([child1 cr_isBelowView:child2]); | 59 EXPECT_FALSE([child1 cr_isBelowView:child2]); |
57 EXPECT_TRUE([child1 cr_isAboveView:child2]); | 60 EXPECT_TRUE([child1 cr_isAboveView:child2]); |
58 EXPECT_TRUE([child2 cr_isBelowView:child1]); | 61 EXPECT_TRUE([child2 cr_isBelowView:child1]); |
59 EXPECT_FALSE([child2 cr_isAboveView:child1]); | 62 EXPECT_FALSE([child2 cr_isAboveView:child1]); |
60 } | 63 } |
61 | 64 |
62 TEST_F(NSViewChromeAdditionsTest, EnsurePosition) { | 65 TEST_F(NSViewChromeAdditionsTest, EnsurePosition) { |
63 scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]); | 66 base::scoped_nsobject<NSView> parent( |
64 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]); | 67 [[NSView alloc] initWithFrame:NSZeroRect]); |
65 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]); | 68 base::scoped_nsobject<NSView> child1( |
| 69 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 70 base::scoped_nsobject<NSView> child2( |
| 71 [[NSView alloc] initWithFrame:NSZeroRect]); |
66 | 72 |
67 [parent addSubview:child1]; | 73 [parent addSubview:child1]; |
68 [parent cr_ensureSubview:child2 | 74 [parent cr_ensureSubview:child2 |
69 isPositioned:NSWindowAbove | 75 isPositioned:NSWindowAbove |
70 relativeTo:child1]; | 76 relativeTo:child1]; |
71 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child1); | 77 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child1); |
72 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child2); | 78 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child2); |
73 | 79 |
74 [child2 removeFromSuperview]; | 80 [child2 removeFromSuperview]; |
75 [parent cr_ensureSubview:child2 | 81 [parent cr_ensureSubview:child2 |
76 isPositioned:NSWindowBelow | 82 isPositioned:NSWindowBelow |
77 relativeTo:child1]; | 83 relativeTo:child1]; |
78 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child2); | 84 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child2); |
79 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child1); | 85 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child1); |
80 } | 86 } |
81 | 87 |
82 // Verify that no view is removed or added when no change is needed. | 88 // Verify that no view is removed or added when no change is needed. |
83 TEST_F(NSViewChromeAdditionsTest, EnsurePositionNoChange) { | 89 TEST_F(NSViewChromeAdditionsTest, EnsurePositionNoChange) { |
84 scoped_nsobject<ParentView> parent( | 90 base::scoped_nsobject<ParentView> parent( |
85 [[ParentView alloc] initWithFrame:NSZeroRect]); | 91 [[ParentView alloc] initWithFrame:NSZeroRect]); |
86 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]); | 92 base::scoped_nsobject<NSView> child1( |
87 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]); | 93 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 94 base::scoped_nsobject<NSView> child2( |
| 95 [[NSView alloc] initWithFrame:NSZeroRect]); |
88 [parent addSubview:child1]; | 96 [parent addSubview:child1]; |
89 [parent addSubview:child2]; | 97 [parent addSubview:child2]; |
90 | 98 |
91 EXPECT_EQ(0, [parent removeCount]); | 99 EXPECT_EQ(0, [parent removeCount]); |
92 EXPECT_EQ(2, [parent addCount]); | 100 EXPECT_EQ(2, [parent addCount]); |
93 [parent cr_ensureSubview:child2 | 101 [parent cr_ensureSubview:child2 |
94 isPositioned:NSWindowAbove | 102 isPositioned:NSWindowAbove |
95 relativeTo:child1]; | 103 relativeTo:child1]; |
96 EXPECT_EQ(0, [parent removeCount]); | 104 EXPECT_EQ(0, [parent removeCount]); |
97 EXPECT_EQ(2, [parent addCount]); | 105 EXPECT_EQ(2, [parent addCount]); |
98 } | 106 } |
OLD | NEW |