| 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/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "components/os_crypt/os_crypt_switches.h" |
| 17 #include "google_apis/gcm/base/mcs_message.h" | 19 #include "google_apis/gcm/base/mcs_message.h" |
| 18 #include "google_apis/gcm/base/mcs_util.h" | 20 #include "google_apis/gcm/base/mcs_util.h" |
| 19 #include "google_apis/gcm/protocol/mcs.pb.h" | 21 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 namespace gcm { | 24 namespace gcm { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Number of persistent ids to use in tests. | 28 // Number of persistent ids to use in tests. |
| 27 const int kNumPersistentIds = 10; | 29 const int kNumPersistentIds = 10; |
| 28 | 30 |
| 29 // Number of per-app messages in tests. | 31 // Number of per-app messages in tests. |
| 30 const int kNumMessagesPerApp = 20; | 32 const int kNumMessagesPerApp = 20; |
| 31 | 33 |
| 32 // App name for testing. | 34 // App name for testing. |
| 33 const char kAppName[] = "my_app"; | 35 const char kAppName[] = "my_app"; |
| 34 | 36 |
| 35 // Category name for testing. | 37 // Category name for testing. |
| 36 const char kCategoryName[] = "my_category"; | 38 const char kCategoryName[] = "my_category"; |
| 37 | 39 |
| 38 const uint64 kDeviceId = 22; | 40 const uint64 kDeviceId = 22; |
| 39 const uint64 kDeviceToken = 55; | 41 const uint64 kDeviceToken = 55; |
| 40 | 42 |
| 41 class GCMStoreImplTest : public testing::Test { | 43 class GCMStoreImplTest : public testing::Test { |
| 42 public: | 44 public: |
| 43 GCMStoreImplTest(); | 45 GCMStoreImplTest(); |
| 44 virtual ~GCMStoreImplTest(); | 46 virtual ~GCMStoreImplTest(); |
| 45 | 47 |
| 48 virtual void SetUp() OVERRIDE; |
| 49 |
| 46 scoped_ptr<GCMStore> BuildGCMStore(); | 50 scoped_ptr<GCMStore> BuildGCMStore(); |
| 47 | 51 |
| 48 std::string GetNextPersistentId(); | 52 std::string GetNextPersistentId(); |
| 49 | 53 |
| 50 void PumpLoop(); | 54 void PumpLoop(); |
| 51 | 55 |
| 52 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst, | 56 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst, |
| 53 scoped_ptr<GCMStore::LoadResult> result); | 57 scoped_ptr<GCMStore::LoadResult> result); |
| 54 void UpdateCallback(bool success); | 58 void UpdateCallback(bool success); |
| 55 | 59 |
| 56 protected: | 60 protected: |
| 57 base::MessageLoop message_loop_; | 61 base::MessageLoop message_loop_; |
| 58 base::ScopedTempDir temp_directory_; | 62 base::ScopedTempDir temp_directory_; |
| 59 bool expected_success_; | 63 bool expected_success_; |
| 60 uint64 next_persistent_id_; | 64 uint64 next_persistent_id_; |
| 61 scoped_ptr<base::RunLoop> run_loop_; | 65 scoped_ptr<base::RunLoop> run_loop_; |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 GCMStoreImplTest::GCMStoreImplTest() | 68 GCMStoreImplTest::GCMStoreImplTest() |
| 65 : expected_success_(true), | 69 : expected_success_(true), |
| 66 next_persistent_id_(base::Time::Now().ToInternalValue()) { | 70 next_persistent_id_(base::Time::Now().ToInternalValue()) { |
| 67 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 71 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 68 run_loop_.reset(new base::RunLoop()); | 72 run_loop_.reset(new base::RunLoop()); |
| 69 } | 73 } |
| 70 | 74 |
| 71 GCMStoreImplTest::~GCMStoreImplTest() {} | 75 GCMStoreImplTest::~GCMStoreImplTest() {} |
| 72 | 76 |
| 77 void GCMStoreImplTest::SetUp() { |
| 78 testing::Test::SetUp(); |
| 79 #if defined(OS_MACOSX) |
| 80 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 81 os_crypt::switches::kUseMockKeychain); |
| 82 #endif // OS_MACOSX |
| 83 } |
| 84 |
| 73 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { | 85 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { |
| 74 return scoped_ptr<GCMStore>(new GCMStoreImpl( | 86 return scoped_ptr<GCMStore>(new GCMStoreImpl( |
| 75 true, | |
| 76 temp_directory_.path(), | 87 temp_directory_.path(), |
| 77 message_loop_.message_loop_proxy())); | 88 message_loop_.message_loop_proxy())); |
| 78 } | 89 } |
| 79 | 90 |
| 80 std::string GCMStoreImplTest::GetNextPersistentId() { | 91 std::string GCMStoreImplTest::GetNextPersistentId() { |
| 81 return base::Uint64ToString(next_persistent_id_++); | 92 return base::Uint64ToString(next_persistent_id_++); |
| 82 } | 93 } |
| 83 | 94 |
| 84 void GCMStoreImplTest::PumpLoop() { message_loop_.RunUntilIdle(); } | 95 void GCMStoreImplTest::PumpLoop() { message_loop_.RunUntilIdle(); } |
| 85 | 96 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 498 |
| 488 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, | 499 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, |
| 489 base::Unretained(this), | 500 base::Unretained(this), |
| 490 &load_result)); | 501 &load_result)); |
| 491 PumpLoop(); | 502 PumpLoop(); |
| 492 } | 503 } |
| 493 | 504 |
| 494 } // namespace | 505 } // namespace |
| 495 | 506 |
| 496 } // namespace gcm | 507 } // namespace gcm |
| OLD | NEW |