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

Unified Diff: components/omnibox/browser/shortcuts_provider_unittest.cc

Issue 1655933004: Refactor to share code between shortcuts tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shortcuts
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/shortcuts_provider_unittest.cc
diff --git a/components/omnibox/browser/shortcuts_provider_unittest.cc b/components/omnibox/browser/shortcuts_provider_unittest.cc
index 7d7fc1283bc7f2e32cbc80ece49cc7b99ce496d4..09fc764082e990e0cc097f0bcba81786b1e7afcb 100644
--- a/components/omnibox/browser/shortcuts_provider_unittest.cc
+++ b/components/omnibox/browser/shortcuts_provider_unittest.cc
@@ -32,6 +32,7 @@
#include "components/omnibox/browser/in_memory_url_index.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/shortcuts_backend.h"
+#include "components/omnibox/browser/shortcuts_provider_test_util.h"
#include "components/omnibox/browser/test_scheme_classifier.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -41,154 +42,127 @@ using base::ASCIIToUTF16;
namespace {
-struct TestShortcutInfo {
- std::string guid;
- std::string text;
- std::string fill_into_edit;
- std::string destination_url;
- std::string contents;
- std::string contents_class;
- std::string description;
- std::string description_class;
- ui::PageTransition transition;
- AutocompleteMatch::Type type;
- std::string keyword;
- int days_from_now;
- int number_of_hits;
-} shortcut_test_db[] = {
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "goog", "www.google.com",
- "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,3,4,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
- 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "slash", "slashdot.org",
- "http://slashdot.org/", "slashdot.org", "0,3,5,1",
- "Slashdot - News for nerds, stuff that matters", "0,2,5,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0,
- 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E2", "news", "slashdot.org",
- "http://slashdot.org/", "slashdot.org", "0,1",
- "Slashdot - News for nerds, stuff that matters", "0,0,11,2,15,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 0,
- 5 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E3", "news", "sports.yahoo.com",
- "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
- "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
- "0,0,23,2,27,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_TITLE, "", 2, 5 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E4", "news weather",
- "www.cnn.com/index.html", "http://www.cnn.com/index.html",
- "www.cnn.com/index.html", "0,1",
- "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video",
- "0,0,19,2,23,0,38,2,45,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_TITLE, "", 1, 10 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E5", "nhl scores", "sports.yahoo.com",
- "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
- "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
- "0,0,29,2,35,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_BODY, "", 1, 10 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E6", "nhl scores",
- "www.nhl.com/scores/index.html", "http://www.nhl.com/scores/index.html",
- "www.nhl.com/scores/index.html", "0,1,4,3,7,1",
- "January 13, 2010 - NHL.com - Scores", "0,0,19,2,22,0,29,2,35,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 5,
- 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E7", "just", "www.testsite.com/a.html",
- "http://www.testsite.com/a.html", "www.testsite.com/a.html", "0,1",
- "Test - site - just a test", "0,0,14,2,18,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5,
- 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E8", "just", "www.testsite.com/b.html",
- "http://www.testsite.com/b.html", "www.testsite.com/b.html", "0,1",
- "Test - site - just a test", "0,0,14,2,18,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5,
- 2 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880E9", "just", "www.testsite.com/c.html",
- "http://www.testsite.com/c.html", "www.testsite.com/c.html", "0,1",
- "Test - site - just a test", "0,0,14,2,18,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 8,
- 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880EA", "just a", "www.testsite.com/d.html",
- "http://www.testsite.com/d.html", "www.testsite.com/d.html", "0,1",
- "Test - site - just a test", "0,0,14,2,18,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "",
- 12, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880EB", "just a t",
- "www.testsite.com/e.html", "http://www.testsite.com/e.html",
- "www.testsite.com/e.html", "0,1", "Test - site - just a test",
- "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880EC", "just a te",
- "www.testsite.com/f.html", "http://www.testsite.com/f.html",
- "www.testsite.com/f.html", "0,1", "Test - site - just a test",
- "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880ED", "ago", "www.daysagotest.com/a.html",
- "http://www.daysagotest.com/a.html", "www.daysagotest.com/a.html",
- "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 1, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880EE", "ago", "www.daysagotest.com/b.html",
- "http://www.daysagotest.com/b.html", "www.daysagotest.com/b.html",
- "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 2, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880EF", "ago", "www.daysagotest.com/c.html",
- "http://www.daysagotest.com/c.html", "www.daysagotest.com/c.html",
- "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 3, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F0", "ago", "www.daysagotest.com/d.html",
- "http://www.daysagotest.com/d.html", "www.daysagotest.com/d.html",
- "0,1,8,3,11,1", "Test - site", "0,0", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 4, 1 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F2", "abcdef.com", "http://abcdef.com",
- "http://abcdef.com/", "Abcdef", "0,1,4,0", "Abcdef", "0,3,4,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
- 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query",
- "https://www.google.com/search?q=query", "query", "0,0",
- "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED,
- AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word",
- "https://www.google.com/search?q=www.word", "www.word", "0,0",
- "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED,
- AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox",
- "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "",
- 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp",
- "http://www/real space/long-url-with-space.html",
- "http://www/real%20space/long-url-with-space.html",
- "www/real space/long-url-with-space.html", "0,3,11,1",
- "Page With Space; Input with Space", "0,0",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
- 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F7", "duplicate", "http://duplicate.com",
- "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
- 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F8", "dupl", "http://duplicate.com",
- "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1,
- 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/",
- "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash",
- "0,1", "No Trailing Slash on fill_into_edit", "0,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
- 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com",
- "http://foo.com", "http://foo.com/", "Foo - Typo in Input",
- "0,1", "Foo - Typo in Input Corrected in fill_into_edit", "0,1",
- ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
- 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ",
- "http://trailing1.com", "http://trailing1.com/",
- "Trailing1 - Space in Shortcut", "0,1",
- "Trailing1 - Space in Shortcut", "0,1", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 1, 100 },
- { "BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ",
- "chrome://trailing2blah", "chrome://trailing2blah/",
- "Trailing2 - Space in Shortcut", "0,1",
- "Trailing2 - Space in Shortcut", "0,1", ui::PAGE_TRANSITION_TYPED,
- AutocompleteMatchType::HISTORY_URL, "", 1, 100 },
+struct TestShortcutInfo shortcut_test_db[] = {
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "goog", "www.google.com",
+ "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,3,4,1",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "slash", "slashdot.org",
+ "http://slashdot.org/", "slashdot.org", "0,3,5,1",
+ "Slashdot - News for nerds, stuff that matters", "0,2,5,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E2", "news", "slashdot.org",
+ "http://slashdot.org/", "slashdot.org", "0,1",
+ "Slashdot - News for nerds, stuff that matters", "0,0,11,2,15,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 0, 5},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E3", "news", "sports.yahoo.com",
+ "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
+ "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
+ "0,0,23,2,27,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 2, 5},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E4", "news weather",
+ "www.cnn.com/index.html", "http://www.cnn.com/index.html",
+ "www.cnn.com/index.html", "0,1",
+ "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video",
+ "0,0,19,2,23,0,38,2,45,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 1, 10},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E5", "nhl scores", "sports.yahoo.com",
+ "http://sports.yahoo.com/", "sports.yahoo.com", "0,1",
+ "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more",
+ "0,0,29,2,35,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_BODY, "", 1, 10},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E6", "nhl scores",
+ "www.nhl.com/scores/index.html", "http://www.nhl.com/scores/index.html",
+ "www.nhl.com/scores/index.html", "0,1,4,3,7,1",
+ "January 13, 2010 - NHL.com - Scores", "0,0,19,2,22,0,29,2,35,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 5, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E7", "just", "www.testsite.com/a.html",
+ "http://www.testsite.com/a.html", "www.testsite.com/a.html", "0,1",
+ "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 5, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E8", "just", "www.testsite.com/b.html",
+ "http://www.testsite.com/b.html", "www.testsite.com/b.html", "0,1",
+ "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 5, 2},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880E9", "just", "www.testsite.com/c.html",
+ "http://www.testsite.com/c.html", "www.testsite.com/c.html", "0,1",
+ "Test - site - just a test", "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 8, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880EA", "just a",
+ "www.testsite.com/d.html", "http://www.testsite.com/d.html",
+ "www.testsite.com/d.html", "0,1", "Test - site - just a test",
+ "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880EB", "just a t",
+ "www.testsite.com/e.html", "http://www.testsite.com/e.html",
+ "www.testsite.com/e.html", "0,1", "Test - site - just a test",
+ "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880EC", "just a te",
+ "www.testsite.com/f.html", "http://www.testsite.com/f.html",
+ "www.testsite.com/f.html", "0,1", "Test - site - just a test",
+ "0,0,14,2,18,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_TITLE, "", 12, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880ED", "ago",
+ "www.daysagotest.com/a.html", "http://www.daysagotest.com/a.html",
+ "www.daysagotest.com/a.html", "0,1,8,3,11,1", "Test - site", "0,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880EE", "ago",
+ "www.daysagotest.com/b.html", "http://www.daysagotest.com/b.html",
+ "www.daysagotest.com/b.html", "0,1,8,3,11,1", "Test - site", "0,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 2, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880EF", "ago",
+ "www.daysagotest.com/c.html", "http://www.daysagotest.com/c.html",
+ "www.daysagotest.com/c.html", "0,1,8,3,11,1", "Test - site", "0,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 3, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F0", "ago",
+ "www.daysagotest.com/d.html", "http://www.daysagotest.com/d.html",
+ "www.daysagotest.com/d.html", "0,1,8,3,11,1", "Test - site", "0,0",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 4, 1},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F2", "abcdef.com", "http://abcdef.com",
+ "http://abcdef.com/", "Abcdef", "0,1,4,0", "Abcdef", "0,3,4,1",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query",
+ "https://www.google.com/search?q=query", "query", "0,0", "Google Search",
+ "0,4", ui::PAGE_TRANSITION_GENERATED,
+ AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word",
+ "https://www.google.com/search?q=www.word", "www.word", "0,0",
+ "Google Search", "0,4", ui::PAGE_TRANSITION_GENERATED,
+ AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox",
+ "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp",
+ "http://www/real space/long-url-with-space.html",
+ "http://www/real%20space/long-url-with-space.html",
+ "www/real space/long-url-with-space.html", "0,3,11,1",
+ "Page With Space; Input with Space", "0,0", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F7", "duplicate",
+ "http://duplicate.com", "http://duplicate.com/", "Duplicate", "0,1",
+ "Duplicate", "0,1", ui::PAGE_TRANSITION_TYPED,
+ AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F8", "dupl", "http://duplicate.com",
+ "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/",
+ "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash",
+ "0,1", "No Trailing Slash on fill_into_edit", "0,1",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com",
+ "http://foo.com", "http://foo.com/", "Foo - Typo in Input", "0,1",
+ "Foo - Typo in Input Corrected in fill_into_edit", "0,1",
+ ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ",
+ "http://trailing1.com", "http://trailing1.com/",
+ "Trailing1 - Space in Shortcut", "0,1", "Trailing1 - Space in Shortcut",
+ "0,1", ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
+ 1, 100},
+ {"BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ",
+ "chrome://trailing2blah", "chrome://trailing2blah/",
+ "Trailing2 - Space in Shortcut", "0,1", "Trailing2 - Space in Shortcut",
+ "0,1", ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "",
+ 1, 100},
};
class FakeAutocompleteProviderClient
@@ -277,42 +251,9 @@ class ShortcutsProviderTest : public testing::Test {
ShortcutsProviderTest();
protected:
- typedef std::pair<std::string, bool> ExpectedURLAndAllowedToBeDefault;
- typedef std::vector<ExpectedURLAndAllowedToBeDefault> ExpectedURLs;
-
- class SetShouldContain
- : public std::unary_function<const ExpectedURLAndAllowedToBeDefault&,
- std::set<std::string> > {
- public:
- explicit SetShouldContain(const ACMatches& matched_urls);
-
- void operator()(const ExpectedURLAndAllowedToBeDefault& expected);
- std::set<ExpectedURLAndAllowedToBeDefault> Leftovers() const {
- return matches_;
- }
-
- private:
- std::set<ExpectedURLAndAllowedToBeDefault> matches_;
- };
-
void SetUp() override;
void TearDown() override;
- // Fills test data into the provider.
- void FillData(TestShortcutInfo* db, size_t db_size);
-
- // Runs an autocomplete query on |text| with the provided
- // |prevent_inline_autocomplete| setting and checks to see that the returned
- // results' destination URLs match those provided. |expected_urls| does not
- // need to be in sorted order, but |expected_top_result| should be the top
- // match, and it should have inline autocompletion
- // |top_result_inline_autocompletion|.
- void RunTest(const base::string16 text,
- bool prevent_inline_autocomplete,
- const ExpectedURLs& expected_urls,
- std::string expected_top_result,
- base::string16 top_result_inline_autocompletion);
-
// Passthrough to the private function in provider_.
int CalculateScore(const std::string& terms,
const ShortcutsDatabase::Shortcut& shortcut,
@@ -321,8 +262,6 @@ class ShortcutsProviderTest : public testing::Test {
base::MessageLoop message_loop_;
scoped_ptr<FakeAutocompleteProviderClient> client_;
scoped_refptr<ShortcutsProvider> provider_;
-
- ACMatches ac_matches_; // The resulting matches after running RunTest.
};
ShortcutsProviderTest::ShortcutsProviderTest() {
@@ -333,7 +272,9 @@ void ShortcutsProviderTest::SetUp() {
ASSERT_TRUE(client_->GetShortcutsBackend());
provider_ = new ShortcutsProvider(client_.get());
- FillData(shortcut_test_db, arraysize(shortcut_test_db));
+ PopulateShortcutsBackendWithTestShortcutData(client_->GetShortcutsBackend(),
+ shortcut_test_db,
+ arraysize(shortcut_test_db));
}
void ShortcutsProviderTest::TearDown() {
@@ -343,79 +284,6 @@ void ShortcutsProviderTest::TearDown() {
provider_ = NULL;
}
-void ShortcutsProviderTest::FillData(TestShortcutInfo* db, size_t db_size) {
- DCHECK(provider_.get());
- scoped_refptr<ShortcutsBackend> backend = client_->GetShortcutsBackend();
- size_t expected_size = backend->shortcuts_map().size() + db_size;
- for (size_t i = 0; i < db_size; ++i) {
- const TestShortcutInfo& cur = db[i];
- ShortcutsDatabase::Shortcut shortcut(
- cur.guid, ASCIIToUTF16(cur.text),
- ShortcutsDatabase::Shortcut::MatchCore(
- ASCIIToUTF16(cur.fill_into_edit), GURL(cur.destination_url),
- ASCIIToUTF16(cur.contents), cur.contents_class,
- ASCIIToUTF16(cur.description), cur.description_class,
- cur.transition, cur.type, ASCIIToUTF16(cur.keyword)),
- base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now),
- cur.number_of_hits);
- backend->AddShortcut(shortcut);
- }
- EXPECT_EQ(expected_size, backend->shortcuts_map().size());
-}
-
-ShortcutsProviderTest::SetShouldContain::SetShouldContain(
- const ACMatches& matched_urls) {
- for (ACMatches::const_iterator iter = matched_urls.begin();
- iter != matched_urls.end(); ++iter)
- matches_.insert(ExpectedURLAndAllowedToBeDefault(
- iter->destination_url.spec(), iter->allowed_to_be_default_match));
-}
-
-void ShortcutsProviderTest::SetShouldContain::operator()(
- const ExpectedURLAndAllowedToBeDefault& expected) {
- EXPECT_EQ(1U, matches_.erase(expected));
-}
-
-void ShortcutsProviderTest::RunTest(
- const base::string16 text,
- bool prevent_inline_autocomplete,
- const ExpectedURLs& expected_urls,
- std::string expected_top_result,
- base::string16 top_result_inline_autocompletion) {
- base::MessageLoop::current()->RunUntilIdle();
- AutocompleteInput input(text, base::string16::npos, std::string(), GURL(),
- metrics::OmniboxEventProto::INVALID_SPEC,
- prevent_inline_autocomplete, false, true, true, false,
- TestSchemeClassifier());
- provider_->Start(input, false);
- EXPECT_TRUE(provider_->done());
-
- ac_matches_ = provider_->matches();
-
- // We should have gotten back at most AutocompleteProvider::kMaxMatches.
- EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
-
- // If the number of expected and actual matches aren't equal then we need
- // test no further, but let's do anyway so that we know which URLs failed.
- EXPECT_EQ(expected_urls.size(), ac_matches_.size());
-
- // Verify that all expected URLs were found and that all found URLs
- // were expected.
- std::set<ExpectedURLAndAllowedToBeDefault> Leftovers =
- for_each(expected_urls.begin(), expected_urls.end(),
- SetShouldContain(ac_matches_)).Leftovers();
- EXPECT_EQ(0U, Leftovers.size());
-
- // See if we got the expected top scorer.
- if (!ac_matches_.empty()) {
- std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1,
- ac_matches_.end(), AutocompleteMatch::MoreRelevant);
- EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec());
- EXPECT_EQ(top_result_inline_autocompletion,
- ac_matches_[0].inline_autocompletion);
- }
-}
-
int ShortcutsProviderTest::CalculateScore(
const std::string& terms,
const ShortcutsDatabase::Shortcut& shortcut,
@@ -429,17 +297,20 @@ int ShortcutsProviderTest::CalculateScore(
TEST_F(ShortcutsProviderTest, SimpleSingleMatch) {
base::string16 text(ASCIIToUTF16("go"));
std::string expected_url("http://www.google.com/");
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ogle.com"));
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("ogle.com"));
// Same test with prevent inline autocomplete.
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
// The match will have an |inline_autocompletion| set, but the value will not
// be used because |allowed_to_be_default_match| will be false.
- RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ogle.com"));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ ASCIIToUTF16("ogle.com"));
// A pair of analogous tests where the shortcut ends at the end of
// |fill_into_edit|. This exercises the inline autocompletion and default
@@ -447,38 +318,47 @@ TEST_F(ShortcutsProviderTest, SimpleSingleMatch) {
text = ASCIIToUTF16("abcdef.com");
expected_url = "http://abcdef.com/";
expected_urls.clear();
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, base::string16());
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ base::string16());
// With prevent inline autocomplete, the suggestion should be the same
// (because there is no completion).
- RunTest(text, true, expected_urls, expected_url, base::string16());
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ base::string16());
// Another test, simply for a query match type, not a navigation URL match
// type.
text = ASCIIToUTF16("que");
expected_url = "https://www.google.com/search?q=query";
expected_urls.clear();
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ry"));
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("ry"));
// Same test with prevent inline autocomplete.
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
// The match will have an |inline_autocompletion| set, but the value will not
// be used because |allowed_to_be_default_match| will be false.
- RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ry"));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ ASCIIToUTF16("ry"));
// A pair of analogous tests where the shortcut ends at the end of
// |fill_into_edit|. This exercises the inline autocompletion and default
// match code.
text = ASCIIToUTF16("query");
expected_urls.clear();
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, base::string16());
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ base::string16());
// With prevent inline autocomplete, the suggestion should be the same
// (because there is no completion).
- RunTest(text, true, expected_urls, expected_url, base::string16());
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ base::string16());
// Now the shortcut ends at the end of |fill_into_edit| but has a
// non-droppable prefix. ("www.", for instance, is not droppable for
@@ -487,8 +367,9 @@ TEST_F(ShortcutsProviderTest, SimpleSingleMatch) {
expected_url = "https://www.google.com/search?q=www.word";
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
- RunTest(text, false, expected_urls, expected_url, base::string16());
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ base::string16());
}
// These tests are like those in SimpleSingleMatch but more complex,
@@ -497,35 +378,39 @@ TEST_F(ShortcutsProviderTest, TrickySingleMatch) {
// Test that about: URLs are fixed up/transformed to chrome:// URLs.
base::string16 text(ASCIIToUTF16("about:o"));
std::string expected_url("chrome://omnibox/");
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("mnibox"));
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("mnibox"));
// Same test with prevent inline autocomplete.
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
// The match will have an |inline_autocompletion| set, but the value will not
// be used because |allowed_to_be_default_match| will be false.
- RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("mnibox"));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ ASCIIToUTF16("mnibox"));
// Test that an input with a space can match URLs with a (escaped) space.
// This would fail if we didn't try to lookup the un-fixed-up string.
text = ASCIIToUTF16("www/real sp");
expected_url = "http://www/real%20space/long-url-with-space.html";
expected_urls.clear();
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url,
- ASCIIToUTF16("ace/long-url-with-space.html"));
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("ace/long-url-with-space.html"));
// Same test with prevent inline autocomplete.
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
// The match will have an |inline_autocompletion| set, but the value will not
// be used because |allowed_to_be_default_match| will be false.
- RunTest(text, true, expected_urls, expected_url,
- ASCIIToUTF16("ace/long-url-with-space.html"));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ ASCIIToUTF16("ace/long-url-with-space.html"));
// Test when the user input has a trailing slash but fill_into_edit does
// not. This should still be allowed to be default.
@@ -533,8 +418,9 @@ TEST_F(ShortcutsProviderTest, TrickySingleMatch) {
expected_url = "http://notrailing.com/";
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, true, expected_urls, expected_url, base::string16());
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ base::string16());
// Test when the user input has a typo that can be fixed up for matching
// fill_into_edit. This should still be allowed to be default.
@@ -542,8 +428,9 @@ TEST_F(ShortcutsProviderTest, TrickySingleMatch) {
expected_url = "http://foo.com/";
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, true, expected_urls, expected_url, base::string16());
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, true, expected_urls, expected_url,
+ base::string16());
// A foursome of tests to verify that trailing spaces prevent the shortcut
// from being allowed to be the default match. For each of two tests, we
@@ -556,89 +443,95 @@ TEST_F(ShortcutsProviderTest, TrickySingleMatch) {
expected_url = "http://trailing1.com/";
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com"));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16(".com"));
text = ASCIIToUTF16("trailing1 ");
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com"));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16(".com"));
text = ASCIIToUTF16("about:trailing2");
expected_url = "chrome://trailing2blah/";
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, true));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah"));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("blah"));
text = ASCIIToUTF16("about:trailing2 ");
expected_urls.clear();
expected_urls.push_back(
- ExpectedURLAndAllowedToBeDefault(expected_url, false));
- RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah"));
+ ShortcutExpectedURLAndAllowedToBeDefault(expected_url, false));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
+ ASCIIToUTF16("blah"));
}
TEST_F(ShortcutsProviderTest, MultiMatch) {
base::string16 text(ASCIIToUTF16("NEWS"));
- ExpectedURLs expected_urls;
+ ShortcutExpectedURLs expected_urls;
// Scores high because of completion length.
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
- "http://slashdot.org/", false));
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault("http://slashdot.org/", false));
// Scores high because of visit count.
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://sports.yahoo.com/", false));
// Scores high because of visit count but less match span,
// which is more important.
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.cnn.com/index.html", false));
- RunTest(text, false, expected_urls, "http://slashdot.org/", base::string16());
+ RunShortcutsProviderTest(provider_, text, false, expected_urls,
+ "http://slashdot.org/", base::string16());
}
TEST_F(ShortcutsProviderTest, RemoveDuplicates) {
base::string16 text(ASCIIToUTF16("dupl"));
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
- "http://duplicate.com/", true));
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(
+ ShortcutExpectedURLAndAllowedToBeDefault("http://duplicate.com/", true));
// Make sure the URL only appears once in the output list.
- RunTest(text, false, expected_urls, "http://duplicate.com/",
- ASCIIToUTF16("icate.com"));
+ RunShortcutsProviderTest(provider_, text, false, expected_urls,
+ "http://duplicate.com/", ASCIIToUTF16("icate.com"));
}
TEST_F(ShortcutsProviderTest, TypedCountMatches) {
base::string16 text(ASCIIToUTF16("just"));
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/b.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/a.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/c.html", false));
- RunTest(text, false, expected_urls, "http://www.testsite.com/b.html",
- base::string16());
+ RunShortcutsProviderTest(provider_, text, false, expected_urls,
+ "http://www.testsite.com/b.html", base::string16());
}
TEST_F(ShortcutsProviderTest, FragmentLengthMatches) {
base::string16 text(ASCIIToUTF16("just a"));
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/d.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/e.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.testsite.com/f.html", false));
- RunTest(text, false, expected_urls, "http://www.testsite.com/d.html",
- base::string16());
+ RunShortcutsProviderTest(provider_, text, false, expected_urls,
+ "http://www.testsite.com/d.html", base::string16());
}
TEST_F(ShortcutsProviderTest, DaysAgoMatches) {
base::string16 text(ASCIIToUTF16("ago"));
- ExpectedURLs expected_urls;
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ ShortcutExpectedURLs expected_urls;
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.daysagotest.com/a.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.daysagotest.com/b.html", false));
- expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(
+ expected_urls.push_back(ShortcutExpectedURLAndAllowedToBeDefault(
"http://www.daysagotest.com/c.html", false));
- RunTest(text, false, expected_urls, "http://www.daysagotest.com/a.html",
- base::string16());
+ RunShortcutsProviderTest(provider_, text, false, expected_urls,
+ "http://www.daysagotest.com/a.html",
+ base::string16());
}
TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) {
@@ -812,7 +705,9 @@ TEST_F(ShortcutsProviderTest, DeleteMatch) {
scoped_refptr<ShortcutsBackend> backend = client_->GetShortcutsBackend();
size_t original_shortcuts_count = backend->shortcuts_map().size();
- FillData(shortcuts_to_test_delete, arraysize(shortcuts_to_test_delete));
+ PopulateShortcutsBackendWithTestShortcutData(
+ client_->GetShortcutsBackend(), shortcuts_to_test_delete,
+ arraysize(shortcuts_to_test_delete));
EXPECT_EQ(original_shortcuts_count + 4, backend->shortcuts_map().size());
EXPECT_FALSE(backend->shortcuts_map().end() ==

Powered by Google App Engine
This is Rietveld 408576698