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

Unified Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Fixed after rebase on master Created 4 years 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/search_engines/template_url_service_sync_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
index 78f74c7843d187baef69723203939c6f2a547447..27a726e0f3c5788d98808deaf79a2f5ffd66550e 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/test/base/testing_profile.h"
#include "components/search_engines/search_engines_pref_names.h"
+#include "components/search_engines/search_engines_test_util.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_prepopulate_data.h"
@@ -164,6 +165,9 @@ class TestTemplateURLServiceClient : public TemplateURLServiceClient {
const base::string16& term) override {}
void AddKeywordGeneratedVisit(const GURL& url) override {}
bool IsOmniboxExtensionURL(const std::string& url) override { return false; }
+ std::string GetExtensionControllingDSEPref() override {
+ return std::string();
+ }
};
} // namespace
@@ -413,7 +417,7 @@ TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) {
}
}
-TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithExtension) {
+TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithOmniboxExtension) {
model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
std::string fake_id("blahblahblah");
@@ -433,6 +437,43 @@ TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithExtension) {
}
}
+TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithSearchOverrideExtension) {
+ model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
+ model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
+
+ // Change default search provider to a extension one.
+ std::unique_ptr<TemplateURLData> extension =
+ GenerateDummyTemplateURLData("extension");
+ auto ext_dse = base::MakeUnique<TemplateURL>(
+ *extension, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
+ auto ext_info = base::MakeUnique<TemplateURL::AssociatedExtensionInfo>("ext");
+ ext_info->wants_to_be_default_engine = true;
+ test_util_a_->AddExtensionControlledTURL(std::move(ext_dse),
+ std::move(ext_info));
+
+ const TemplateURL* ext_turl = model()->GetDefaultSearchProvider();
+ EXPECT_TRUE(model()->IsExtensionControlledDefaultSearch());
+
+ // Extension default search must not be synced across browsers.
+ syncer::SyncDataList all_sync_data =
+ model()->GetAllSyncData(syncer::SEARCH_ENGINES);
+
+ EXPECT_EQ(2U, all_sync_data.size());
+
+ for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin();
+ iter != all_sync_data.end(); ++iter) {
+ std::string guid = GetGUID(*iter);
+ const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid);
+ std::unique_ptr<TemplateURL> deserialized(Deserialize(*iter));
+ AssertEquals(*service_turl, *deserialized);
+ EXPECT_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION,
+ deserialized->type());
+ EXPECT_NE(ext_turl->keyword(), deserialized->keyword());
+ EXPECT_NE(ext_turl->short_name(), deserialized->short_name());
+ EXPECT_NE(ext_turl->url(), deserialized->url());
+ }
+}
+
TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) {
model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
@@ -1706,6 +1747,61 @@ TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) {
EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider());
}
+TEST_F(TemplateURLServiceSyncTest, SyncWithExtensionDefaultSearch) {
vasilii 2016/12/13 17:16:39 You have one test above that checks GetAllSyncData
Alexander Yashkin 2016/12/14 19:25:21 Added checks after AddExtensionControlledTURL.
+ // First start off with a few entries and make sure we can set an extension
+ // default search provider.
+ syncer::SyncDataList initial_data = CreateInitialSyncData();
+ model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
+ PassProcessor(),
+ CreateAndPassSyncErrorFactory());
+ model()->SetUserSelectedDefaultSearchProvider(
+ model()->GetTemplateURLForGUID("key2"));
+
+ EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
+ ASSERT_FALSE(model()->is_default_search_managed());
+ ASSERT_TRUE(model()->GetDefaultSearchProvider());
+
+ // Change the default search provider to a extension one.
+ std::unique_ptr<TemplateURLData> extension =
+ GenerateDummyTemplateURLData("extensiondefault");
+ auto ext_dse = base::MakeUnique<TemplateURL>(
+ *extension, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
+ auto ext_info = base::MakeUnique<TemplateURL::AssociatedExtensionInfo>("ext");
+ ext_info->wants_to_be_default_engine = true;
+ test_util_a_->AddExtensionControlledTURL(std::move(ext_dse),
+ std::move(ext_info));
+
+ const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider();
+ EXPECT_TRUE(model()->IsExtensionControlledDefaultSearch());
+
+ // Add a new entry from Sync. It should still sync in despite the default
+ // being extension controlled.
+ syncer::SyncChangeList changes;
+ changes.push_back(CreateTestSyncChange(
+ syncer::SyncChange::ACTION_ADD,
+ CreateTestTemplateURL(ASCIIToUTF16("newkeyword"),
+ "http://new.com/{searchTerms}", "newdefault")));
+ model()->ProcessSyncChanges(FROM_HERE, changes);
+
+ EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
+
+ // Change kSyncedDefaultSearchProviderGUID to point to the new entry and
+ // ensure that the DSP remains extension controlled.
+ profile_a()->GetTestingPrefService()->SetString(
+ prefs::kSyncedDefaultSearchProviderGUID, "newdefault");
+
+ EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider());
+ EXPECT_TRUE(model()->IsExtensionControlledDefaultSearch());
+
+ // Remove extension DSE. Ensure that the DSP changes to the expected pending
+ // entry from Sync.
+ const TemplateURL* expected_default =
+ model()->GetTemplateURLForGUID("newdefault");
+ test_util_a_->RemoveExtensionDefaultSearchFromPrefs("ext");
+
+ EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider());
+}
+
TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) {
// If the value from Sync is a duplicate of the local default and is newer, it
// should safely replace the local value and set as the new default.

Powered by Google App Engine
This is Rietveld 408576698