summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorcaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 15:30:27 +0000
committercaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 15:30:27 +0000
commitaf45603ceec5270899b4f7518a219715c58fbcd7 (patch)
treee455a8c7e52c909e62135bd8f8b79bcb6472d211 /chrome
parentf30f48309343391319624595ad49575cabd76d52 (diff)
downloadchromium_src-af45603ceec5270899b4f7518a219715c58fbcd7.zip
chromium_src-af45603ceec5270899b4f7518a219715c58fbcd7.tar.gz
chromium_src-af45603ceec5270899b4f7518a219715c58fbcd7.tar.bz2
Test fixes and clean up in preparation for moving DSE to Prefs.
TBR= dbeam@chromium.org (TBR'ing for a pref name change in options UI). BUG=365762 Review URL: https://codereview.chromium.org/265393007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_provider_unittest.cc9
-rw-r--r--chrome/browser/resources/options/browser_options.html2
-rw-r--r--chrome/browser/search_engines/search_provider_install_data.cc83
-rw-r--r--chrome/browser/search_engines/search_provider_install_data.h27
-rw-r--r--chrome/browser/search_engines/search_provider_install_data_unittest.cc38
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view_browsertest.cc17
-rw-r--r--chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc201
-rw-r--r--chrome/test/data/policy/policy_test_cases.json32
8 files changed, 203 insertions, 206 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
index fb0c318..a2cd035 100644
--- a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
@@ -303,10 +303,11 @@ void AutocompleteProviderTest::
ASSERT_NE(0, default_provider_id);
// Create another TemplateURL for KeywordProvider.
- data.short_name = base::ASCIIToUTF16("k");
- data.SetKeyword(base::ASCIIToUTF16("k"));
- data.SetURL("http://keyword/{searchTerms}");
- TemplateURL* keyword_t_url = new TemplateURL(&profile_, data);
+ TemplateURLData data2;
+ data2.short_name = base::ASCIIToUTF16("k");
+ data2.SetKeyword(base::ASCIIToUTF16("k"));
+ data2.SetURL("http://keyword/{searchTerms}");
+ TemplateURL* keyword_t_url = new TemplateURL(&profile_, data2);
turl_model->Add(keyword_t_url);
ASSERT_NE(0, keyword_t_url->id());
diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html
index 3423293..80d7ba1 100644
--- a/chrome/browser/resources/options/browser_options.html
+++ b/chrome/browser/resources/options/browser_options.html
@@ -139,7 +139,7 @@
<div class="settings-row">
<select id="default-search-engine" class="weakrtl"></select>
<span class="controlled-setting-indicator"
- pref="default_search_provider.enabled">
+ pref="default_search_provider_data.template_url_data">
</span>
<button id="manage-default-search-engines"
i18n-content="defaultSearchManageEngines">
diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc
index 64b14fd..95d5a77 100644
--- a/chrome/browser/search_engines/search_provider_install_data.cc
+++ b/chrome/browser/search_engines/search_provider_install_data.cc
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner_helpers.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/search_engines/search_terms_data.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"
#include "chrome/browser/search_engines/util.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "content/public/browser/browser_thread.h"
@@ -36,6 +38,30 @@ typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
namespace {
+void LoadDataOnUIThread(TemplateURLService* template_url_service,
+ const base::Callback<void(ScopedVector<TemplateURL>,
+ TemplateURL*)>& callback) {
+ ScopedVector<TemplateURL> template_url_copies;
+ TemplateURL* default_provider_copy = NULL;
+ TemplateURLService::TemplateURLVector original_template_urls =
+ template_url_service->GetTemplateURLs();
+ TemplateURL* original_default_provider =
+ template_url_service->GetDefaultSearchProvider();
+ for (TemplateURLService::TemplateURLVector::const_iterator it =
+ original_template_urls.begin();
+ it != original_template_urls.end();
+ ++it) {
+ template_url_copies.push_back(new TemplateURL(NULL, (*it)->data()));
+ if (*it == original_default_provider)
+ default_provider_copy = template_url_copies.back();
+ }
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(callback,
+ base::Passed(template_url_copies.Pass()),
+ base::Unretained(default_provider_copy)));
+}
+
// Implementation of SearchTermsData that may be used on the I/O thread.
class IOThreadSearchTermsData : public SearchTermsData {
public:
@@ -165,9 +191,9 @@ static bool IsSameOrigin(const GURL& requested_origin,
} // namespace
SearchProviderInstallData::SearchProviderInstallData(
- Profile* profile, content::RenderProcessHost* host)
- : web_service_(WebDataService::FromBrowserContext(profile)),
- load_handle_(0),
+ Profile* profile,
+ content::RenderProcessHost* host)
+ : template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
google_base_url_(UIThreadSearchTermsData(profile).GoogleBaseURLValue()),
weak_factory_(this) {
// GoogleURLObserver is responsible for killing itself when
@@ -179,11 +205,6 @@ SearchProviderInstallData::SearchProviderInstallData(
SearchProviderInstallData::~SearchProviderInstallData() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- if (load_handle_) {
- DCHECK(web_service_.get());
- web_service_->CancelRequest(load_handle_);
- }
}
void SearchProviderInstallData::CallWhenLoaded(const base::Closure& closure) {
@@ -194,14 +215,24 @@ void SearchProviderInstallData::CallWhenLoaded(const base::Closure& closure) {
return;
}
+ bool do_load = closure_queue_.empty();
closure_queue_.push_back(closure);
- if (load_handle_)
+
+ // If the queue wasn't empty, there was already a load in progress.
+ if (!do_load)
return;
- if (web_service_.get())
- load_handle_ = web_service_->GetKeywords(this);
- else
+ if (template_url_service_) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&LoadDataOnUIThread,
+ template_url_service_,
+ base::Bind(&SearchProviderInstallData::OnTemplateURLsLoaded,
+ weak_factory_.GetWeakPtr())));
+ } else {
OnLoadFailed();
+ }
}
SearchProviderInstallData::State SearchProviderInstallData::GetInstallState(
@@ -233,35 +264,17 @@ void SearchProviderInstallData::OnGoogleURLChange(
google_base_url_ = google_base_url;
}
-void SearchProviderInstallData::OnWebDataServiceRequestDone(
- WebDataService::Handle h,
- const WDTypedResult* result) {
+void SearchProviderInstallData::OnTemplateURLsLoaded(
+ ScopedVector<TemplateURL> template_urls,
+ TemplateURL* default_provider) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // Reset the load_handle so that we don't try and cancel the load in
- // the destructor.
- load_handle_ = 0;
-
- if (!result) {
- // Results are null if the database went away or (most likely) wasn't
- // loaded.
- OnLoadFailed();
- return;
- }
+ template_urls_ = template_urls.Pass();
- TemplateURL* default_search_provider = NULL;
- int new_resource_keyword_version = 0;
- std::vector<TemplateURL*> extracted_template_urls;
- GetSearchProvidersUsingKeywordResult(*result, NULL, NULL,
- &extracted_template_urls, &default_search_provider,
- &new_resource_keyword_version, NULL);
- template_urls_.get().insert(template_urls_.get().begin(),
- extracted_template_urls.begin(),
- extracted_template_urls.end());
IOThreadSearchTermsData search_terms_data(google_base_url_);
provider_map_.reset(new SearchHostToURLsMap());
provider_map_->Init(template_urls_.get(), search_terms_data);
- SetDefault(default_search_provider);
+ SetDefault(default_provider);
NotifyLoaded();
}
diff --git a/chrome/browser/search_engines/search_provider_install_data.h b/chrome/browser/search_engines/search_provider_install_data.h
index dc196eaa..853e449 100644
--- a/chrome/browser/search_engines/search_provider_install_data.h
+++ b/chrome/browser/search_engines/search_provider_install_data.h
@@ -13,11 +13,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/webdata/web_data_service.h"
class GURL;
+class Profile;
class SearchHostToURLsMap;
class TemplateURL;
+class TemplateURLService;
namespace content {
class RenderProcessHost;
@@ -27,7 +28,7 @@ class RenderProcessHost;
// loading the data on demand (when CallWhenLoaded is called) and then throwing
// away the results after the callbacks are done, so the results are always up
// to date with what is in the database.
-class SearchProviderInstallData : public WebDataServiceConsumer {
+class SearchProviderInstallData {
public:
enum State {
// The search provider is not installed.
@@ -61,13 +62,9 @@ class SearchProviderInstallData : public WebDataServiceConsumer {
void OnGoogleURLChange(const std::string& google_base_url);
private:
- // WebDataServiceConsumer
- // Notification that the keywords have been loaded.
- // This is invoked from WebDataService, and should not be directly
- // invoked.
- virtual void OnWebDataServiceRequestDone(
- WebDataService::Handle h,
- const WDTypedResult* result) OVERRIDE;
+ // Receives a copy of the TemplateURLService's keywords on the IO thread.
+ void OnTemplateURLsLoaded(ScopedVector<TemplateURL> template_urls,
+ TemplateURL* default_provider);
// Stores information about the default search provider.
void SetDefault(const TemplateURL* template_url);
@@ -80,14 +77,12 @@ class SearchProviderInstallData : public WebDataServiceConsumer {
// install state has been loaded.
void NotifyLoaded();
- // The list of closures to call after the load has finished.
- std::vector<base::Closure> closure_queue_;
-
- // Service used to store entries.
- scoped_refptr<WebDataService> web_service_;
+ // The original data source. Only accessed on the UI thread.
+ TemplateURLService* template_url_service_;
- // If non-zero, we're waiting on a load.
- WebDataService::Handle load_handle_;
+ // The list of closures to call after the load has finished. If empty, there
+ // is no pending load.
+ std::vector<base::Closure> closure_queue_;
// Holds results of a load that was done using this class.
scoped_ptr<SearchHostToURLsMap> provider_map_;
diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
index ebc6616..a554255 100644
--- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc
+++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
@@ -125,8 +125,6 @@ class SearchProviderInstallDataTest : public testing::Test {
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
- void SimulateDefaultSearchIsManaged(const std::string& url);
-
protected:
TemplateURL* AddNewTemplateURL(const std::string& url,
const base::string16& keyword);
@@ -172,29 +170,6 @@ void SearchProviderInstallDataTest::TearDown() {
testing::Test::TearDown();
}
-void SearchProviderInstallDataTest::SimulateDefaultSearchIsManaged(
- const std::string& url) {
- ASSERT_FALSE(url.empty());
- TestingPrefServiceSyncable* service =
- util_.profile()->GetTestingPrefService();
- service->SetManagedPref(prefs::kDefaultSearchProviderEnabled,
- base::Value::CreateBooleanValue(true));
- service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL,
- base::Value::CreateStringValue(url));
- service->SetManagedPref(prefs::kDefaultSearchProviderName,
- base::Value::CreateStringValue("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()));
- util_.model()->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
-}
-
TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL(
const std::string& url,
const base::string16& keyword) {
@@ -239,8 +214,17 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
// Set a managed preference that establishes a default search provider.
std::string host2 = "www.managedtest.com";
- std::string url2 = "http://" + host2 + "/p{searchTerms}";
- SimulateDefaultSearchIsManaged(url2);
+ util_.SetManagedDefaultSearchPreferences(
+ true,
+ "managed",
+ "managed",
+ "http://" + host2 + "/p{searchTerms}",
+ std::string(),
+ std::string(),
+ std::string(),
+ std::string(),
+ std::string());
+
EXPECT_TRUE(util_.model()->is_default_search_managed());
// Wait for the changes to be saved.
diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
index 1279447..2250313 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
@@ -241,13 +241,6 @@ class OmniboxViewTest : public InProcessBrowserTest,
ui_test_utils::WaitForTemplateURLServiceToLoad(model);
ASSERT_TRUE(model->loaded());
- // Remove built-in template urls, like google.com, bing.com etc., as they
- // may appear as autocomplete suggests and interfere with our tests.
- model->SetUserSelectedDefaultSearchProvider(NULL);
- TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs();
- for (TemplateURLService::TemplateURLVector::const_iterator
- i = builtins.begin(); i != builtins.end(); ++i)
- model->Remove(*i);
TemplateURLData data;
data.short_name = ASCIIToUTF16(kSearchShortName);
@@ -259,6 +252,16 @@ class OmniboxViewTest : public InProcessBrowserTest,
data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
model->Add(new TemplateURL(profile, data));
+
+ // Remove built-in template urls, like google.com, bing.com etc., as they
+ // may appear as autocomplete suggests and interfere with our tests.
+ TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs();
+ for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin();
+ i != urls.end();
+ ++i) {
+ if ((*i)->prepopulate_id() != 0)
+ model->Remove(*i);
+ }
}
void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
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 f13247e..93fbef8 100644
--- a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
@@ -2,20 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/message_loop/message_loop.h"
+#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.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"
+#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
#include "chrome/browser/ui/search_engines/template_url_table_model.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/browser/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/table_model_observer.h"
@@ -31,11 +27,35 @@ static const base::string16 kB1(ASCIIToUTF16("b1"));
class KeywordEditorControllerTest : public testing::Test,
public ui::TableModelObserver {
public:
- // Initializes all of the state.
- void Init(bool simulate_load_failure);
+ KeywordEditorControllerTest()
+ : simulate_load_failure_(false),
+ model_changed_count_(0),
+ items_changed_count_(0),
+ added_count_(0),
+ removed_count_(0) {}
+
+ explicit KeywordEditorControllerTest(bool simulate_load_failure)
+ : simulate_load_failure_(simulate_load_failure),
+ model_changed_count_(0),
+ items_changed_count_(0),
+ added_count_(0),
+ removed_count_(0) {}
+
+ virtual void SetUp() OVERRIDE {
+ util_.SetUp();
+
+ if (simulate_load_failure_)
+ util_.model()->OnWebDataServiceRequestDone(0, NULL);
+ else
+ util_.ChangeModelToLoadState();
+
+ controller_.reset(new KeywordEditorController(util_.profile()));
+ controller_->table_model()->SetObserver(this);
+ }
- virtual void SetUp() {
- Init(false);
+ virtual void TearDown() OVERRIDE {
+ controller_.reset();
+ util_.TearDown();
}
virtual void OnModelChanged() OVERRIDE {
@@ -69,35 +89,29 @@ 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());
+ util_.SetManagedDefaultSearchPreferences(true,
+ "managed",
+ "managed",
+ url,
+ std::string(),
+ std::string(),
+ std::string(),
+ std::string(),
+ std::string());
}
- TemplateURLTableModel* table_model() const {
- return controller_->table_model();
- }
+ TemplateURLTableModel* table_model() { return controller_->table_model(); }
+ KeywordEditorController* controller() { return controller_.get(); }
+ const TemplateURLServiceTestUtil* util() const { return &util_; }
- protected:
- base::MessageLoopForUI message_loop_;
- scoped_ptr<TestingProfile> profile_;
+ int items_changed_count() const { return items_changed_count_; }
+ int added_count() const { return added_count_; }
+ int removed_count() const { return removed_count_; }
+
+ private:
scoped_ptr<KeywordEditorController> controller_;
- TemplateURLService* model_;
+ TemplateURLServiceTestUtil util_;
+ bool simulate_load_failure_;
int model_changed_count_;
int items_changed_count_;
@@ -105,27 +119,16 @@ class KeywordEditorControllerTest : public testing::Test,
int removed_count_;
};
-void KeywordEditorControllerTest::Init(bool simulate_load_failure) {
- ClearChangeCount();
-
- // If init is called twice, make sure that the controller is destroyed before
- // the profile is.
- controller_.reset();
- profile_.reset(new TestingProfile());
- TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(), &TemplateURLServiceFactory::BuildInstanceFor);
-
- model_ = TemplateURLServiceFactory::GetForProfile(profile_.get());
- if (simulate_load_failure)
- model_->OnWebDataServiceRequestDone(0, NULL);
-
- controller_.reset(new KeywordEditorController(profile_.get()));
- controller_->table_model()->SetObserver(this);
-}
+class KeywordEditorControllerNoWebDataTest
+ : public KeywordEditorControllerTest {
+ public:
+ KeywordEditorControllerNoWebDataTest() : KeywordEditorControllerTest(true) {}
+};
// Tests adding a TemplateURL.
TEST_F(KeywordEditorControllerTest, Add) {
- controller_->AddTemplateURL(kA, kB, "http://c");
+ int original_row_count = table_model()->RowCount();
+ controller()->AddTemplateURL(kA, kB, "http://c");
// Verify the observer was notified.
VerifyChangeCount(0, 0, 1, 0);
@@ -133,13 +136,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 = util()->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());
@@ -147,12 +148,12 @@ TEST_F(KeywordEditorControllerTest, Add) {
// Tests modifying a TemplateURL.
TEST_F(KeywordEditorControllerTest, Modify) {
- controller_->AddTemplateURL(kA, kB, "http://c");
+ controller()->AddTemplateURL(kA, kB, "http://c");
ClearChangeCount();
// Modify the entry.
- TemplateURL* turl = model_->GetTemplateURLs()[0];
- controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1");
+ TemplateURL* turl = util()->model()->GetTemplateURLs()[0];
+ controller()->ModifyTemplateURL(turl, kA1, kB1, "http://c1");
// Make sure it was updated appropriately.
VerifyChangeCount(0, 1, 0, 0);
@@ -163,98 +164,98 @@ 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 = util()->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 ||
- removed_count_ > 0);
- ASSERT_TRUE(model_->GetDefaultSearchProvider() == turl);
+ ASSERT_TRUE(items_changed_count() > 0 || added_count() > 0 ||
+ removed_count() > 0);
+ ASSERT_TRUE(util()->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);
}
// Tests that a TemplateURL can't be made the default if the default search
// provider is managed via policy.
TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) {
- controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
- controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}");
+ controller()->AddTemplateURL(kA, kB, "http://c{searchTerms}");
+ controller()->AddTemplateURL(kA1, kB1, "http://d{searchTerms}");
ClearChangeCount();
const TemplateURL* turl1 =
- model_->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
+ util()->model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
ASSERT_TRUE(turl1 != NULL);
const TemplateURL* turl2 =
- model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
+ util()->model()->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
ASSERT_TRUE(turl2 != NULL);
- EXPECT_TRUE(controller_->CanMakeDefault(turl1));
- EXPECT_TRUE(controller_->CanMakeDefault(turl2));
+ EXPECT_TRUE(controller()->CanMakeDefault(turl1));
+ EXPECT_TRUE(controller()->CanMakeDefault(turl2));
SimulateDefaultSearchIsManaged(turl2->url());
- EXPECT_TRUE(model_->is_default_search_managed());
+ EXPECT_TRUE(util()->model()->is_default_search_managed());
- EXPECT_FALSE(controller_->CanMakeDefault(turl1));
- EXPECT_FALSE(controller_->CanMakeDefault(turl2));
+ EXPECT_FALSE(controller()->CanMakeDefault(turl1));
+ EXPECT_FALSE(controller()->CanMakeDefault(turl2));
}
// Tests that a TemplateURL can't be edited if it is the managed default search
// provider.
TEST_F(KeywordEditorControllerTest, EditManagedDefault) {
- controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
- controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}");
+ controller()->AddTemplateURL(kA, kB, "http://c{searchTerms}");
+ controller()->AddTemplateURL(kA1, kB1, "http://d{searchTerms}");
ClearChangeCount();
const TemplateURL* turl1 =
- model_->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
+ util()->model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
ASSERT_TRUE(turl1 != NULL);
const TemplateURL* turl2 =
- model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
+ util()->model()->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
ASSERT_TRUE(turl2 != NULL);
- EXPECT_TRUE(controller_->CanEdit(turl1));
- EXPECT_TRUE(controller_->CanEdit(turl2));
+ EXPECT_TRUE(controller()->CanEdit(turl1));
+ EXPECT_TRUE(controller()->CanEdit(turl2));
// Simulate setting a managed default. This will add another template URL to
// the model.
SimulateDefaultSearchIsManaged(turl2->url());
- EXPECT_TRUE(model_->is_default_search_managed());
- EXPECT_TRUE(controller_->CanEdit(turl1));
- EXPECT_TRUE(controller_->CanEdit(turl2));
- EXPECT_FALSE(controller_->CanEdit(model_->GetDefaultSearchProvider()));
+ EXPECT_TRUE(util()->model()->is_default_search_managed());
+ EXPECT_TRUE(controller()->CanEdit(turl1));
+ EXPECT_TRUE(controller()->CanEdit(turl2));
+ EXPECT_FALSE(
+ controller()->CanEdit(util()->model()->GetDefaultSearchProvider()));
}
-TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) {
- // Simulate a failure to load Web Data.
- Init(true);
-
- controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
+TEST_F(KeywordEditorControllerNoWebDataTest, MakeDefaultNoWebData) {
+ 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"));
- TemplateURL* turl = new TemplateURL(profile_.get(), data);
- model_->Add(turl);
+ TemplateURL* turl = new TemplateURL(util()->profile(), data);
+ util()->model()->Add(turl);
// Table model should have updated.
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);
}
diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json
index 5f31e3c..eaa0749 100644
--- a/chrome/test/data/policy/policy_test_cases.json
+++ b/chrome/test/data/policy/policy_test_cases.json
@@ -751,7 +751,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderEnabled": false },
"pref_mappings": [
- { "pref": "default_search_provider.enabled",
+ { "pref": "default_search_provider_data.template_url_data",
"indicator_tests": [
{ "policy": { "DefaultSearchProviderEnabled": false } },
{ "policy": { "DefaultSearchProviderEnabled": true, "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google" } }
@@ -764,7 +764,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderName": "google.com" },
"pref_mappings": [
- { "pref": "default_search_provider.name" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -772,7 +772,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google" },
"pref_mappings": [
- { "pref": "default_search_provider.keyword" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -780,7 +780,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google" },
"pref_mappings": [
- { "pref": "default_search_provider.search_url",
+ { "pref": "default_search_provider_data.template_url_data",
"indicator_selector": "[setting=search-engine]",
"indicator_tests": [
{ "policy": { "DefaultSearchProviderEnabled": true, "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}" } }
@@ -793,7 +793,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderSuggestURL": "http://www.google.com/suggest?q={searchTerms}" },
"pref_mappings": [
- { "pref": "default_search_provider.suggest_url" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -801,7 +801,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderInstantURL": "http://www.google.com/instant?q={searchTerms}" },
"pref_mappings": [
- { "pref": "default_search_provider.instant_url" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -809,7 +809,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderNewTabURL": "http://www.google.com/newtab" },
"pref_mappings": [
- { "pref": "default_search_provider.new_tab_url" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -817,7 +817,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderIconURL": "http://www.google.com/favicon.ico" },
"pref_mappings": [
- { "pref": "default_search_provider.icon_url" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -825,7 +825,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderEncodings": ["UTF-8"] },
"pref_mappings": [
- { "pref": "default_search_provider.encodings" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -833,7 +833,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderAlternateURLs": ["http://www.google.com/#q={searchTerms}", "http://www.google.com/search#q={searchTerms}"] },
"pref_mappings": [
- { "pref": "default_search_provider.alternate_urls" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -841,7 +841,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderSearchTermsReplacementKey": "espv" },
"pref_mappings": [
- { "pref": "default_search_provider.search_terms_replacement_key" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -849,7 +849,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderImageURL": "http://www.google.com/searchbyimage/upload" },
"pref_mappings": [
- { "pref": "default_search_provider.image_url" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -857,7 +857,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderSearchURLPostParams": "" },
"pref_mappings": [
- { "pref": "default_search_provider.search_url_post_params" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -865,7 +865,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderSuggestURLPostParams": "" },
"pref_mappings": [
- { "pref": "default_search_provider.suggest_url_post_params" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -873,7 +873,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderInstantURLPostParams": "" },
"pref_mappings": [
- { "pref": "default_search_provider.instant_url_post_params" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},
@@ -881,7 +881,7 @@
"os": ["win", "linux", "mac", "chromeos"],
"test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderKeyword": "google", "DefaultSearchProviderImageURLPostParams": "image_content={imageThumbnail},image_url={imageURL},sbisrc={imageSearchSource}" },
"pref_mappings": [
- { "pref": "default_search_provider.image_url_post_params" }
+ { "pref": "default_search_provider_data.template_url_data" }
]
},