| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cookies_tree_model.h" | 5 #include "chrome/browser/cookies_tree_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/browser/content_settings/content_settings_details.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/mock_browsing_data_appcache_helper.h" | 11 #include "chrome/browser/mock_browsing_data_appcache_helper.h" |
| 11 #include "chrome/browser/mock_browsing_data_database_helper.h" | 12 #include "chrome/browser/mock_browsing_data_database_helper.h" |
| 12 #include "chrome/browser/mock_browsing_data_indexed_db_helper.h" | 13 #include "chrome/browser/mock_browsing_data_indexed_db_helper.h" |
| 13 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" | 14 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" |
| 14 #include "chrome/common/net/url_request_context_getter.h" | 15 #include "chrome/common/net/url_request_context_getter.h" |
| 15 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
| 16 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
| 17 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
| 18 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
| 19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 class StubSettingsObserver : public NotificationObserver { | 26 class StubSettingsObserver : public NotificationObserver { |
| 26 public: | 27 public: |
| 27 StubSettingsObserver() : counter(0) { | 28 StubSettingsObserver() : counter(0) { |
| 28 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, | 29 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, |
| 29 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
| 30 } | 31 } |
| 31 | 32 |
| 32 virtual void Observe(NotificationType type, | 33 virtual void Observe(NotificationType type, |
| 33 const NotificationSource& source, | 34 const NotificationSource& source, |
| 34 const NotificationDetails& details) { | 35 const NotificationDetails& details) { |
| 35 ++counter; | 36 ++counter; |
| 36 Details<HostContentSettingsMap::ContentSettingsDetails> | 37 Details<ContentSettingsDetails> settings_details(details); |
| 37 settings_details(details); | |
| 38 last_pattern = settings_details.ptr()->pattern(); | 38 last_pattern = settings_details.ptr()->pattern(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 HostContentSettingsMap::Pattern last_pattern; | 41 ContentSettingsPattern last_pattern; |
| 42 int counter; | 42 int counter; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 NotificationRegistrar registrar_; | 45 NotificationRegistrar registrar_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class CookiesTreeModelTest : public testing::Test { | 48 class CookiesTreeModelTest : public testing::Test { |
| 49 public: | 49 public: |
| 50 CookiesTreeModelTest() : ui_thread_(BrowserThread::UI, &message_loop_), | 50 CookiesTreeModelTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
| 51 io_thread_(BrowserThread::IO, &message_loop_) { | 51 io_thread_(BrowserThread::IO, &message_loop_) { |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 663 } |
| 664 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" | 664 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" |
| 665 { | 665 { |
| 666 EXPECT_STREQ("A,B,C,D,F,G,H", GetMonsterCookies(monster).c_str()); | 666 EXPECT_STREQ("A,B,C,D,F,G,H", GetMonsterCookies(monster).c_str()); |
| 667 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); | 667 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 | 670 |
| 671 TEST_F(CookiesTreeModelTest, ContentSettings) { | 671 TEST_F(CookiesTreeModelTest, ContentSettings) { |
| 672 GURL host("http://example.com/"); | 672 GURL host("http://example.com/"); |
| 673 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 673 ContentSettingsPattern pattern("[*.]example.com"); |
| 674 net::CookieMonster* monster = profile_->GetCookieMonster(); | 674 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 675 monster->SetCookie(host, "A=1"); | 675 monster->SetCookie(host, "A=1"); |
| 676 | 676 |
| 677 CookiesTreeModel cookies_model(monster, | 677 CookiesTreeModel cookies_model(monster, |
| 678 new MockBrowsingDataDatabaseHelper(profile_.get()), | 678 new MockBrowsingDataDatabaseHelper(profile_.get()), |
| 679 new MockBrowsingDataLocalStorageHelper(profile_.get()), | 679 new MockBrowsingDataLocalStorageHelper(profile_.get()), |
| 680 new MockBrowsingDataLocalStorageHelper(profile_.get()), | 680 new MockBrowsingDataLocalStorageHelper(profile_.get()), |
| 681 new MockBrowsingDataAppCacheHelper(profile_.get()), | 681 new MockBrowsingDataAppCacheHelper(profile_.get()), |
| 682 new MockBrowsingDataIndexedDBHelper(profile_.get())); | 682 new MockBrowsingDataIndexedDBHelper(profile_.get())); |
| 683 | 683 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 696 content_settings, CONTENT_SETTING_SESSION_ONLY); | 696 content_settings, CONTENT_SETTING_SESSION_ONLY); |
| 697 | 697 |
| 698 EXPECT_EQ(2, observer.counter); | 698 EXPECT_EQ(2, observer.counter); |
| 699 EXPECT_EQ(pattern, observer.last_pattern); | 699 EXPECT_EQ(pattern, observer.last_pattern); |
| 700 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 700 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
| 701 content_settings->GetContentSetting( | 701 content_settings->GetContentSetting( |
| 702 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 702 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 703 } | 703 } |
| 704 | 704 |
| 705 } // namespace | 705 } // namespace |
| OLD | NEW |