OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 9 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
10 #include "chrome/browser/prefs/browser_prefs.h" | 10 #include "chrome/browser/prefs/browser_prefs.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 &settings); | 482 &settings); |
483 ASSERT_TRUE(NULL != settings) << "Dictionary has no key: " | 483 ASSERT_TRUE(NULL != settings) << "Dictionary has no key: " |
484 << primary_pattern.ToString(); | 484 << primary_pattern.ToString(); |
485 ASSERT_EQ(1U, settings->size()); | 485 ASSERT_EQ(1U, settings->size()); |
486 settings->GetInteger("javascript", &setting_value); | 486 settings->GetInteger("javascript", &setting_value); |
487 EXPECT_EQ(setting_value, CONTENT_SETTING_ALLOW); | 487 EXPECT_EQ(setting_value, CONTENT_SETTING_ALLOW); |
488 | 488 |
489 provider.ShutdownOnUIThread(); | 489 provider.ShutdownOnUIThread(); |
490 } | 490 } |
491 | 491 |
| 492 |
| 493 TEST_F(PrefProviderTest, FixOrRemoveMalformedPatternKeysFromObsoletePref) { |
| 494 TestingProfile profile; |
| 495 PrefService* prefs = profile.GetPrefs(); |
| 496 |
| 497 // Set obsolete preference for content settings pattern. |
| 498 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue()); |
| 499 settings_dictionary->SetInteger("cookies", 2); |
| 500 settings_dictionary->SetInteger("images", 2); |
| 501 settings_dictionary->SetInteger("popups", 2); |
| 502 scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue()); |
| 503 // Good pattern key. |
| 504 all_settings_dictionary->SetWithoutPathExpansion( |
| 505 "http://www.example.com", settings_dictionary->DeepCopy()); |
| 506 // Bad pattern key that will be ignored since there is already a good pattern |
| 507 // key for the primary patter of the bad pattern key. |
| 508 all_settings_dictionary->SetWithoutPathExpansion( |
| 509 "http://www.example.com,", settings_dictionary->DeepCopy()); |
| 510 |
| 511 // Bad pattern key that should be removed. |
| 512 all_settings_dictionary->SetWithoutPathExpansion( |
| 513 "http://www.broken.com*", settings_dictionary->DeepCopy()); |
| 514 |
| 515 all_settings_dictionary->SetWithoutPathExpansion( |
| 516 "http://www.bar.com,", settings_dictionary->DeepCopy()); |
| 517 |
| 518 // Bad pattern key with a trailing comma that is supposed to be fixed. |
| 519 // A trailing comma means that the secondary pattern string is empty and hence |
| 520 // invalid. |
| 521 all_settings_dictionary->SetWithoutPathExpansion( |
| 522 "http://www.foo.com,", settings_dictionary->DeepCopy()); |
| 523 // Bad pattern key with an invalid secondary pattern that should be removed. |
| 524 all_settings_dictionary->SetWithoutPathExpansion( |
| 525 "http://www.foo.com,error*", settings_dictionary->DeepCopy()); |
| 526 // Pattern keys with valid pattern pairs. |
| 527 all_settings_dictionary->SetWithoutPathExpansion( |
| 528 "http://www.foo.com,[*.]bar.com", settings_dictionary->DeepCopy()); |
| 529 prefs->Set(prefs::kContentSettingsPatterns, *all_settings_dictionary); |
| 530 all_settings_dictionary->SetWithoutPathExpansion( |
| 531 "http://www.example2.com,*", settings_dictionary->DeepCopy()); |
| 532 prefs->Set(prefs::kContentSettingsPatterns, *all_settings_dictionary); |
| 533 |
| 534 content_settings::PrefProvider provider(prefs, false); |
| 535 |
| 536 // Tests that the broken pattern keys got fixed or removed. |
| 537 const DictionaryValue* patterns_dictionary = |
| 538 prefs->GetDictionary(prefs::kContentSettingsPatterns); |
| 539 EXPECT_EQ(4U, patterns_dictionary->size()); |
| 540 EXPECT_TRUE(patterns_dictionary->HasKey("http://www.example.com")); |
| 541 EXPECT_TRUE(patterns_dictionary->HasKey("http://www.bar.com")); |
| 542 EXPECT_TRUE(patterns_dictionary->HasKey("http://www.foo.com")); |
| 543 EXPECT_TRUE(patterns_dictionary->HasKey("http://www.example2.com")); |
| 544 |
| 545 // Broken pattern keys that should be removed |
| 546 EXPECT_FALSE(patterns_dictionary->HasKey("http://www.bar.com,")); |
| 547 EXPECT_FALSE(patterns_dictionary->HasKey("http://www.foo.com,")); |
| 548 EXPECT_FALSE(patterns_dictionary->HasKey("http://www.foo.com,error*")); |
| 549 EXPECT_FALSE(patterns_dictionary->HasKey( |
| 550 "http://www.foo.com,[*.]bar.com")); |
| 551 EXPECT_FALSE(patterns_dictionary->HasKey("http://www.example2.com,*")); |
| 552 |
| 553 EXPECT_FALSE(patterns_dictionary->HasKey("http://www.broken.com*")); |
| 554 |
| 555 provider.ShutdownOnUIThread(); |
| 556 } |
| 557 |
492 } // namespace content_settings | 558 } // namespace content_settings |
OLD | NEW |