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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete.h" 10 #include "chrome/browser/autocomplete/autocomplete.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 11 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #include "chrome/browser/ui/gtk/gtk_util.h"
12 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
13 14
14 namespace { 15 namespace {
15 16
16 static const float kLargeWidth = 10000; 17 static const float kLargeWidth = 10000;
17 18
18 const GdkColor kContentTextColor = GDK_COLOR_RGB(0x00, 0x00, 0x00); 19 const GdkColor kContentTextColor = GDK_COLOR_RGB(0x00, 0x00, 0x00);
(...skipping 18 matching lines...) Expand all
37 gtk_widget_destroy(window_); 38 gtk_widget_destroy(window_);
38 39
39 PlatformTest::TearDown(); 40 PlatformTest::TearDown();
40 } 41 }
41 42
42 // The google C++ Testing Framework documentation suggests making 43 // The google C++ Testing Framework documentation suggests making
43 // accessors in the fixture so that each test doesn't need to be a 44 // accessors in the fixture so that each test doesn't need to be a
44 // friend of the class being tested. This method just proxies the 45 // friend of the class being tested. This method just proxies the
45 // call through after adding the fixture's layout_. 46 // call through after adding the fixture's layout_.
46 void SetupLayoutForMatch( 47 void SetupLayoutForMatch(
47 const std::wstring& text, 48 const string16& text,
48 const AutocompleteMatch::ACMatchClassifications& classifications, 49 const AutocompleteMatch::ACMatchClassifications& classifications,
49 const GdkColor* base_color, 50 const GdkColor* base_color,
50 const GdkColor* dim_color, 51 const GdkColor* dim_color,
51 const GdkColor* url_color, 52 const GdkColor* url_color,
52 const std::string& prefix_text) { 53 const std::string& prefix_text) {
53 AutocompletePopupViewGtk::SetupLayoutForMatch(layout_, 54 AutocompletePopupViewGtk::SetupLayoutForMatch(layout_,
54 text, 55 text,
55 classifications, 56 classifications,
56 base_color, 57 base_color,
57 dim_color, 58 dim_color,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 PangoLayout* layout_; 182 PangoLayout* layout_;
182 183
183 private: 184 private:
184 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtkTest); 185 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtkTest);
185 }; 186 };
186 187
187 // Simple inputs with no matches should result in styled output who's 188 // Simple inputs with no matches should result in styled output who's
188 // text matches the input string, with the passed-in color, and 189 // text matches the input string, with the passed-in color, and
189 // nothing bolded. 190 // nothing bolded.
190 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringNoMatch) { 191 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringNoMatch) {
191 const std::wstring kContents = L"This is a test"; 192 const string16 kContents = ASCIIToUTF16("This is a test");
192 193
193 AutocompleteMatch::ACMatchClassifications classifications; 194 AutocompleteMatch::ACMatchClassifications classifications;
194 195
195 SetupLayoutForMatch(kContents, 196 SetupLayoutForMatch(kContents,
196 classifications, 197 classifications,
197 &kContentTextColor, 198 &kContentTextColor,
198 &kDimContentTextColor, 199 &kDimContentTextColor,
199 &kURLTextColor, 200 &kURLTextColor,
200 std::string()); 201 std::string());
201 202
(...skipping 15 matching lines...) Expand all
217 EXPECT_EQ(kContents.size(), weightLength); 218 EXPECT_EQ(kContents.size(), weightLength);
218 EXPECT_TRUE(RunHasWeight(0U, 219 EXPECT_TRUE(RunHasWeight(0U,
219 kContents.size(), 220 kContents.size(),
220 PANGO_WEIGHT_NORMAL)); 221 PANGO_WEIGHT_NORMAL));
221 } 222 }
222 } 223 }
223 224
224 // Identical to DecorateMatchedStringNoMatch, except test that URL 225 // Identical to DecorateMatchedStringNoMatch, except test that URL
225 // style gets a different color than we passed in. 226 // style gets a different color than we passed in.
226 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLNoMatch) { 227 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLNoMatch) {
227 const std::wstring kContents = L"This is a test"; 228 const string16 kContents = ASCIIToUTF16("This is a test");
228 AutocompleteMatch::ACMatchClassifications classifications; 229 AutocompleteMatch::ACMatchClassifications classifications;
229 230
230 classifications.push_back( 231 classifications.push_back(
231 ACMatchClassification(0U, ACMatchClassification::URL)); 232 ACMatchClassification(0U, ACMatchClassification::URL));
232 233
233 SetupLayoutForMatch(kContents, 234 SetupLayoutForMatch(kContents,
234 classifications, 235 classifications,
235 &kContentTextColor, 236 &kContentTextColor,
236 &kDimContentTextColor, 237 &kDimContentTextColor,
237 &kURLTextColor, 238 &kURLTextColor,
(...skipping 15 matching lines...) Expand all
253 if (weightLength) { 254 if (weightLength) {
254 EXPECT_EQ(kContents.size(), weightLength); 255 EXPECT_EQ(kContents.size(), weightLength);
255 EXPECT_TRUE(RunHasWeight(0U, 256 EXPECT_TRUE(RunHasWeight(0U,
256 kContents.size(), 257 kContents.size(),
257 PANGO_WEIGHT_NORMAL)); 258 PANGO_WEIGHT_NORMAL));
258 } 259 }
259 } 260 }
260 261
261 // Test that DIM works as expected. 262 // Test that DIM works as expected.
262 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringDimNoMatch) { 263 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringDimNoMatch) {
263 const std::wstring kContents = L"This is a test"; 264 const string16 kContents = ASCIIToUTF16("This is a test");
264 // Dim "is". 265 // Dim "is".
265 const guint runLength1 = 5, runLength2 = 2, runLength3 = 7; 266 const guint runLength1 = 5, runLength2 = 2, runLength3 = 7;
266 // Make sure nobody messed up the inputs. 267 // Make sure nobody messed up the inputs.
267 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size()); 268 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
268 269
269 // Push each run onto classifications. 270 // Push each run onto classifications.
270 AutocompleteMatch::ACMatchClassifications classifications; 271 AutocompleteMatch::ACMatchClassifications classifications;
271 classifications.push_back( 272 classifications.push_back(
272 ACMatchClassification(0U, ACMatchClassification::NONE)); 273 ACMatchClassification(0U, ACMatchClassification::NONE));
273 classifications.push_back( 274 classifications.push_back(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_EQ(kContents.size(), weightLength); 316 EXPECT_EQ(kContents.size(), weightLength);
316 EXPECT_TRUE(RunHasWeight(0U, 317 EXPECT_TRUE(RunHasWeight(0U,
317 kContents.size(), 318 kContents.size(),
318 PANGO_WEIGHT_NORMAL)); 319 PANGO_WEIGHT_NORMAL));
319 } 320 }
320 } 321 }
321 322
322 // Test that the matched run gets bold-faced, but keeps the same 323 // Test that the matched run gets bold-faced, but keeps the same
323 // color. 324 // color.
324 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringMatch) { 325 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringMatch) {
325 const std::wstring kContents = L"This is a test"; 326 const string16 kContents = ASCIIToUTF16("This is a test");
326 // Match "is". 327 // Match "is".
327 const guint runLength1 = 5, runLength2 = 2, runLength3 = 7; 328 const guint runLength1 = 5, runLength2 = 2, runLength3 = 7;
328 // Make sure nobody messed up the inputs. 329 // Make sure nobody messed up the inputs.
329 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size()); 330 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
330 331
331 // Push each run onto classifications. 332 // Push each run onto classifications.
332 AutocompleteMatch::ACMatchClassifications classifications; 333 AutocompleteMatch::ACMatchClassifications classifications;
333 classifications.push_back( 334 classifications.push_back(
334 ACMatchClassification(0U, ACMatchClassification::NONE)); 335 ACMatchClassification(0U, ACMatchClassification::NONE));
335 classifications.push_back( 336 classifications.push_back(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 RunLengthForAttrType(0U, 374 RunLengthForAttrType(0U,
374 kContents.size(), 375 kContents.size(),
375 PANGO_ATTR_FOREGROUND)); 376 PANGO_ATTR_FOREGROUND));
376 EXPECT_TRUE(RunHasColor(0U, 377 EXPECT_TRUE(RunHasColor(0U,
377 kContents.size(), 378 kContents.size(),
378 kContentTextColor)); 379 kContentTextColor));
379 } 380 }
380 381
381 // Just like DecorateMatchedStringURLMatch, this time with URL style. 382 // Just like DecorateMatchedStringURLMatch, this time with URL style.
382 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLMatch) { 383 TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLMatch) {
383 const std::wstring kContents = L"http://hello.world/"; 384 const string16 kContents = ASCIIToUTF16("http://hello.world/");
384 // Match "hello". 385 // Match "hello".
385 const guint runLength1 = 7, runLength2 = 5, runLength3 = 7; 386 const guint runLength1 = 7, runLength2 = 5, runLength3 = 7;
386 // Make sure nobody messed up the inputs. 387 // Make sure nobody messed up the inputs.
387 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size()); 388 EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
388 389
389 // Push each run onto classifications. 390 // Push each run onto classifications.
390 AutocompleteMatch::ACMatchClassifications classifications; 391 AutocompleteMatch::ACMatchClassifications classifications;
391 classifications.push_back( 392 classifications.push_back(
392 ACMatchClassification(0U, ACMatchClassification::URL)); 393 ACMatchClassification(0U, ACMatchClassification::URL));
393 const int kURLMatch = 394 const int kURLMatch =
(...skipping 15 matching lines...) Expand all
409 // One color for the entire string, and it's not the one we passed 410 // One color for the entire string, and it's not the one we passed
410 // in. 411 // in.
411 EXPECT_EQ(kContents.size(), 412 EXPECT_EQ(kContents.size(),
412 RunLengthForAttrType(0U, 413 RunLengthForAttrType(0U,
413 kContents.size(), 414 kContents.size(),
414 PANGO_ATTR_FOREGROUND)); 415 PANGO_ATTR_FOREGROUND));
415 EXPECT_TRUE(RunHasColor(0U, 416 EXPECT_TRUE(RunHasColor(0U,
416 kContents.size(), 417 kContents.size(),
417 kURLTextColor)); 418 kURLTextColor));
418 } 419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698