Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: components/proximity_auth/cryptauth/cryptauth_device_manager_unittest.cc

Issue 1248533003: Hook up CryptAuthGCMManager to the enrollment and device sync managers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix webui Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/proximity_auth/cryptauth/cryptauth_device_manager.h" 5 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/test/simple_test_clock.h" 11 #include "base/test/simple_test_clock.h"
12 #include "components/proximity_auth/cryptauth/base64url.h" 12 #include "components/proximity_auth/cryptauth/base64url.h"
13 #include "components/proximity_auth/cryptauth/fake_cryptauth_gcm_manager.h"
13 #include "components/proximity_auth/cryptauth/mock_cryptauth_client.h" 14 #include "components/proximity_auth/cryptauth/mock_cryptauth_client.h"
14 #include "components/proximity_auth/cryptauth/mock_sync_scheduler.h" 15 #include "components/proximity_auth/cryptauth/mock_sync_scheduler.h"
15 #include "components/proximity_auth/cryptauth/pref_names.h" 16 #include "components/proximity_auth/cryptauth/pref_names.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using ::testing::_; 20 using ::testing::_;
20 using ::testing::DoAll; 21 using ::testing::DoAll;
21 using ::testing::NiceMock; 22 using ::testing::NiceMock;
22 using ::testing::Return; 23 using ::testing::Return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_TRUE(expected_unlock_key.unlock_key()); 98 EXPECT_TRUE(expected_unlock_key.unlock_key());
98 EXPECT_FALSE(expected_unlock_key.unlockable()); 99 EXPECT_FALSE(expected_unlock_key.unlockable());
99 } 100 }
100 } 101 }
101 102
102 // Harness for testing CryptAuthDeviceManager. 103 // Harness for testing CryptAuthDeviceManager.
103 class TestCryptAuthDeviceManager : public CryptAuthDeviceManager { 104 class TestCryptAuthDeviceManager : public CryptAuthDeviceManager {
104 public: 105 public:
105 TestCryptAuthDeviceManager(scoped_ptr<base::Clock> clock, 106 TestCryptAuthDeviceManager(scoped_ptr<base::Clock> clock,
106 scoped_ptr<CryptAuthClientFactory> client_factory, 107 scoped_ptr<CryptAuthClientFactory> client_factory,
108 CryptAuthGCMManager* gcm_manager,
107 PrefService* pref_service) 109 PrefService* pref_service)
108 : CryptAuthDeviceManager(clock.Pass(), 110 : CryptAuthDeviceManager(clock.Pass(),
109 client_factory.Pass(), 111 client_factory.Pass(),
112 gcm_manager,
110 pref_service), 113 pref_service),
111 scoped_sync_scheduler_(new NiceMock<MockSyncScheduler>()), 114 scoped_sync_scheduler_(new NiceMock<MockSyncScheduler>()),
112 weak_sync_scheduler_factory_(scoped_sync_scheduler_.get()) {} 115 weak_sync_scheduler_factory_(scoped_sync_scheduler_.get()) {}
113 116
114 ~TestCryptAuthDeviceManager() override {} 117 ~TestCryptAuthDeviceManager() override {}
115 118
116 scoped_ptr<SyncScheduler> CreateSyncScheduler() override { 119 scoped_ptr<SyncScheduler> CreateSyncScheduler() override {
117 EXPECT_TRUE(scoped_sync_scheduler_); 120 EXPECT_TRUE(scoped_sync_scheduler_);
118 return scoped_sync_scheduler_.Pass(); 121 return scoped_sync_scheduler_.Pass();
119 } 122 }
(...skipping 20 matching lines...) Expand all
140 143
141 class ProximityAuthCryptAuthDeviceManagerTest 144 class ProximityAuthCryptAuthDeviceManagerTest
142 : public testing::Test, 145 : public testing::Test,
143 public CryptAuthDeviceManager::Observer, 146 public CryptAuthDeviceManager::Observer,
144 public MockCryptAuthClientFactory::Observer { 147 public MockCryptAuthClientFactory::Observer {
145 protected: 148 protected:
146 ProximityAuthCryptAuthDeviceManagerTest() 149 ProximityAuthCryptAuthDeviceManagerTest()
147 : clock_(new base::SimpleTestClock()), 150 : clock_(new base::SimpleTestClock()),
148 client_factory_(new MockCryptAuthClientFactory( 151 client_factory_(new MockCryptAuthClientFactory(
149 MockCryptAuthClientFactory::MockType::MAKE_STRICT_MOCKS)), 152 MockCryptAuthClientFactory::MockType::MAKE_STRICT_MOCKS)),
153 gcm_manager_("existing gcm registration id"),
150 device_manager_(make_scoped_ptr(clock_), 154 device_manager_(make_scoped_ptr(clock_),
151 make_scoped_ptr(client_factory_), 155 make_scoped_ptr(client_factory_),
156 &gcm_manager_,
152 &pref_service_) { 157 &pref_service_) {
153 client_factory_->AddObserver(this); 158 client_factory_->AddObserver(this);
154 } 159 }
155 160
156 ~ProximityAuthCryptAuthDeviceManagerTest() { 161 ~ProximityAuthCryptAuthDeviceManagerTest() {
157 client_factory_->RemoveObserver(this); 162 client_factory_->RemoveObserver(this);
158 } 163 }
159 164
160 // testing::Test: 165 // testing::Test:
161 void SetUp() override { 166 void SetUp() override {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 259 }
255 260
256 // Owned by |device_manager_|. 261 // Owned by |device_manager_|.
257 base::SimpleTestClock* clock_; 262 base::SimpleTestClock* clock_;
258 263
259 // Owned by |device_manager_|. 264 // Owned by |device_manager_|.
260 MockCryptAuthClientFactory* client_factory_; 265 MockCryptAuthClientFactory* client_factory_;
261 266
262 TestingPrefServiceSimple pref_service_; 267 TestingPrefServiceSimple pref_service_;
263 268
269 FakeCryptAuthGCMManager gcm_manager_;
270
264 TestCryptAuthDeviceManager device_manager_; 271 TestCryptAuthDeviceManager device_manager_;
265 272
266 cryptauth::GetMyDevicesResponse get_my_devices_response_; 273 cryptauth::GetMyDevicesResponse get_my_devices_response_;
267 274
268 cryptauth::GetMyDevicesRequest get_my_devices_request_; 275 cryptauth::GetMyDevicesRequest get_my_devices_request_;
269 276
270 CryptAuthClient::GetMyDevicesCallback success_callback_; 277 CryptAuthClient::GetMyDevicesCallback success_callback_;
271 278
272 CryptAuthClient::ErrorCallback error_callback_; 279 CryptAuthClient::ErrorCallback error_callback_;
273 280
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 clock->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds)); 323 clock->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds));
317 base::TimeDelta elapsed_time = clock->Now() - base::Time::FromDoubleT(0); 324 base::TimeDelta elapsed_time = clock->Now() - base::Time::FromDoubleT(0);
318 325
319 TestingPrefServiceSimple pref_service; 326 TestingPrefServiceSimple pref_service;
320 CryptAuthDeviceManager::RegisterPrefs(pref_service.registry()); 327 CryptAuthDeviceManager::RegisterPrefs(pref_service.registry());
321 328
322 TestCryptAuthDeviceManager device_manager( 329 TestCryptAuthDeviceManager device_manager(
323 clock.Pass(), 330 clock.Pass(),
324 make_scoped_ptr(new MockCryptAuthClientFactory( 331 make_scoped_ptr(new MockCryptAuthClientFactory(
325 MockCryptAuthClientFactory::MockType::MAKE_STRICT_MOCKS)), 332 MockCryptAuthClientFactory::MockType::MAKE_STRICT_MOCKS)),
326 &pref_service); 333 &gcm_manager_, &pref_service);
327 334
328 EXPECT_CALL( 335 EXPECT_CALL(
329 *(device_manager.GetSyncScheduler()), 336 *(device_manager.GetSyncScheduler()),
330 Start(elapsed_time, SyncScheduler::Strategy::AGGRESSIVE_RECOVERY)); 337 Start(elapsed_time, SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
331 device_manager.Start(); 338 device_manager.Start();
332 EXPECT_TRUE(device_manager.GetLastSyncTime().is_null()); 339 EXPECT_TRUE(device_manager.GetLastSyncTime().is_null());
333 EXPECT_EQ(0u, device_manager.unlock_keys().size()); 340 EXPECT_EQ(0u, device_manager.unlock_keys().size());
334 } 341 }
335 342
336 TEST_F(ProximityAuthCryptAuthDeviceManagerTest, InitWithExistingPrefs) { 343 TEST_F(ProximityAuthCryptAuthDeviceManagerTest, InitWithExistingPrefs) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 ASSERT_FALSE(success_callback_.is_null()); 525 ASSERT_FALSE(success_callback_.is_null());
519 EXPECT_CALL(*this, OnSyncFinishedProxy( 526 EXPECT_CALL(*this, OnSyncFinishedProxy(
520 CryptAuthDeviceManager::SyncResult::SUCCESS, 527 CryptAuthDeviceManager::SyncResult::SUCCESS,
521 CryptAuthDeviceManager::DeviceChangeResult::CHANGED)); 528 CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
522 success_callback_.Run(response); 529 success_callback_.Run(response);
523 530
524 ExpectUnlockKeysAndPrefAreEqual(expected_unlock_keys, 531 ExpectUnlockKeysAndPrefAreEqual(expected_unlock_keys,
525 device_manager_.unlock_keys(), pref_service_); 532 device_manager_.unlock_keys(), pref_service_);
526 } 533 }
527 534
535 TEST_F(ProximityAuthCryptAuthDeviceManagerTest, SyncOnGCMPushMessage) {
536 device_manager_.Start();
537
538 EXPECT_CALL(*sync_scheduler(), ForceSync());
539 gcm_manager_.PushResyncMessage();
540
541 FireSchedulerForSync(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
542
543 EXPECT_CALL(*this, OnSyncFinishedProxy(
544 CryptAuthDeviceManager::SyncResult::SUCCESS,
545 CryptAuthDeviceManager::DeviceChangeResult::CHANGED));
546 success_callback_.Run(get_my_devices_response_);
547
548 ExpectUnlockKeysAndPrefAreEqual(std::vector<cryptauth::ExternalDeviceInfo>(
549 1, get_my_devices_response_.devices(0)),
550 device_manager_.unlock_keys(), pref_service_);
551 }
552
528 } // namespace proximity_auth 553 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698