| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 9 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 10 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 | 13 |
| 14 class HyperlinkButtonCellTest : public CocoaTest { | 14 class HyperlinkButtonCellTest : public CocoaTest { |
| 15 public: | 15 public: |
| 16 HyperlinkButtonCellTest() { | 16 HyperlinkButtonCellTest() { |
| 17 NSRect frame = NSMakeRect(0, 0, 50, 30); | 17 NSRect frame = NSMakeRect(0, 0, 50, 30); |
| 18 scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]); | 18 base::scoped_nsobject<NSButton> view( |
| 19 [[NSButton alloc] initWithFrame:frame]); |
| 19 view_ = view.get(); | 20 view_ = view.get(); |
| 20 scoped_nsobject<HyperlinkButtonCell> cell( | 21 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 21 [[HyperlinkButtonCell alloc] initTextCell:@"Testing"]); | 22 [[HyperlinkButtonCell alloc] initTextCell:@"Testing"]); |
| 22 cell_ = cell.get(); | 23 cell_ = cell.get(); |
| 23 [view_ setCell:cell_]; | 24 [view_ setCell:cell_]; |
| 24 [[test_window() contentView] addSubview:view_]; | 25 [[test_window() contentView] addSubview:view_]; |
| 25 } | 26 } |
| 26 | 27 |
| 27 void TestCellCustomization(HyperlinkButtonCell* cell) { | 28 void TestCellCustomization(HyperlinkButtonCell* cell) { |
| 28 EXPECT_FALSE([cell isBordered]); | 29 EXPECT_FALSE([cell isBordered]); |
| 29 EXPECT_EQ(NSNoCellMask, [cell_ highlightsBy]); | 30 EXPECT_EQ(NSNoCellMask, [cell_ highlightsBy]); |
| 30 EXPECT_TRUE([cell showsBorderOnlyWhileMouseInside]); | 31 EXPECT_TRUE([cell showsBorderOnlyWhileMouseInside]); |
| 31 EXPECT_TRUE([cell textColor]); | 32 EXPECT_TRUE([cell textColor]); |
| 32 } | 33 } |
| 33 | 34 |
| 34 protected: | 35 protected: |
| 35 bool HasUnderlineAttribute(NSDictionary* attributes) { | 36 bool HasUnderlineAttribute(NSDictionary* attributes) { |
| 36 NSNumber* number = base::mac::ObjCCastStrict<NSNumber>( | 37 NSNumber* number = base::mac::ObjCCastStrict<NSNumber>( |
| 37 [attributes objectForKey:NSUnderlineStyleAttributeName]); | 38 [attributes objectForKey:NSUnderlineStyleAttributeName]); |
| 38 return [number unsignedIntegerValue] != 0; | 39 return [number unsignedIntegerValue] != 0; |
| 39 } | 40 } |
| 40 | 41 |
| 41 NSButton* view_; | 42 NSButton* view_; |
| 42 HyperlinkButtonCell* cell_; | 43 HyperlinkButtonCell* cell_; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 TEST_VIEW(HyperlinkButtonCellTest, view_) | 46 TEST_VIEW(HyperlinkButtonCellTest, view_) |
| 46 | 47 |
| 47 // Tests the three designated intializers. | 48 // Tests the three designated intializers. |
| 48 TEST_F(HyperlinkButtonCellTest, Initializers) { | 49 TEST_F(HyperlinkButtonCellTest, Initializers) { |
| 49 TestCellCustomization(cell_); // |-initTextFrame:| | 50 TestCellCustomization(cell_); // |-initTextFrame:| |
| 50 scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] init]); | 51 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 52 [[HyperlinkButtonCell alloc] init]); |
| 51 TestCellCustomization(cell.get()); | 53 TestCellCustomization(cell.get()); |
| 52 | 54 |
| 53 // Need to create a dummy archiver to test |-initWithCoder:|. | 55 // Need to create a dummy archiver to test |-initWithCoder:|. |
| 54 NSData* emptyData = [NSKeyedArchiver archivedDataWithRootObject:@""]; | 56 NSData* emptyData = [NSKeyedArchiver archivedDataWithRootObject:@""]; |
| 55 NSCoder* coder = | 57 NSCoder* coder = |
| 56 [[[NSKeyedUnarchiver alloc] initForReadingWithData:emptyData] autorelease]; | 58 [[[NSKeyedUnarchiver alloc] initForReadingWithData:emptyData] autorelease]; |
| 57 cell.reset([[HyperlinkButtonCell alloc] initWithCoder:coder]); | 59 cell.reset([[HyperlinkButtonCell alloc] initWithCoder:coder]); |
| 58 TestCellCustomization(cell); | 60 TestCellCustomization(cell); |
| 59 } | 61 } |
| 60 | 62 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 [cell_ mouseExited:nil]; | 102 [cell_ mouseExited:nil]; |
| 101 EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); | 103 EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); |
| 102 | 104 |
| 103 [cell_ setUnderlineOnHover:YES]; | 105 [cell_ setUnderlineOnHover:YES]; |
| 104 EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); | 106 EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); |
| 105 [cell_ mouseEntered:nil]; | 107 [cell_ mouseEntered:nil]; |
| 106 EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); | 108 EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); |
| 107 [cell_ mouseExited:nil]; | 109 [cell_ mouseExited:nil]; |
| 108 EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); | 110 EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); |
| 109 } | 111 } |
| OLD | NEW |