OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/ssl/default_channel_id_store.h" | 5 #include "net/ssl/default_channel_id_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "crypto/ec_private_key.h" | 21 #include "crypto/ec_private_key.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/test/channel_id_test_util.h" | 23 #include "net/test/channel_id_test_util.h" |
| 24 #include "net/test/gtest_util.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
| 28 using net::test::IsError; |
| 29 using net::test::IsOk; |
| 30 |
26 namespace net { | 31 namespace net { |
27 | 32 |
28 namespace { | 33 namespace { |
29 | 34 |
30 void CallCounter(int* counter) { | 35 void CallCounter(int* counter) { |
31 (*counter)++; | 36 (*counter)++; |
32 } | 37 } |
33 | 38 |
34 void GetChannelIDCallbackNotCalled( | 39 void GetChannelIDCallbackNotCalled( |
35 int err, | 40 int err, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 EXPECT_EQ(ERR_IO_PENDING, | 215 EXPECT_EQ(ERR_IO_PENDING, |
211 store.GetChannelID("verisign.com", &key, | 216 store.GetChannelID("verisign.com", &key, |
212 base::Bind(&AsyncGetChannelIDHelper::Callback, | 217 base::Bind(&AsyncGetChannelIDHelper::Callback, |
213 base::Unretained(&helper)))); | 218 base::Unretained(&helper)))); |
214 | 219 |
215 // Wait for load & queued get tasks. | 220 // Wait for load & queued get tasks. |
216 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
217 EXPECT_EQ(1, store.GetChannelIDCount()); | 222 EXPECT_EQ(1, store.GetChannelIDCount()); |
218 EXPECT_FALSE(key); | 223 EXPECT_FALSE(key); |
219 EXPECT_TRUE(helper.called_); | 224 EXPECT_TRUE(helper.called_); |
220 EXPECT_EQ(OK, helper.err_); | 225 EXPECT_THAT(helper.err_, IsOk()); |
221 EXPECT_EQ("verisign.com", helper.server_identifier_); | 226 EXPECT_EQ("verisign.com", helper.server_identifier_); |
222 EXPECT_TRUE(KeysEqual(expected_key.get(), helper.key_.get())); | 227 EXPECT_TRUE(KeysEqual(expected_key.get(), helper.key_.get())); |
223 } | 228 } |
224 | 229 |
225 TEST(DefaultChannelIDStoreTest, TestDeleteAll) { | 230 TEST(DefaultChannelIDStoreTest, TestDeleteAll) { |
226 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 231 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
227 DefaultChannelIDStore store(persistent_store.get()); | 232 DefaultChannelIDStore store(persistent_store.get()); |
228 | 233 |
229 store.SetChannelID(base::WrapUnique(new ChannelIDStore::ChannelID( | 234 store.SetChannelID(base::WrapUnique(new ChannelIDStore::ChannelID( |
230 "verisign.com", base::Time(), crypto::ECPrivateKey::Create()))); | 235 "verisign.com", base::Time(), crypto::ECPrivateKey::Create()))); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 373 |
369 EXPECT_EQ(0, delete_finished); | 374 EXPECT_EQ(0, delete_finished); |
370 EXPECT_FALSE(a_helper.called_); | 375 EXPECT_FALSE(a_helper.called_); |
371 EXPECT_FALSE(b_helper.called_); | 376 EXPECT_FALSE(b_helper.called_); |
372 // Wait for load & queued tasks. | 377 // Wait for load & queued tasks. |
373 base::RunLoop().RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
374 EXPECT_EQ(1, delete_finished); | 379 EXPECT_EQ(1, delete_finished); |
375 EXPECT_EQ(1, store.GetChannelIDCount()); | 380 EXPECT_EQ(1, store.GetChannelIDCount()); |
376 EXPECT_FALSE(key); | 381 EXPECT_FALSE(key); |
377 EXPECT_TRUE(a_helper.called_); | 382 EXPECT_TRUE(a_helper.called_); |
378 EXPECT_EQ(ERR_FILE_NOT_FOUND, a_helper.err_); | 383 EXPECT_THAT(a_helper.err_, IsError(ERR_FILE_NOT_FOUND)); |
379 EXPECT_EQ("a.com", a_helper.server_identifier_); | 384 EXPECT_EQ("a.com", a_helper.server_identifier_); |
380 EXPECT_FALSE(a_helper.key_); | 385 EXPECT_FALSE(a_helper.key_); |
381 EXPECT_TRUE(b_helper.called_); | 386 EXPECT_TRUE(b_helper.called_); |
382 EXPECT_EQ(OK, b_helper.err_); | 387 EXPECT_THAT(b_helper.err_, IsOk()); |
383 EXPECT_EQ("b.com", b_helper.server_identifier_); | 388 EXPECT_EQ("b.com", b_helper.server_identifier_); |
384 EXPECT_TRUE(KeysEqual(expected_key.get(), b_helper.key_.get())); | 389 EXPECT_TRUE(KeysEqual(expected_key.get(), b_helper.key_.get())); |
385 } | 390 } |
386 | 391 |
387 TEST(DefaultChannelIDStoreTest, TestGetAll) { | 392 TEST(DefaultChannelIDStoreTest, TestGetAll) { |
388 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 393 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
389 DefaultChannelIDStore store(persistent_store.get()); | 394 DefaultChannelIDStore store(persistent_store.get()); |
390 | 395 |
391 EXPECT_EQ(0, store.GetChannelIDCount()); | 396 EXPECT_EQ(0, store.GetChannelIDCount()); |
392 store.SetChannelID(base::WrapUnique(new ChannelIDStore::ChannelID( | 397 store.SetChannelID(base::WrapUnique(new ChannelIDStore::ChannelID( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 ++channel_id; | 495 ++channel_id; |
491 EXPECT_EQ("copied.com", channel_id->server_identifier()); | 496 EXPECT_EQ("copied.com", channel_id->server_identifier()); |
492 EXPECT_TRUE(KeysEqual(copied_key.get(), channel_id->key())); | 497 EXPECT_TRUE(KeysEqual(copied_key.get(), channel_id->key())); |
493 | 498 |
494 ++channel_id; | 499 ++channel_id; |
495 EXPECT_EQ("preexisting.com", channel_id->server_identifier()); | 500 EXPECT_EQ("preexisting.com", channel_id->server_identifier()); |
496 EXPECT_TRUE(KeysEqual(preexisting_key.get(), channel_id->key())); | 501 EXPECT_TRUE(KeysEqual(preexisting_key.get(), channel_id->key())); |
497 } | 502 } |
498 | 503 |
499 } // namespace net | 504 } // namespace net |
OLD | NEW |