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 "google_apis/gcm/engine/gcm_store_impl.h" | 5 #include "google_apis/gcm/engine/gcm_store_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.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/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "components/os_crypt/os_crypt_switches.h" | 18 #include "google_apis/gcm/base/fake_encryptor.h" |
19 #include "google_apis/gcm/base/mcs_message.h" | 19 #include "google_apis/gcm/base/mcs_message.h" |
20 #include "google_apis/gcm/base/mcs_util.h" | 20 #include "google_apis/gcm/base/mcs_util.h" |
21 #include "google_apis/gcm/protocol/mcs.pb.h" | 21 #include "google_apis/gcm/protocol/mcs.pb.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace gcm { | 24 namespace gcm { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Number of persistent ids to use in tests. | 28 // Number of persistent ids to use in tests. |
(...skipping 24 matching lines...) Expand all Loading... |
53 | 53 |
54 void PumpLoop(); | 54 void PumpLoop(); |
55 | 55 |
56 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst, | 56 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst, |
57 scoped_ptr<GCMStore::LoadResult> result); | 57 scoped_ptr<GCMStore::LoadResult> result); |
58 void UpdateCallback(bool success); | 58 void UpdateCallback(bool success); |
59 | 59 |
60 protected: | 60 protected: |
61 base::MessageLoop message_loop_; | 61 base::MessageLoop message_loop_; |
62 base::ScopedTempDir temp_directory_; | 62 base::ScopedTempDir temp_directory_; |
| 63 FakeEncryptor fake_encryptor_; |
63 bool expected_success_; | 64 bool expected_success_; |
64 uint64 next_persistent_id_; | 65 uint64 next_persistent_id_; |
65 scoped_ptr<base::RunLoop> run_loop_; | 66 scoped_ptr<base::RunLoop> run_loop_; |
66 }; | 67 }; |
67 | 68 |
68 GCMStoreImplTest::GCMStoreImplTest() | 69 GCMStoreImplTest::GCMStoreImplTest() |
69 : expected_success_(true), | 70 : expected_success_(true), |
70 next_persistent_id_(base::Time::Now().ToInternalValue()) { | 71 next_persistent_id_(base::Time::Now().ToInternalValue()) { |
71 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 72 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
72 run_loop_.reset(new base::RunLoop()); | 73 run_loop_.reset(new base::RunLoop()); |
73 } | 74 } |
74 | 75 |
75 GCMStoreImplTest::~GCMStoreImplTest() {} | 76 GCMStoreImplTest::~GCMStoreImplTest() {} |
76 | 77 |
77 void GCMStoreImplTest::SetUp() { | 78 void GCMStoreImplTest::SetUp() { |
78 testing::Test::SetUp(); | 79 testing::Test::SetUp(); |
79 #if defined(OS_MACOSX) | |
80 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
81 os_crypt::switches::kUseMockKeychain); | |
82 #endif // OS_MACOSX | |
83 } | 80 } |
84 | 81 |
85 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { | 82 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { |
86 return scoped_ptr<GCMStore>(new GCMStoreImpl( | 83 return scoped_ptr<GCMStore>(new GCMStoreImpl( |
87 temp_directory_.path(), | 84 temp_directory_.path(), |
88 message_loop_.message_loop_proxy())); | 85 message_loop_.message_loop_proxy(), |
| 86 &fake_encryptor_)); |
89 } | 87 } |
90 | 88 |
91 std::string GCMStoreImplTest::GetNextPersistentId() { | 89 std::string GCMStoreImplTest::GetNextPersistentId() { |
92 return base::Uint64ToString(next_persistent_id_++); | 90 return base::Uint64ToString(next_persistent_id_++); |
93 } | 91 } |
94 | 92 |
95 void GCMStoreImplTest::PumpLoop() { message_loop_.RunUntilIdle(); } | 93 void GCMStoreImplTest::PumpLoop() { message_loop_.RunUntilIdle(); } |
96 | 94 |
97 void GCMStoreImplTest::LoadCallback( | 95 void GCMStoreImplTest::LoadCallback( |
98 scoped_ptr<GCMStore::LoadResult>* result_dst, | 96 scoped_ptr<GCMStore::LoadResult>* result_dst, |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 544 |
547 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, | 545 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, |
548 base::Unretained(this), | 546 base::Unretained(this), |
549 &load_result)); | 547 &load_result)); |
550 PumpLoop(); | 548 PumpLoop(); |
551 } | 549 } |
552 | 550 |
553 } // namespace | 551 } // namespace |
554 | 552 |
555 } // namespace gcm | 553 } // namespace gcm |
OLD | NEW |