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> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/history/history_database.h" | 24 #include "chrome/browser/history/history_database.h" |
25 #include "chrome/browser/history/history_service.h" | 25 #include "chrome/browser/history/history_service.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/history/in_memory_url_index.h" | 27 #include "chrome/browser/history/in_memory_url_index.h" |
28 #include "chrome/browser/history/url_index_private_data.h" | 28 #include "chrome/browser/history/url_index_private_data.h" |
29 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" | 29 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" |
30 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
31 #include "chrome/test/base/testing_browser_process.h" | 31 #include "chrome/test/base/testing_browser_process.h" |
32 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
33 #include "components/bookmarks/test/bookmark_test_helpers.h" | 33 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 34 #include "components/history/core/browser/history_service_observer.h" |
34 #include "components/history/core/browser/url_database.h" | 35 #include "components/history/core/browser/url_database.h" |
35 #include "components/metrics/proto/omnibox_event.pb.h" | 36 #include "components/metrics/proto/omnibox_event.pb.h" |
36 #include "components/omnibox/autocomplete_match.h" | 37 #include "components/omnibox/autocomplete_match.h" |
37 #include "components/omnibox/autocomplete_result.h" | 38 #include "components/omnibox/autocomplete_result.h" |
38 #include "components/search_engines/search_terms_data.h" | 39 #include "components/search_engines/search_terms_data.h" |
39 #include "components/search_engines/template_url.h" | 40 #include "components/search_engines/template_url.h" |
40 #include "components/search_engines/template_url_service.h" | 41 #include "components/search_engines/template_url_service.h" |
41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
42 #include "content/public/test/test_browser_thread.h" | 43 #include "content/public/test/test_browser_thread.h" |
43 #include "content/public/test/test_utils.h" | 44 #include "content/public/test/test_utils.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, | 98 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, |
98 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, | 99 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, |
99 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, | 100 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, |
100 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, | 101 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, |
101 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 | 102 // 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" | 103 {"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." | 104 "%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} | 105 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} |
105 }; | 106 }; |
106 | 107 |
| 108 // Wait for OnURLsDeletedNotification. |
| 109 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { |
| 110 public: |
| 111 explicit WaitForURLsDeletedObserver(content::MessageLoopRunner* runner); |
| 112 ~WaitForURLsDeletedObserver() override; |
| 113 |
| 114 // history::HistoryServiceObserver: |
| 115 void OnURLsDeleted( |
| 116 HistoryService* service, |
| 117 const history::URLsDeletedDetails& deleted_details) override; |
| 118 |
| 119 private: |
| 120 // weak |
| 121 content::MessageLoopRunner* runner_; |
| 122 }; |
| 123 |
| 124 WaitForURLsDeletedObserver::WaitForURLsDeletedObserver( |
| 125 content::MessageLoopRunner* runner) |
| 126 : runner_(runner) { |
| 127 } |
| 128 |
| 129 WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() { |
| 130 } |
| 131 |
| 132 void WaitForURLsDeletedObserver::OnURLsDeleted( |
| 133 HistoryService* service, |
| 134 const history::URLsDeletedDetails& deleted_details) { |
| 135 runner_->Quit(); |
| 136 } |
| 137 |
| 138 void WaitForURLsDeletedNotification(HistoryService* history_service) { |
| 139 scoped_refptr<content::MessageLoopRunner> runner = |
| 140 new content::MessageLoopRunner; |
| 141 WaitForURLsDeletedObserver observer(runner.get()); |
| 142 ScopedObserver<HistoryService, history::HistoryServiceObserver> |
| 143 scoped_observer(&observer); |
| 144 scoped_observer.Add(history_service); |
| 145 runner->Run(); |
| 146 } |
| 147 |
107 class HistoryQuickProviderTest : public testing::Test { | 148 class HistoryQuickProviderTest : public testing::Test { |
108 public: | 149 public: |
109 HistoryQuickProviderTest() | 150 HistoryQuickProviderTest() |
110 : ui_thread_(BrowserThread::UI, &message_loop_), | 151 : ui_thread_(BrowserThread::UI, &message_loop_), |
111 file_thread_(BrowserThread::FILE, &message_loop_) {} | 152 file_thread_(BrowserThread::FILE, &message_loop_) {} |
112 | 153 |
113 protected: | 154 protected: |
114 class SetShouldContain : public std::unary_function<const std::string&, | 155 class SetShouldContain : public std::unary_function<const std::string&, |
115 std::set<std::string> > { | 156 std::set<std::string> > { |
116 public: | 157 public: |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 EXPECT_EQ(1U, ac_matches_.size()); | 610 EXPECT_EQ(1U, ac_matches_.size()); |
570 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); | 611 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); |
571 provider_->DeleteMatch(ac_matches_[0]); | 612 provider_->DeleteMatch(ac_matches_[0]); |
572 | 613 |
573 // Check that the underlying URL is deleted from the history DB (this implies | 614 // 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 | 615 // 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, | 616 // is sent, in response to which the secondary data stores (InMemoryDatabase, |
576 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. | 617 // 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 | 618 // To ensure that the deletion has been propagated everywhere before we start |
578 // verifying post-deletion states, first wait until we see the notification. | 619 // verifying post-deletion states, first wait until we see the notification. |
579 content::WindowedNotificationObserver observer( | 620 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)); | 621 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); |
584 | 622 |
585 // Just to be on the safe side, explicitly verify that we have deleted enough | 623 // 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. | 624 // data so that we will not be serving the same result again. |
587 expected_urls.clear(); | 625 expected_urls.clear(); |
588 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 626 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
589 ASCIIToUTF16("NONE EXPECTED"), base::string16()); | 627 ASCIIToUTF16("NONE EXPECTED"), base::string16()); |
590 } | 628 } |
591 | 629 |
592 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { | 630 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 | 813 |
776 TEST_F(HQPOrderingTest, TEAMatch) { | 814 TEST_F(HQPOrderingTest, TEAMatch) { |
777 std::vector<std::string> expected_urls; | 815 std::vector<std::string> expected_urls; |
778 expected_urls.push_back("http://www.teamliquid.net/"); | 816 expected_urls.push_back("http://www.teamliquid.net/"); |
779 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 817 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
780 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 818 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
781 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 819 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
782 ASCIIToUTF16("www.teamliquid.net"), | 820 ASCIIToUTF16("www.teamliquid.net"), |
783 ASCIIToUTF16("mliquid.net")); | 821 ASCIIToUTF16("mliquid.net")); |
784 } | 822 } |
OLD | NEW |