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

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 1005303003: Split the aggregate dictionary of content settings exceptions into per-type dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android fix 4. Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.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 "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 25 matching lines...) Expand all
36 using ::testing::_; 36 using ::testing::_;
37 37
38 namespace content_settings { 38 namespace content_settings {
39 39
40 class DeadlockCheckerThread : public base::PlatformThread::Delegate { 40 class DeadlockCheckerThread : public base::PlatformThread::Delegate {
41 public: 41 public:
42 explicit DeadlockCheckerThread(PrefProvider* provider) 42 explicit DeadlockCheckerThread(PrefProvider* provider)
43 : provider_(provider) {} 43 : provider_(provider) {}
44 44
45 void ThreadMain() override { 45 void ThreadMain() override {
46 bool got_lock = provider_->content_settings_pref()->lock_.Try(); 46 EXPECT_TRUE(provider_->TestAllLocks());
47 EXPECT_TRUE(got_lock);
48 if (got_lock)
49 provider_->content_settings_pref()->lock_.Release();
50 } 47 }
51 private: 48 private:
52 PrefProvider* provider_; 49 PrefProvider* provider_;
53 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); 50 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread);
54 }; 51 };
55 52
56 // A helper for observing an preference changes and testing whether 53 // A helper for observing an preference changes and testing whether
57 // |PrefProvider| holds a lock when the preferences change. 54 // |PrefProvider| holds a lock when the preferences change.
58 class DeadlockCheckerObserver { 55 class DeadlockCheckerObserver {
59 public: 56 public:
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); 455 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
459 base::Time second = pref_content_settings_provider.GetLastUsage( 456 base::Time second = pref_content_settings_provider.GetLastUsage(
460 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); 457 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
461 458
462 base::TimeDelta delta = second - first; 459 base::TimeDelta delta = second - first;
463 EXPECT_EQ(delta.InSeconds(), 10); 460 EXPECT_EQ(delta.InSeconds(), 10);
464 461
465 pref_content_settings_provider.ShutdownOnUIThread(); 462 pref_content_settings_provider.ShutdownOnUIThread();
466 } 463 }
467 464
465
466 // TODO(msramek): This tests the correct migration behavior between the old
467 // aggregate dictionary preferences for all content settings types and the new
468 // dictionary preferences for individual types. Remove this when the migration
469 // period is over.
470 TEST(PrefProviderTest, SyncingOldToNew) {
471 TestingPrefServiceSyncable prefs;
472 PrefProvider::RegisterProfilePrefs(prefs.registry());
473 PrefProvider provider(&prefs, false);
474
475 const std::string pattern_1 = "google.com,*";
476 const std::string pattern_2 = "www.google.com,*";
477 base::DictionaryValue* exceptions_1 = new base::DictionaryValue();
478 base::DictionaryValue* exceptions_2 = new base::DictionaryValue();
479
480 // Add exceptions for images and app banner.
481 exceptions_1->SetIntegerWithoutPathExpansion(
482 GetTypeName(CONTENT_SETTINGS_TYPE_IMAGES), CONTENT_SETTING_ALLOW);
483 exceptions_1->SetIntegerWithoutPathExpansion(
484 GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW);
485 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
486 // Add both an "allow" and "block" exception for PMI.
487 exceptions_1->SetIntegerWithoutPathExpansion(
488 GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW);
489 exceptions_2->SetIntegerWithoutPathExpansion(
490 GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_BLOCK);
491 #endif
492
493 // Change the old dictionary preference and observe changes
494 // in the new preferences.
495 {
496 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
497 base::DictionaryValue* old_dictionary = update.Get();
498 old_dictionary->SetWithoutPathExpansion(pattern_1, exceptions_1);
499 old_dictionary->SetWithoutPathExpansion(pattern_2, exceptions_2);
500 }
501
502 // The images exception was synced.
503 {
504 DictionaryPrefUpdate update(
505 &prefs, prefs::kContentSettingsImagesPatternPairs);
506 const base::DictionaryValue* images_dictionary = update.Get();
507
508 EXPECT_EQ(1u, images_dictionary->size());
509 const base::DictionaryValue* images_exception;
510 EXPECT_TRUE(images_dictionary->GetDictionaryWithoutPathExpansion(
511 pattern_1, &images_exception));
512
513 // And it has a correct value.
514 int images_exception_value = CONTENT_SETTING_DEFAULT;
515 EXPECT_TRUE(images_exception->GetIntegerWithoutPathExpansion(
516 "setting", &images_exception_value));
517 EXPECT_EQ(CONTENT_SETTING_ALLOW, images_exception_value);
518 }
519
520 // The app banner exception was not synced.
521 {
522 DictionaryPrefUpdate update(
523 &prefs, prefs::kContentSettingsAppBannerPatternPairs);
524 base::DictionaryValue* app_banner_dictionary = update.Get();
525 EXPECT_TRUE(app_banner_dictionary->empty());
526 }
527
528 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
529 // The "block" exception for PMI was migrated, but "allow" was not.
530 DictionaryPrefUpdate update(
531 &prefs, prefs::kContentSettingsProtectedMediaIdentifierPatternPairs);
532 const base::DictionaryValue* pmi_dictionary = update.Get();
533 EXPECT_TRUE(pmi_dictionary->HasKey(pattern_1));
534 EXPECT_FALSE(pmi_dictionary->HasKey(pattern_2));
535 #endif
536
537 provider.ShutdownOnUIThread();
538 }
539
540 TEST(PrefProviderTest, SyncingNewToOld) {
541 TestingPrefServiceSyncable prefs;
542 PrefProvider::RegisterProfilePrefs(prefs.registry());
543 PrefProvider provider(&prefs, false);
544
545 const std::string pattern = "google.com,*";
546 base::DictionaryValue block_exception;
547 block_exception.SetIntegerWithoutPathExpansion(
548 "setting", CONTENT_SETTING_BLOCK);
549
550 // Add a notifications exception.
551 {
552 DictionaryPrefUpdate update(
553 &prefs, prefs::kContentSettingsNotificationsPatternPairs);
554 base::DictionaryValue* notifications_dictionary = update.Get();
555
556 notifications_dictionary->SetWithoutPathExpansion(
557 pattern, block_exception.DeepCopy());
558 }
559
560 // Add a microphone exception.
561 {
562 DictionaryPrefUpdate update(
563 &prefs, prefs::kContentSettingsMediaStreamMicPatternPairs);
564 base::DictionaryValue* microphone_dictionary = update.Get();
565
566 microphone_dictionary->SetWithoutPathExpansion(
567 pattern, block_exception.DeepCopy());
568 }
569
570 // Only the notifications exception should appear in the old dictionary.
571 {
572 DictionaryPrefUpdate update(
573 &prefs, prefs::kContentSettingsPatternPairs);
574 const base::DictionaryValue* old_dictionary = update.Get();
575
576 const base::DictionaryValue* exception;
577 EXPECT_TRUE(old_dictionary->GetDictionaryWithoutPathExpansion(
578 pattern, &exception));
579 EXPECT_EQ(1u, exception->size());
580 EXPECT_FALSE(exception->HasKey(
581 GetTypeName(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)));
582
583 int notifications_exception_value = CONTENT_SETTING_DEFAULT;
584 exception->GetIntegerWithoutPathExpansion(
585 GetTypeName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS),
586 &notifications_exception_value);
587 DCHECK_EQ(CONTENT_SETTING_BLOCK, notifications_exception_value);
588 }
589
590 provider.ShutdownOnUIThread();
591 }
592
468 } // namespace content_settings 593 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698