Index: chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc |
diff --git a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc |
index 68ef24f2b07389ade79424948ba8ae0069a4780b..59f99c132e5ee633e64173b817eb43508fc787a8 100644 |
--- a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc |
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc |
@@ -11,6 +11,7 @@ |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
#include "chrome/browser/ui/search_engines/template_url_table_model.h" |
+#include "chrome/browser/webdata/web_data_service_factory.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_pref_service.h" |
@@ -32,62 +33,17 @@ class KeywordEditorControllerTest : public testing::Test, |
// Initializes all of the state. |
void Init(bool simulate_load_failure); |
- virtual void SetUp() { |
- Init(false); |
- } |
- |
- virtual void OnModelChanged() { |
- model_changed_count_++; |
- } |
- |
- virtual void OnItemsChanged(int start, int length) { |
- items_changed_count_++; |
- } |
- |
- virtual void OnItemsAdded(int start, int length) { |
- added_count_++; |
- } |
- |
- virtual void OnItemsRemoved(int start, int length) { |
- removed_count_++; |
- } |
+ virtual void SetUp() OVERRIDE; |
+ virtual void OnModelChanged() OVERRIDE; |
+ virtual void OnItemsChanged(int start, int length) OVERRIDE; |
+ virtual void OnItemsAdded(int start, int length) OVERRIDE; |
+ virtual void OnItemsRemoved(int start, int length) OVERRIDE; |
void VerifyChangeCount(int model_changed_count, int item_changed_count, |
- int added_count, int removed_count) { |
- ASSERT_EQ(model_changed_count, model_changed_count_); |
- ASSERT_EQ(item_changed_count, items_changed_count_); |
- ASSERT_EQ(added_count, added_count_); |
- ASSERT_EQ(removed_count, removed_count_); |
- ClearChangeCount(); |
- } |
- |
- void ClearChangeCount() { |
- model_changed_count_ = items_changed_count_ = added_count_ = |
- removed_count_ = 0; |
- } |
- |
- void SimulateDefaultSearchIsManaged(const std::string& url) { |
- ASSERT_FALSE(url.empty()); |
- TestingPrefService* service = profile_->GetTestingPrefService(); |
- service->SetManagedPref(prefs::kDefaultSearchProviderEnabled, |
- Value::CreateBooleanValue(true)); |
- service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL, |
- Value::CreateStringValue(url)); |
- service->SetManagedPref(prefs::kDefaultSearchProviderName, |
- Value::CreateStringValue("managed")); |
- // Clear the IDs that are not specified via policy. |
- service->SetManagedPref(prefs::kDefaultSearchProviderID, |
- new StringValue(std::string())); |
- service->SetManagedPref(prefs::kDefaultSearchProviderPrepopulateID, |
- new StringValue(std::string())); |
- model_->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, |
- content::NotificationService::AllSources(), |
- content::NotificationService::NoDetails()); |
- } |
- |
- TemplateURLTableModel* table_model() const { |
- return controller_->table_model(); |
- } |
+ int added_count, int removed_count); |
+ void ClearChangeCount(); |
+ void SimulateDefaultSearchIsManaged(const std::string& url); |
+ TemplateURLTableModel* table_model() const; |
protected: |
MessageLoopForUI message_loop_; |
@@ -110,6 +66,8 @@ void KeywordEditorControllerTest::Init(bool simulate_load_failure) { |
profile_.reset(new TestingProfile()); |
profile_->CreateTemplateURLService(); |
+ WebDataServiceFactory::GetInstance()->SetTestingFactory(profile_.get(), NULL); |
+ |
model_ = TemplateURLServiceFactory::GetForProfile(profile_.get()); |
if (simulate_load_failure) |
model_->OnWebDataServiceRequestDone(0, NULL); |
@@ -118,6 +76,66 @@ void KeywordEditorControllerTest::Init(bool simulate_load_failure) { |
controller_->table_model()->SetObserver(this); |
} |
+void KeywordEditorControllerTest::SetUp() { |
+ Init(false); |
+} |
+ |
+void KeywordEditorControllerTest::OnModelChanged() { |
+ model_changed_count_++; |
+} |
+ |
+void KeywordEditorControllerTest::OnItemsChanged(int start, int length) { |
+ items_changed_count_++; |
+} |
+ |
+void KeywordEditorControllerTest::OnItemsAdded(int start, int length) { |
+ added_count_++; |
+} |
+ |
+void KeywordEditorControllerTest::OnItemsRemoved(int start, int length) { |
+ removed_count_++; |
+} |
+ |
+void KeywordEditorControllerTest::VerifyChangeCount(int model_changed_count, |
+ int item_changed_count, |
+ int added_count, |
+ int removed_count) { |
+ ASSERT_EQ(model_changed_count, model_changed_count_); |
+ ASSERT_EQ(item_changed_count, items_changed_count_); |
+ ASSERT_EQ(added_count, added_count_); |
+ ASSERT_EQ(removed_count, removed_count_); |
+ ClearChangeCount(); |
+} |
+ |
+void KeywordEditorControllerTest::ClearChangeCount() { |
+ model_changed_count_ = items_changed_count_ = added_count_ = |
+ removed_count_ = 0; |
+} |
+ |
+void KeywordEditorControllerTest::SimulateDefaultSearchIsManaged( |
+ const std::string& url) { |
+ ASSERT_FALSE(url.empty()); |
+ TestingPrefService* service = profile_->GetTestingPrefService(); |
+ service->SetManagedPref(prefs::kDefaultSearchProviderEnabled, |
+ Value::CreateBooleanValue(true)); |
+ service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL, |
+ Value::CreateStringValue(url)); |
+ service->SetManagedPref(prefs::kDefaultSearchProviderName, |
+ Value::CreateStringValue("managed")); |
+ // Clear the IDs that are not specified via policy. |
+ service->SetManagedPref(prefs::kDefaultSearchProviderID, |
+ new StringValue(std::string())); |
+ service->SetManagedPref(prefs::kDefaultSearchProviderPrepopulateID, |
+ new StringValue(std::string())); |
+ model_->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, |
+ content::NotificationService::AllSources(), |
+ content::NotificationService::NoDetails()); |
+} |
+ |
+TemplateURLTableModel* KeywordEditorControllerTest::table_model() const { |
+ return controller_->table_model(); |
+} |
+ |
// Tests adding a TemplateURL. |
TEST_F(KeywordEditorControllerTest, Add) { |
controller_->AddTemplateURL(kA, kB, "http://c"); |