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" |
| 9 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 10 #include "chrome/browser/cocoa/browser_test_helper.h" |
8 #include "chrome/browser/cocoa/location_bar_view_mac.h" | 11 #include "chrome/browser/cocoa/location_bar_view_mac.h" |
| 12 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
10 | 14 |
11 // TODO(shess): Figure out how to unittest this. The code below was | 15 // TODO(shess): Figure out how to unittest this. The code below was |
12 // testing the hacked-up behavior so you didn't have to be pedantic | 16 // testing the hacked-up behavior so you didn't have to be pedantic |
13 // WRT http://. But that approach is completely and utterly wrong in | 17 // WRT http://. But that approach is completely and utterly wrong in |
14 // a world where omnibox is running. | 18 // a world where omnibox is running. |
15 // http://code.google.com/p/chromium/issues/detail?id=9977 | 19 // http://code.google.com/p/chromium/issues/detail?id=9977 |
16 | 20 |
17 #if 0 | 21 #if 0 |
18 class LocationBarViewMacTest : public testing::Test { | 22 class LocationBarViewMacTest : public testing::Test { |
(...skipping 25 matching lines...) Expand all Loading... |
44 | 48 |
45 [field_ setStringValue:@"http://example.com"]; | 49 [field_ setStringValue:@"http://example.com"]; |
46 EXPECT_EQ(locationBarView_->GetInputString(), | 50 EXPECT_EQ(locationBarView_->GetInputString(), |
47 ASCIIToWide("http://example.com/")); | 51 ASCIIToWide("http://example.com/")); |
48 | 52 |
49 [field_ setStringValue:@"https://www.example.com"]; | 53 [field_ setStringValue:@"https://www.example.com"]; |
50 EXPECT_EQ(locationBarView_->GetInputString(), | 54 EXPECT_EQ(locationBarView_->GetInputString(), |
51 ASCIIToWide("https://www.example.com/")); | 55 ASCIIToWide("https://www.example.com/")); |
52 } | 56 } |
53 #endif | 57 #endif |
| 58 |
| 59 namespace { |
| 60 |
| 61 class LocationBarViewMacTest : public testing::Test { |
| 62 public: |
| 63 LocationBarViewMacTest() { |
| 64 // Make sure this is wide enough to play games with the cell |
| 65 // decorations. |
| 66 NSRect frame = NSMakeRect(0, 0, 300, 30); |
| 67 field_.reset([[AutocompleteTextField alloc] initWithFrame:frame]); |
| 68 [field_ setStringValue:@"Testing"]; |
| 69 [cocoa_helper_.contentView() addSubview:field_.get()]; |
| 70 } |
| 71 |
| 72 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
| 73 BrowserTestHelper helper_; |
| 74 scoped_nsobject<AutocompleteTextField> field_; |
| 75 }; |
| 76 |
| 77 TEST_F(LocationBarViewMacTest, OnChangedImpl) { |
| 78 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 79 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 80 |
| 81 const std::wstring kKeyword(L"Google"); |
| 82 const NSString* kSearchHint = @"Type to search"; |
| 83 const NSString* kKeywordPrefix = @"Press "; |
| 84 const NSString* kKeywordSuffix = @" to search Google"; |
| 85 const NSString* kKeywordString = @"Search Google:"; |
| 86 |
| 87 // With no special hints requested, none set. |
| 88 LocationBarViewMac::OnChangedImpl( |
| 89 field_.get(), std::wstring(), std::wstring(), false, false, image); |
| 90 EXPECT_FALSE([cell keywordString]); |
| 91 EXPECT_FALSE([cell hintString]); |
| 92 |
| 93 // Request only a search hint. |
| 94 LocationBarViewMac::OnChangedImpl( |
| 95 field_.get(), std::wstring(), std::wstring(), false, true, image); |
| 96 EXPECT_FALSE([cell keywordString]); |
| 97 EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); |
| 98 |
| 99 // Request a keyword hint, same results whether |search_hint| |
| 100 // parameter is true or false. |
| 101 LocationBarViewMac::OnChangedImpl( |
| 102 field_.get(), kKeyword, kKeyword, true, true, image); |
| 103 EXPECT_FALSE([cell keywordString]); |
| 104 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); |
| 105 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); |
| 106 LocationBarViewMac::OnChangedImpl( |
| 107 field_.get(), kKeyword, kKeyword, true, false, image); |
| 108 EXPECT_FALSE([cell keywordString]); |
| 109 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); |
| 110 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); |
| 111 |
| 112 // Request keyword-search mode, same results whether |search_hint| |
| 113 // parameter is true or false. |
| 114 LocationBarViewMac::OnChangedImpl( |
| 115 field_.get(), kKeyword, kKeyword, false, true, image); |
| 116 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); |
| 117 EXPECT_FALSE([cell hintString]); |
| 118 LocationBarViewMac::OnChangedImpl( |
| 119 field_.get(), kKeyword, kKeyword, false, false, image); |
| 120 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kKeywordString]); |
| 121 EXPECT_FALSE([cell hintString]); |
| 122 |
| 123 // Transition back to baseline. |
| 124 LocationBarViewMac::OnChangedImpl( |
| 125 field_.get(), std::wstring(), std::wstring(), false, false, image); |
| 126 EXPECT_FALSE([cell keywordString]); |
| 127 EXPECT_FALSE([cell hintString]); |
| 128 } |
| 129 |
| 130 } // namespace |
OLD | NEW |