shortcuts_provider_unittest.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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 }, 189a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch { "BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ", 190a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "http://trailing1.com", "http://trailing1.com/", 191a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "Trailing1 - Space in Shortcut", "0,1", 192a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "Trailing1 - Space in Shortcut", "0,1", content::PAGE_TRANSITION_TYPED, 193a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutocompleteMatchType::HISTORY_URL, "", 1, 100 }, 194a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch { "BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ", 195a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "chrome://trailing2blah", "chrome://trailing2blah/", 196a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "Trailing2 - Space in Shortcut", "0,1", 197a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch "Trailing2 - Space in Shortcut", "0,1", content::PAGE_TRANSITION_TYPED, 198a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutocompleteMatchType::HISTORY_URL, "", 1, 100 }, 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// ClassifyTest --------------------------------------------------------------- 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Helper class to make running tests of ClassifyAllMatchesInString() more 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// convenient. 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ClassifyTest { 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ClassifyTest(const base::string16& text, ACMatchClassifications matches); 2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ~ClassifyTest(); 2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ACMatchClassifications RunTest(const base::string16& find_text); 2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 text_; 2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const ACMatchClassifications matches_; 2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 2194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ClassifyTest::ClassifyTest(const base::string16& text, 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ACMatchClassifications matches) 2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) : text_(text), 2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches_(matches) { 2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)ClassifyTest::~ClassifyTest() { 2274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ACMatchClassifications ClassifyTest::RunTest(const base::string16& find_text) { 2304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return ShortcutsProvider::ClassifyAllMatchesInString(find_text, 2314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ShortcutsProvider::CreateWordMapForString(find_text), text_, matches_); 2324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// ShortcutsProviderTest ------------------------------------------------------ 2364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ShortcutsProviderTest : public testing::Test, 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public AutocompleteProviderListener { 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShortcutsProviderTest(); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // AutocompleteProviderListener: 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef std::pair<std::string, bool> ExpectedURLAndAllowedToBeDefault; 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef std::vector<ExpectedURLAndAllowedToBeDefault> ExpectedURLs; 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class SetShouldContain 250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : public std::unary_function<const ExpectedURLAndAllowedToBeDefault&, 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<std::string> > { 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit SetShouldContain(const ACMatches& matched_urls); 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void operator()(const ExpectedURLAndAllowedToBeDefault& expected); 256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> Leftovers() const { 257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return matches_; 258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 261a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> matches_; 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp(); 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void TearDown(); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fills test data into the provider. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void FillData(TestShortcutInfo* db, size_t db_size); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Runs an autocomplete query on |text| with the provided 271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |prevent_inline_autocomplete| setting and checks to see that the returned 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // results' destination URLs match those provided. |expected_urls| does not 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // need to be in sorted order, but |expected_top_result| should be the top 274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match, and it should have inline autocompletion 275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |top_result_inline_autocompletion|. 276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void RunTest(const base::string16 text, 277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool prevent_inline_autocomplete, 278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLs& expected_urls, 279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string expected_top_result, 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 top_result_inline_autocompletion); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Passthrough to the private function in provider_. 2834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int CalculateScore(const std::string& terms, 28423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const history::ShortcutsDatabase::Shortcut& shortcut, 2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int max_relevance); 2864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 28790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoopForUI message_loop_; 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TestBrowserThread ui_thread_; 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TestBrowserThread file_thread_; 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestingProfile profile_; 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatches ac_matches_; // The resulting matches after running RunTest. 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<ShortcutsBackend> backend_; 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<ShortcutsProvider> provider_; 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShortcutsProviderTest::ShortcutsProviderTest() 3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) : ui_thread_(content::BrowserThread::UI, &message_loop_), 3014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) file_thread_(content::BrowserThread::FILE, &message_loop_) { 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::OnProviderUpdate(bool updated_matches) {} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::SetUp() { 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &profile_, &ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(backend_.get()); 311bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_ = new ShortcutsProvider(this, &profile_); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FillData(shortcut_test_db, arraysize(shortcut_test_db)); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::TearDown() { 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run all pending tasks or else some threads hold on to the message loop 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and prevent it from being deleted. 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_.RunUntilIdle(); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_ = NULL; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::FillData(TestShortcutInfo* db, size_t db_size) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(provider_.get()); 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t expected_size = backend_->shortcuts_map().size() + db_size; 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < db_size; ++i) { 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const TestShortcutInfo& cur = db[i]; 32823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut shortcut( 3294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.guid, ASCIIToUTF16(cur.text), 33023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut::MatchCore( 3314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASCIIToUTF16(cur.fill_into_edit), GURL(cur.destination_url), 33223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16(cur.contents), cur.contents_class, 33323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16(cur.description), cur.description_class, 3344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.transition, cur.type, ASCIIToUTF16(cur.keyword)), 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now), 3364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) cur.number_of_hits); 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->AddShortcut(shortcut); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_size, backend_->shortcuts_map().size()); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShortcutsProviderTest::SetShouldContain::SetShouldContain( 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ACMatches& matched_urls) { 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (ACMatches::const_iterator iter = matched_urls.begin(); 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iter != matched_urls.end(); ++iter) 346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) matches_.insert(ExpectedURLAndAllowedToBeDefault( 347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->destination_url.spec(), iter->allowed_to_be_default_match)); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShortcutsProviderTest::SetShouldContain::operator()( 351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLAndAllowedToBeDefault& expected) { 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1U, matches_.erase(expected)); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ShortcutsProviderTest::RunTest( 356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 text, 357a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool prevent_inline_autocomplete, 358a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ExpectedURLs& expected_urls, 359a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string expected_top_result, 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 top_result_inline_autocompletion) { 36190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop::current()->RunUntilIdle(); 362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(), 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AutocompleteInput::INVALID_SPEC, 3640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch prevent_inline_autocomplete, false, true, true); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->Start(input, false); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(provider_->done()); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ac_matches_ = provider_->matches(); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should have gotten back at most AutocompleteProvider::kMaxMatches. 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the number of expected and actual matches aren't equal then we need 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // test no further, but let's do anyway so that we know which URLs failed. 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_urls.size(), ac_matches_.size()); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Verify that all expected URLs were found and that all found URLs 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // were expected. 379a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::set<ExpectedURLAndAllowedToBeDefault> Leftovers = 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for_each(expected_urls.begin(), expected_urls.end(), 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetShouldContain(ac_matches_)).Leftovers(); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0U, Leftovers.size()); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See if we got the expected top scorer. 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!ac_matches_.empty()) { 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1, 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ac_matches_.end(), AutocompleteMatch::MoreRelevant); 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec()); 389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(top_result_inline_autocompletion, 390a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ac_matches_[0].inline_autocompletion); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)int ShortcutsProviderTest::CalculateScore( 3954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const std::string& terms, 39623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const history::ShortcutsDatabase::Shortcut& shortcut, 3974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int max_relevance) { 3984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut, 3994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) max_relevance); 4004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 4014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Actual tests --------------------------------------------------------------- 4044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, SimpleSingleMatch) { 406a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("go")); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string expected_url("http://www.google.com/"); 408a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 411a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Same test with prevent inline autocomplete. 413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 416a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 417a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 418a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ogle.com")); 419a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 420a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // A pair of analogous tests where the shortcut ends at the end of 421a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |fill_into_edit|. This exercises the inline autocompletion and default 422a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match code. 423a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("abcdef.com"); 424a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "http://abcdef.com/"; 425a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 426a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 427a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 428a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // With prevent inline autocomplete, the suggestion should be the same 429a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // (because there is no completion). 430a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, base::string16()); 431a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 432a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Another test, simply for a query match type, not a navigation URL match 433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // type. 434a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("que"); 435a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "https://www.google.com/search?q=query"; 436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 437a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 438a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("ry")); 439a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 440a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Same test with prevent inline autocomplete. 441a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 442a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 443a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 445a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 446a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("ry")); 447a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 448a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // A pair of analogous tests where the shortcut ends at the end of 449a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |fill_into_edit|. This exercises the inline autocompletion and default 450a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // match code. 451a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("query"); 452a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 453a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 454a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 455a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // With prevent inline autocomplete, the suggestion should be the same 456a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // (because there is no completion). 457a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, base::string16()); 458a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 459a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Now the shortcut ends at the end of |fill_into_edit| but has a 460a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // non-droppable prefix. ("www.", for instance, is not droppable for 461a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // queries.) 462a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) text = ASCIIToUTF16("word"); 463a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url = "https://www.google.com/search?q=www.word"; 464a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.clear(); 465a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back( 466a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 467a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, base::string16()); 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// These tests are like those in SimpleSingleMatch but more complex, 4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// involving URLs that need to be fixed up to match properly. 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShortcutsProviderTest, TrickySingleMatch) { 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Test that about: URLs are fixed up/transformed to chrome:// URLs. 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("about:o")); 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string expected_url("chrome://omnibox/"); 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLs expected_urls; 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same test with prevent inline autocomplete. 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back( 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("mnibox")); 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Test that an input with a space can match URLs with a (escaped) space. 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This would fail if we didn't try to lookup the un-fixed-up string. 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) text = ASCIIToUTF16("www/real sp"); 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_url = "http://www/real%20space/long-url-with-space.html"; 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("ace/long-url-with-space.html")); 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same test with prevent inline autocomplete. 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.clear(); 4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back( 5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLAndAllowedToBeDefault(expected_url, false)); 5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The match will have an |inline_autocompletion| set, but the value will not 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // be used because |allowed_to_be_default_match| will be false. 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, true, expected_urls, expected_url, 5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("ace/long-url-with-space.html")); 505c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 506c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Test when the user input has a trailing slash but fill_into_edit does 507c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // not. This should still be allowed to be default. 508c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch text = ASCIIToUTF16("notrailing.com/"); 509c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_url = "http://notrailing.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()); 514c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 515c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Test when the user input has a typo that can be fixed up for matching 516c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // fill_into_edit. This should still be allowed to be default. 517c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch text = ASCIIToUTF16("http:///foo.com"); 518c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_url = "http://foo.com/"; 519c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.clear(); 520c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch expected_urls.push_back( 521c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, true)); 522c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch RunTest(text, true, expected_urls, expected_url, base::string16()); 523a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 524a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // A foursome of tests to verify that trailing spaces prevent the shortcut 525a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // from being allowed to be the default match. For each of two tests, we 526a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // first verify that the match is allowed to be default without the trailing 527a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // space but is not allowed to be default with the trailing space. In both 528a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // of these with-trailing-space cases, we actually get an 529a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // inline_autocompletion, though it's never used because the match is 530a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // prohibited from being default. 531a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text = ASCIIToUTF16("trailing1"); 532a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_url = "http://trailing1.com/"; 533a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.clear(); 534a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.push_back( 535a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, true)); 536a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); 537a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text = ASCIIToUTF16("trailing1 "); 538a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.clear(); 539a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.push_back( 540a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, false)); 541a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); 542a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text = ASCIIToUTF16("about:trailing2"); 543a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_url = "chrome://trailing2blah/"; 544a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.clear(); 545a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.push_back( 546a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, true)); 547a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); 548a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text = ASCIIToUTF16("about:trailing2 "); 549a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.clear(); 550a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_urls.push_back( 551a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ExpectedURLAndAllowedToBeDefault(expected_url, false)); 552a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, MultiMatch) { 556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("NEWS")); 557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of completion length. 559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://slashdot.org/", false)); 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of visit count. 562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://sports.yahoo.com/", false)); 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Scores high because of visit count but less match span, 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which is more important. 566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 567a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.cnn.com/index.html", false)); 568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://slashdot.org/", base::string16()); 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShortcutsProviderTest, RemoveDuplicates) { 5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("dupl")); 5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExpectedURLs expected_urls; 5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "http://duplicate.com/", true)); 5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Make sure the URL only appears once in the output list. 5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://duplicate.com/", 5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("icate.com")); 5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, TypedCountMatches) { 582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("just")); 583a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/b.html", false)); 586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 587a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/a.html", false)); 588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 589a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/c.html", false)); 590a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.testsite.com/b.html", 591a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, FragmentLengthMatches) { 595a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("just a")); 596a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 597a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/d.html", false)); 599a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 600a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/e.html", false)); 601a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 602a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.testsite.com/f.html", false)); 603a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.testsite.com/d.html", 604a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, DaysAgoMatches) { 608a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("ago")); 609a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 610a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 611a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/a.html", false)); 612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 613a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/b.html", false)); 614a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 615a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "http://www.daysagotest.com/c.html", false)); 616a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, "http://www.daysagotest.com/a.html", 617a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16()); 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, ClassifyAllMatchesInString) { 6214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ACMatchClassifications matches = 6224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsFromString("0,0"); 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test(ASCIIToUTF16("A man, a plan, a canal Panama"), 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) matches); 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_a = classify_test.RunTest(ASCIIToUTF16("man")); 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be: '--MMM------------------------' 6284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0", AutocompleteMatch::ClassificationsToString(spans_a)); 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_b = classify_test.RunTest(ASCIIToUTF16("man p")); 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be: '--MMM----M-------------M-----' 6324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,9,2,10,0,23,2,24,0", 6334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_b)); 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_c = 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test.RunTest(ASCIIToUTF16("man plan panama")); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should be:'--MMM----MMMM----------MMMMMM' 6384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,9,2,13,0,23,2", 6394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_c)); 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test2(ASCIIToUTF16("Yahoo! Sports - Sports News, " 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Scores, Rumors, Fantasy Games, and more"), matches); 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_d = classify_test2.RunTest(ASCIIToUTF16("ne")); 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should match first two letters of the "news". 6464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,23,2,25,0", 6474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_d)); 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_e = 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test2.RunTest(ASCIIToUTF16("news r")); 6514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (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," 6524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "66,2,67,0", AutocompleteMatch::ClassificationsToString(spans_e)); 6534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,1"); 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test3(ASCIIToUTF16("livescore.goal.com"), matches); 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_f = classify_test3.RunTest(ASCIIToUTF16("go")); 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ACMatch spans should match first two letters of the "goal". 6594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,1,10,3,12,1", 6604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_f)); 6614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,0,13,1"); 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test4(ASCIIToUTF16("Email login: mail.somecorp.com"), 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) matches); 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_g = classify_test4.RunTest(ASCIIToUTF16("ail")); 6674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,2,2,5,0,13,1,14,3,17,1", 6684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_g)); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_h = 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test4.RunTest(ASCIIToUTF16("lo log")); 6724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,0,6,2,9,0,13,1", 6734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_h)); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_i = 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test4.RunTest(ASCIIToUTF16("ail em")); 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 'Email' and 'ail' should be matched. 6784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,2,5,0,13,1,14,3,17,1", 6794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_i)); 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some web sites do not have a description. If the string being searched is 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // empty, the classifications must also be empty: http://crbug.com/148647 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extra parens in the next line hack around C++03's "most vexing parse". 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class ClassifyTest classify_test5((base::string16()), 6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ACMatchClassifications()); 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_j = classify_test5.RunTest(ASCIIToUTF16("man")); 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(0U, spans_j.size()); 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Matches which end at beginning of classification merge properly. 6904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,4,9,0"); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test6(ASCIIToUTF16("html password example"), matches); 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Extra space in the next string avoids having the string be a prefix of the 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // text above, which would allow for two different valid classification sets, 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // one of which uses two spans (the first of which would mark all of "html 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // pass" as a match) and one which uses four (which marks the individual words 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // as matches but not the space between them). This way only the latter is 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // valid. 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_k = 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test6.RunTest(ASCIIToUTF16("html pass")); 7014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,6,4,4,5,6,9,0", 7024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_k)); 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Multiple matches with both beginning and end at beginning of 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // classifications merge properly. 7064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) matches = AutocompleteMatch::ClassificationsFromString("0,1,11,0"); 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ClassifyTest classify_test7(ASCIIToUTF16("http://a.co is great"), matches); 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACMatchClassifications spans_l = 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) classify_test7.RunTest(ASCIIToUTF16("ht co")); 7114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ("0,3,2,1,9,3,11,0", 7124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatch::ClassificationsToString(spans_l)); 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, CalculateScore) { 71623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut shortcut( 7174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string(), ASCIIToUTF16("test"), 71823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) history::ShortcutsDatabase::Shortcut::MatchCore( 7194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASCIIToUTF16("www.test.com"), GURL("http://www.test.com"), 72023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16("www.test.com"), "0,1,4,3,8,1", 72123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) ASCIIToUTF16("A test"), "0,0,2,2", content::PAGE_TRANSITION_TYPED, 72223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, base::string16()), 7234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::Time::Now(), 1); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Maximal score. 7260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const int max_relevance = 7270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ShortcutsProvider::kShortcutsProviderDefaultMaxRelevance; 7284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const int kMaxScore = CalculateScore("test", shortcut, max_relevance); 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Score decreases as percent of the match is decreased. 7314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_three_quarters = CalculateScore("tes", shortcut, max_relevance); 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_three_quarters, kMaxScore); 7334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_one_half = CalculateScore("te", shortcut, max_relevance); 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_one_half, score_three_quarters); 7354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_one_quarter = CalculateScore("t", shortcut, max_relevance); 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_one_quarter, score_one_half); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should decay with time - one week. 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(7); 7404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_week_old = CalculateScore("test", shortcut, max_relevance); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_week_old, kMaxScore); 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should decay more in two weeks. 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int score_two_weeks_old = CalculateScore("test", shortcut, max_relevance); 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_week_old); 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But not if it was activly clicked on. 2 hits slow decaying power. 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.number_of_hits = 2; 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int score_popular_two_weeks_old = 7524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CalculateScore("test", shortcut, max_relevance); 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_popular_two_weeks_old); 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But still decayed. 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_popular_two_weeks_old, kMaxScore); 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3 hits slow decaying power even more. 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.number_of_hits = 3; 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int score_more_popular_two_weeks_old = 7614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CalculateScore("test", shortcut, max_relevance); 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_two_weeks_old, score_more_popular_two_weeks_old); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_popular_two_weeks_old, score_more_popular_two_weeks_old); 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // But still decayed. 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_LT(score_more_popular_two_weeks_old, kMaxScore); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ShortcutsProviderTest, DeleteMatch) { 7694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestShortcutInfo shortcuts_to_test_delete[] = { 7704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F1", "delete", "www.deletetest.com/1", 7714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1", "http://www.deletetest.com/1", "0,2", 7724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 1, 1}, 7744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F2", "erase", "www.deletetest.com/1", 7754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1", "http://www.deletetest.com/1", "0,2", 7764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 1, 1}, 7784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F3", "keep", "www.deletetest.com/1/2", 7794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/1/2", "http://www.deletetest.com/1/2", "0,2", 7804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Keep this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_TITLE, "", 1, 1}, 7824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) { "BD85DBA2-8C29-49F9-84AE-48E1E90881F4", "delete", "www.deletetest.com/2", 7834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "http://www.deletetest.com/2", "http://www.deletetest.com/2", "0,2", 7844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "Erase this shortcut!", "0,0", content::PAGE_TRANSITION_TYPED, 7854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AutocompleteMatchType::HISTORY_URL, "", 1, 1}, 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t original_shortcuts_count = backend_->shortcuts_map().size(); 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FillData(shortcuts_to_test_delete, arraysize(shortcuts_to_test_delete)); 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 4, backend_->shortcuts_map().size()); 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("erase"))); 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 798868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AutocompleteMatch match( 799868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) provider_.get(), 1200, true, AutocompleteMatchType::HISTORY_TITLE); 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.destination_url = GURL(shortcuts_to_test_delete[0].destination_url); 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) match.contents = ASCIIToUTF16(shortcuts_to_test_delete[0].contents); 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) match.description = ASCIIToUTF16(shortcuts_to_test_delete[0].description); 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->DeleteMatch(match); 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // shortcuts_to_test_delete[0] and shortcuts_to_test_delete[1] should be 8084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // deleted, but not shortcuts_to_test_delete[2] or 8094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // shortcuts_to_test_delete[3], which have different URLs. 8104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 2, backend_->shortcuts_map().size()); 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(backend_->shortcuts_map().end() == 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(backend_->shortcuts_map().end() == 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("erase"))); 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); 8174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); 8184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider_->DeleteMatch(match); 8214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(backend_->shortcuts_map().end() == 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 8264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(ShortcutsProviderTest, Extension) { 8274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Try an input string that matches an extension URL. 828a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 text(ASCIIToUTF16("echo")); 8294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string expected_url( 8304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); 831a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ExpectedURLs expected_urls; 832a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( 833a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) expected_url, true)); 834a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); 8354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 8364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Claim the extension has been unloaded. 8374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_refptr<const extensions::Extension> extension = 8384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) extensions::ExtensionBuilder() 8394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .SetManifest(extensions::DictionaryBuilder() 8404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Set("name", "Echo") 8414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Set("version", "1.0")) 8424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") 8434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) .Build(); 8444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) extensions::UnloadedExtensionInfo details( 8451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); 8464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::NotificationService::current()->Notify( 84723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 8484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::Source<Profile>(&profile_), 8494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::Details<extensions::UnloadedExtensionInfo>(&details)); 8504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 8514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Now the URL should have disappeared. 852a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); 8534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 854