| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "base/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/cocoa/autocomplete_text_field.h" | 8 #include "chrome/browser/cocoa/autocomplete_text_field.h" |
| 9 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h" | 9 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 10 #include "chrome/browser/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/cocoa/browser_test_helper.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 ASCIIToWide("http://example.com/")); | 52 ASCIIToWide("http://example.com/")); |
| 53 | 53 |
| 54 [field_ setStringValue:@"https://www.example.com"]; | 54 [field_ setStringValue:@"https://www.example.com"]; |
| 55 EXPECT_EQ(locationBarView_->GetInputString(), | 55 EXPECT_EQ(locationBarView_->GetInputString(), |
| 56 ASCIIToWide("https://www.example.com/")); | 56 ASCIIToWide("https://www.example.com/")); |
| 57 } | 57 } |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 class LocationBarViewMacTest : public PlatformTest { | 62 class LocationBarViewMacTest : public CocoaTest { |
| 63 public: | 63 public: |
| 64 LocationBarViewMacTest() { | 64 LocationBarViewMacTest() { |
| 65 // Make sure this is wide enough to play games with the cell | 65 // Make sure this is wide enough to play games with the cell |
| 66 // decorations. | 66 // decorations. |
| 67 NSRect frame = NSMakeRect(0, 0, 400.0, 30); | 67 NSRect frame = NSMakeRect(0, 0, 400.0, 30); |
| 68 field_.reset([[AutocompleteTextField alloc] initWithFrame:frame]); | 68 scoped_nsobject<AutocompleteTextField> field( |
| 69 [[AutocompleteTextField alloc] initWithFrame:frame]); |
| 70 field_ = field.get(); |
| 69 [field_ setStringValue:@"Testing"]; | 71 [field_ setStringValue:@"Testing"]; |
| 70 [cocoa_helper_.contentView() addSubview:field_.get()]; | 72 [[test_window() contentView] addSubview:field_]; |
| 71 } | 73 } |
| 72 | 74 |
| 73 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | |
| 74 BrowserTestHelper helper_; | 75 BrowserTestHelper helper_; |
| 75 scoped_nsobject<AutocompleteTextField> field_; | 76 AutocompleteTextField* field_; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 TEST_F(LocationBarViewMacTest, OnChangedImpl) { | 79 TEST_F(LocationBarViewMacTest, OnChangedImpl) { |
| 79 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 80 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 80 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 81 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 81 | 82 |
| 82 const std::wstring kKeyword(L"Google"); | 83 const std::wstring kKeyword(L"Google"); |
| 83 const NSString* kSearchHint = @"Type to search"; | 84 const NSString* kSearchHint = @"Type to search"; |
| 84 const NSString* kKeywordPrefix = @"Press "; | 85 const NSString* kKeywordPrefix = @"Press "; |
| 85 const NSString* kKeywordSuffix = @" to search Google"; | 86 const NSString* kKeywordSuffix = @" to search Google"; |
| 86 const NSString* kKeywordString = @"Search Google:"; | 87 const NSString* kKeywordString = @"Search Google:"; |
| 87 // 0x2026 is Unicode ellipses. | 88 // 0x2026 is Unicode ellipses. |
| 88 const NSString* kPartialString = | 89 const NSString* kPartialString = |
| 89 [NSString stringWithFormat:@"Search Go%C:", 0x2026]; | 90 [NSString stringWithFormat:@"Search Go%C:", 0x2026]; |
| 90 | 91 |
| 91 // With no special hints requested, none set. | 92 // With no special hints requested, none set. |
| 92 LocationBarViewMac::OnChangedImpl( | 93 LocationBarViewMac::OnChangedImpl( |
| 93 field_.get(), std::wstring(), std::wstring(), false, false, image); | 94 field_, std::wstring(), std::wstring(), false, false, image); |
| 94 EXPECT_FALSE([cell keywordString]); | 95 EXPECT_FALSE([cell keywordString]); |
| 95 EXPECT_FALSE([cell hintString]); | 96 EXPECT_FALSE([cell hintString]); |
| 96 | 97 |
| 97 // Request only a search hint. | 98 // Request only a search hint. |
| 98 LocationBarViewMac::OnChangedImpl( | 99 LocationBarViewMac::OnChangedImpl( |
| 99 field_.get(), std::wstring(), std::wstring(), false, true, image); | 100 field_, std::wstring(), std::wstring(), false, true, image); |
| 100 EXPECT_FALSE([cell keywordString]); | 101 EXPECT_FALSE([cell keywordString]); |
| 101 EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); | 102 EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); |
| 102 | 103 |
| 103 // Request a keyword hint, same results whether |search_hint| | 104 // Request a keyword hint, same results whether |search_hint| |
| 104 // parameter is true or false. | 105 // parameter is true or false. |
| 105 LocationBarViewMac::OnChangedImpl( | 106 LocationBarViewMac::OnChangedImpl( |
| 106 field_.get(), kKeyword, kKeyword, true, true, image); | 107 field_, kKeyword, kKeyword, true, true, image); |
| 107 EXPECT_FALSE([cell keywordString]); | 108 EXPECT_FALSE([cell keywordString]); |
| 108 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); | 109 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); |
| 109 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); | 110 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); |
| 110 LocationBarViewMac::OnChangedImpl( | 111 LocationBarViewMac::OnChangedImpl( |
| 111 field_.get(), kKeyword, kKeyword, true, false, image); | 112 field_, kKeyword, kKeyword, true, false, image); |
| 112 EXPECT_FALSE([cell keywordString]); | 113 EXPECT_FALSE([cell keywordString]); |
| 113 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); | 114 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); |
| 114 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); | 115 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); |
| 115 | 116 |
| 116 // Request keyword-search mode, same results whether |search_hint| | 117 // Request keyword-search mode, same results whether |search_hint| |
| 117 // parameter is true or false. | 118 // parameter is true or false. |
| 118 LocationBarViewMac::OnChangedImpl( | 119 LocationBarViewMac::OnChangedImpl( |
| 119 field_.get(), kKeyword, kKeyword, false, true, image); | 120 field_, kKeyword, kKeyword, false, true, image); |
| 120 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); | 121 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); |
| 121 EXPECT_FALSE([cell hintString]); | 122 EXPECT_FALSE([cell hintString]); |
| 122 LocationBarViewMac::OnChangedImpl( | 123 LocationBarViewMac::OnChangedImpl( |
| 123 field_.get(), kKeyword, kKeyword, false, false, image); | 124 field_, kKeyword, kKeyword, false, false, image); |
| 124 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); | 125 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); |
| 125 EXPECT_FALSE([cell hintString]); | 126 EXPECT_FALSE([cell hintString]); |
| 126 | 127 |
| 127 // Check that a partial keyword-search string is passed down in case | 128 // Check that a partial keyword-search string is passed down in case |
| 128 // the view is narrow. | 129 // the view is narrow. |
| 129 // TODO(shess): Is this test a good argument for re-writing using a | 130 // TODO(shess): Is this test a good argument for re-writing using a |
| 130 // mock field? | 131 // mock field? |
| 131 NSRect frame([field_ frame]); | 132 NSRect frame([field_ frame]); |
| 132 frame.size.width = 10.0; | 133 frame.size.width = 10.0; |
| 133 [field_ setFrame:frame]; | 134 [field_ setFrame:frame]; |
| 134 LocationBarViewMac::OnChangedImpl( | 135 LocationBarViewMac::OnChangedImpl( |
| 135 field_.get(), kKeyword, kKeyword, false, true, image); | 136 field_, kKeyword, kKeyword, false, true, image); |
| 136 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kPartialString]); | 137 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kPartialString]); |
| 137 EXPECT_FALSE([cell hintString]); | 138 EXPECT_FALSE([cell hintString]); |
| 138 | 139 |
| 139 // Transition back to baseline. | 140 // Transition back to baseline. |
| 140 LocationBarViewMac::OnChangedImpl( | 141 LocationBarViewMac::OnChangedImpl( |
| 141 field_.get(), std::wstring(), std::wstring(), false, false, image); | 142 field_, std::wstring(), std::wstring(), false, false, image); |
| 142 EXPECT_FALSE([cell keywordString]); | 143 EXPECT_FALSE([cell keywordString]); |
| 143 EXPECT_FALSE([cell hintString]); | 144 EXPECT_FALSE([cell hintString]); |
| 144 } | 145 } |
| 145 | 146 |
| 146 } // namespace | 147 } // namespace |
| OLD | NEW |