OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 ASSERT_FALSE(fetcher_->IsTokenValid()); | 217 ASSERT_FALSE(fetcher_->IsTokenValid()); |
218 } | 218 } |
219 | 219 |
220 TEST_F(DeviceTokenFetcherTest, FetchWithNonManagedUsername) { | 220 TEST_F(DeviceTokenFetcherTest, FetchWithNonManagedUsername) { |
221 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(0); | 221 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(0); |
222 SimulateSuccessfulLoginAndRunPending("___@gmail.com"); | 222 SimulateSuccessfulLoginAndRunPending("___@gmail.com"); |
223 ASSERT_FALSE(fetcher_->IsTokenPending()); | 223 ASSERT_FALSE(fetcher_->IsTokenPending()); |
224 ASSERT_FALSE(fetcher_->IsTokenValid()); | 224 ASSERT_FALSE(fetcher_->IsTokenValid()); |
225 } | 225 } |
226 | 226 |
| 227 TEST_F(DeviceTokenFetcherTest, RestartImmediately) { |
| 228 // Create a token. |
| 229 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 230 MockDeviceManagementBackendSucceedRegister()); |
| 231 SimulateSuccessfulLoginAndRunPending(kTestManagedDomainUsername); |
| 232 ASSERT_FALSE(fetcher_->IsTokenPending()); |
| 233 std::string device_token = fetcher_->GetDeviceToken(); |
| 234 |
| 235 // Restart a new fetcher immediately without calling StartFetching(). The |
| 236 // existing token should not be loaded, but rather a new token generated. |
| 237 FilePath token_path; |
| 238 GetDeviceTokenPath(fetcher_, &token_path); |
| 239 scoped_refptr<TestingDeviceTokenFetcher> fetcher2( |
| 240 new TestingDeviceTokenFetcher( |
| 241 backend_.get(), profile_.get(), token_path)); |
| 242 fetcher2->Restart(); |
| 243 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 244 MockDeviceManagementBackendSucceedRegister()); |
| 245 fetcher2->SimulateLogin(kTestManagedDomainUsername); |
| 246 loop_.RunAllPending(); |
| 247 ASSERT_FALSE(fetcher2->IsTokenPending()); |
| 248 ASSERT_NE(device_token, fetcher2->GetDeviceToken()); |
| 249 } |
| 250 |
227 } // namespace policy | 251 } // namespace policy |
OLD | NEW |