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

Side by Side Diff: chrome/browser/cocoa/location_bar/location_bar_view_mac_unittest.mm

Issue 2805070: [Mac] First part of Omnibox decoration refactor. Enable ev bubble. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: comment clarification Created 10 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/scoped_nsobject.h"
6 #include "base/scoped_ptr.h"
7 #include "base/string_util.h"
8 #include "chrome/browser/cocoa/browser_test_helper.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h"
11 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h"
12 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h"
15
16 // TODO(shess): Figure out how to unittest this. The code below was
17 // testing the hacked-up behavior so you didn't have to be pedantic
18 // WRT http://. But that approach is completely and utterly wrong in
19 // a world where omnibox is running.
20 // http://code.google.com/p/chromium/issues/detail?id=9977
21
22 #if 0
23 class LocationBarViewMacTest : public PlatformTest {
24 public:
25 LocationBarViewMacTest()
26 : field_([[NSTextField alloc] init]),
27 locationBarView_(new LocationBarViewMac(field_, NULL, NULL, NULL)) {
28 }
29
30 scoped_nsobject<NSTextField> field_;
31 scoped_ptr<LocationBarViewMac> locationBarView_;
32 };
33
34 TEST_F(LocationBarViewMacTest, GetInputString) {
35 // Test a few obvious cases to make sure things work end-to-end, but
36 // trust url_fixer_upper_unittest.cc to do the bulk of the work.
37 [field_ setStringValue:@"ahost"];
38 EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://ahost/"));
39
40 [field_ setStringValue:@"bhost\n"];
41 EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://bhost/"));
42
43 [field_ setStringValue:@"chost/"];
44 EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://chost/"));
45
46 [field_ setStringValue:@"www.example.com"];
47 EXPECT_EQ(locationBarView_->GetInputString(),
48 ASCIIToWide("http://www.example.com/"));
49
50 [field_ setStringValue:@"http://example.com"];
51 EXPECT_EQ(locationBarView_->GetInputString(),
52 ASCIIToWide("http://example.com/"));
53
54 [field_ setStringValue:@"https://www.example.com"];
55 EXPECT_EQ(locationBarView_->GetInputString(),
56 ASCIIToWide("https://www.example.com/"));
57 }
58 #endif
59
60 namespace {
61
62 class LocationBarViewMacTest : public CocoaTest {
63 public:
64 LocationBarViewMacTest() {
65 // Make sure this is wide enough to play games with the cell
66 // decorations.
67 NSRect frame = NSMakeRect(0, 0, 400.0, 30);
68 scoped_nsobject<AutocompleteTextField> field(
69 [[AutocompleteTextField alloc] initWithFrame:frame]);
70 field_ = field.get();
71 [field_ setStringValue:@"Testing"];
72 [[test_window() contentView] addSubview:field_];
73 }
74
75 BrowserTestHelper helper_;
76 AutocompleteTextField* field_;
77 };
78
79 TEST_F(LocationBarViewMacTest, OnChangedImpl) {
80 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
81 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
82
83 const std::wstring kKeyword(L"Google");
84 NSString* const kKeywordPrefix = @"Press ";
85 NSString* const kKeywordSuffix = @" to search Google";
86 NSString* const kKeywordString = @"Search Google:";
87 // 0x2026 is Unicode ellipses.
88 NSString* const kPartialString =
89 [NSString stringWithFormat:@"Search Go%C:", 0x2026];
90
91 // With no special hints requested, none set.
92 LocationBarViewMac::OnChangedImpl(field_, std::wstring(), std::wstring(),
93 false, false, image);
94 EXPECT_FALSE([cell keywordString]);
95 EXPECT_FALSE([cell hintString]);
96
97 // Request a keyword hint.
98 LocationBarViewMac::OnChangedImpl(field_, kKeyword, kKeyword,
99 true, false, image);
100 EXPECT_FALSE([cell keywordString]);
101 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]);
102 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]);
103
104 // Request keyword-search mode.
105 LocationBarViewMac::OnChangedImpl(
106 field_, kKeyword, kKeyword, false, false, image);
107 EXPECT_TRUE([[[cell keywordString] string] hasSuffix:kKeywordString]);
108 EXPECT_FALSE([cell hintString]);
109
110 // Check that a partial keyword-search string is passed down in case
111 // the view is narrow.
112 // TODO(shess): Is this test a good argument for re-writing using a
113 // mock field?
114 NSRect frame([field_ frame]);
115 frame.size.width = 10.0;
116 [field_ setFrame:frame];
117 LocationBarViewMac::OnChangedImpl(field_, kKeyword, kKeyword, false,
118 false, image);
119 EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kPartialString]);
120 EXPECT_FALSE([cell hintString]);
121
122 // Transition back to baseline.
123 LocationBarViewMac::OnChangedImpl(
124 field_, std::wstring(), std::wstring(), false, false, image);
125 EXPECT_FALSE([cell keywordString]);
126 EXPECT_FALSE([cell hintString]);
127 }
128
129 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698