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

Unified Diff: chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc

Issue 268643002: Use the DefaultSearchManager as the exclusive authority on DSE, ignoring Web Data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: D'oh. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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 f13247e7527459c2e2072ac0272bb61b626c874d..658ee230c2bb20ec8ef7f823e61e5e3a4325d1f9 100644
--- a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
@@ -5,8 +5,10 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search_engines/default_search_manager.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -71,22 +73,16 @@ class KeywordEditorControllerTest : public testing::Test,
void SimulateDefaultSearchIsManaged(const std::string& url) {
ASSERT_FALSE(url.empty());
TestingPrefServiceSyncable* service = profile_->GetTestingPrefService();
- service->SetManagedPref(prefs::kDefaultSearchProviderEnabled,
- new base::FundamentalValue(true));
- service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL,
- new base::StringValue(url));
- service->SetManagedPref(prefs::kDefaultSearchProviderName,
- new base::StringValue("managed"));
- service->SetManagedPref(prefs::kDefaultSearchProviderKeyword,
- new base::StringValue("managed"));
- // Clear the IDs that are not specified via policy.
- service->SetManagedPref(prefs::kDefaultSearchProviderID,
- new base::StringValue(std::string()));
- service->SetManagedPref(prefs::kDefaultSearchProviderPrepopulateID,
- new base::StringValue(std::string()));
- model_->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
+ scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
+ value->Set(DefaultSearchManager::kShortName,
+ base::Value::CreateStringValue("managed"));
+ value->Set(DefaultSearchManager::kKeyword,
+ base::Value::CreateStringValue("managed"));
+ value->Set(DefaultSearchManager::kURL,
+ base::Value::CreateStringValue(url));
+ service->SetManagedPref(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName,
+ value.release());
}
TemplateURLTableModel* table_model() const {
@@ -125,6 +121,7 @@ void KeywordEditorControllerTest::Init(bool simulate_load_failure) {
// Tests adding a TemplateURL.
TEST_F(KeywordEditorControllerTest, Add) {
+ int original_row_count = table_model()->RowCount();
controller_->AddTemplateURL(kA, kB, "http://c");
// Verify the observer was notified.
@@ -133,13 +130,11 @@ TEST_F(KeywordEditorControllerTest, Add) {
return;
// Verify the TableModel has the new data.
- ASSERT_EQ(1, table_model()->RowCount());
+ ASSERT_EQ(original_row_count + 1, table_model()->RowCount());
- // Verify the TemplateURLService has the new entry.
- ASSERT_EQ(1U, model_->GetTemplateURLs().size());
-
- // Verify the entry is what we added.
- const TemplateURL* turl = model_->GetTemplateURLs()[0];
+ // Verify the TemplateURLService has the new data.
+ const TemplateURL* turl = model_->GetTemplateURLForKeyword(kB);
+ ASSERT_TRUE(turl);
EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name());
EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword());
EXPECT_EQ("http://c", turl->url());
@@ -163,12 +158,12 @@ TEST_F(KeywordEditorControllerTest, Modify) {
// Tests making a TemplateURL the default search provider.
TEST_F(KeywordEditorControllerTest, MakeDefault) {
- controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
+ int index = controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
ClearChangeCount();
- const TemplateURL* turl = model_->GetTemplateURLs()[0];
- int new_default = controller_->MakeDefaultTemplateURL(0);
- EXPECT_EQ(0, new_default);
+ const TemplateURL* turl = model_->GetTemplateURLForKeyword(kB);
+ int new_default = controller_->MakeDefaultTemplateURL(index);
+ EXPECT_EQ(index, new_default);
// Making an item the default sends a handful of changes. Which are sent isn't
// important, what is important is 'something' is sent.
ASSERT_TRUE(items_changed_count_ > 0 || added_count_ > 0 ||
@@ -176,7 +171,7 @@ TEST_F(KeywordEditorControllerTest, MakeDefault) {
ASSERT_TRUE(model_->GetDefaultSearchProvider() == turl);
// Making it default a second time should fail.
- new_default = controller_->MakeDefaultTemplateURL(0);
+ new_default = controller_->MakeDefaultTemplateURL(index);
EXPECT_EQ(-1, new_default);
}
@@ -234,17 +229,19 @@ TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) {
// Simulate a failure to load Web Data.
Init(true);
- controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
+ int index = controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
ClearChangeCount();
// This should not result in a crash.
- int new_default = controller_->MakeDefaultTemplateURL(0);
- EXPECT_EQ(0, new_default);
+ int new_default = controller_->MakeDefaultTemplateURL(index);
+ EXPECT_EQ(index, new_default);
}
// Mutates the TemplateURLService and make sure table model is updating
// appropriately.
TEST_F(KeywordEditorControllerTest, MutateTemplateURLService) {
+ int original_row_count = table_model()->RowCount();
+
TemplateURLData data;
data.short_name = ASCIIToUTF16("b");
data.SetKeyword(ASCIIToUTF16("a"));
@@ -255,6 +252,6 @@ TEST_F(KeywordEditorControllerTest, MutateTemplateURLService) {
VerifyChangeCount(1, 0, 0, 0);
// And should contain the newly added TemplateURL.
- ASSERT_EQ(1, table_model()->RowCount());
- ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl));
+ ASSERT_EQ(original_row_count + 1, table_model()->RowCount());
+ ASSERT_GE(table_model()->IndexOfTemplateURL(turl), 0);
}

Powered by Google App Engine
This is Rietveld 408576698