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