shortcuts_provider_unittest.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/shortcuts_provider.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <math.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <functional> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 169ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h" 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_input.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_match.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_provider.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 24ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/autocomplete/autocomplete_result.h" 2523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "chrome/browser/autocomplete/shortcuts_backend.h" 2623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "chrome/browser/autocomplete/shortcuts_backend_factory.h" 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/history/history_service.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/history/in_memory_url_index.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/history/url_database.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_profile.h" 334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/notification_service.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_browser_thread.h" 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h" 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension_builder.h" 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/value_builder.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16; 414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// TestShortcutInfo ----------------------------------------------------------- 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct TestShortcutInfo { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid; 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string text; 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string fill_into_edit; 504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string destination_url; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string contents; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string contents_class; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string description; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string description_class; 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PageTransition transition; 564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::Type type; 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string keyword; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int days_from_now; 594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int number_of_hits; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} shortcut_test_db[] = { 614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "goog", "www.google.com", 624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,3,4,1", 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 100 }, 654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "slash", "slashdot.org", 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://slashdot.org/", "slashdot.org", "0,3,5,1", 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Slashdot - News for nerds, stuff that matters", "0,2,5,0", 684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, 694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 100 }, 704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E2", "news", "slashdot.org", 714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://slashdot.org/", "slashdot.org", "0,1", 724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Slashdot - News for nerds, stuff that matters", "0,0,11,2,15,0", 734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 0, 744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5 }, 754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E3", "news", "sports.yahoo.com", 764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://sports.yahoo.com/", "sports.yahoo.com", "0,1", 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more", 784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,0,23,2,27,0", content::PAGE_TRANSITION_TYPED, 794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 2, 5 }, 804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E4", "news weather", 814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.cnn.com/index.html", "http://www.cnn.com/index.html", 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "www.cnn.com/index.html", "0,1", 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video", 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,0,19,2,23,0,38,2,45,0", content::PAGE_TRANSITION_TYPED, 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 1, 10 }, 864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E5", "nhl scores", "sports.yahoo.com", 874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://sports.yahoo.com/", "sports.yahoo.com", "0,1", 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games, and more", 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,0,29,2,35,0", content::PAGE_TRANSITION_TYPED, 904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_BODY, "", 1, 10 }, 914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E6", "nhl scores", 924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.nhl.com/scores/index.html", "http://www.nhl.com/scores/index.html", 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "www.nhl.com/scores/index.html", "0,1,4,3,7,1", 944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "January 13, 2010 - NHL.com - Scores", "0,0,19,2,22,0,29,2,35,0", 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 5, 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1 }, 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E7", "just", "www.testsite.com/a.html", 984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.testsite.com/a.html", "www.testsite.com/a.html", "0,1", 994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Test - site - just a test", "0,0,14,2,18,0", 1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5, 1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1 }, 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E8", "just", "www.testsite.com/b.html", 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.testsite.com/b.html", "www.testsite.com/b.html", "0,1", 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Test - site - just a test", "0,0,14,2,18,0", 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 5, 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2 }, 1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880E9", "just", "www.testsite.com/c.html", 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.testsite.com/c.html", "www.testsite.com/c.html", "0,1", 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Test - site - just a test", "0,0,14,2,18,0", 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 8, 1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1 }, 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880EA", "just a", "www.testsite.com/d.html", 1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.testsite.com/d.html", "www.testsite.com/d.html", "0,1", 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Test - site - just a test", "0,0,14,2,18,0", 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_TITLE, "", 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 12, 1 }, 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880EB", "just a t", 1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.testsite.com/e.html", "http://www.testsite.com/e.html", 1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.testsite.com/e.html", "0,1", "Test - site - just a test", 1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,0,14,2,18,0", content::PAGE_TRANSITION_TYPED, 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 }, 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880EC", "just a te", 1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.testsite.com/f.html", "http://www.testsite.com/f.html", 1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "www.testsite.com/f.html", "0,1", "Test - site - just a test", 1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,0,14,2,18,0", content::PAGE_TRANSITION_TYPED, 1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 12, 1 }, 1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880ED", "ago", "www.daysagotest.com/a.html", 1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.daysagotest.com/a.html", "www.daysagotest.com/a.html", 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,1,8,3,11,1", "Test - site", "0,0", content::PAGE_TRANSITION_TYPED, 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 1, 1 }, 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880EE", "ago", "www.daysagotest.com/b.html", 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.daysagotest.com/b.html", "www.daysagotest.com/b.html", 1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,1,8,3,11,1", "Test - site", "0,0", content::PAGE_TRANSITION_TYPED, 1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 2, 1 }, 1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880EF", "ago", "www.daysagotest.com/c.html", 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.daysagotest.com/c.html", "www.daysagotest.com/c.html", 1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,1,8,3,11,1", "Test - site", "0,0", content::PAGE_TRANSITION_TYPED, 1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 3, 1 }, 1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F0", "ago", "www.daysagotest.com/d.html", 1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.daysagotest.com/d.html", "www.daysagotest.com/d.html", 1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "0,1,8,3,11,1", "Test - site", "0,0", content::PAGE_TRANSITION_TYPED, 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 4, 1 }, 1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo", 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo", 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Run Echo command: echo", "0,0", "Echo", "0,4", 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::EXTENSION_APP, 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "echo", 1, 1 }, 148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F2", "abcdef.com", "http://abcdef.com", 149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://abcdef.com/", "Abcdef", "0,1,4,0", "Abcdef", "0,3,4,1", 150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 100 }, 152a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query", 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "https://www.google.com/search?q=query", "query", "0,0", 154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, 155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, 156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word", 157a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "https://www.google.com/search?q=www.word", "www.word", "0,0", 158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, 159a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox", 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "", 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "", 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1, 100 }, 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp", 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://www/real space/long-url-with-space.html", 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://www/real%20space/long-url-with-space.html", 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "www/real space/long-url-with-space.html", "0,3,11,1", 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Page With Space; Input with Space", "0,0", 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1, 100 }, 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F7", "duplicate", "http://duplicate.com", 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1", 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 100 }, 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90880F8", "dupl", "http://duplicate.com", 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://duplicate.com/", "Duplicate", "0,1", "Duplicate", "0,1", 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 100 }, 179c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch { "BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/", 180c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash", 181c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch "0,1", "No Trailing Slash on fill_into_edit", "0,1", 182c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 183c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1, 100 }, 184c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch { "BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com", 185c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch "http://foo.com", "http://foo.com/", "Foo - Typo in Input", 186c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch "0,1", "Foo - Typo in Input Corrected in fill_into_edit", "0,1", 187c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 188c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1, 100 }, 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// ClassifyTest --------------------------------------------------------------- 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Helper class to make running tests of ClassifyAllMatchesInString() more 1974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// convenient. 1984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ClassifyTest { 1994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ClassifyTest(const base::string16& text, ACMatchClassifications matches); 2014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ~ClassifyTest(); 2024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ACMatchClassifications RunTest(const base::string16& find_text); 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 text_; 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const ACMatchClassifications matches_; 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ClassifyTest::ClassifyTest(const base::string16& text, 211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ACMatchClassifications matches) 2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) : text_(text), 2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches_(matches) { 2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)ClassifyTest::~ClassifyTest() { 2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ACMatchClassifications ClassifyTest::RunTest(const base::string16& find_text) { 2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return ShortcutsProvider::ClassifyAllMatchesInString(find_text, 2214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ShortcutsProvider::CreateWordMapForString(find_text), text_, matches_); 2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// ShortcutsProviderTest ------------------------------------------------------ 2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ShortcutsProviderTest : public testing::Test, 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public AutocompleteProviderListener { 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShortcutsProviderTest(); 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // AutocompleteProviderListener: 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef std::pair<std::string, bool> ExpectedURLAndAllowedToBeDefault; 237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef std::vector<ExpectedURLAndAllowedToBeDefault> ExpectedURLs; 238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class SetShouldContain 240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : public std::unary_function<const ExpectedURLAndAllowedToBeDefault&, 241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<std::string> > { 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SetShouldContain(const ACMatches& matched_urls); 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void operator()(const ExpectedURLAndAllowedToBeDefault& expected); 246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> Leftovers() const { 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return matches_; 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> matches_; 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp(); 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void TearDown(); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fills test data into the provider. 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void FillData(TestShortcutInfo* db, size_t db_size); 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 260a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Runs an autocomplete query on |text| with the provided 261a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |prevent_inline_autocomplete| setting and checks to see that the returned 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // results' destination URLs match those provided. |expected_urls| does not 263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // need to be in sorted order, but |expected_top_result| should be the top 264a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match, and it should have inline autocompletion 265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |top_result_inline_autocompletion|. 266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void RunTest(const base::string16 text, 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool prevent_inline_autocomplete, 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLs& expected_urls, 269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string expected_top_result, 270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 top_result_inline_autocompletion); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Passthrough to the private function in provider_. 2734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int CalculateScore(const std::string& terms, 27423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const history::ShortcutsDatabase::Shortcut& shortcut, 2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int max_relevance); 2764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 27790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoopForUI message_loop_; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TestBrowserThread ui_thread_; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TestBrowserThread file_thread_; 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestingProfile profile_; 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatches ac_matches_; // The resulting matches after running RunTest. 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<ShortcutsBackend> backend_; 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<ShortcutsProvider> provider_; 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShortcutsProviderTest::ShortcutsProviderTest() 2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) : ui_thread_(content::BrowserThread::UI, &message_loop_), 2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) file_thread_(content::BrowserThread::FILE, &message_loop_) { 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::OnProviderUpdate(bool updated_matches) {} 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::SetUp() { 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &profile_, &ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(backend_.get()); 301bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_ = new ShortcutsProvider(this, &profile_); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FillData(shortcut_test_db, arraysize(shortcut_test_db)); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::TearDown() { 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run all pending tasks or else some threads hold on to the message loop 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and prevent it from being deleted. 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_.RunUntilIdle(); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_ = NULL; 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::FillData(TestShortcutInfo* db, size_t db_size) { 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(provider_.get()); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t expected_size = backend_->shortcuts_map().size() + db_size; 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < db_size; ++i) { 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const TestShortcutInfo& cur = db[i]; 31823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut shortcut( 3194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.guid, ASCIIToUTF16(cur.text), 32023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut::MatchCore( 3214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASCIIToUTF16(cur.fill_into_edit), GURL(cur.destination_url), 32223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16(cur.contents), cur.contents_class, 32323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16(cur.description), cur.description_class, 3244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.transition, cur.type, ASCIIToUTF16(cur.keyword)), 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now), 3264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.number_of_hits); 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->AddShortcut(shortcut); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_size, backend_->shortcuts_map().size()); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShortcutsProviderTest::SetShouldContain::SetShouldContain( 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ACMatches& matched_urls) { 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (ACMatches::const_iterator iter = matched_urls.begin(); 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iter != matched_urls.end(); ++iter) 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) matches_.insert(ExpectedURLAndAllowedToBeDefault( 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->destination_url.spec(), iter->allowed_to_be_default_match)); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::SetShouldContain::operator()( 341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLAndAllowedToBeDefault& expected) { 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1U, matches_.erase(expected)); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ShortcutsProviderTest::RunTest( 346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 text, 347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool prevent_inline_autocomplete, 348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLs& expected_urls, 349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string expected_top_result, 350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 top_result_inline_autocompletion) { 35190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop::current()->RunUntilIdle(); 352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(), 353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteInput::INVALID_SPEC, 354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) prevent_inline_autocomplete, false, true, 355d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch AutocompleteInput::ALL_MATCHES); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->Start(input, false); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(provider_->done()); 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ac_matches_ = provider_->matches(); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should have gotten back at most AutocompleteProvider::kMaxMatches. 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the number of expected and actual matches aren't equal then we need 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // test no further, but let's do anyway so that we know which URLs failed. 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_urls.size(), ac_matches_.size()); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Verify that all expected URLs were found and that all found URLs 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // were expected. 370a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> Leftovers = 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for_each(expected_urls.begin(), expected_urls.end(), 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetShouldContain(ac_matches_)).Leftovers(); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0U, Leftovers.size()); 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See if we got the expected top scorer. 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!ac_matches_.empty()) { 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1, 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ac_matches_.end(), AutocompleteMatch::MoreRelevant); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec()); 380a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(top_result_inline_autocompletion, 381a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ac_matches_[0].inline_autocompletion); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)int ShortcutsProviderTest::CalculateScore( 3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const std::string& terms, 38723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const history::ShortcutsDatabase::Shortcut& shortcut, 3884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int max_relevance) { 3894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut, 3904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) max_relevance); 3914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 3924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Actual tests --------------------------------------------------------------- 3954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, SimpleSingleMatch) { 397a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("go")); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string expected_url("http://www.google.com/"); 399a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 400a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 401a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 402a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 403a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Same test with prevent inline autocomplete. 404a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 405a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 406a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 407a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 408a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 411a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // A pair of analogous tests where the shortcut ends at the end of 412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |fill_into_edit|. This exercises the inline autocompletion and default 413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match code. 414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("abcdef.com"); 415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "http://abcdef.com/"; 416a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 417a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 418a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 419a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // With prevent inline autocomplete, the suggestion should be the same 420a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // (because there is no completion). 421a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, base::string16()); 422a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 423a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Another test, simply for a query match type, not a navigation URL match 424a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // type. 425a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("que"); 426a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "https://www.google.com/search?q=query"; 427a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 428a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 429a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ry")); 430a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 431a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Same test with prevent inline autocomplete. 432a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 434a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 435a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 437a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ry")); 438a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 439a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // A pair of analogous tests where the shortcut ends at the end of 440a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |fill_into_edit|. This exercises the inline autocompletion and default 441a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match code. 442a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("query"); 443a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 445a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 446a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // With prevent inline autocomplete, the suggestion should be the same 447a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // (because there is no completion). 448a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, base::string16()); 449a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 450a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Now the shortcut ends at the end of |fill_into_edit| but has a 451a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // non-droppable prefix. ("www.", for instance, is not droppable for 452a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // queries.) 453a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("word"); 454a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "https://www.google.com/search?q=www.word"; 455a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 456a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 457a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 458a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// These tests are like those in SimpleSingleMatch but more complex, 4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// involving URLs that need to be fixed up to match properly. 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShortcutsProviderTest, TrickySingleMatch) { 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Test that about: URLs are fixed up/transformed to chrome:// URLs. 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("about:o")); 4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string expected_url("chrome://omnibox/"); 4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLs expected_urls; 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same test with prevent inline autocomplete. 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back( 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Test that an input with a space can match URLs with a (escaped) space. 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This would fail if we didn't try to lookup the un-fixed-up string. 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) text = ASCIIToUTF16("www/real sp"); 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_url = "http://www/real%20space/long-url-with-space.html"; 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("ace/long-url-with-space.html")); 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same test with prevent inline autocomplete. 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back( 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("ace/long-url-with-space.html")); 496c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 497c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Test when the user input has a trailing slash but fill_into_edit does 498c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // not. This should still be allowed to be default. 499c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch text = ASCIIToUTF16("notrailing.com/"); 500c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_url = "http://notrailing.com/"; 501c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.clear(); 502c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.push_back( 503c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, true)); 504c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch RunTest(text, true, expected_urls, expected_url, base::string16()); 505c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 506c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Test when the user input has a typo that can be fixed up for matching 507c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // fill_into_edit. This should still be allowed to be default. 508c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch text = ASCIIToUTF16("http:///foo.com"); 509c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_url = "http://foo.com/"; 510c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.clear(); 511c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.push_back( 512c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, true)); 513c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch RunTest(text, true, expected_urls, expected_url, base::string16()); 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, MultiMatch) { 517a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("NEWS")); 518a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of completion length. 520a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 521a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://slashdot.org/", false)); 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of visit count. 523a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 524a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://sports.yahoo.com/", false)); 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of visit count but less match span, 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which is more important. 527a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 528a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.cnn.com/index.html", false)); 529a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://slashdot.org/", base::string16()); 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShortcutsProviderTest, RemoveDuplicates) { 5335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("dupl")); 5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLs expected_urls; 5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://duplicate.com/", true)); 5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Make sure the URL only appears once in the output list. 5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://duplicate.com/", 5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("icate.com")); 5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, TypedCountMatches) { 543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("just")); 544a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 545a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/b.html", false)); 547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 548a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/a.html", false)); 549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/c.html", false)); 551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.testsite.com/b.html", 552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, FragmentLengthMatches) { 556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("just a")); 557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/d.html", false)); 560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/e.html", false)); 562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/f.html", false)); 564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.testsite.com/d.html", 565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, DaysAgoMatches) { 569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("ago")); 570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 571a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/a.html", false)); 573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 574a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/b.html", false)); 575a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/c.html", false)); 577a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.daysagotest.com/a.html", 578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) { 5824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ACMatchClassifications matches = 5834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsFromString("0,0"); 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test(ASCIIToUTF16("A man, a plan, a canal Panama"), 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) matches); 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_a = classify_test.RunTest(ASCIIToUTF16("man")); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be: '--MMM------------------------' 5894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0", AutocompleteMatch::ClassificationsToString(spans_a)); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_b = classify_test.RunTest(ASCIIToUTF16("man p")); 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be: '--MMM----M-------------M-----' 5934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,9,2,10,0,23,2,24,0", 5944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_b)); 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_c = 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test.RunTest(ASCIIToUTF16("man plan panama")); 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be:'--MMM----MMMM----------MMMMMM' 5994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,9,2,13,0,23,2", 6004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_c)); 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test2(ASCIIToUTF16("Yahoo! Sports - Sports News, " 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Scores, Rumors, Fantasy Games, and more"), matches); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_d = classify_test2.RunTest(ASCIIToUTF16("ne")); 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should match first two letters of the "news". 6074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,23,2,25,0", 6084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_d)); 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_e = 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test2.RunTest(ASCIIToUTF16("news r")); 6124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,10,2,11,0,19,2,20,0,23,2,27,0,32,2,33,0,37,2,38,0,41,2,42,0," 6134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "66,2,67,0", AutocompleteMatch::ClassificationsToString(spans_e)); 6144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,1"); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test3(ASCIIToUTF16("livescore.goal.com"), matches); 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_f = classify_test3.RunTest(ASCIIToUTF16("go")); 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should match first two letters of the "goal". 6204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,1,10,3,12,1", 6214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_f)); 6224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,0,13,1"); 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test4(ASCIIToUTF16("Email login: mail.somecorp.com"), 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) matches); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_g = classify_test4.RunTest(ASCIIToUTF16("ail")); 6284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,13,1,14,3,17,1", 6294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_g)); 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_h = 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test4.RunTest(ASCIIToUTF16("lo log")); 6334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,6,2,9,0,13,1", 6344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_h)); 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_i = 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test4.RunTest(ASCIIToUTF16("ail em")); 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 'Email' and 'ail' should be matched. 6394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,2,5,0,13,1,14,3,17,1", 6404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_i)); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some web sites do not have a description. If the string being searched is 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // empty, the classifications must also be empty: http://crbug.com/148647 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extra parens in the next line hack around C++03's "most vexing parse". 6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class ClassifyTest classify_test5((base::string16()), 6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ACMatchClassifications()); 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_j = classify_test5.RunTest(ASCIIToUTF16("man")); 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(0U, spans_j.size()); 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Matches which end at beginning of classification merge properly. 6514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,4,9,0"); 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test6(ASCIIToUTF16("html password example"), matches); 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extra space in the next string avoids having the string be a prefix of the 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // text above, which would allow for two different valid classification sets, 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // one of which uses two spans (the first of which would mark all of "html 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // pass" as a match) and one which uses four (which marks the individual words 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // as matches but not the space between them). This way only the latter is 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // valid. 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_k = 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test6.RunTest(ASCIIToUTF16("html pass")); 6624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,6,4,4,5,6,9,0", 6634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_k)); 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Multiple matches with both beginning and end at beginning of 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // classifications merge properly. 6674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,1,11,0"); 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test7(ASCIIToUTF16("http://a.co is great"), matches); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_l = 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test7.RunTest(ASCIIToUTF16("ht co")); 6724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,3,2,1,9,3,11,0", 6734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_l)); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, CalculateScore) { 67723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut shortcut( 6784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string(), ASCIIToUTF16("test"), 67923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut::MatchCore( 6804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASCIIToUTF16("www.test.com"), GURL("http://www.test.com"), 68123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16("www.test.com"), "0,1,4,3,8,1", 68223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16("A test"), "0,0,2,2", content::PAGE_TRANSITION_TYPED, 68323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, base::string16()), 6844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::Time::Now(), 1); 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Maximal score. 687ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const int max_relevance = AutocompleteResult::kLowestDefaultScore - 1; 6884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const int kMaxScore = CalculateScore("test", shortcut, max_relevance); 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Score decreases as percent of the match is decreased. 6914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_three_quarters = CalculateScore("tes", shortcut, max_relevance); 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_three_quarters, kMaxScore); 6934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_one_half = CalculateScore("te", shortcut, max_relevance); 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_one_half, score_three_quarters); 6954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_one_quarter = CalculateScore("t", shortcut, max_relevance); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_one_quarter, score_one_half); 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should decay with time - one week. 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(7); 7004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_week_old = CalculateScore("test", shortcut, max_relevance); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_week_old, kMaxScore); 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should decay more in two weeks. 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_two_weeks_old = CalculateScore("test", shortcut, max_relevance); 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_week_old); 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But not if it was activly clicked on. 2 hits slow decaying power. 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.number_of_hits = 2; 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int score_popular_two_weeks_old = 7124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CalculateScore("test", shortcut, max_relevance); 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_popular_two_weeks_old); 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But still decayed. 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_popular_two_weeks_old, kMaxScore); 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3 hits slow decaying power even more. 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.number_of_hits = 3; 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int score_more_popular_two_weeks_old = 7214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CalculateScore("test", shortcut, max_relevance); 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_more_popular_two_weeks_old); 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_popular_two_weeks_old, score_more_popular_two_weeks_old); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But still decayed. 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_more_popular_two_weeks_old, kMaxScore); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, DeleteMatch) { 7294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestShortcutInfo shortcuts_to_test_delete[] = { 7304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F1", "delete", "www.deletetest.com/1", 7314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1", "http://www.deletetest.com/1", "0,2", 7324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 1, 1}, 7344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F2", "erase", "www.deletetest.com/1", 7354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1", "http://www.deletetest.com/1", "0,2", 7364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 1, 1}, 7384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F3", "keep", "www.deletetest.com/1/2", 7394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1/2", "http://www.deletetest.com/1/2", "0,2", 7404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Keep this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 1, 1}, 7424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F4", "delete", "www.deletetest.com/2", 7434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/2", "http://www.deletetest.com/2", "0,2", 7444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 1, 1}, 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t original_shortcuts_count = backend_->shortcuts_map().size(); 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FillData(shortcuts_to_test_delete, arraysize(shortcuts_to_test_delete)); 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 4, backend_->shortcuts_map().size()); 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("erase"))); 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 758868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AutocompleteMatch match( 759868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) provider_.get(), 1200, true, AutocompleteMatchType::HISTORY_TITLE); 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.destination_url = GURL(shortcuts_to_test_delete[0].destination_url); 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) match.contents = ASCIIToUTF16(shortcuts_to_test_delete[0].contents); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) match.description = ASCIIToUTF16(shortcuts_to_test_delete[0].description); 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->DeleteMatch(match); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // shortcuts_to_test_delete[0] and shortcuts_to_test_delete[1] should be 7684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // deleted, but not shortcuts_to_test_delete[2] or 7694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // shortcuts_to_test_delete[3], which have different URLs. 7704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 2, backend_->shortcuts_map().size()); 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(backend_->shortcuts_map().end() == 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("erase"))); 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); 7774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); 7784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->DeleteMatch(match); 7814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(backend_->shortcuts_map().end() == 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 7864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(ShortcutsProviderTest, Extension) { 7874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Try an input string that matches an extension URL. 788a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("echo")); 7894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string expected_url( 7904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); 791a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 792a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 793a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url, true)); 794a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); 7954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 7964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Claim the extension has been unloaded. 7974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_refptr<const extensions::Extension> extension = 7984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) extensions::ExtensionBuilder() 7994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .SetManifest(extensions::DictionaryBuilder() 8004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Set("name", "Echo") 8014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Set("version", "1.0")) 8024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") 8034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Build(); 8044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) extensions::UnloadedExtensionInfo details( 8051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); 8064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NotificationService::current()->Notify( 80723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 8084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::Source<Profile>(&profile_), 8094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::Details<extensions::UnloadedExtensionInfo>(&details)); 8104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 8114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Now the URL should have disappeared. 812a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); 8134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 814