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

Side by Side Diff: chrome/browser/ui/cocoa/nsview_additions_unittest.mm

Issue 11876036: Alternate NTP: Don't hide bookmark bar on instant (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/nsview_additions.h"
6
7 #include "base/memory/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #import "testing/gtest_mac.h"
11
12 typedef CocoaTest NSViewChromeAdditionsTest;
13
14 @interface ParentView : NSView {
15 @private
16 int removeCount_;
17 int addCount_;
18 }
19
20 @property(readonly, nonatomic) int removeCount;
21 @property(readonly, nonatomic) int addCount;
22
23 @end
24
25 @implementation ParentView
26
27 @synthesize removeCount = removeCount_;
28 @synthesize addCount = addCount_;
29
30 - (void)willRemoveSubview:(NSView*)view {
31 ++removeCount_;
32 }
33
34 - (void)didAddSubview:(NSView*)view {
35 ++addCount_;
36 }
37
38 @end
39
40 TEST_F(NSViewChromeAdditionsTest, BelowAboveView) {
41 scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
42 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
43 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
44
45 [parent addSubview:child1];
46 [parent addSubview:child2];
47 EXPECT_TRUE([child1 cr_isBelowView:child2]);
48 EXPECT_FALSE([child1 cr_isAboveView:child2]);
49 EXPECT_FALSE([child2 cr_isBelowView:child1]);
50 EXPECT_TRUE([child2 cr_isAboveView:child1]);
51
52 [child1 removeFromSuperview];
53 [child2 removeFromSuperview];
54 [parent addSubview:child2];
55 [parent addSubview:child1];
56 EXPECT_FALSE([child1 cr_isBelowView:child2]);
57 EXPECT_TRUE([child1 cr_isAboveView:child2]);
58 EXPECT_TRUE([child2 cr_isBelowView:child1]);
59 EXPECT_FALSE([child2 cr_isAboveView:child1]);
60 }
61
62 TEST_F(NSViewChromeAdditionsTest, EnsurePosition) {
63 scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
64 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
65 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
66
67 [parent addSubview:child1];
68 [parent cr_ensureSubview:child2
69 isPositioned:NSWindowAbove
70 relativeTo:child1];
71 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child1);
72 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child2);
73
74 [child2 removeFromSuperview];
75 [parent cr_ensureSubview:child2
76 isPositioned:NSWindowBelow
77 relativeTo:child1];
78 EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child2);
79 EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child1);
80 }
81
82 // Verify that no view is removed or added when no change is needed.
83 TEST_F(NSViewChromeAdditionsTest, EnsurePositionNoChange) {
84 scoped_nsobject<ParentView> parent(
85 [[ParentView alloc] initWithFrame:NSZeroRect]);
86 scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
87 scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
88 [parent addSubview:child1];
89 [parent addSubview:child2];
90
91 EXPECT_EQ(0, [parent removeCount]);
92 EXPECT_EQ(2, [parent addCount]);
93 [parent cr_ensureSubview:child2
94 isPositioned:NSWindowAbove
95 relativeTo:child1];
96 EXPECT_EQ(0, [parent removeCount]);
97 EXPECT_EQ(2, [parent addCount]);
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698