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/shortcuts_provider_unittest.cc

Issue 10831004: Several changes to speed up the ShortcutsProvider: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shortcuts_provider.h" 5 #include "chrome/browser/autocomplete/shortcuts_provider.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 TEST_F(ShortcutsProviderTest, DaysAgoMatches) { 297 TEST_F(ShortcutsProviderTest, DaysAgoMatches) {
298 string16 text(ASCIIToUTF16("ago")); 298 string16 text(ASCIIToUTF16("ago"));
299 std::vector<std::string> expected_urls; 299 std::vector<std::string> expected_urls;
300 expected_urls.push_back("http://www.daysagotest.com/a.html"); 300 expected_urls.push_back("http://www.daysagotest.com/a.html");
301 expected_urls.push_back("http://www.daysagotest.com/b.html"); 301 expected_urls.push_back("http://www.daysagotest.com/b.html");
302 expected_urls.push_back("http://www.daysagotest.com/c.html"); 302 expected_urls.push_back("http://www.daysagotest.com/c.html");
303 RunTest(text, expected_urls, "http://www.daysagotest.com/a.html"); 303 RunTest(text, expected_urls, "http://www.daysagotest.com/a.html");
304 } 304 }
305 305
306 // Helper class to make running tests of ClassifyAllMatchesInString() more
307 // convenient.
308 class ClassifyTest {
309 public:
310 ClassifyTest(const string16& text, ACMatchClassifications matches);
311 ~ClassifyTest();
312
313 ACMatchClassifications RunTest(const string16& find_text);
314
315 private:
316 const string16 text_;
317 const ACMatchClassifications matches_;
318 };
319
320 ClassifyTest::ClassifyTest(const string16& text, ACMatchClassifications matches)
321 : text_(text),
322 matches_(matches) {
323 }
324
325 ClassifyTest::~ClassifyTest() {
326 }
327
328 ACMatchClassifications ClassifyTest::RunTest(const string16& find_text) {
329 return ShortcutsProvider::ClassifyAllMatchesInString(find_text,
330 ShortcutsProvider::CreateWordMapForString(find_text), text_, matches_);
331 }
332
306 TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) { 333 TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) {
307 string16 data(ASCIIToUTF16("A man, a plan, a canal Panama"));
308 ACMatchClassifications matches; 334 ACMatchClassifications matches;
309 // Non-matched text does not have special attributes.
310 matches.push_back(ACMatchClassification(0, ACMatchClassification::NONE)); 335 matches.push_back(ACMatchClassification(0, ACMatchClassification::NONE));
336 ClassifyTest classify_test(ASCIIToUTF16("A man, a plan, a canal Panama"),
337 matches);
311 338
312 ACMatchClassifications spans_a = 339 ACMatchClassifications spans_a = classify_test.RunTest(ASCIIToUTF16("man"));
313 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("man"),
314 data,
315 matches);
316 // ACMatch spans should be: '--MMM------------------------' 340 // ACMatch spans should be: '--MMM------------------------'
317 ASSERT_EQ(3U, spans_a.size()); 341 ASSERT_EQ(3U, spans_a.size());
318 EXPECT_EQ(0U, spans_a[0].offset); 342 EXPECT_EQ(0U, spans_a[0].offset);
319 EXPECT_EQ(ACMatchClassification::NONE, spans_a[0].style); 343 EXPECT_EQ(ACMatchClassification::NONE, spans_a[0].style);
320 EXPECT_EQ(2U, spans_a[1].offset); 344 EXPECT_EQ(2U, spans_a[1].offset);
321 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[1].style); 345 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[1].style);
322 EXPECT_EQ(5U, spans_a[2].offset); 346 EXPECT_EQ(5U, spans_a[2].offset);
323 EXPECT_EQ(ACMatchClassification::NONE, spans_a[2].style); 347 EXPECT_EQ(ACMatchClassification::NONE, spans_a[2].style);
324 348
325 ACMatchClassifications spans_b = 349 ACMatchClassifications spans_b = classify_test.RunTest(ASCIIToUTF16("man p"));
326 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("man p"),
327 data,
328 matches);
329 // ACMatch spans should be: '--MMM----M-------------M-----' 350 // ACMatch spans should be: '--MMM----M-------------M-----'
330 ASSERT_EQ(7U, spans_b.size()); 351 ASSERT_EQ(7U, spans_b.size());
331 EXPECT_EQ(0U, spans_b[0].offset); 352 EXPECT_EQ(0U, spans_b[0].offset);
332 EXPECT_EQ(ACMatchClassification::NONE, spans_b[0].style); 353 EXPECT_EQ(ACMatchClassification::NONE, spans_b[0].style);
333 EXPECT_EQ(2U, spans_b[1].offset); 354 EXPECT_EQ(2U, spans_b[1].offset);
334 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[1].style); 355 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[1].style);
335 EXPECT_EQ(5U, spans_b[2].offset); 356 EXPECT_EQ(5U, spans_b[2].offset);
336 EXPECT_EQ(ACMatchClassification::NONE, spans_b[2].style); 357 EXPECT_EQ(ACMatchClassification::NONE, spans_b[2].style);
337 EXPECT_EQ(9U, spans_b[3].offset); 358 EXPECT_EQ(9U, spans_b[3].offset);
338 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[3].style); 359 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[3].style);
339 EXPECT_EQ(10U, spans_b[4].offset); 360 EXPECT_EQ(10U, spans_b[4].offset);
340 EXPECT_EQ(ACMatchClassification::NONE, spans_b[4].style); 361 EXPECT_EQ(ACMatchClassification::NONE, spans_b[4].style);
341 EXPECT_EQ(23U, spans_b[5].offset); 362 EXPECT_EQ(23U, spans_b[5].offset);
342 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[5].style); 363 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[5].style);
343 EXPECT_EQ(24U, spans_b[6].offset); 364 EXPECT_EQ(24U, spans_b[6].offset);
344 EXPECT_EQ(ACMatchClassification::NONE, spans_b[6].style); 365 EXPECT_EQ(ACMatchClassification::NONE, spans_b[6].style);
345 366
346 ACMatchClassifications spans_c = 367 ACMatchClassifications spans_c =
347 ShortcutsProvider::ClassifyAllMatchesInString( 368 classify_test.RunTest(ASCIIToUTF16("man plan panama"));
348 ASCIIToUTF16("man plan panama"), data, matches);
349 // ACMatch spans should be:'--MMM----MMMM----------MMMMMM' 369 // ACMatch spans should be:'--MMM----MMMM----------MMMMMM'
350 ASSERT_EQ(6U, spans_c.size()); 370 ASSERT_EQ(6U, spans_c.size());
351 EXPECT_EQ(0U, spans_c[0].offset); 371 EXPECT_EQ(0U, spans_c[0].offset);
352 EXPECT_EQ(ACMatchClassification::NONE, spans_c[0].style); 372 EXPECT_EQ(ACMatchClassification::NONE, spans_c[0].style);
353 EXPECT_EQ(2U, spans_c[1].offset); 373 EXPECT_EQ(2U, spans_c[1].offset);
354 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[1].style); 374 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[1].style);
355 EXPECT_EQ(5U, spans_c[2].offset); 375 EXPECT_EQ(5U, spans_c[2].offset);
356 EXPECT_EQ(ACMatchClassification::NONE, spans_c[2].style); 376 EXPECT_EQ(ACMatchClassification::NONE, spans_c[2].style);
357 EXPECT_EQ(9U, spans_c[3].offset); 377 EXPECT_EQ(9U, spans_c[3].offset);
358 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[3].style); 378 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[3].style);
359 EXPECT_EQ(13U, spans_c[4].offset); 379 EXPECT_EQ(13U, spans_c[4].offset);
360 EXPECT_EQ(ACMatchClassification::NONE, spans_c[4].style); 380 EXPECT_EQ(ACMatchClassification::NONE, spans_c[4].style);
361 EXPECT_EQ(23U, spans_c[5].offset); 381 EXPECT_EQ(23U, spans_c[5].offset);
362 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[5].style); 382 EXPECT_EQ(ACMatchClassification::MATCH, spans_c[5].style);
363 383
364 data = ASCIIToUTF16( 384 ClassifyTest classify_test2(ASCIIToUTF16("Yahoo! Sports - Sports News, "
365 "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more"); 385 "Scores, Rumors, Fantasy Games, and more"), matches);
366 matches.clear();
367 matches.push_back(ACMatchClassification(0, ACMatchClassification::NONE));
368 386
369 ACMatchClassifications spans_d = 387 ACMatchClassifications spans_d = classify_test2.RunTest(ASCIIToUTF16("ne"));
370 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("ne"),
371 data,
372 matches);
373 // ACMatch spans should match first two letters of the "news". 388 // ACMatch spans should match first two letters of the "news".
374 ASSERT_EQ(3U, spans_d.size()); 389 ASSERT_EQ(3U, spans_d.size());
375 EXPECT_EQ(0U, spans_d[0].offset); 390 EXPECT_EQ(0U, spans_d[0].offset);
376 EXPECT_EQ(ACMatchClassification::NONE, spans_d[0].style); 391 EXPECT_EQ(ACMatchClassification::NONE, spans_d[0].style);
377 EXPECT_EQ(23U, spans_d[1].offset); 392 EXPECT_EQ(23U, spans_d[1].offset);
378 EXPECT_EQ(ACMatchClassification::MATCH, spans_d[1].style); 393 EXPECT_EQ(ACMatchClassification::MATCH, spans_d[1].style);
379 EXPECT_EQ(25U, spans_d[2].offset); 394 EXPECT_EQ(25U, spans_d[2].offset);
380 EXPECT_EQ(ACMatchClassification::NONE, spans_d[2].style); 395 EXPECT_EQ(ACMatchClassification::NONE, spans_d[2].style);
381 396
382 ACMatchClassifications spans_e = 397 ACMatchClassifications spans_e =
383 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("news r"), 398 classify_test2.RunTest(ASCIIToUTF16("news r"));
384 data,
385 matches);
386 // ACMatch spans should be the same as original matches. 399 // ACMatch spans should be the same as original matches.
387 ASSERT_EQ(15U, spans_e.size()); 400 ASSERT_EQ(15U, spans_e.size());
388 EXPECT_EQ(0U, spans_e[0].offset); 401 EXPECT_EQ(0U, spans_e[0].offset);
389 EXPECT_EQ(ACMatchClassification::NONE, spans_e[0].style); 402 EXPECT_EQ(ACMatchClassification::NONE, spans_e[0].style);
390 // "r" in "Sports". 403 // "r" in "Sports".
391 EXPECT_EQ(10U, spans_e[1].offset); 404 EXPECT_EQ(10U, spans_e[1].offset);
392 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[1].style); 405 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[1].style);
393 EXPECT_EQ(11U, spans_e[2].offset); 406 EXPECT_EQ(11U, spans_e[2].offset);
394 EXPECT_EQ(ACMatchClassification::NONE, spans_e[2].style); 407 EXPECT_EQ(ACMatchClassification::NONE, spans_e[2].style);
395 // "r" in second "Sports". 408 // "r" in second "Sports".
(...skipping 20 matching lines...) Expand all
416 EXPECT_EQ(41U, spans_e[11].offset); 429 EXPECT_EQ(41U, spans_e[11].offset);
417 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[11].style); 430 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[11].style);
418 EXPECT_EQ(42U, spans_e[12].offset); 431 EXPECT_EQ(42U, spans_e[12].offset);
419 EXPECT_EQ(ACMatchClassification::NONE, spans_e[12].style); 432 EXPECT_EQ(ACMatchClassification::NONE, spans_e[12].style);
420 // "r" in "more". 433 // "r" in "more".
421 EXPECT_EQ(66U, spans_e[13].offset); 434 EXPECT_EQ(66U, spans_e[13].offset);
422 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[13].style); 435 EXPECT_EQ(ACMatchClassification::MATCH, spans_e[13].style);
423 EXPECT_EQ(67U, spans_e[14].offset); 436 EXPECT_EQ(67U, spans_e[14].offset);
424 EXPECT_EQ(ACMatchClassification::NONE, spans_e[14].style); 437 EXPECT_EQ(ACMatchClassification::NONE, spans_e[14].style);
425 438
426 data = ASCIIToUTF16("livescore.goal.com");
427 matches.clear(); 439 matches.clear();
428 // Matches for URL.
429 matches.push_back(ACMatchClassification(0, ACMatchClassification::URL)); 440 matches.push_back(ACMatchClassification(0, ACMatchClassification::URL));
441 ClassifyTest classify_test3(ASCIIToUTF16("livescore.goal.com"), matches);
430 442
431 ACMatchClassifications spans_f = 443 ACMatchClassifications spans_f = classify_test3.RunTest(ASCIIToUTF16("go"));
432 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("go"),
433 data,
434 matches);
435 // ACMatch spans should match first two letters of the "goal". 444 // ACMatch spans should match first two letters of the "goal".
436 ASSERT_EQ(3U, spans_f.size()); 445 ASSERT_EQ(3U, spans_f.size());
437 EXPECT_EQ(0U, spans_f[0].offset); 446 EXPECT_EQ(0U, spans_f[0].offset);
438 EXPECT_EQ(ACMatchClassification::URL, spans_f[0].style); 447 EXPECT_EQ(ACMatchClassification::URL, spans_f[0].style);
439 EXPECT_EQ(10U, spans_f[1].offset); 448 EXPECT_EQ(10U, spans_f[1].offset);
440 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH, 449 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH,
441 spans_f[1].style); 450 spans_f[1].style);
442 EXPECT_EQ(12U, spans_f[2].offset); 451 EXPECT_EQ(12U, spans_f[2].offset);
443 EXPECT_EQ(ACMatchClassification::URL, spans_f[2].style); 452 EXPECT_EQ(ACMatchClassification::URL, spans_f[2].style);
444 453
445 data = ASCIIToUTF16("Email login: mail.somecorp.com");
446 matches.clear(); 454 matches.clear();
447 // Matches for URL.
448 matches.push_back(ACMatchClassification(0, ACMatchClassification::NONE)); 455 matches.push_back(ACMatchClassification(0, ACMatchClassification::NONE));
449 matches.push_back(ACMatchClassification(13, ACMatchClassification::URL)); 456 matches.push_back(ACMatchClassification(13, ACMatchClassification::URL));
457 ClassifyTest classify_test4(ASCIIToUTF16("Email login: mail.somecorp.com"),
458 matches);
450 459
451 ACMatchClassifications spans_g = 460 ACMatchClassifications spans_g = classify_test4.RunTest(ASCIIToUTF16("ail"));
452 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("ail"),
453 data,
454 matches);
455 ASSERT_EQ(6U, spans_g.size()); 461 ASSERT_EQ(6U, spans_g.size());
456 EXPECT_EQ(0U, spans_g[0].offset); 462 EXPECT_EQ(0U, spans_g[0].offset);
457 EXPECT_EQ(ACMatchClassification::NONE, spans_g[0].style); 463 EXPECT_EQ(ACMatchClassification::NONE, spans_g[0].style);
458 EXPECT_EQ(2U, spans_g[1].offset); 464 EXPECT_EQ(2U, spans_g[1].offset);
459 EXPECT_EQ(ACMatchClassification::MATCH, spans_g[1].style); 465 EXPECT_EQ(ACMatchClassification::MATCH, spans_g[1].style);
460 EXPECT_EQ(5U, spans_g[2].offset); 466 EXPECT_EQ(5U, spans_g[2].offset);
461 EXPECT_EQ(ACMatchClassification::NONE, spans_g[2].style); 467 EXPECT_EQ(ACMatchClassification::NONE, spans_g[2].style);
462 EXPECT_EQ(13U, spans_g[3].offset); 468 EXPECT_EQ(13U, spans_g[3].offset);
463 EXPECT_EQ(ACMatchClassification::URL, spans_g[3].style); 469 EXPECT_EQ(ACMatchClassification::URL, spans_g[3].style);
464 EXPECT_EQ(14U, spans_g[4].offset); 470 EXPECT_EQ(14U, spans_g[4].offset);
465 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH, 471 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH,
466 spans_g[4].style); 472 spans_g[4].style);
467 EXPECT_EQ(17U, spans_g[5].offset); 473 EXPECT_EQ(17U, spans_g[5].offset);
468 EXPECT_EQ(ACMatchClassification::URL, spans_g[5].style); 474 EXPECT_EQ(ACMatchClassification::URL, spans_g[5].style);
469 475
470 ACMatchClassifications spans_h = 476 ACMatchClassifications spans_h =
471 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("lo log"), 477 classify_test4.RunTest(ASCIIToUTF16("lo log"));
472 data,
473 matches);
474 ASSERT_EQ(4U, spans_h.size()); 478 ASSERT_EQ(4U, spans_h.size());
475 EXPECT_EQ(0U, spans_h[0].offset); 479 EXPECT_EQ(0U, spans_h[0].offset);
476 EXPECT_EQ(ACMatchClassification::NONE, spans_h[0].style); 480 EXPECT_EQ(ACMatchClassification::NONE, spans_h[0].style);
477 EXPECT_EQ(6U, spans_h[1].offset); 481 EXPECT_EQ(6U, spans_h[1].offset);
478 EXPECT_EQ(ACMatchClassification::MATCH, spans_h[1].style); 482 EXPECT_EQ(ACMatchClassification::MATCH, spans_h[1].style);
479 EXPECT_EQ(9U, spans_h[2].offset); 483 EXPECT_EQ(9U, spans_h[2].offset);
480 EXPECT_EQ(ACMatchClassification::NONE, spans_h[2].style); 484 EXPECT_EQ(ACMatchClassification::NONE, spans_h[2].style);
481 EXPECT_EQ(13U, spans_h[3].offset); 485 EXPECT_EQ(13U, spans_h[3].offset);
482 EXPECT_EQ(ACMatchClassification::URL, spans_h[3].style); 486 EXPECT_EQ(ACMatchClassification::URL, spans_h[3].style);
483 487
484 ACMatchClassifications spans_i = 488 ACMatchClassifications spans_i =
485 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("ail em"), 489 classify_test4.RunTest(ASCIIToUTF16("ail em"));
486 data,
487 matches);
488 // 'Email' and 'ail' should be matched. 490 // 'Email' and 'ail' should be matched.
489 ASSERT_EQ(5U, spans_i.size()); 491 ASSERT_EQ(5U, spans_i.size());
490 EXPECT_EQ(0U, spans_i[0].offset); 492 EXPECT_EQ(0U, spans_i[0].offset);
491 EXPECT_EQ(ACMatchClassification::MATCH, spans_i[0].style); 493 EXPECT_EQ(ACMatchClassification::MATCH, spans_i[0].style);
492 EXPECT_EQ(5U, spans_i[1].offset); 494 EXPECT_EQ(5U, spans_i[1].offset);
493 EXPECT_EQ(ACMatchClassification::NONE, spans_i[1].style); 495 EXPECT_EQ(ACMatchClassification::NONE, spans_i[1].style);
494 EXPECT_EQ(13U, spans_i[2].offset); 496 EXPECT_EQ(13U, spans_i[2].offset);
495 EXPECT_EQ(ACMatchClassification::URL, spans_i[2].style); 497 EXPECT_EQ(ACMatchClassification::URL, spans_i[2].style);
496 EXPECT_EQ(14U, spans_i[3].offset); 498 EXPECT_EQ(14U, spans_i[3].offset);
497 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH, 499 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH,
498 spans_i[3].style); 500 spans_i[3].style);
499 EXPECT_EQ(17U, spans_i[4].offset); 501 EXPECT_EQ(17U, spans_i[4].offset);
500 EXPECT_EQ(ACMatchClassification::URL, spans_i[4].style); 502 EXPECT_EQ(ACMatchClassification::URL, spans_i[4].style);
501 503
502 // Some web sites do not have a description, so second and third parameters in 504 // Some web sites do not have a description, so second and third parameters in
503 // ClassifyAllMatchesInString could be empty. 505 // ClassifyAllMatchesInString could be empty.
504 ACMatchClassifications spans_j = 506 // Extra parens in the next line hack around C++03's "most vexing parse".
505 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("man"), 507 class ClassifyTest classify_test5((string16()), ACMatchClassifications());
506 string16(), 508 ACMatchClassifications spans_j = classify_test5.RunTest(ASCIIToUTF16("man"));
507 ACMatchClassifications());
508 ASSERT_EQ(0U, spans_j.size()); 509 ASSERT_EQ(0U, spans_j.size());
509 510
510 // Matches which end at beginning of classification merge properly. 511 // Matches which end at beginning of classification merge properly.
511 data = ASCIIToUTF16("html password example");
512 matches.clear(); 512 matches.clear();
513 matches.push_back(ACMatchClassification(0, ACMatchClassification::DIM)); 513 matches.push_back(ACMatchClassification(0, ACMatchClassification::DIM));
514 matches.push_back(ACMatchClassification(9, ACMatchClassification::NONE)); 514 matches.push_back(ACMatchClassification(9, ACMatchClassification::NONE));
515 ClassifyTest classify_test6(ASCIIToUTF16("html password example"), matches);
516
517 // Extra space in the next string avoids having the string be a prefix of the
518 // text above, which would allow for two different valid classification sets,
519 // one of which uses two spans (the first of which would mark all of "html
520 // pass" as a match) and one which uses four (which marks the individual words
521 // as matches but not the space between them). This way only the latter is
522 // valid.
515 ACMatchClassifications spans_k = 523 ACMatchClassifications spans_k =
516 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("html pass"), 524 classify_test6.RunTest(ASCIIToUTF16("html pass"));
517 data,
518 matches);
519 ASSERT_EQ(4U, spans_k.size()); 525 ASSERT_EQ(4U, spans_k.size());
520 EXPECT_EQ(0U, spans_k[0].offset); 526 EXPECT_EQ(0U, spans_k[0].offset);
521 EXPECT_EQ(ACMatchClassification::DIM | ACMatchClassification::MATCH, 527 EXPECT_EQ(ACMatchClassification::DIM | ACMatchClassification::MATCH,
522 spans_k[0].style); 528 spans_k[0].style);
523 EXPECT_EQ(4U, spans_k[1].offset); 529 EXPECT_EQ(4U, spans_k[1].offset);
524 EXPECT_EQ(ACMatchClassification::DIM, spans_k[1].style); 530 EXPECT_EQ(ACMatchClassification::DIM, spans_k[1].style);
525 EXPECT_EQ(5U, spans_k[2].offset); 531 EXPECT_EQ(5U, spans_k[2].offset);
526 EXPECT_EQ(ACMatchClassification::DIM | ACMatchClassification::MATCH, 532 EXPECT_EQ(ACMatchClassification::DIM | ACMatchClassification::MATCH,
527 spans_k[2].style); 533 spans_k[2].style);
528 EXPECT_EQ(9U, spans_k[3].offset); 534 EXPECT_EQ(9U, spans_k[3].offset);
529 EXPECT_EQ(ACMatchClassification::NONE, spans_k[3].style); 535 EXPECT_EQ(ACMatchClassification::NONE, spans_k[3].style);
530 536
531 // Multiple matches with both beginning and end at beginning of 537 // Multiple matches with both beginning and end at beginning of
532 // classifications merge properly. 538 // classifications merge properly.
533 data = ASCIIToUTF16("http://a.co is great");
534 matches.clear(); 539 matches.clear();
535 matches.push_back(ACMatchClassification(0, ACMatchClassification::URL)); 540 matches.push_back(ACMatchClassification(0, ACMatchClassification::URL));
536 matches.push_back(ACMatchClassification(11, ACMatchClassification::NONE)); 541 matches.push_back(ACMatchClassification(11, ACMatchClassification::NONE));
542 ClassifyTest classify_test7(ASCIIToUTF16("http://a.co is great"), matches);
543
537 ACMatchClassifications spans_l = 544 ACMatchClassifications spans_l =
538 ShortcutsProvider::ClassifyAllMatchesInString(ASCIIToUTF16("ht co"), 545 classify_test7.RunTest(ASCIIToUTF16("ht co"));
539 data,
540 matches);
541 ASSERT_EQ(4U, spans_l.size()); 546 ASSERT_EQ(4U, spans_l.size());
542 EXPECT_EQ(0U, spans_l[0].offset); 547 EXPECT_EQ(0U, spans_l[0].offset);
543 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH, 548 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH,
544 spans_l[0].style); 549 spans_l[0].style);
545 EXPECT_EQ(2U, spans_l[1].offset); 550 EXPECT_EQ(2U, spans_l[1].offset);
546 EXPECT_EQ(ACMatchClassification::URL, spans_l[1].style); 551 EXPECT_EQ(ACMatchClassification::URL, spans_l[1].style);
547 EXPECT_EQ(9U, spans_l[2].offset); 552 EXPECT_EQ(9U, spans_l[2].offset);
548 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH, 553 EXPECT_EQ(ACMatchClassification::URL | ACMatchClassification::MATCH,
549 spans_l[2].style); 554 spans_l[2].style);
550 EXPECT_EQ(11U, spans_l[3].offset); 555 EXPECT_EQ(11U, spans_l[3].offset);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 665
661 match.destination_url = GURL(shortcuts_to_test_delete[2].url); 666 match.destination_url = GURL(shortcuts_to_test_delete[2].url);
662 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[2].contents); 667 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[2].contents);
663 match.description = ASCIIToUTF16(shortcuts_to_test_delete[2].description); 668 match.description = ASCIIToUTF16(shortcuts_to_test_delete[2].description);
664 669
665 provider_->DeleteMatch(match); 670 provider_->DeleteMatch(match);
666 EXPECT_EQ(original_shortcuts_count, backend_->shortcuts_map().size()); 671 EXPECT_EQ(original_shortcuts_count, backend_->shortcuts_map().size());
667 EXPECT_TRUE(backend_->shortcuts_map().end() == 672 EXPECT_TRUE(backend_->shortcuts_map().end() ==
668 backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 673 backend_->shortcuts_map().find(ASCIIToUTF16("delete")));
669 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698