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

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

Issue 229733004: Omnibox: Make Bookmarks Set Inline_Autocompletion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's comments Created 6 years, 8 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/bookmark_provider.h" 5 #include "chrome/browser/autocomplete/bookmark_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/autocomplete/autocomplete_provider.h" 16 #include "chrome/browser/autocomplete/autocomplete_provider.h"
17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
18 #include "chrome/browser/bookmarks/bookmark_model.h" 18 #include "chrome/browser/bookmarks/bookmark_model.h"
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
20 #include "chrome/browser/bookmarks/bookmark_title_match.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 // The bookmark corpus against which we will simulate searches. 24 // The bookmark corpus against which we will simulate searches.
24 struct BookmarksTestInfo { 25 struct BookmarksTestInfo {
25 std::string title; 26 std::string title;
26 std::string url; 27 std::string url;
27 } bookmark_provider_test_data[] = { 28 } bookmark_provider_test_data[] = {
28 { "abc def", "http://www.catsanddogs.com/a" }, 29 { "abc def", "http://www.catsanddogs.com/a" },
29 { "abcde", "http://www.catsanddogs.com/b" }, 30 { "abcde", "http://www.catsanddogs.com/b" },
30 { "abcdef", "http://www.catsanddogs.com/c" }, 31 { "abcdef", "http://www.catsanddogs.com/c" },
31 { "a definition", "http://www.catsanddogs.com/d" }, 32 { "a definition", "http://www.catsanddogs.com/d" },
32 { "carry carbon carefully", "http://www.catsanddogs.com/e" }, 33 { "carry carbon carefully", "http://www.catsanddogs.com/e" },
33 { "ghi jkl", "http://www.catsanddogs.com/f" }, 34 { "ghi jkl", "http://www.catsanddogs.com/f" },
34 { "jkl ghi", "http://www.catsanddogs.com/g" }, 35 { "jkl ghi", "http://www.catsanddogs.com/g" },
35 { "frankly frankly frank", "http://www.catsanddogs.com/h" }, 36 { "frankly frankly frank", "http://www.catsanddogs.com/h" },
36 { "foobar foobar", "http://www.foobar.com/" }, 37 { "foobar foobar", "http://www.foobar.com/" },
38 // For testing inline_autocompletion.
39 { "http://blah.com/", "http://blah.com/" },
40 { "http://fiddle.com/", "http://fiddle.com/" },
41 { "http://www.www.com/", "http://www.www.com/" },
42 { "chrome://version", "chrome://version" },
43 { "chrome://omnibox", "chrome://omnibox" },
37 // For testing ranking with different URLs. 44 // For testing ranking with different URLs.
38 {"achlorhydric featherheads resuscitates mockingbirds", 45 {"achlorhydric featherheads resuscitates mockingbirds",
39 "http://www.featherheads.com/a" }, 46 "http://www.featherheads.com/a" },
40 {"achlorhydric mockingbirds resuscitates featherhead", 47 {"achlorhydric mockingbirds resuscitates featherhead",
41 "http://www.featherheads.com/b" }, 48 "http://www.featherheads.com/b" },
42 {"featherhead resuscitates achlorhydric mockingbirds", 49 {"featherhead resuscitates achlorhydric mockingbirds",
43 "http://www.featherheads.com/c" }, 50 "http://www.featherheads.com/c" },
44 {"mockingbirds resuscitates featherheads achlorhydric", 51 {"mockingbirds resuscitates featherheads achlorhydric",
45 "http://www.featherheads.com/d" }, 52 "http://www.featherheads.com/d" },
46 // For testing URL boosting. 53 // For testing URL boosting.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 continue; 339 continue;
333 EXPECT_LT(j, matches.size()) << " Missing match '" 340 EXPECT_LT(j, matches.size()) << " Missing match '"
334 << query_data[i].matches[j] << "' for query: '" 341 << query_data[i].matches[j] << "' for query: '"
335 << query_data[i].query << "'."; 342 << query_data[i].query << "'.";
336 if (j >= matches.size()) 343 if (j >= matches.size())
337 continue; 344 continue;
338 EXPECT_EQ(query_data[i].matches[j], 345 EXPECT_EQ(query_data[i].matches[j],
339 base::UTF16ToUTF8(matches[j].description)) 346 base::UTF16ToUTF8(matches[j].description))
340 << " Mismatch at [" << base::IntToString(j) << "] for query '" 347 << " Mismatch at [" << base::IntToString(j) << "] for query '"
341 << query_data[i].query << "'."; 348 << query_data[i].query << "'.";
342 EXPECT_FALSE(matches[j].allowed_to_be_default_match);
343 } 349 }
344 } 350 }
345 } 351 }
352
353 TEST_F(BookmarkProviderTest, InlineAutocompletion) {
354 // Simulate searches.
355 struct QueryData {
356 const std::string query;
357 const std::string url;
358 const bool allowed_to_be_default_match;
359 const std::string inline_autocompletion;
360 } query_data[] = {
361 { "bla", "http://blah.com/", true, "h.com" },
362 { "blah ", "http://blah.com/", false, ".com" },
363 { "http://bl", "http://blah.com/", true, "ah.com" },
364 { "fiddle.c", "http://fiddle.com/", true, "om" },
365 { "www", "http://www.www.com/", true, ".com" },
366 { "chro", "chrome://version", true, "me://version" },
367 { "chrome://ve", "chrome://version", true, "rsion" },
368 { "chrome ver", "chrome://version", false, "" },
369 { "versi", "chrome://version", false, "" },
370 { "abou", "chrome://omnibox", false, "" },
371 { "about:om", "chrome://omnibox", true, "nibox" }
372 // Note: when adding a new URL to this test, be sure to add it to the list
373 // of bookmarks at the top of the file as well. All items in this list
374 // need to be in the bookmarks list because BookmarkProvider's
375 // TitleMatchToACMatch() has an assertion that verifies the URL is
376 // actually bookmarked.
377 };
378
379 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
380 const std::string description = "for query=" + query_data[i].query +
381 " and url=" + query_data[i].url;
382 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
383 base::string16::npos, base::string16(), GURL(),
384 AutocompleteInput::INVALID_SPEC, false, false,
385 false, AutocompleteInput::ALL_MATCHES);
386 AutocompleteInput fixed_up_input(input);
387 provider_->FixupUserInput(&fixed_up_input);
388 BookmarkNode node(GURL(query_data[i].url));
389 node.SetTitle(base::ASCIIToUTF16(query_data[i].url));
390 BookmarkTitleMatch bookmark_match;
391 bookmark_match.node = &node;
392 const AutocompleteMatch& ac_match =
393 provider_->TitleMatchToACMatch(input, fixed_up_input, bookmark_match);
394 EXPECT_EQ(query_data[i].allowed_to_be_default_match,
395 ac_match.allowed_to_be_default_match) << description;
396 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].inline_autocompletion),
397 ac_match.inline_autocompletion) << description;
398 }
399 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/bookmark_provider.cc ('k') | chrome/browser/autocomplete/builtin_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698