Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "net/ssl/server_bound_cert_service.h" | 12 #include "net/ssl/channel_id_service.h" |
| 13 #include "net/url_request/url_request_context.h" | 13 #include "net/url_request/url_request_context.h" |
| 14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 | 18 |
| 19 class BrowsingDataServerBoundCertHelperTest | 19 class BrowsingDataChannelIDHelperTest |
| 20 : public testing::Test, | 20 : public testing::Test, |
| 21 public net::SSLConfigService::Observer { | 21 public net::SSLConfigService::Observer { |
| 22 public: | 22 public: |
| 23 BrowsingDataServerBoundCertHelperTest() : ssl_config_changed_count_(0) { | 23 BrowsingDataChannelIDHelperTest() : ssl_config_changed_count_(0) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
| 27 testing_profile_.reset(new TestingProfile()); | 27 testing_profile_.reset(new TestingProfile()); |
| 28 | 28 |
| 29 testing_profile_->GetSSLConfigService()->AddObserver(this); | 29 testing_profile_->GetSSLConfigService()->AddObserver(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual void TearDown() OVERRIDE { | 32 virtual void TearDown() OVERRIDE { |
| 33 testing_profile_->GetSSLConfigService()->RemoveObserver(this); | 33 testing_profile_->GetSSLConfigService()->RemoveObserver(this); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void CreateCertsForTest() { | 36 void CreateCertsForTest() { |
|
wtc
2014/07/01 19:50:48
CreateCertsForTest => CreateChannelIDsForTest
Ryan Hamilton
2014/07/21 19:12:03
Done.
| |
| 37 net::URLRequestContext* context = | 37 net::URLRequestContext* context = |
| 38 testing_profile_->GetRequestContext()->GetURLRequestContext(); | 38 testing_profile_->GetRequestContext()->GetURLRequestContext(); |
| 39 net::ServerBoundCertStore* cert_store = | 39 net::ChannelIDStore* cert_store = |
|
wtc
2014/07/01 19:50:48
cert_store => channel_id_store
Ryan Hamilton
2014/07/21 19:12:03
Done.
| |
| 40 context->server_bound_cert_service()->GetCertStore(); | 40 context->channel_id_service()->GetCertStore(); |
| 41 cert_store->SetServerBoundCert("https://www.google.com:443", | 41 cert_store->SetChannelID("https://www.google.com:443", |
| 42 base::Time(), base::Time(), | 42 base::Time(), base::Time(), |
| 43 "key", "cert"); | 43 "key", "cert"); |
| 44 cert_store->SetServerBoundCert("https://www.youtube.com:443", | 44 cert_store->SetChannelID("https://www.youtube.com:443", |
| 45 base::Time(), base::Time(), | 45 base::Time(), base::Time(), |
| 46 "key", "cert"); | 46 "key", "cert"); |
|
wtc
2014/07/01 19:50:48
Fix the indentation of these two SetChannelID call
Ryan Hamilton
2014/07/21 19:12:03
Done.
| |
| 47 } | 47 } |
| 48 | 48 |
| 49 void FetchCallback( | 49 void FetchCallback( |
| 50 const net::ServerBoundCertStore::ServerBoundCertList& certs) { | 50 const net::ChannelIDStore::ChannelIDList& certs) { |
|
wtc
2014/07/01 19:50:48
certs => channel_ids
Ryan Hamilton
2014/07/21 19:12:03
Done.
| |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 server_bound_cert_list_ = certs; | 52 channel_id_list_ = certs; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // net::SSLConfigService::Observer implementation: | 55 // net::SSLConfigService::Observer implementation: |
| 56 virtual void OnSSLConfigChanged() OVERRIDE { | 56 virtual void OnSSLConfigChanged() OVERRIDE { |
| 57 ssl_config_changed_count_++; | 57 ssl_config_changed_count_++; |
| 58 } | 58 } |
| 59 | 59 |
| 60 protected: | 60 protected: |
| 61 content::TestBrowserThreadBundle thread_bundle_; | 61 content::TestBrowserThreadBundle thread_bundle_; |
| 62 scoped_ptr<TestingProfile> testing_profile_; | 62 scoped_ptr<TestingProfile> testing_profile_; |
| 63 | 63 |
| 64 net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_; | 64 net::ChannelIDStore::ChannelIDList channel_id_list_; |
| 65 | 65 |
| 66 int ssl_config_changed_count_; | 66 int ssl_config_changed_count_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(BrowsingDataServerBoundCertHelperTest, FetchData) { | 69 TEST_F(BrowsingDataChannelIDHelperTest, FetchData) { |
| 70 CreateCertsForTest(); | 70 CreateCertsForTest(); |
| 71 scoped_refptr<BrowsingDataServerBoundCertHelper> helper( | 71 scoped_refptr<BrowsingDataChannelIDHelper> helper( |
| 72 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get())); | 72 BrowsingDataChannelIDHelper::Create(testing_profile_.get())); |
| 73 | 73 |
| 74 helper->StartFetching( | 74 helper->StartFetching( |
| 75 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, | 75 base::Bind(&BrowsingDataChannelIDHelperTest::FetchCallback, |
| 76 base::Unretained(this))); | 76 base::Unretained(this))); |
| 77 | 77 |
| 78 // Blocks until BrowsingDataServerBoundCertHelperTest::FetchCallback is | 78 // Blocks until BrowsingDataChannelIDHelperTest::FetchCallback is |
| 79 // notified. | 79 // notified. |
| 80 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 81 | 81 |
| 82 ASSERT_EQ(2UL, server_bound_cert_list_.size()); | 82 ASSERT_EQ(2UL, channel_id_list_.size()); |
| 83 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it = | 83 net::ChannelIDStore::ChannelIDList::const_iterator it = |
| 84 server_bound_cert_list_.begin(); | 84 channel_id_list_.begin(); |
| 85 | 85 |
| 86 // Correct because fetching server_bound_cert_list_ will get them out in the | 86 // Correct because fetching channel_id_list_ will get them out in the |
| 87 // same order CreateCertsForTest put them in. | 87 // same order CreateCertsForTest put them in. |
| 88 ASSERT_TRUE(it != server_bound_cert_list_.end()); | 88 ASSERT_TRUE(it != channel_id_list_.end()); |
| 89 EXPECT_EQ("https://www.google.com:443", it->server_identifier()); | 89 EXPECT_EQ("https://www.google.com:443", it->server_identifier()); |
| 90 | 90 |
| 91 ASSERT_TRUE(++it != server_bound_cert_list_.end()); | 91 ASSERT_TRUE(++it != channel_id_list_.end()); |
| 92 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); | 92 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); |
| 93 | 93 |
| 94 ASSERT_TRUE(++it == server_bound_cert_list_.end()); | 94 ASSERT_TRUE(++it == channel_id_list_.end()); |
| 95 | 95 |
| 96 EXPECT_EQ(0, ssl_config_changed_count_); | 96 EXPECT_EQ(0, ssl_config_changed_count_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(BrowsingDataServerBoundCertHelperTest, DeleteCert) { | 99 TEST_F(BrowsingDataChannelIDHelperTest, DeleteCert) { |
|
wtc
2014/07/01 19:50:47
DeleteCert => DeleteChannelID
Ryan Hamilton
2014/07/21 19:12:03
Done.
| |
| 100 CreateCertsForTest(); | 100 CreateCertsForTest(); |
| 101 scoped_refptr<BrowsingDataServerBoundCertHelper> helper( | 101 scoped_refptr<BrowsingDataChannelIDHelper> helper( |
| 102 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get())); | 102 BrowsingDataChannelIDHelper::Create(testing_profile_.get())); |
| 103 | 103 |
| 104 helper->DeleteServerBoundCert("https://www.google.com:443"); | 104 helper->DeleteChannelID("https://www.google.com:443"); |
| 105 | 105 |
| 106 helper->StartFetching( | 106 helper->StartFetching( |
| 107 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, | 107 base::Bind(&BrowsingDataChannelIDHelperTest::FetchCallback, |
| 108 base::Unretained(this))); | 108 base::Unretained(this))); |
| 109 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
| 110 | 110 |
| 111 EXPECT_EQ(1, ssl_config_changed_count_); | 111 EXPECT_EQ(1, ssl_config_changed_count_); |
| 112 ASSERT_EQ(1UL, server_bound_cert_list_.size()); | 112 ASSERT_EQ(1UL, channel_id_list_.size()); |
| 113 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it = | 113 net::ChannelIDStore::ChannelIDList::const_iterator it = |
| 114 server_bound_cert_list_.begin(); | 114 channel_id_list_.begin(); |
| 115 | 115 |
| 116 ASSERT_TRUE(it != server_bound_cert_list_.end()); | 116 ASSERT_TRUE(it != channel_id_list_.end()); |
| 117 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); | 117 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); |
| 118 | 118 |
| 119 ASSERT_TRUE(++it == server_bound_cert_list_.end()); | 119 ASSERT_TRUE(++it == channel_id_list_.end()); |
| 120 | 120 |
| 121 helper->DeleteServerBoundCert("https://www.youtube.com:443"); | 121 helper->DeleteChannelID("https://www.youtube.com:443"); |
| 122 | 122 |
| 123 helper->StartFetching( | 123 helper->StartFetching( |
| 124 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, | 124 base::Bind(&BrowsingDataChannelIDHelperTest::FetchCallback, |
| 125 base::Unretained(this))); | 125 base::Unretained(this))); |
| 126 base::RunLoop().RunUntilIdle(); | 126 base::RunLoop().RunUntilIdle(); |
| 127 | 127 |
| 128 EXPECT_EQ(2, ssl_config_changed_count_); | 128 EXPECT_EQ(2, ssl_config_changed_count_); |
| 129 ASSERT_EQ(0UL, server_bound_cert_list_.size()); | 129 ASSERT_EQ(0UL, channel_id_list_.size()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(BrowsingDataServerBoundCertHelperTest, CannedEmpty) { | 132 TEST_F(BrowsingDataChannelIDHelperTest, CannedEmpty) { |
| 133 std::string origin = "https://www.google.com"; | 133 std::string origin = "https://www.google.com"; |
| 134 | 134 |
| 135 scoped_refptr<CannedBrowsingDataServerBoundCertHelper> helper( | 135 scoped_refptr<CannedBrowsingDataChannelIDHelper> helper( |
| 136 new CannedBrowsingDataServerBoundCertHelper()); | 136 new CannedBrowsingDataChannelIDHelper()); |
| 137 | 137 |
| 138 ASSERT_TRUE(helper->empty()); | 138 ASSERT_TRUE(helper->empty()); |
| 139 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert( | 139 helper->AddChannelID(net::ChannelIDStore::ChannelID( |
| 140 origin, base::Time(), base::Time(), "key", "cert")); | 140 origin, base::Time(), base::Time(), "key", "cert")); |
| 141 ASSERT_FALSE(helper->empty()); | 141 ASSERT_FALSE(helper->empty()); |
| 142 helper->Reset(); | 142 helper->Reset(); |
| 143 ASSERT_TRUE(helper->empty()); | 143 ASSERT_TRUE(helper->empty()); |
| 144 } | 144 } |
| OLD | NEW |