Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 20 #include "chrome/browser/autocomplete/history_url_provider.h" | 20 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | |
| 23 #include "chrome/browser/history/history_backend.h" | 22 #include "chrome/browser/history/history_backend.h" |
| 24 #include "chrome/browser/history/history_database.h" | 23 #include "chrome/browser/history/history_database.h" |
| 25 #include "chrome/browser/history/history_service.h" | 24 #include "chrome/browser/history/history_service.h" |
| 26 #include "chrome/browser/history/history_service_factory.h" | 25 #include "chrome/browser/history/history_service_factory.h" |
| 27 #include "chrome/browser/history/in_memory_url_index.h" | 26 #include "chrome/browser/history/in_memory_url_index.h" |
| 28 #include "chrome/browser/history/url_index_private_data.h" | 27 #include "chrome/browser/history/url_index_private_data.h" |
| 29 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" | 28 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" |
| 30 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 31 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 32 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 33 #include "components/bookmarks/test/bookmark_test_helpers.h" | 32 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 33 #include "components/history/core/browser/history_service_observer.h" | |
| 34 #include "components/history/core/browser/url_database.h" | 34 #include "components/history/core/browser/url_database.h" |
| 35 #include "components/metrics/proto/omnibox_event.pb.h" | 35 #include "components/metrics/proto/omnibox_event.pb.h" |
| 36 #include "components/omnibox/autocomplete_match.h" | 36 #include "components/omnibox/autocomplete_match.h" |
| 37 #include "components/omnibox/autocomplete_result.h" | 37 #include "components/omnibox/autocomplete_result.h" |
| 38 #include "components/search_engines/search_terms_data.h" | 38 #include "components/search_engines/search_terms_data.h" |
| 39 #include "components/search_engines/template_url.h" | 39 #include "components/search_engines/template_url.h" |
| 40 #include "components/search_engines/template_url_service.h" | 40 #include "components/search_engines/template_url_service.h" |
| 41 #include "content/public/browser/notification_service.h" | |
| 42 #include "content/public/test/test_browser_thread.h" | 41 #include "content/public/test/test_browser_thread.h" |
| 43 #include "content/public/test/test_utils.h" | 42 #include "content/public/test/test_utils.h" |
| 44 #include "sql/transaction.h" | 43 #include "sql/transaction.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 45 |
| 47 using base::ASCIIToUTF16; | 46 using base::ASCIIToUTF16; |
| 48 using base::Time; | 47 using base::Time; |
| 49 using base::TimeDelta; | 48 using base::TimeDelta; |
| 50 | 49 |
| 51 using content::BrowserThread; | 50 using content::BrowserThread; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, | 96 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, |
| 98 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, | 97 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, |
| 99 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, | 98 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, |
| 100 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, | 99 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, |
| 101 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 | 100 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 |
| 102 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" | 101 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" |
| 103 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." | 102 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." |
| 104 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} | 103 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} |
| 105 }; | 104 }; |
| 106 | 105 |
| 106 // Wait for OnURLsDeletedNotification. | |
|
sky
2014/12/11 15:59:54
Waits for OnOURSDeletedNotification and when run q
nshaik
2014/12/12 05:40:55
Done.
| |
| 107 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { | |
| 108 public: | |
| 109 explicit WaitForURLsDeletedObserver(content::MessageLoopRunner* runner); | |
| 110 ~WaitForURLsDeletedObserver() override; | |
| 111 | |
| 112 private: | |
| 113 // history::HistoryServiceObserver: | |
| 114 void OnURLsDeleted(HistoryService* service, | |
| 115 bool all_history, | |
| 116 bool expired, | |
| 117 const history::URLRows& deleted_rows, | |
| 118 const std::set<GURL>& favicon_urls) override; | |
| 119 // weak | |
|
Peter Kasting
2014/12/11 19:59:34
Nit: Blank line above this; also, comments should
nshaik
2014/12/12 05:40:56
Done.
| |
| 120 content::MessageLoopRunner* runner_; | |
| 121 }; | |
|
sky
2014/12/11 15:59:54
DISALLOW_...
nshaik
2014/12/12 05:40:56
Done.
| |
| 122 | |
| 123 WaitForURLsDeletedObserver::WaitForURLsDeletedObserver( | |
| 124 content::MessageLoopRunner* runner) | |
| 125 : runner_(runner) { | |
| 126 } | |
| 127 | |
| 128 WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() { | |
| 129 } | |
| 130 | |
| 131 void WaitForURLsDeletedObserver::OnURLsDeleted( | |
| 132 HistoryService* service, | |
| 133 bool all_history, | |
| 134 bool expired, | |
| 135 const history::URLRows& deleted_rows, | |
| 136 const std::set<GURL>& favicon_urls) { | |
| 137 runner_->Quit(); | |
| 138 } | |
| 139 | |
| 140 void WaitForURLsDeletedNotification(HistoryService* history_service) { | |
| 141 scoped_refptr<content::MessageLoopRunner> runner = | |
|
sky
2014/12/11 15:59:54
Why not use a RunLoop on the stack here? Seems sim
sdefresne
2014/12/11 16:04:08
content::MessageLoopRunner is a base::RefCounted a
sky
2014/12/11 17:02:04
I'm suggesting you change this line to:
base::Run
nshaik
2014/12/12 05:40:55
Done.
| |
| 142 new content::MessageLoopRunner; | |
| 143 WaitForURLsDeletedObserver observer(runner.get()); | |
| 144 ScopedObserver<HistoryService, history::HistoryServiceObserver> | |
| 145 scoped_observer(&observer); | |
| 146 scoped_observer.Add(history_service); | |
| 147 runner->Run(); | |
| 148 } | |
| 149 | |
| 107 class HistoryQuickProviderTest : public testing::Test { | 150 class HistoryQuickProviderTest : public testing::Test { |
| 108 public: | 151 public: |
| 109 HistoryQuickProviderTest() | 152 HistoryQuickProviderTest() |
| 110 : ui_thread_(BrowserThread::UI, &message_loop_), | 153 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 111 file_thread_(BrowserThread::FILE, &message_loop_) {} | 154 file_thread_(BrowserThread::FILE, &message_loop_) {} |
| 112 | 155 |
| 113 protected: | 156 protected: |
| 114 class SetShouldContain : public std::unary_function<const std::string&, | 157 class SetShouldContain : public std::unary_function<const std::string&, |
| 115 std::set<std::string> > { | 158 std::set<std::string> > { |
| 116 public: | 159 public: |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 EXPECT_EQ(1U, ac_matches_.size()); | 612 EXPECT_EQ(1U, ac_matches_.size()); |
| 570 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); | 613 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); |
| 571 provider_->DeleteMatch(ac_matches_[0]); | 614 provider_->DeleteMatch(ac_matches_[0]); |
| 572 | 615 |
| 573 // Check that the underlying URL is deleted from the history DB (this implies | 616 // Check that the underlying URL is deleted from the history DB (this implies |
| 574 // that all visits are gone as well). Also verify that a deletion notification | 617 // that all visits are gone as well). Also verify that a deletion notification |
| 575 // is sent, in response to which the secondary data stores (InMemoryDatabase, | 618 // is sent, in response to which the secondary data stores (InMemoryDatabase, |
| 576 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. | 619 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. |
| 577 // To ensure that the deletion has been propagated everywhere before we start | 620 // To ensure that the deletion has been propagated everywhere before we start |
| 578 // verifying post-deletion states, first wait until we see the notification. | 621 // verifying post-deletion states, first wait until we see the notification. |
| 579 content::WindowedNotificationObserver observer( | 622 WaitForURLsDeletedNotification(history_service_); |
| 580 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 581 content::NotificationService::AllSources()); | |
| 582 observer.Wait(); | |
| 583 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); | 623 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); |
| 584 | 624 |
| 585 // Just to be on the safe side, explicitly verify that we have deleted enough | 625 // Just to be on the safe side, explicitly verify that we have deleted enough |
| 586 // data so that we will not be serving the same result again. | 626 // data so that we will not be serving the same result again. |
| 587 expected_urls.clear(); | 627 expected_urls.clear(); |
| 588 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 628 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
| 589 ASCIIToUTF16("NONE EXPECTED"), base::string16()); | 629 ASCIIToUTF16("NONE EXPECTED"), base::string16()); |
| 590 } | 630 } |
| 591 | 631 |
| 592 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { | 632 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 | 815 |
| 776 TEST_F(HQPOrderingTest, TEAMatch) { | 816 TEST_F(HQPOrderingTest, TEAMatch) { |
| 777 std::vector<std::string> expected_urls; | 817 std::vector<std::string> expected_urls; |
| 778 expected_urls.push_back("http://www.teamliquid.net/"); | 818 expected_urls.push_back("http://www.teamliquid.net/"); |
| 779 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 819 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
| 780 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 820 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
| 781 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 821 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
| 782 ASCIIToUTF16("www.teamliquid.net"), | 822 ASCIIToUTF16("www.teamliquid.net"), |
| 783 ASCIIToUTF16("mliquid.net")); | 823 ASCIIToUTF16("mliquid.net")); |
| 784 } | 824 } |
| OLD | NEW |