| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/gcm_driver/instance_id/instance_id_driver.h" | 5 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 class InstanceIDDriverTest : public testing::Test { | 39 class InstanceIDDriverTest : public testing::Test { |
| 40 public: | 40 public: |
| 41 InstanceIDDriverTest(); | 41 InstanceIDDriverTest(); |
| 42 ~InstanceIDDriverTest() override; | 42 ~InstanceIDDriverTest() override; |
| 43 | 43 |
| 44 // testing::Test: | 44 // testing::Test: |
| 45 void SetUp() override; | 45 void SetUp() override; |
| 46 | 46 |
| 47 void WaitForAsyncOperation(); | 47 void WaitForAsyncOperation(); |
| 48 | 48 |
| 49 void DeleteIDCompleted(InstanceID* instance_id, InstanceID::Result result); | 49 void DeleteIDCompleted(InstanceID::Result result); |
| 50 | 50 |
| 51 InstanceIDDriver* driver() const { return driver_.get(); } | 51 InstanceIDDriver* driver() const { return driver_.get(); } |
| 52 InstanceID::Result delete_id_result() const { return delete_id_result_; } | 52 InstanceID::Result delete_id_result() const { return delete_id_result_; } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 base::MessageLoopForUI message_loop_; | 55 base::MessageLoopForUI message_loop_; |
| 56 scoped_ptr<gcm::FakeGCMDriver> gcm_driver_; | 56 scoped_ptr<gcm::FakeGCMDriver> gcm_driver_; |
| 57 scoped_ptr<InstanceIDDriver> driver_; | 57 scoped_ptr<InstanceIDDriver> driver_; |
| 58 InstanceID::Result delete_id_result_; | 58 InstanceID::Result delete_id_result_; |
| 59 base::Closure async_operation_completed_callback_; | 59 base::Closure async_operation_completed_callback_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 gcm_driver_.reset(new gcm::FakeGCMDriver); | 72 gcm_driver_.reset(new gcm::FakeGCMDriver); |
| 73 driver_.reset(new InstanceIDDriver(gcm_driver_.get())); | 73 driver_.reset(new InstanceIDDriver(gcm_driver_.get())); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void InstanceIDDriverTest::WaitForAsyncOperation() { | 76 void InstanceIDDriverTest::WaitForAsyncOperation() { |
| 77 base::RunLoop run_loop; | 77 base::RunLoop run_loop; |
| 78 async_operation_completed_callback_ = run_loop.QuitClosure(); | 78 async_operation_completed_callback_ = run_loop.QuitClosure(); |
| 79 run_loop.Run(); | 79 run_loop.Run(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void InstanceIDDriverTest::DeleteIDCompleted(InstanceID* instance_id, | 82 void InstanceIDDriverTest::DeleteIDCompleted(InstanceID::Result result) { |
| 83 InstanceID::Result result) { | |
| 84 delete_id_result_ = result; | 83 delete_id_result_ = result; |
| 85 if (!async_operation_completed_callback_.is_null()) | 84 if (!async_operation_completed_callback_.is_null()) |
| 86 async_operation_completed_callback_.Run(); | 85 async_operation_completed_callback_.Run(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 TEST_F(InstanceIDDriverTest, NewID) { | 88 TEST_F(InstanceIDDriverTest, NewID) { |
| 90 // Creation time should not be set when the ID is not created. | 89 // Creation time should not be set when the ID is not created. |
| 91 InstanceID* instance_id1 = driver()->GetInstanceID(kTestAppID1); | 90 InstanceID* instance_id1 = driver()->GetInstanceID(kTestAppID1); |
| 92 EXPECT_TRUE(instance_id1->GetCreationTime().is_null()); | 91 EXPECT_TRUE(instance_id1->GetCreationTime().is_null()); |
| 93 | 92 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 124 EXPECT_EQ(InstanceID::SUCCESS, delete_id_result()); | 123 EXPECT_EQ(InstanceID::SUCCESS, delete_id_result()); |
| 125 EXPECT_TRUE(instance_id->GetCreationTime().is_null()); | 124 EXPECT_TRUE(instance_id->GetCreationTime().is_null()); |
| 126 | 125 |
| 127 std::string id2 = instance_id->GetID(); | 126 std::string id2 = instance_id->GetID(); |
| 128 EXPECT_FALSE(id2.empty()); | 127 EXPECT_FALSE(id2.empty()); |
| 129 EXPECT_NE(id1, id2); | 128 EXPECT_NE(id1, id2); |
| 130 EXPECT_FALSE(instance_id->GetCreationTime().is_null()); | 129 EXPECT_FALSE(instance_id->GetCreationTime().is_null()); |
| 131 } | 130 } |
| 132 | 131 |
| 133 } // instance_id | 132 } // instance_id |
| OLD | NEW |