Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider_unittest.cc

Issue 1368293012: HistoryQuickProviderTest.DeleteMatch thread safety fix. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/omnibox/browser/history_quick_provider.h" 5 #include "components/omnibox/browser/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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 // As above, simply with a cursor position specified. 202 // As above, simply with a cursor position specified.
203 void RunTestWithCursor(const base::string16 text, 203 void RunTestWithCursor(const base::string16 text,
204 const size_t cursor_position, 204 const size_t cursor_position,
205 bool prevent_inline_autocomplete, 205 bool prevent_inline_autocomplete,
206 std::vector<std::string> expected_urls, 206 std::vector<std::string> expected_urls,
207 bool can_inline_top_result, 207 bool can_inline_top_result,
208 base::string16 expected_fill_into_edit, 208 base::string16 expected_fill_into_edit,
209 base::string16 autocompletion); 209 base::string16 autocompletion);
210 210
211 // TODO(shess): From history_service.h in reference to history_backend:
212 // > This class has most of the implementation and runs on the 'thread_'.
213 // > You MUST communicate with this class ONLY through the thread_'s
214 // > message_loop().
215 // Direct use of this object in tests is almost certainly not thread-safe.
211 history::HistoryBackend* history_backend() { 216 history::HistoryBackend* history_backend() {
212 return history_service_->history_backend_.get(); 217 return history_service_->history_backend_.get();
213 } 218 }
214 219
220 // Call history_backend()->GetURL(url, NULL) on the history thread, returning
221 // the result.
222 bool GetURLProxy(const GURL& url);
223
224 // Background task posted by GetURLProxy().
225 static void GetURLTask(history::HistoryBackend* backend,
226 const GURL& url,
227 bool* result_storage);
228
215 base::MessageLoopForUI message_loop_; 229 base::MessageLoopForUI message_loop_;
216 content::TestBrowserThread ui_thread_; 230 content::TestBrowserThread ui_thread_;
217 content::TestBrowserThread file_thread_; 231 content::TestBrowserThread file_thread_;
218 232
219 scoped_ptr<TestingProfile> profile_; 233 scoped_ptr<TestingProfile> profile_;
220 scoped_ptr<ChromeAutocompleteProviderClient> client_; 234 scoped_ptr<ChromeAutocompleteProviderClient> client_;
221 history::HistoryService* history_service_; 235 history::HistoryService* history_service_;
222 236
223 ACMatches ac_matches_; // The resulting matches after running RunTest. 237 ACMatches ac_matches_; // The resulting matches after running RunTest.
224 238
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 << "), we noticed scores are not monotonically decreasing."; 401 << "), we noticed scores are not monotonically decreasing.";
388 best_score = actual->relevance; 402 best_score = actual->relevance;
389 } 403 }
390 404
391 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); 405 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match);
392 if (can_inline_top_result) 406 if (can_inline_top_result)
393 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion); 407 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion);
394 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit); 408 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit);
395 } 409 }
396 410
411 bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) {
412 bool result = false;
413 base::RunLoop runner;
414 history_service_->PostTaskAndReplyForTest(
415 base::Bind(&GetURLTask, base::Unretained(history_backend()),
416 url, &result),
417 runner.QuitClosure());
418 runner.Run();
419 return result;
420 }
421
422 // static
423 void HistoryQuickProviderTest::GetURLTask(history::HistoryBackend* backend,
424 const GURL& url,
425 bool* result_storage) {
426 *result_storage = backend->GetURL(url, NULL);
427 }
428
397 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 429 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
398 std::vector<std::string> expected_urls; 430 std::vector<std::string> expected_urls;
399 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 431 expected_urls.push_back("http://slashdot.org/favorite_page.html");
400 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 432 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
401 ASCIIToUTF16("slashdot.org/favorite_page.html"), 433 ASCIIToUTF16("slashdot.org/favorite_page.html"),
402 ASCIIToUTF16(".org/favorite_page.html")); 434 ASCIIToUTF16(".org/favorite_page.html"));
403 } 435 }
404 436
405 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { 437 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) {
406 std::vector<std::string> expected_urls; 438 std::vector<std::string> expected_urls;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 641
610 TEST_F(HistoryQuickProviderTest, DeleteMatch) { 642 TEST_F(HistoryQuickProviderTest, DeleteMatch) {
611 GURL test_url("http://slashdot.org/favorite_page.html"); 643 GURL test_url("http://slashdot.org/favorite_page.html");
612 std::vector<std::string> expected_urls; 644 std::vector<std::string> expected_urls;
613 expected_urls.push_back(test_url.spec()); 645 expected_urls.push_back(test_url.spec());
614 // Fill up ac_matches_; we don't really care about the test yet. 646 // Fill up ac_matches_; we don't really care about the test yet.
615 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 647 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
616 ASCIIToUTF16("slashdot.org/favorite_page.html"), 648 ASCIIToUTF16("slashdot.org/favorite_page.html"),
617 ASCIIToUTF16(".org/favorite_page.html")); 649 ASCIIToUTF16(".org/favorite_page.html"));
618 EXPECT_EQ(1U, ac_matches_.size()); 650 EXPECT_EQ(1U, ac_matches_.size());
619 EXPECT_TRUE(history_backend()->GetURL(test_url, NULL)); 651 EXPECT_TRUE(GetURLProxy(test_url));
620 provider_->DeleteMatch(ac_matches_[0]); 652 provider_->DeleteMatch(ac_matches_[0]);
621 653
622 // Check that the underlying URL is deleted from the history DB (this implies 654 // Check that the underlying URL is deleted from the history DB (this implies
623 // that all visits are gone as well). Also verify that a deletion notification 655 // that all visits are gone as well). Also verify that a deletion notification
624 // is sent, in response to which the secondary data stores (InMemoryDatabase, 656 // is sent, in response to which the secondary data stores (InMemoryDatabase,
625 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. 657 // InMemoryURLIndex) will drop any data they might have pertaining to the URL.
626 // To ensure that the deletion has been propagated everywhere before we start 658 // To ensure that the deletion has been propagated everywhere before we start
627 // verifying post-deletion states, first wait until we see the notification. 659 // verifying post-deletion states, first wait until we see the notification.
628 WaitForURLsDeletedNotification(history_service_); 660 WaitForURLsDeletedNotification(history_service_);
629 EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); 661 EXPECT_FALSE(GetURLProxy(test_url));
630 662
631 // Just to be on the safe side, explicitly verify that we have deleted enough 663 // Just to be on the safe side, explicitly verify that we have deleted enough
632 // data so that we will not be serving the same result again. 664 // data so that we will not be serving the same result again.
633 expected_urls.clear(); 665 expected_urls.clear();
634 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 666 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
635 ASCIIToUTF16("NONE EXPECTED"), base::string16()); 667 ASCIIToUTF16("NONE EXPECTED"), base::string16());
636 } 668 }
637 669
638 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { 670 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) {
639 std::vector<std::string> expected_urls; 671 std::vector<std::string> expected_urls;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 862
831 TEST_F(HQPOrderingTest, TEAMatch) { 863 TEST_F(HQPOrderingTest, TEAMatch) {
832 std::vector<std::string> expected_urls; 864 std::vector<std::string> expected_urls;
833 expected_urls.push_back("http://www.teamliquid.net/"); 865 expected_urls.push_back("http://www.teamliquid.net/");
834 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 866 expected_urls.push_back("http://www.teamliquid.net/tlpd");
835 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 867 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
836 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 868 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
837 ASCIIToUTF16("www.teamliquid.net"), 869 ASCIIToUTF16("www.teamliquid.net"),
838 ASCIIToUTF16("mliquid.net")); 870 ASCIIToUTF16("mliquid.net"));
839 } 871 }
OLDNEW
« no previous file with comments | « no previous file | components/history/core/browser/history_service.h » ('j') | components/history/core/browser/history_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698