| 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/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/styled_text_field.h" | 9 #import "chrome/browser/ui/cocoa/styled_text_field.h" |
| 9 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h" | 10 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/styled_text_field_test_helper.h" | 11 #import "chrome/browser/ui/cocoa/styled_text_field_test_helper.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Width of the field so that we don't have to ask |field_| for it all | 16 // Width of the field so that we don't have to ask |field_| for it all |
| 17 // the time. | 17 // the time. |
| 18 static const CGFloat kWidth(300.0); | 18 static const CGFloat kWidth(300.0); |
| 19 | 19 |
| 20 class StyledTextFieldTest : public CocoaTest { | 20 class StyledTextFieldTest : public CocoaTest { |
| 21 public: | 21 public: |
| 22 StyledTextFieldTest() { | 22 StyledTextFieldTest() { |
| 23 // Make sure this is wide enough to play games with the cell | 23 // Make sure this is wide enough to play games with the cell |
| 24 // decorations. | 24 // decorations. |
| 25 NSRect frame = NSMakeRect(0, 0, kWidth, 30); | 25 NSRect frame = NSMakeRect(0, 0, kWidth, 30); |
| 26 | 26 |
| 27 scoped_nsobject<StyledTextFieldTestCell> cell( | 27 base::scoped_nsobject<StyledTextFieldTestCell> cell( |
| 28 [[StyledTextFieldTestCell alloc] initTextCell:@"Testing"]); | 28 [[StyledTextFieldTestCell alloc] initTextCell:@"Testing"]); |
| 29 cell_ = cell.get(); | 29 cell_ = cell.get(); |
| 30 [cell_ setEditable:YES]; | 30 [cell_ setEditable:YES]; |
| 31 [cell_ setBordered:YES]; | 31 [cell_ setBordered:YES]; |
| 32 | 32 |
| 33 scoped_nsobject<StyledTextField> field( | 33 base::scoped_nsobject<StyledTextField> field( |
| 34 [[StyledTextField alloc] initWithFrame:frame]); | 34 [[StyledTextField alloc] initWithFrame:frame]); |
| 35 field_ = field.get(); | 35 field_ = field.get(); |
| 36 [field_ setCell:cell_]; | 36 [field_ setCell:cell_]; |
| 37 | 37 |
| 38 [[test_window() contentView] addSubview:field_]; | 38 [[test_window() contentView] addSubview:field_]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Helper to return the field-editor frame being used w/in |field_|. | 41 // Helper to return the field-editor frame being used w/in |field_|. |
| 42 NSRect EditorFrame() { | 42 NSRect EditorFrame() { |
| 43 EXPECT_TRUE([field_ currentEditor]); | 43 EXPECT_TRUE([field_ currentEditor]); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame)); | 187 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame)); |
| 188 | 188 |
| 189 // Setting the same margin and using -resetFieldEditorFrameIfNeeded should | 189 // Setting the same margin and using -resetFieldEditorFrameIfNeeded should |
| 190 // result in the same frame as the standard focus machinery. | 190 // result in the same frame as the standard focus machinery. |
| 191 [cell_ setRightMargin:kRightMargin]; | 191 [cell_ setRightMargin:kRightMargin]; |
| 192 [field_ resetFieldEditorFrameIfNeeded]; | 192 [field_ resetFieldEditorFrameIfNeeded]; |
| 193 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); | 193 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace | 196 } // namespace |
| OLD | NEW |