Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h" | 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 base::Closure CreateClosure() { | 84 base::Closure CreateClosure() { |
| 85 return base::Bind(&MockCallbackTarget::Run, base::Unretained(this)); | 85 return base::Bind(&MockCallbackTarget::Run, base::Unretained(this)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(MockCallbackTarget); | 89 DISALLOW_COPY_AND_ASSIGN(MockCallbackTarget); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // Returns the details of the default search provider from |prefs| in a format | 92 // Returns the details of the default search provider from |prefs| in a format |
| 93 // suitable for usage as |expected_details| in ExpectDetailsMatch(). | 93 // suitable for usage as |expected_details| in ExpectDetailsMatch(). |
| 94 scoped_ptr<base::DictionaryValue> GetDefaultSearchProviderDetailsFromPrefs( | 94 const base::DictionaryValue* GetDefaultSearchProviderDetailsFromPrefs( |
| 95 const PrefService* prefs) { | 95 const PrefService* prefs) { |
| 96 const char kDefaultSearchProviderPrefix[] = "default_search_provider"; | 96 return prefs->GetDictionary("default_search_provider_data.template_url_data"); |
|
gab
2014/05/07 20:25:09
Use the constant perf name here?
erikwright (departed)
2014/05/07 22:26:47
Done.
| |
| 97 scoped_ptr<base::DictionaryValue> pref_values_with_path_expansion( | |
| 98 prefs->GetPreferenceValues()); | |
| 99 const base::DictionaryValue* dsp_details = NULL; | |
| 100 EXPECT_TRUE(pref_values_with_path_expansion->GetDictionary( | |
| 101 kDefaultSearchProviderPrefix, &dsp_details)); | |
| 102 return scoped_ptr<base::DictionaryValue>( | |
| 103 dsp_details ? dsp_details->DeepCopy() : new base::DictionaryValue); | |
| 104 } | 97 } |
| 105 | 98 |
| 106 // Verifies that the |details| of a search engine as provided by the delegate | 99 // Verifies that the |details| of a search engine as provided by the delegate |
| 107 // are correct in comparison to the |expected_details| coming from the Prefs. | 100 // are correct in comparison to the |expected_details| coming from the Prefs. |
| 108 void ExpectDetailsMatch(const base::DictionaryValue& expected_details, | 101 void ExpectDetailsMatch(const base::DictionaryValue& expected_details, |
| 109 const base::DictionaryValue& details) { | 102 const base::DictionaryValue& details) { |
| 110 for (base::DictionaryValue::Iterator it(expected_details); !it.IsAtEnd(); | 103 for (base::DictionaryValue::Iterator it(expected_details); !it.IsAtEnd(); |
| 111 it.Advance()) { | 104 it.Advance()) { |
| 112 SCOPED_TRACE(testing::Message("Key: ") << it.key()); | 105 SCOPED_TRACE(testing::Message("Key: ") << it.key()); |
| 113 if (it.key() == "enabled" || it.key() == "synced_guid") { | 106 if (it.key() == "enabled" || it.key() == "synced_guid") { |
| 114 // These attributes should not be present. | 107 // These attributes should not be present. |
| 115 EXPECT_FALSE(details.HasKey(it.key())); | 108 EXPECT_FALSE(details.HasKey(it.key())); |
| 116 continue; | 109 continue; |
| 117 } | 110 } |
| 118 const base::Value* expected_value = &it.value(); | 111 const base::Value* expected_value = &it.value(); |
| 119 const base::Value* actual_value = NULL; | 112 const base::Value* actual_value = NULL; |
| 120 ASSERT_TRUE(details.Get(it.key(), &actual_value)); | 113 ASSERT_TRUE(details.Get(it.key(), &actual_value)); |
| 121 | 114 |
| 122 if (it.key() == "id") { | 115 if (it.key() == "id" || it.key() == "last_modified") { |
| 123 // Ignore ID as it is dynamically assigned by the TemplateURLService. | 116 // Ignore ID as it is dynamically assigned by the TemplateURLService. |
| 124 } else if (it.key() == "encodings") { | 117 // last_modified may get updated during a run, so ignore value |
| 125 // Encoding list is stored in Prefs as a single string with tokens | 118 // differences. |
| 126 // delimited by semicolons. | |
| 127 std::string expected_encodings; | |
| 128 ASSERT_TRUE(expected_value->GetAsString(&expected_encodings)); | |
| 129 const base::ListValue* actual_encodings_list = NULL; | |
| 130 ASSERT_TRUE(actual_value->GetAsList(&actual_encodings_list)); | |
| 131 std::vector<std::string> actual_encodings_vector; | |
| 132 for (base::ListValue::const_iterator it = actual_encodings_list->begin(); | |
| 133 it != actual_encodings_list->end(); ++it) { | |
| 134 std::string encoding; | |
| 135 ASSERT_TRUE((*it)->GetAsString(&encoding)); | |
| 136 actual_encodings_vector.push_back(encoding); | |
| 137 } | |
| 138 EXPECT_EQ(expected_encodings, JoinString(actual_encodings_vector, ';')); | |
| 139 } else { | 119 } else { |
| 140 // Everything else is the same format. | 120 // Everything else is the same format. |
| 141 EXPECT_TRUE(actual_value->Equals(expected_value)) | 121 EXPECT_TRUE(actual_value->Equals(expected_value)) |
| 142 << "Expected: " << *expected_value << ". Actual: " << *actual_value; | 122 << "Expected: " << *expected_value << ". Actual: " << *actual_value; |
| 143 } | 123 } |
| 144 } | 124 } |
| 145 } | 125 } |
| 146 | 126 |
| 147 // If |simulate_failure| is false, then replies to the pending request on | 127 // If |simulate_failure| is false, then replies to the pending request on |
| 148 // |fetcher| with a brandcoded config that only specifies a home page URL. | 128 // |fetcher| with a brandcoded config that only specifies a home page URL. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 // TemplateURLService into Prefs. | 352 // TemplateURLService into Prefs. |
| 373 scoped_ptr<TemplateURL> owned_custom_dsp(CreateTestTemplateURL()); | 353 scoped_ptr<TemplateURL> owned_custom_dsp(CreateTestTemplateURL()); |
| 374 TemplateURL* custom_dsp = owned_custom_dsp.get(); | 354 TemplateURL* custom_dsp = owned_custom_dsp.get(); |
| 375 template_url_service->Add(owned_custom_dsp.release()); | 355 template_url_service->Add(owned_custom_dsp.release()); |
| 376 template_url_service->SetUserSelectedDefaultSearchProvider(custom_dsp); | 356 template_url_service->SetUserSelectedDefaultSearchProvider(custom_dsp); |
| 377 | 357 |
| 378 PrefService* prefs = profile()->GetPrefs(); | 358 PrefService* prefs = profile()->GetPrefs(); |
| 379 ASSERT_TRUE(prefs); | 359 ASSERT_TRUE(prefs); |
| 380 scoped_ptr<base::DictionaryValue> dsp_details( | 360 scoped_ptr<base::DictionaryValue> dsp_details( |
| 381 resetter_delegate()->GetDefaultSearchProviderDetails()); | 361 resetter_delegate()->GetDefaultSearchProviderDetails()); |
| 382 scoped_ptr<base::DictionaryValue> expected_dsp_details( | 362 const base::DictionaryValue* expected_dsp_details = |
| 383 GetDefaultSearchProviderDetailsFromPrefs(prefs)); | 363 GetDefaultSearchProviderDetailsFromPrefs(prefs); |
| 384 | 364 |
| 385 ExpectDetailsMatch(*expected_dsp_details, *dsp_details); | 365 ExpectDetailsMatch(*expected_dsp_details, *dsp_details); |
| 386 EXPECT_FALSE(resetter_delegate()->IsDefaultSearchProviderManaged()); | 366 EXPECT_FALSE(resetter_delegate()->IsDefaultSearchProviderManaged()); |
| 387 } | 367 } |
| 388 | 368 |
| 389 TEST_F(AutomaticProfileResetterDelegateTest, | 369 TEST_F(AutomaticProfileResetterDelegateTest, |
| 390 DefaultSearchProviderDataWhenManaged) { | 370 DefaultSearchProviderDataWhenManaged) { |
| 391 const char kTestSearchURL[] = "http://example.com/search?q={searchTerms}"; | 371 const char kTestSearchURL[] = "http://example.com/search?q={searchTerms}"; |
| 392 const char kTestName[] = "name"; | 372 const char kTestName[] = "name"; |
| 393 const char kTestKeyword[] = "keyword"; | 373 const char kTestKeyword[] = "keyword"; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 ASSERT_TRUE(details->GetString("keyword", &keyword)); | 426 ASSERT_TRUE(details->GetString("keyword", &keyword)); |
| 447 TemplateURL* search_engine = | 427 TemplateURL* search_engine = |
| 448 template_url_service->GetTemplateURLForKeyword( | 428 template_url_service->GetTemplateURLForKeyword( |
| 449 base::ASCIIToUTF16(keyword)); | 429 base::ASCIIToUTF16(keyword)); |
| 450 ASSERT_TRUE(search_engine); | 430 ASSERT_TRUE(search_engine); |
| 451 template_url_service->SetUserSelectedDefaultSearchProvider( | 431 template_url_service->SetUserSelectedDefaultSearchProvider( |
| 452 prepopulated_engines[i]); | 432 prepopulated_engines[i]); |
| 453 | 433 |
| 454 PrefService* prefs = profile()->GetPrefs(); | 434 PrefService* prefs = profile()->GetPrefs(); |
| 455 ASSERT_TRUE(prefs); | 435 ASSERT_TRUE(prefs); |
| 456 scoped_ptr<base::DictionaryValue> expected_dsp_details( | 436 const base::DictionaryValue* expected_dsp_details = |
| 457 GetDefaultSearchProviderDetailsFromPrefs(prefs)); | 437 GetDefaultSearchProviderDetailsFromPrefs(prefs); |
| 458 ExpectDetailsMatch(*expected_dsp_details, *details); | 438 ExpectDetailsMatch(*expected_dsp_details, *details); |
| 459 } | 439 } |
| 460 } | 440 } |
| 461 | 441 |
| 462 TEST_F(AutomaticProfileResetterDelegateTest, | 442 TEST_F(AutomaticProfileResetterDelegateTest, |
| 463 FetchAndWaitOnDefaultSettingsVanilla) { | 443 FetchAndWaitOnDefaultSettingsVanilla) { |
| 464 google_util::BrandForTesting scoped_brand_for_testing((std::string())); | 444 google_util::BrandForTesting scoped_brand_for_testing((std::string())); |
| 465 | 445 |
| 466 // Expect ready_callback to be called just after empty brandcoded settings | 446 // Expect ready_callback to be called just after empty brandcoded settings |
| 467 // are loaded, given this is a vanilla build. Fail if it is not called, or | 447 // are loaded, given this is a vanilla build. Fail if it is not called, or |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 if (ProfileResetGlobalError::IsSupportedOnPlatform()) | 595 if (ProfileResetGlobalError::IsSupportedOnPlatform()) |
| 616 ExpectResetPromptState(true /*active*/); | 596 ExpectResetPromptState(true /*active*/); |
| 617 else | 597 else |
| 618 ExpectResetPromptState(false /*active*/); | 598 ExpectResetPromptState(false /*active*/); |
| 619 resetter_delegate()->DismissPrompt(); | 599 resetter_delegate()->DismissPrompt(); |
| 620 ExpectResetPromptState(false /*active*/); | 600 ExpectResetPromptState(false /*active*/); |
| 621 resetter_delegate()->DismissPrompt(); | 601 resetter_delegate()->DismissPrompt(); |
| 622 } | 602 } |
| 623 | 603 |
| 624 } // namespace | 604 } // namespace |
| OLD | NEW |