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 "chrome/browser/net/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 "content/public/test/test_browser_thread.h" | |
16 #include "net/http/transport_security_state.h" | 15 #include "net/http/transport_security_state.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 | 17 |
19 using net::TransportSecurityState; | 18 using net::TransportSecurityState; |
20 | 19 |
21 class TransportSecurityPersisterTest : public testing::Test { | 20 class TransportSecurityPersisterTest : public testing::Test { |
22 public: | 21 public: |
23 TransportSecurityPersisterTest() | 22 TransportSecurityPersisterTest() |
24 : message_loop_(base::MessageLoop::TYPE_IO), | 23 : message_loop_(base::MessageLoop::TYPE_IO) { |
25 test_file_thread_(content::BrowserThread::FILE, &message_loop_), | |
26 test_io_thread_(content::BrowserThread::IO, &message_loop_) { | |
27 } | 24 } |
28 | 25 |
29 virtual ~TransportSecurityPersisterTest() { | 26 virtual ~TransportSecurityPersisterTest() { |
30 message_loop_.RunUntilIdle(); | 27 message_loop_.RunUntilIdle(); |
31 } | 28 } |
32 | 29 |
33 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
34 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
35 persister_.reset( | 32 persister_.reset(new TransportSecurityPersister( |
36 new TransportSecurityPersister(&state_, temp_dir_.path(), false)); | 33 &state_, temp_dir_.path(), message_loop_.message_loop_proxy(), false)); |
37 } | 34 } |
38 | 35 |
39 protected: | 36 protected: |
40 // Ordering is important here. If member variables are not destroyed in the | 37 // Ordering is important here. If member variables are not destroyed in the |
41 // right order, then DCHECKs will fail all over the place. | 38 // right order, then DCHECKs will fail all over the place. |
42 base::MessageLoop message_loop_; | 39 base::MessageLoop message_loop_; |
43 | 40 |
44 // Needed for ImportantFileWriter, which TransportSecurityPersister uses. | |
45 content::TestBrowserThread test_file_thread_; | |
46 | |
47 // TransportSecurityPersister runs on the IO thread. | |
48 content::TestBrowserThread test_io_thread_; | |
49 | |
50 base::ScopedTempDir temp_dir_; | 41 base::ScopedTempDir temp_dir_; |
51 TransportSecurityState state_; | 42 TransportSecurityState state_; |
52 scoped_ptr<TransportSecurityPersister> persister_; | 43 scoped_ptr<TransportSecurityPersister> persister_; |
53 }; | 44 }; |
54 | 45 |
55 TEST_F(TransportSecurityPersisterTest, SerializeData1) { | 46 TEST_F(TransportSecurityPersisterTest, SerializeData1) { |
56 std::string output; | 47 std::string output; |
57 bool dirty; | 48 bool dirty; |
58 | 49 |
59 EXPECT_TRUE(persister_->SerializeData(&output)); | 50 EXPECT_TRUE(persister_->SerializeData(&output)); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 std::string ser; | 193 std::string ser; |
203 EXPECT_TRUE(persister_->SerializeData(&ser)); | 194 EXPECT_TRUE(persister_->SerializeData(&ser)); |
204 bool dirty; | 195 bool dirty; |
205 EXPECT_TRUE(persister_->LoadEntries(ser, &dirty)); | 196 EXPECT_TRUE(persister_->LoadEntries(ser, &dirty)); |
206 EXPECT_TRUE(state_.GetDomainState(kTestDomain, false, &domain_state)); | 197 EXPECT_TRUE(state_.GetDomainState(kTestDomain, false, &domain_state)); |
207 EXPECT_EQ(1u, domain_state.dynamic_spki_hashes.size()); | 198 EXPECT_EQ(1u, domain_state.dynamic_spki_hashes.size()); |
208 EXPECT_EQ(sha1.tag, domain_state.dynamic_spki_hashes[0].tag); | 199 EXPECT_EQ(sha1.tag, domain_state.dynamic_spki_hashes[0].tag); |
209 EXPECT_EQ(0, memcmp(domain_state.dynamic_spki_hashes[0].data(), sha1.data(), | 200 EXPECT_EQ(0, memcmp(domain_state.dynamic_spki_hashes[0].data(), sha1.data(), |
210 sha1.size())); | 201 sha1.size())); |
211 } | 202 } |
OLD | NEW |