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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/nsview_additions_unittest.mm
diff --git a/chrome/browser/ui/cocoa/nsview_additions_unittest.mm b/chrome/browser/ui/cocoa/nsview_additions_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ffb7e0ffc3053aab42d59c36d06685951623acb8
--- /dev/null
+++ b/chrome/browser/ui/cocoa/nsview_additions_unittest.mm
@@ -0,0 +1,98 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/nsview_additions.h"
+
+#include "base/memory/scoped_nsobject.h"
+#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "testing/gtest_mac.h"
+
+typedef CocoaTest NSViewChromeAdditionsTest;
+
+@interface ParentView : NSView {
+ @private
+ int removeCount_;
+ int addCount_;
+}
+
+@property(readonly, nonatomic) int removeCount;
+@property(readonly, nonatomic) int addCount;
+
+@end
+
+@implementation ParentView
+
+@synthesize removeCount = removeCount_;
+@synthesize addCount = addCount_;
+
+- (void)willRemoveSubview:(NSView*)view {
+ ++removeCount_;
+}
+
+- (void)didAddSubview:(NSView*)view {
+ ++addCount_;
+}
+
+@end
+
+TEST_F(NSViewChromeAdditionsTest, BelowAboveView) {
+ scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
+
+ [parent addSubview:child1];
+ [parent addSubview:child2];
+ EXPECT_TRUE([child1 cr_isBelowView:child2]);
+ EXPECT_FALSE([child1 cr_isAboveView:child2]);
+ EXPECT_FALSE([child2 cr_isBelowView:child1]);
+ EXPECT_TRUE([child2 cr_isAboveView:child1]);
+
+ [child1 removeFromSuperview];
+ [child2 removeFromSuperview];
+ [parent addSubview:child2];
+ [parent addSubview:child1];
+ EXPECT_FALSE([child1 cr_isBelowView:child2]);
+ EXPECT_TRUE([child1 cr_isAboveView:child2]);
+ EXPECT_TRUE([child2 cr_isBelowView:child1]);
+ EXPECT_FALSE([child2 cr_isAboveView:child1]);
+}
+
+TEST_F(NSViewChromeAdditionsTest, EnsurePosition) {
+ scoped_nsobject<NSView> parent([[NSView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
+
+ [parent addSubview:child1];
+ [parent cr_ensureSubview:child2
+ isPositioned:NSWindowAbove
+ relativeTo:child1];
+ EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child1);
+ EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child2);
+
+ [child2 removeFromSuperview];
+ [parent cr_ensureSubview:child2
+ isPositioned:NSWindowBelow
+ relativeTo:child1];
+ EXPECT_NSEQ([[parent subviews] objectAtIndex:0], child2);
+ EXPECT_NSEQ([[parent subviews] objectAtIndex:1], child1);
+}
+
+// Verify that no view is removed or added when no change is needed.
+TEST_F(NSViewChromeAdditionsTest, EnsurePositionNoChange) {
+ scoped_nsobject<ParentView> parent(
+ [[ParentView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child1([[NSView alloc] initWithFrame:NSZeroRect]);
+ scoped_nsobject<NSView> child2([[NSView alloc] initWithFrame:NSZeroRect]);
+ [parent addSubview:child1];
+ [parent addSubview:child2];
+
+ EXPECT_EQ(0, [parent removeCount]);
+ EXPECT_EQ(2, [parent addCount]);
+ [parent cr_ensureSubview:child2
+ isPositioned:NSWindowAbove
+ relativeTo:child1];
+ EXPECT_EQ(0, [parent removeCount]);
+ EXPECT_EQ(2, [parent addCount]);
+}

Powered by Google App Engine
This is Rietveld 408576698