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_service.h" | 23 #include "chrome/browser/history/history_service.h" |
25 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/history/in_memory_url_index.h" | 25 #include "chrome/browser/history/in_memory_url_index.h" |
27 #include "chrome/browser/history/url_index_private_data.h" | 26 #include "chrome/browser/history/url_index_private_data.h" |
28 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" | 27 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" |
29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
30 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
31 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
32 #include "components/bookmarks/test/bookmark_test_helpers.h" | 31 #include "components/bookmarks/test/bookmark_test_helpers.h" |
33 #include "components/history/core/browser/history_database.h" | 32 #include "components/history/core/browser/history_database.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 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. |
| 107 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { |
| 108 public: |
| 109 explicit WaitForURLsDeletedObserver(base::RunLoop* 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 |
| 120 // Weak. Owned by our owner. |
| 121 base::RunLoop* runner_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(WaitForURLsDeletedObserver); |
| 124 }; |
| 125 |
| 126 WaitForURLsDeletedObserver::WaitForURLsDeletedObserver(base::RunLoop* runner) |
| 127 : runner_(runner) { |
| 128 } |
| 129 |
| 130 WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() { |
| 131 } |
| 132 |
| 133 void WaitForURLsDeletedObserver::OnURLsDeleted( |
| 134 HistoryService* service, |
| 135 bool all_history, |
| 136 bool expired, |
| 137 const history::URLRows& deleted_rows, |
| 138 const std::set<GURL>& favicon_urls) { |
| 139 runner_->Quit(); |
| 140 } |
| 141 |
| 142 void WaitForURLsDeletedNotification(HistoryService* history_service) { |
| 143 base::RunLoop runner; |
| 144 WaitForURLsDeletedObserver observer(&runner); |
| 145 ScopedObserver<HistoryService, history::HistoryServiceObserver> |
| 146 scoped_observer(&observer); |
| 147 scoped_observer.Add(history_service); |
| 148 runner.Run(); |
| 149 } |
| 150 |
107 class HistoryQuickProviderTest : public testing::Test { | 151 class HistoryQuickProviderTest : public testing::Test { |
108 public: | 152 public: |
109 HistoryQuickProviderTest() | 153 HistoryQuickProviderTest() |
110 : ui_thread_(BrowserThread::UI, &message_loop_), | 154 : ui_thread_(BrowserThread::UI, &message_loop_), |
111 file_thread_(BrowserThread::FILE, &message_loop_) {} | 155 file_thread_(BrowserThread::FILE, &message_loop_) {} |
112 | 156 |
113 protected: | 157 protected: |
114 class SetShouldContain : public std::unary_function<const std::string&, | 158 class SetShouldContain : public std::unary_function<const std::string&, |
115 std::set<std::string> > { | 159 std::set<std::string> > { |
116 public: | 160 public: |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 EXPECT_EQ(1U, ac_matches_.size()); | 611 EXPECT_EQ(1U, ac_matches_.size()); |
568 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); | 612 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); |
569 provider_->DeleteMatch(ac_matches_[0]); | 613 provider_->DeleteMatch(ac_matches_[0]); |
570 | 614 |
571 // Check that the underlying URL is deleted from the history DB (this implies | 615 // Check that the underlying URL is deleted from the history DB (this implies |
572 // that all visits are gone as well). Also verify that a deletion notification | 616 // that all visits are gone as well). Also verify that a deletion notification |
573 // is sent, in response to which the secondary data stores (InMemoryDatabase, | 617 // is sent, in response to which the secondary data stores (InMemoryDatabase, |
574 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. | 618 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. |
575 // To ensure that the deletion has been propagated everywhere before we start | 619 // To ensure that the deletion has been propagated everywhere before we start |
576 // verifying post-deletion states, first wait until we see the notification. | 620 // verifying post-deletion states, first wait until we see the notification. |
577 content::WindowedNotificationObserver observer( | 621 WaitForURLsDeletedNotification(history_service_); |
578 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
579 content::NotificationService::AllSources()); | |
580 observer.Wait(); | |
581 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); | 622 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); |
582 | 623 |
583 // Just to be on the safe side, explicitly verify that we have deleted enough | 624 // Just to be on the safe side, explicitly verify that we have deleted enough |
584 // data so that we will not be serving the same result again. | 625 // data so that we will not be serving the same result again. |
585 expected_urls.clear(); | 626 expected_urls.clear(); |
586 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 627 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
587 ASCIIToUTF16("NONE EXPECTED"), base::string16()); | 628 ASCIIToUTF16("NONE EXPECTED"), base::string16()); |
588 } | 629 } |
589 | 630 |
590 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { | 631 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 | 824 |
784 TEST_F(HQPOrderingTest, TEAMatch) { | 825 TEST_F(HQPOrderingTest, TEAMatch) { |
785 std::vector<std::string> expected_urls; | 826 std::vector<std::string> expected_urls; |
786 expected_urls.push_back("http://www.teamliquid.net/"); | 827 expected_urls.push_back("http://www.teamliquid.net/"); |
787 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 828 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
788 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 829 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
789 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 830 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
790 ASCIIToUTF16("www.teamliquid.net"), | 831 ASCIIToUTF16("www.teamliquid.net"), |
791 ASCIIToUTF16("mliquid.net")); | 832 ASCIIToUTF16("mliquid.net")); |
792 } | 833 } |
OLD | NEW |