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

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

Issue 237653002: Import policy data into default search dictionary pref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits and rebase on ToT Created 6 years, 8 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
« no previous file with comments | « chrome/browser/search_engines/default_search_policy_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/default_search_policy_handler_unittest.cc
diff --git a/chrome/browser/search_engines/default_search_policy_handler_unittest.cc b/chrome/browser/search_engines/default_search_policy_handler_unittest.cc
index 16189a6338c6c480694b19d39a1a55a232a3f253..8dea354f22ded22e7066bddf968e18628f5e28f4 100644
--- a/chrome/browser/search_engines/default_search_policy_handler_unittest.cc
+++ b/chrome/browser/search_engines/default_search_policy_handler_unittest.cc
@@ -3,12 +3,20 @@
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/search_engines/default_search_manager.h"
#include "chrome/browser/search_engines/default_search_policy_handler.h"
#include "chrome/common/pref_names.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/policy/core/browser/configuration_policy_pref_store_test.h"
#include "policy/policy_constants.h"
+namespace {
+// TODO(caitkp): Should we find a way to route this through DefaultSearchManager
+// to avoid hardcoding this here?
+const char kDefaultSearchProviderData[] =
+ "default_search_provider_data.template_url_data";
+} // namespace
+
namespace policy {
class DefaultSearchPolicyHandlerTest
@@ -36,6 +44,8 @@ class DefaultSearchPolicyHandlerTest
static const char kImageURL[];
static const char kImageParams[];
static const char kNewTabURL[];
+ static const char kFileSearchURL[];
+ static const char kHostName[];
// Build a default search policy by setting search-related keys in |policy| to
// reasonable values. You can update any of the keys after calling this
@@ -63,6 +73,9 @@ const char DefaultSearchPolicyHandlerTest::kImageParams[] =
"image_content=content,image_url=http://test.com/test.png";
const char DefaultSearchPolicyHandlerTest::kNewTabURL[] =
"http://test.com/newtab";
+const char DefaultSearchPolicyHandlerTest::kFileSearchURL[] =
+ "file:///c:/path/to/search?t={searchTerms}";
+const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com";
void DefaultSearchPolicyHandlerTest::
BuildDefaultSearchPolicy(PolicyMap* policy) {
@@ -119,10 +132,10 @@ TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
EXPECT_TRUE(base::StringValue(kSearchURL).Equals(value));
EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderName, &value));
- EXPECT_TRUE(base::StringValue("test.com").Equals(value));
+ EXPECT_TRUE(base::StringValue(kHostName).Equals(value));
EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, &value));
- EXPECT_TRUE(base::StringValue("test.com").Equals(value));
+ EXPECT_TRUE(base::StringValue(kHostName).Equals(value));
EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL,
&value));
@@ -297,4 +310,179 @@ TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
EXPECT_TRUE(base::Value::Equals(&expected_search_url, value));
}
+// Checks that for a fully defined search policy, all elements have been
+// read properly into the dictionary pref.
+TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPref) {
+ PolicyMap policy;
+ BuildDefaultSearchPolicy(&policy);
+ UpdateProviderPolicy(policy);
+
+ const base::Value* temp = NULL;
+ const base::DictionaryValue* dictionary;
+ std::string value;
+ const base::ListValue* list_value;
+ EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ temp->GetAsDictionary(&dictionary);
+
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
+ EXPECT_EQ(kSearchURL, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
+ EXPECT_EQ(kName, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
+ EXPECT_EQ(kKeyword, value);
+
+ EXPECT_TRUE(
+ dictionary->GetString(DefaultSearchManager::kSuggestionsURL, &value));
+ EXPECT_EQ(kSuggestURL, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kFaviconURL, &value));
+ EXPECT_EQ(kIconURL, value);
+
+ base::ListValue encodings;
+ encodings.AppendString("UTF-16");
+ encodings.AppendString("UTF-8");
+
+ EXPECT_TRUE(
+ dictionary->GetList(DefaultSearchManager::kInputEncodings, &list_value));
+ EXPECT_TRUE(encodings.Equals(list_value));
+
+ EXPECT_TRUE(
+ dictionary->GetList(DefaultSearchManager::kAlternateURLs, &list_value));
+ EXPECT_TRUE(default_alternate_urls_.Equals(list_value));
+
+ EXPECT_TRUE(dictionary->GetString(
+ DefaultSearchManager::kSearchTermsReplacementKey, &value));
+ EXPECT_EQ(kReplacementKey, value);
+
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kImageURL, &value));
+ EXPECT_EQ(kImageURL, value);
+
+ EXPECT_TRUE(
+ dictionary->GetString(DefaultSearchManager::kImageURLPostParams, &value));
+ EXPECT_EQ(kImageParams, value);
+
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kSearchURLPostParams,
+ &value));
+ EXPECT_EQ(std::string(), value);
+
+ EXPECT_TRUE(dictionary->GetString(
+ DefaultSearchManager::kSuggestionsURLPostParams, &value));
+ EXPECT_EQ(std::string(), value);
+
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
+ &value));
+ EXPECT_EQ(std::string(), value);
+}
+
+// Checks that disabling default search is properly reflected the dictionary
+// pref.
+TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefDSEDisabled) {
+ PolicyMap policy;
+ policy.Set(key::kDefaultSearchProviderEnabled,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(false),
+ NULL);
+ UpdateProviderPolicy(policy);
+ const base::Value* temp = NULL;
+ const base::DictionaryValue* dictionary;
+ EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ temp->GetAsDictionary(&dictionary);
+ bool disabled = false;
+ EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
+ &disabled));
+ EXPECT_TRUE(disabled);
+}
+
+// Checks that if the policy for default search is valid, i.e. there's a
+// search URL, that all the elements have been given proper defaults.
+TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefMinimallyDefined) {
+ PolicyMap policy;
+ policy.Set(key::kDefaultSearchProviderEnabled,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(true),
+ NULL);
+ policy.Set(key::kDefaultSearchProviderSearchURL,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateStringValue(kSearchURL),
+ NULL);
+ UpdateProviderPolicy(policy);
+
+ const base::Value* temp = NULL;
+ const base::DictionaryValue* dictionary;
+ std::string value;
+ const base::ListValue* list_value;
+ EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ temp->GetAsDictionary(&dictionary);
+
+ // Name and keyword should be derived from host.
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
+ EXPECT_EQ(kSearchURL, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
+ EXPECT_EQ(kHostName, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
+ EXPECT_EQ(kHostName, value);
+
+ // Everything else should be set to the default value.
+ EXPECT_TRUE(
+ dictionary->GetString(DefaultSearchManager::kSuggestionsURL, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kFaviconURL, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(
+ dictionary->GetList(DefaultSearchManager::kInputEncodings, &list_value));
+ EXPECT_TRUE(base::ListValue().Equals(list_value));
+ EXPECT_TRUE(
+ dictionary->GetList(DefaultSearchManager::kAlternateURLs, &list_value));
+ EXPECT_TRUE(base::ListValue().Equals(list_value));
+ EXPECT_TRUE(dictionary->GetString(
+ DefaultSearchManager::kSearchTermsReplacementKey, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kImageURL, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(
+ dictionary->GetString(DefaultSearchManager::kImageURLPostParams, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kSearchURLPostParams,
+ &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(dictionary->GetString(
+ DefaultSearchManager::kSuggestionsURLPostParams, &value));
+ EXPECT_EQ(std::string(), value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
+ &value));
+ EXPECT_EQ(std::string(), value);
+}
+
+// Checks that setting a file URL as the default search is reflected properly in
+// the dictionary pref.
+TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefFileURL) {
+ PolicyMap policy;
+ policy.Set(key::kDefaultSearchProviderEnabled,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateBooleanValue(true),
+ NULL);
+ policy.Set(key::kDefaultSearchProviderSearchURL,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateStringValue(kFileSearchURL),
+ NULL);
+ UpdateProviderPolicy(policy);
+
+ const base::Value* temp = NULL;
+ const base::DictionaryValue* dictionary;
+ std::string value;
+
+ EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ temp->GetAsDictionary(&dictionary);
+
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
+ EXPECT_EQ(kFileSearchURL, value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
+ EXPECT_EQ("_", value);
+ EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
+ EXPECT_EQ("_", value);
+}
} // namespace policy
« no previous file with comments | « chrome/browser/search_engines/default_search_policy_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698