OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/thread.h" | 6 #include "base/thread.h" |
7 #include "chrome/browser/webdata/web_database.h" | 7 #include "chrome/browser/webdata/web_database.h" |
8 #include "chrome/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 672 matching lines...) Loading... |
683 // Wait for the request to be processed. | 683 // Wait for the request to be processed. |
684 profile_->BlockUntilHistoryProcessesPendingRequests(); | 684 profile_->BlockUntilHistoryProcessesPendingRequests(); |
685 | 685 |
686 // And make sure the url and visit were added. | 686 // And make sure the url and visit were added. |
687 EXPECT_TRUE(callback.success); | 687 EXPECT_TRUE(callback.success); |
688 EXPECT_NE(0, callback.row.id()); | 688 EXPECT_NE(0, callback.row.id()); |
689 ASSERT_EQ(1U, callback.visits.size()); | 689 ASSERT_EQ(1U, callback.visits.size()); |
690 EXPECT_EQ(PageTransition::KEYWORD_GENERATED, | 690 EXPECT_EQ(PageTransition::KEYWORD_GENERATED, |
691 PageTransition::StripQualifier(callback.visits[0].transition)); | 691 PageTransition::StripQualifier(callback.visits[0].transition)); |
692 } | 692 } |
| 693 |
| 694 // Make sure that MergeEnginesFromPrepopulateData() deletes prepopulated engines |
| 695 // that no longer exist in the prepopulate data. |
| 696 TEST_F(TemplateURLModelTest, MergeDeletesUnusedProviders) { |
| 697 VerifyLoad(); |
| 698 |
| 699 // Create an URL that appears to have been prepopulated but won't be in the |
| 700 // current data. |
| 701 TemplateURL* t_url = new TemplateURL(); |
| 702 t_url->SetURL(L"http://www.unittest.com/", 0, 0); |
| 703 t_url->set_keyword(L"unittest"); |
| 704 t_url->set_short_name(L"unittest"); |
| 705 t_url->set_safe_for_autoreplace(true); |
| 706 GURL favicon_url("http://favicon.url"); |
| 707 t_url->SetFavIconURL(favicon_url); |
| 708 t_url->set_date_created(Time::FromTimeT(100)); |
| 709 t_url->set_prepopulate_id(999999); |
| 710 |
| 711 // Make a few copies now, since as we add each to the model it takes ownership |
| 712 // of them and deletes them when finished. |
| 713 TemplateURL* t_url2 = new TemplateURL(*t_url); |
| 714 TemplateURL* t_url3 = new TemplateURL(*t_url); |
| 715 |
| 716 // Ensure that merging clears this engine. |
| 717 model_->Add(t_url); |
| 718 EXPECT_EQ(t_url, model_->GetTemplateURLForKeyword(L"unittest")); |
| 719 model_->MergeEnginesFromPrepopulateData(); |
| 720 ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"unittest") == NULL); |
| 721 |
| 722 // Ensure that merging won't clear it if the user has edited it. |
| 723 t_url2->set_safe_for_autoreplace(false); |
| 724 model_->Add(t_url2); |
| 725 ASSERT_EQ(t_url2, model_->GetTemplateURLForKeyword(L"unittest")); |
| 726 model_->MergeEnginesFromPrepopulateData(); |
| 727 ASSERT_FALSE(model_->GetTemplateURLForKeyword(L"unittest") == NULL); |
| 728 model_->Remove(t_url2); |
| 729 |
| 730 // Ensure that merging won't clear it if it's the default engine. |
| 731 model_->Add(t_url3); |
| 732 ASSERT_EQ(t_url3, model_->GetTemplateURLForKeyword(L"unittest")); |
| 733 model_->SetDefaultSearchProvider(t_url3); |
| 734 ASSERT_EQ(t_url3, model_->GetDefaultSearchProvider()); |
| 735 model_->MergeEnginesFromPrepopulateData(); |
| 736 ASSERT_EQ(t_url3, model_->GetTemplateURLForKeyword(L"unittest")); |
| 737 ASSERT_EQ(t_url3, model_->GetDefaultSearchProvider()); |
| 738 // Don't remove |t_url3|; we'd need to make it non-default first, and why |
| 739 // bother when the model shutdown will clean it up for us. |
| 740 } |
OLD | NEW |