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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h" 5 #include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 cert_store->SetServerBoundCert("https://www.youtube.com:443", 50 cert_store->SetServerBoundCert("https://www.youtube.com:443",
51 net::CLIENT_CERT_RSA_SIGN, 51 net::CLIENT_CERT_RSA_SIGN,
52 base::Time(), base::Time(), 52 base::Time(), base::Time(),
53 "key", "cert"); 53 "key", "cert");
54 } 54 }
55 55
56 void FetchCallback( 56 void FetchCallback(
57 const net::ServerBoundCertStore::ServerBoundCertList& certs) { 57 const net::ServerBoundCertStore::ServerBoundCertList& certs) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 server_bound_cert_list_ = certs; 59 server_bound_cert_list_ = certs;
60 MessageLoop::current()->Quit(); 60 base::MessageLoop::current()->Quit();
61 } 61 }
62 62
63 // net::SSLConfigService::Observer implementation: 63 // net::SSLConfigService::Observer implementation:
64 virtual void OnSSLConfigChanged() OVERRIDE { 64 virtual void OnSSLConfigChanged() OVERRIDE {
65 ssl_config_changed_count_++; 65 ssl_config_changed_count_++;
66 } 66 }
67 67
68 protected: 68 protected:
69 MessageLoop message_loop_; 69 base::MessageLoop message_loop_;
70 scoped_ptr<content::TestBrowserThread> ui_thread_; 70 scoped_ptr<content::TestBrowserThread> ui_thread_;
71 scoped_ptr<content::TestBrowserThread> io_thread_; 71 scoped_ptr<content::TestBrowserThread> io_thread_;
72 scoped_ptr<TestingProfile> testing_profile_; 72 scoped_ptr<TestingProfile> testing_profile_;
73 73
74 net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_; 74 net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_;
75 75
76 int ssl_config_changed_count_; 76 int ssl_config_changed_count_;
77 }; 77 };
78 78
79 TEST_F(BrowsingDataServerBoundCertHelperTest, FetchData) { 79 TEST_F(BrowsingDataServerBoundCertHelperTest, FetchData) {
80 CreateCertsForTest(); 80 CreateCertsForTest();
81 scoped_refptr<BrowsingDataServerBoundCertHelper> helper( 81 scoped_refptr<BrowsingDataServerBoundCertHelper> helper(
82 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get())); 82 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get()));
83 83
84 helper->StartFetching( 84 helper->StartFetching(
85 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, 85 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
86 base::Unretained(this))); 86 base::Unretained(this)));
87 87
88 // Blocks until BrowsingDataServerBoundCertHelperTest::FetchCallback is 88 // Blocks until BrowsingDataServerBoundCertHelperTest::FetchCallback is
89 // notified. 89 // notified.
90 MessageLoop::current()->Run(); 90 base::MessageLoop::current()->Run();
91 91
92 ASSERT_EQ(2UL, server_bound_cert_list_.size()); 92 ASSERT_EQ(2UL, server_bound_cert_list_.size());
93 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it = 93 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it =
94 server_bound_cert_list_.begin(); 94 server_bound_cert_list_.begin();
95 95
96 // Correct because fetching server_bound_cert_list_ will get them out in the 96 // Correct because fetching server_bound_cert_list_ will get them out in the
97 // same order CreateCertsForTest put them in. 97 // same order CreateCertsForTest put them in.
98 ASSERT_TRUE(it != server_bound_cert_list_.end()); 98 ASSERT_TRUE(it != server_bound_cert_list_.end());
99 EXPECT_EQ("https://www.google.com:443", it->server_identifier()); 99 EXPECT_EQ("https://www.google.com:443", it->server_identifier());
100 100
101 ASSERT_TRUE(++it != server_bound_cert_list_.end()); 101 ASSERT_TRUE(++it != server_bound_cert_list_.end());
102 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); 102 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier());
103 103
104 ASSERT_TRUE(++it == server_bound_cert_list_.end()); 104 ASSERT_TRUE(++it == server_bound_cert_list_.end());
105 105
106 EXPECT_EQ(0, ssl_config_changed_count_); 106 EXPECT_EQ(0, ssl_config_changed_count_);
107 } 107 }
108 108
109 TEST_F(BrowsingDataServerBoundCertHelperTest, DeleteCert) { 109 TEST_F(BrowsingDataServerBoundCertHelperTest, DeleteCert) {
110 CreateCertsForTest(); 110 CreateCertsForTest();
111 scoped_refptr<BrowsingDataServerBoundCertHelper> helper( 111 scoped_refptr<BrowsingDataServerBoundCertHelper> helper(
112 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get())); 112 BrowsingDataServerBoundCertHelper::Create(testing_profile_.get()));
113 113
114 helper->DeleteServerBoundCert("https://www.google.com:443"); 114 helper->DeleteServerBoundCert("https://www.google.com:443");
115 115
116 helper->StartFetching( 116 helper->StartFetching(
117 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, 117 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
118 base::Unretained(this))); 118 base::Unretained(this)));
119 MessageLoop::current()->Run(); 119 base::MessageLoop::current()->Run();
120 120
121 EXPECT_EQ(1, ssl_config_changed_count_); 121 EXPECT_EQ(1, ssl_config_changed_count_);
122 ASSERT_EQ(1UL, server_bound_cert_list_.size()); 122 ASSERT_EQ(1UL, server_bound_cert_list_.size());
123 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it = 123 net::ServerBoundCertStore::ServerBoundCertList::const_iterator it =
124 server_bound_cert_list_.begin(); 124 server_bound_cert_list_.begin();
125 125
126 ASSERT_TRUE(it != server_bound_cert_list_.end()); 126 ASSERT_TRUE(it != server_bound_cert_list_.end());
127 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier()); 127 EXPECT_EQ("https://www.youtube.com:443", it->server_identifier());
128 128
129 ASSERT_TRUE(++it == server_bound_cert_list_.end()); 129 ASSERT_TRUE(++it == server_bound_cert_list_.end());
130 130
131 helper->DeleteServerBoundCert("https://www.youtube.com:443"); 131 helper->DeleteServerBoundCert("https://www.youtube.com:443");
132 132
133 helper->StartFetching( 133 helper->StartFetching(
134 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, 134 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
135 base::Unretained(this))); 135 base::Unretained(this)));
136 MessageLoop::current()->Run(); 136 base::MessageLoop::current()->Run();
137 EXPECT_EQ(2, ssl_config_changed_count_); 137 EXPECT_EQ(2, ssl_config_changed_count_);
138 ASSERT_EQ(0UL, server_bound_cert_list_.size()); 138 ASSERT_EQ(0UL, server_bound_cert_list_.size());
139 } 139 }
140 140
141 TEST_F(BrowsingDataServerBoundCertHelperTest, CannedUnique) { 141 TEST_F(BrowsingDataServerBoundCertHelperTest, CannedUnique) {
142 std::string origin = "https://www.google.com:443"; 142 std::string origin = "https://www.google.com:443";
143 143
144 scoped_refptr<CannedBrowsingDataServerBoundCertHelper> helper( 144 scoped_refptr<CannedBrowsingDataServerBoundCertHelper> helper(
145 new CannedBrowsingDataServerBoundCertHelper()); 145 new CannedBrowsingDataServerBoundCertHelper());
146 146
147 ASSERT_TRUE(helper->empty()); 147 ASSERT_TRUE(helper->empty());
148 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert( 148 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert(
149 origin, net::CLIENT_CERT_RSA_SIGN, base::Time(), base::Time(), "key", 149 origin, net::CLIENT_CERT_RSA_SIGN, base::Time(), base::Time(), "key",
150 "cert")); 150 "cert"));
151 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert( 151 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert(
152 origin, net::CLIENT_CERT_ECDSA_SIGN, base::Time(), base::Time(), "key", 152 origin, net::CLIENT_CERT_ECDSA_SIGN, base::Time(), base::Time(), "key",
153 "cert")); 153 "cert"));
154 154
155 helper->StartFetching( 155 helper->StartFetching(
156 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback, 156 base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
157 base::Unretained(this))); 157 base::Unretained(this)));
158 MessageLoop::current()->Run(); 158 base::MessageLoop::current()->Run();
159 159
160 ASSERT_EQ(1UL, server_bound_cert_list_.size()); 160 ASSERT_EQ(1UL, server_bound_cert_list_.size());
161 net::ServerBoundCertStore::ServerBoundCert& cert = 161 net::ServerBoundCertStore::ServerBoundCert& cert =
162 server_bound_cert_list_.front(); 162 server_bound_cert_list_.front();
163 163
164 EXPECT_EQ("https://www.google.com:443", cert.server_identifier()); 164 EXPECT_EQ("https://www.google.com:443", cert.server_identifier());
165 EXPECT_EQ(net::CLIENT_CERT_ECDSA_SIGN, cert.type()); 165 EXPECT_EQ(net::CLIENT_CERT_ECDSA_SIGN, cert.type());
166 EXPECT_EQ(0, ssl_config_changed_count_); 166 EXPECT_EQ(0, ssl_config_changed_count_);
167 } 167 }
168 168
169 TEST_F(BrowsingDataServerBoundCertHelperTest, CannedEmpty) { 169 TEST_F(BrowsingDataServerBoundCertHelperTest, CannedEmpty) {
170 std::string origin = "https://www.google.com"; 170 std::string origin = "https://www.google.com";
171 171
172 scoped_refptr<CannedBrowsingDataServerBoundCertHelper> helper( 172 scoped_refptr<CannedBrowsingDataServerBoundCertHelper> helper(
173 new CannedBrowsingDataServerBoundCertHelper()); 173 new CannedBrowsingDataServerBoundCertHelper());
174 174
175 ASSERT_TRUE(helper->empty()); 175 ASSERT_TRUE(helper->empty());
176 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert( 176 helper->AddServerBoundCert(net::ServerBoundCertStore::ServerBoundCert(
177 origin, net::CLIENT_CERT_RSA_SIGN, base::Time(), base::Time(), "key", 177 origin, net::CLIENT_CERT_RSA_SIGN, base::Time(), base::Time(), "key",
178 "cert")); 178 "cert"));
179 ASSERT_FALSE(helper->empty()); 179 ASSERT_FALSE(helper->empty());
180 helper->Reset(); 180 helper->Reset();
181 ASSERT_TRUE(helper->empty()); 181 ASSERT_TRUE(helper->empty());
182 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698