| 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 d78f33e6ee171d023db48d6b0559e34cdc195fa1..1ee380c54bff60cf5acac66d31746517799ef0b9 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"
|
| @@ -33,66 +34,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(""));
|
| - service->SetManagedPref(
|
| - prefs::kDefaultSearchProviderPrepopulateID, new StringValue(""));
|
| - model_->Observe(
|
| - chrome::NOTIFICATION_PREF_CHANGED,
|
| - content::Source<PrefService>(profile_->GetTestingPrefService()),
|
| - content::Details<std::string>(NULL));
|
| - }
|
| -
|
| - 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_;
|
| @@ -115,6 +67,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);
|
| @@ -123,6 +77,70 @@ 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(""));
|
| + service->SetManagedPref(
|
| + prefs::kDefaultSearchProviderPrepopulateID, new StringValue(""));
|
| + model_->Observe(
|
| + chrome::NOTIFICATION_PREF_CHANGED,
|
| + content::Source<PrefService>(profile_->GetTestingPrefService()),
|
| + content::Details<std::string>(NULL));
|
| +}
|
| +
|
| +TemplateURLTableModel* KeywordEditorControllerTest::table_model() const {
|
| + return controller_->table_model();
|
| +}
|
| +
|
| // Tests adding a TemplateURL.
|
| TEST_F(KeywordEditorControllerTest, Add) {
|
| controller_->AddTemplateURL(kA, kB, "http://c");
|
|
|