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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_browsertest.cc

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/format_macros.h"
5 #include "base/string_util.h" 6 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autocomplete/autocomplete.h" 8 #include "chrome/browser/autocomplete/autocomplete.h"
8 #include "chrome/browser/autocomplete/autocomplete_edit.h" 9 #include "chrome/browser/autocomplete/autocomplete_edit.h"
9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 10 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 11 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
12 #include "chrome/browser/browser_window.h" 13 #include "chrome/browser/browser_window.h"
13 #include "chrome/browser/history/history.h" 14 #include "chrome/browser/history/history.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
(...skipping 10 matching lines...) Expand all
25 // http://crbug.com/52928 26 // http://crbug.com/52928
26 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
27 #define MAYBE_Autocomplete FLAKY_Autocomplete 28 #define MAYBE_Autocomplete FLAKY_Autocomplete
28 #else 29 #else
29 #define MAYBE_Autocomplete Autocomplete 30 #define MAYBE_Autocomplete Autocomplete
30 #endif 31 #endif
31 32
32 33
33 namespace { 34 namespace {
34 35
35 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { 36 string16 AutocompleteResultAsString(const AutocompleteResult& result) {
36 std::wstring output(StringPrintf(L"{%d} ", result.size())); 37 std::string output(base::StringPrintf("{%" PRIuS "} ", result.size()));
37 for (size_t i = 0; i < result.size(); ++i) { 38 for (size_t i = 0; i < result.size(); ++i) {
38 AutocompleteMatch match = result.match_at(i); 39 AutocompleteMatch match = result.match_at(i);
39 std::wstring provider_name(ASCIIToWide(match.provider->name())); 40 std::string provider_name = match.provider->name();
40 output.append(StringPrintf(L"[\"%ls\" by \"%ls\"] ", 41 output.append(base::StringPrintf("[\"%s\" by \"%s\"] ",
41 match.contents.c_str(), 42 UTF16ToUTF8(match.contents).c_str(),
42 provider_name.c_str())); 43 provider_name.c_str()));
43 } 44 }
44 return output; 45 return UTF8ToUTF16(output);
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 class AutocompleteBrowserTest : public InProcessBrowserTest { 50 class AutocompleteBrowserTest : public InProcessBrowserTest {
50 protected: 51 protected:
51 LocationBar* GetLocationBar() const { 52 LocationBar* GetLocationBar() const {
52 return browser()->window()->GetLocationBar(); 53 return browser()->window()->GetLocationBar();
53 } 54 }
54 55
55 AutocompleteController* GetAutocompleteController() const { 56 AutocompleteController* GetAutocompleteController() const {
56 return GetLocationBar()->location_entry()->model()->popup_model()-> 57 return GetLocationBar()->location_entry()->model()->popup_model()->
57 autocomplete_controller(); 58 autocomplete_controller();
58 } 59 }
59 }; 60 };
60 61
61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { 62 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) {
62 LocationBar* location_bar = GetLocationBar(); 63 LocationBar* location_bar = GetLocationBar();
63 64
64 EXPECT_TRUE(location_bar->GetInputString().empty()); 65 EXPECT_TRUE(location_bar->GetInputString().empty());
65 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 66 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
66 location_bar->location_entry()->GetText()); 67 location_bar->location_entry()->GetText());
67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across 68 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across
68 // platforms. 69 // platforms.
69 70
70 location_bar->FocusLocation(true); 71 location_bar->FocusLocation(true);
71 72
72 EXPECT_TRUE(location_bar->GetInputString().empty()); 73 EXPECT_TRUE(location_bar->GetInputString().empty());
73 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 74 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
74 location_bar->location_entry()->GetText()); 75 location_bar->location_entry()->GetText());
75 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 76 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
76 77
77 location_bar->location_entry()->SetUserText(L"chrome"); 78 location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome"));
78 79
79 EXPECT_TRUE(location_bar->GetInputString().empty()); 80 EXPECT_TRUE(location_bar->GetInputString().empty());
80 EXPECT_EQ(L"chrome", location_bar->location_entry()->GetText()); 81 EXPECT_EQ(ASCIIToUTF16("chrome"), location_bar->location_entry()->GetText());
81 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 82 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
82 83
83 location_bar->location_entry()->RevertAll(); 84 location_bar->location_entry()->RevertAll();
84 85
85 EXPECT_TRUE(location_bar->GetInputString().empty()); 86 EXPECT_TRUE(location_bar->GetInputString().empty());
86 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 87 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
87 location_bar->location_entry()->GetText()); 88 location_bar->location_entry()->GetText());
88 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 89 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
89 90
90 location_bar->location_entry()->SetUserText(L"chrome"); 91 location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome"));
91 location_bar->Revert(); 92 location_bar->Revert();
92 93
93 EXPECT_TRUE(location_bar->GetInputString().empty()); 94 EXPECT_TRUE(location_bar->GetInputString().empty());
94 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 95 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
95 location_bar->location_entry()->GetText()); 96 location_bar->location_entry()->GetText());
96 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 97 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
97 } 98 }
98 99
99 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { 100 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
100 // The results depend on the history backend being loaded. Make sure it is 101 // The results depend on the history backend being loaded. Make sure it is
101 // loaded so that the autocomplete results are consistent. 102 // loaded so that the autocomplete results are consistent.
102 ui_test_utils::WaitForHistoryToLoad(browser()); 103 ui_test_utils::WaitForHistoryToLoad(browser());
103 104
104 LocationBar* location_bar = GetLocationBar(); 105 LocationBar* location_bar = GetLocationBar();
105 AutocompleteController* autocomplete_controller = GetAutocompleteController(); 106 AutocompleteController* autocomplete_controller = GetAutocompleteController();
106 107
107 { 108 {
108 autocomplete_controller->Start(L"chrome", std::wstring(), 109 autocomplete_controller->Start(ASCIIToUTF16("chrome"), string16(),
109 true, false, true, true); 110 true, false, true, true);
110 111
111 EXPECT_TRUE(autocomplete_controller->done()); 112 EXPECT_TRUE(autocomplete_controller->done());
112 EXPECT_TRUE(location_bar->GetInputString().empty()); 113 EXPECT_TRUE(location_bar->GetInputString().empty());
113 EXPECT_TRUE(location_bar->location_entry()->GetText().empty()); 114 EXPECT_TRUE(location_bar->location_entry()->GetText().empty());
114 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 115 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
115 const AutocompleteResult& result = autocomplete_controller->result(); 116 const AutocompleteResult& result = autocomplete_controller->result();
116 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result); 117 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result);
117 AutocompleteMatch match = result.match_at(0); 118 AutocompleteMatch match = result.match_at(0);
118 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 119 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
119 EXPECT_FALSE(match.deletable); 120 EXPECT_FALSE(match.deletable);
120 } 121 }
121 122
122 { 123 {
123 location_bar->Revert(); 124 location_bar->Revert();
124 125
125 EXPECT_TRUE(location_bar->GetInputString().empty()); 126 EXPECT_TRUE(location_bar->GetInputString().empty());
126 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 127 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
127 location_bar->location_entry()->GetText()); 128 location_bar->location_entry()->GetText());
128 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 129 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
129 const AutocompleteResult& result = autocomplete_controller->result(); 130 const AutocompleteResult& result = autocomplete_controller->result();
130 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result); 131 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result);
131 } 132 }
132 } 133 }
133 134
134 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { 135 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) {
135 // http://code.google.com/p/chromium/issues/detail?id=38385 136 // http://code.google.com/p/chromium/issues/detail?id=38385
136 // Make sure that tabbing away from an empty omnibar causes a revert 137 // Make sure that tabbing away from an empty omnibar causes a revert
137 // and select all. 138 // and select all.
138 LocationBar* location_bar = GetLocationBar(); 139 LocationBar* location_bar = GetLocationBar();
139 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 140 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
140 location_bar->location_entry()->GetText()); 141 location_bar->location_entry()->GetText());
141 location_bar->location_entry()->SetUserText(L""); 142 location_bar->location_entry()->SetUserText(string16());
142 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), 143 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
143 PageTransition::START_PAGE); 144 PageTransition::START_PAGE);
144 ui_test_utils::WaitForNavigation( 145 ui_test_utils::WaitForNavigation(
145 &browser()->GetSelectedTabContents()->controller()); 146 &browser()->GetSelectedTabContents()->controller());
146 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 147 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
147 location_bar->location_entry()->GetText()); 148 location_bar->location_entry()->GetText());
148 browser()->CloseTab(); 149 browser()->CloseTab();
149 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 150 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
150 location_bar->location_entry()->GetText()); 151 location_bar->location_entry()->GetText());
151 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 152 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
152 } 153 }
153 154
154 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { 155 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
155 LocationBar* location_bar = GetLocationBar(); 156 LocationBar* location_bar = GetLocationBar();
156 157
157 // Focus search when omnibox is blank 158 // Focus search when omnibox is blank
158 { 159 {
159 EXPECT_TRUE(location_bar->GetInputString().empty()); 160 EXPECT_TRUE(location_bar->GetInputString().empty());
160 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 161 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL),
161 location_bar->location_entry()->GetText()); 162 location_bar->location_entry()->GetText());
162 163
163 location_bar->FocusSearch(); 164 location_bar->FocusSearch();
164 EXPECT_TRUE(location_bar->GetInputString().empty()); 165 EXPECT_TRUE(location_bar->GetInputString().empty());
165 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 166 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText());
166 167
167 size_t selection_start, selection_end; 168 size_t selection_start, selection_end;
168 location_bar->location_entry()->GetSelectionBounds(&selection_start, 169 location_bar->location_entry()->GetSelectionBounds(&selection_start,
169 &selection_end); 170 &selection_end);
170 EXPECT_EQ(1U, selection_start); 171 EXPECT_EQ(1U, selection_start);
171 EXPECT_EQ(1U, selection_end); 172 EXPECT_EQ(1U, selection_end);
172 } 173 }
173 174
174 // Focus search when omnibox is _not_ alread in forced query mode. 175 // Focus search when omnibox is _not_ alread in forced query mode.
175 { 176 {
176 location_bar->location_entry()->SetUserText(L"foo"); 177 location_bar->location_entry()->SetUserText(ASCIIToUTF16("foo"));
177 EXPECT_TRUE(location_bar->GetInputString().empty()); 178 EXPECT_TRUE(location_bar->GetInputString().empty());
178 EXPECT_EQ(L"foo", location_bar->location_entry()->GetText()); 179 EXPECT_EQ(ASCIIToUTF16("foo"), location_bar->location_entry()->GetText());
179 180
180 location_bar->FocusSearch(); 181 location_bar->FocusSearch();
181 EXPECT_TRUE(location_bar->GetInputString().empty()); 182 EXPECT_TRUE(location_bar->GetInputString().empty());
182 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 183 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText());
183 184
184 size_t selection_start, selection_end; 185 size_t selection_start, selection_end;
185 location_bar->location_entry()->GetSelectionBounds(&selection_start, 186 location_bar->location_entry()->GetSelectionBounds(&selection_start,
186 &selection_end); 187 &selection_end);
187 EXPECT_EQ(1U, selection_start); 188 EXPECT_EQ(1U, selection_start);
188 EXPECT_EQ(1U, selection_end); 189 EXPECT_EQ(1U, selection_end);
189 } 190 }
190 191
191 // Focus search when omnibox _is_ already in forced query mode, but no query 192 // Focus search when omnibox _is_ already in forced query mode, but no query
192 // has been typed. 193 // has been typed.
193 { 194 {
194 location_bar->location_entry()->SetUserText(L"?"); 195 location_bar->location_entry()->SetUserText(ASCIIToUTF16("?"));
195 EXPECT_TRUE(location_bar->GetInputString().empty()); 196 EXPECT_TRUE(location_bar->GetInputString().empty());
196 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 197 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText());
197 198
198 location_bar->FocusSearch(); 199 location_bar->FocusSearch();
199 EXPECT_TRUE(location_bar->GetInputString().empty()); 200 EXPECT_TRUE(location_bar->GetInputString().empty());
200 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 201 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText());
201 202
202 size_t selection_start, selection_end; 203 size_t selection_start, selection_end;
203 location_bar->location_entry()->GetSelectionBounds(&selection_start, 204 location_bar->location_entry()->GetSelectionBounds(&selection_start,
204 &selection_end); 205 &selection_end);
205 EXPECT_EQ(1U, selection_start); 206 EXPECT_EQ(1U, selection_start);
206 EXPECT_EQ(1U, selection_end); 207 EXPECT_EQ(1U, selection_end);
207 } 208 }
208 209
209 // Focus search when omnibox _is_ already in forced query mode, and some query 210 // Focus search when omnibox _is_ already in forced query mode, and some query
210 // has been typed. 211 // has been typed.
211 { 212 {
212 location_bar->location_entry()->SetUserText(L"?foo"); 213 location_bar->location_entry()->SetUserText(ASCIIToUTF16("?foo"));
213 EXPECT_TRUE(location_bar->GetInputString().empty()); 214 EXPECT_TRUE(location_bar->GetInputString().empty());
214 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); 215 EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText());
215 216
216 location_bar->FocusSearch(); 217 location_bar->FocusSearch();
217 EXPECT_TRUE(location_bar->GetInputString().empty()); 218 EXPECT_TRUE(location_bar->GetInputString().empty());
218 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); 219 EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText());
219 220
220 size_t selection_start, selection_end; 221 size_t selection_start, selection_end;
221 location_bar->location_entry()->GetSelectionBounds(&selection_start, 222 location_bar->location_entry()->GetSelectionBounds(&selection_start,
222 &selection_end); 223 &selection_end);
223 EXPECT_EQ(1U, std::min(selection_start, selection_end)); 224 EXPECT_EQ(1U, std::min(selection_start, selection_end));
224 EXPECT_EQ(4U, std::max(selection_start, selection_end)); 225 EXPECT_EQ(4U, std::max(selection_start, selection_end));
225 } 226 }
226 227
227 // Focus search when omnibox is in forced query mode with leading whitespace. 228 // Focus search when omnibox is in forced query mode with leading whitespace.
228 { 229 {
229 location_bar->location_entry()->SetUserText(L" ?foo"); 230 location_bar->location_entry()->SetUserText(ASCIIToUTF16(" ?foo"));
230 EXPECT_TRUE(location_bar->GetInputString().empty()); 231 EXPECT_TRUE(location_bar->GetInputString().empty());
231 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); 232 EXPECT_EQ(ASCIIToUTF16(" ?foo"),
233 location_bar->location_entry()->GetText());
232 234
233 location_bar->FocusSearch(); 235 location_bar->FocusSearch();
234 EXPECT_TRUE(location_bar->GetInputString().empty()); 236 EXPECT_TRUE(location_bar->GetInputString().empty());
235 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); 237 EXPECT_EQ(ASCIIToUTF16(" ?foo"),
238 location_bar->location_entry()->GetText());
236 239
237 size_t selection_start, selection_end; 240 size_t selection_start, selection_end;
238 location_bar->location_entry()->GetSelectionBounds(&selection_start, 241 location_bar->location_entry()->GetSelectionBounds(&selection_start,
239 &selection_end); 242 &selection_end);
240 EXPECT_EQ(4U, std::min(selection_start, selection_end)); 243 EXPECT_EQ(4U, std::min(selection_start, selection_end));
241 EXPECT_EQ(7U, std::max(selection_start, selection_end)); 244 EXPECT_EQ(7U, std::max(selection_start, selection_end));
242 } 245 }
243 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698