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/net/transport_security_persister.h" | 5 #include "net/http/transport_security_persister.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "net/http/transport_security_state.h" | 15 #include "net/http/transport_security_state.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
| 18 using net::TransportSecurityPersister; |
18 using net::TransportSecurityState; | 19 using net::TransportSecurityState; |
19 | 20 |
20 class TransportSecurityPersisterTest : public testing::Test { | 21 class TransportSecurityPersisterTest : public testing::Test { |
21 public: | 22 public: |
22 TransportSecurityPersisterTest() | 23 TransportSecurityPersisterTest() { |
23 : message_loop_(base::MessageLoop::TYPE_IO) { | |
24 } | 24 } |
25 | 25 |
26 virtual ~TransportSecurityPersisterTest() { | 26 virtual ~TransportSecurityPersisterTest() { |
27 message_loop_.RunUntilIdle(); | 27 base::MessageLoopForIO::current()->RunUntilIdle(); |
28 } | 28 } |
29 | 29 |
30 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
32 persister_.reset(new TransportSecurityPersister( | 32 persister_.reset(new TransportSecurityPersister( |
33 &state_, temp_dir_.path(), message_loop_.message_loop_proxy(), false)); | 33 &state_, |
| 34 temp_dir_.path(), |
| 35 base::MessageLoopForIO::current()->message_loop_proxy(), |
| 36 false)); |
34 } | 37 } |
35 | 38 |
36 protected: | 39 protected: |
37 // Ordering is important here. If member variables are not destroyed in the | |
38 // right order, then DCHECKs will fail all over the place. | |
39 base::MessageLoop message_loop_; | |
40 | |
41 base::ScopedTempDir temp_dir_; | 40 base::ScopedTempDir temp_dir_; |
42 TransportSecurityState state_; | 41 TransportSecurityState state_; |
43 scoped_ptr<TransportSecurityPersister> persister_; | 42 scoped_ptr<TransportSecurityPersister> persister_; |
44 }; | 43 }; |
45 | 44 |
46 TEST_F(TransportSecurityPersisterTest, SerializeData1) { | 45 TEST_F(TransportSecurityPersisterTest, SerializeData1) { |
47 std::string output; | 46 std::string output; |
48 bool dirty; | 47 bool dirty; |
49 | 48 |
50 EXPECT_TRUE(persister_->SerializeData(&output)); | 49 EXPECT_TRUE(persister_->SerializeData(&output)); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 std::string ser; | 192 std::string ser; |
194 EXPECT_TRUE(persister_->SerializeData(&ser)); | 193 EXPECT_TRUE(persister_->SerializeData(&ser)); |
195 bool dirty; | 194 bool dirty; |
196 EXPECT_TRUE(persister_->LoadEntries(ser, &dirty)); | 195 EXPECT_TRUE(persister_->LoadEntries(ser, &dirty)); |
197 EXPECT_TRUE(state_.GetDomainState(kTestDomain, false, &domain_state)); | 196 EXPECT_TRUE(state_.GetDomainState(kTestDomain, false, &domain_state)); |
198 EXPECT_EQ(1u, domain_state.dynamic_spki_hashes.size()); | 197 EXPECT_EQ(1u, domain_state.dynamic_spki_hashes.size()); |
199 EXPECT_EQ(sha1.tag, domain_state.dynamic_spki_hashes[0].tag); | 198 EXPECT_EQ(sha1.tag, domain_state.dynamic_spki_hashes[0].tag); |
200 EXPECT_EQ(0, memcmp(domain_state.dynamic_spki_hashes[0].data(), sha1.data(), | 199 EXPECT_EQ(0, memcmp(domain_state.dynamic_spki_hashes[0].data(), sha1.data(), |
201 sha1.size())); | 200 sha1.size())); |
202 } | 201 } |
OLD | NEW |