Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/prefs/testing_pref_service.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "chrome/browser/chromeos/cros/mock_cert_library.h" | |
| 11 #include "chrome/test/base/scoped_testing_local_state.h" | |
| 12 #include "chrome/test/base/testing_browser_process.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/test/test_browser_thread.h" | |
| 15 #include "net/url_request/url_request_test_util.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 using ::testing::_; | |
| 20 using ::testing::AnyNumber; | |
| 21 using ::testing::Return; | |
| 22 using ::testing::StrEq; | |
| 23 using ::testing::StrictMock; | |
| 24 | |
| 25 namespace chromeos { | |
| 26 | |
| 27 class DeviceOAuth2TokenServiceTest : public testing::Test { | |
| 28 public: | |
| 29 DeviceOAuth2TokenServiceTest() | |
| 30 : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()), | |
| 31 local_state_(scoped_testing_local_state_.Get()), | |
|
Mattias Nissler (ping if slow)
2013/04/04 13:11:11
any reason to keep a separate pointer member as a
David Roche
2013/04/04 14:52:49
Done.
| |
| 32 ui_thread_(content::BrowserThread::UI, &message_loop_) {} | |
| 33 virtual ~DeviceOAuth2TokenServiceTest() {} | |
| 34 | |
| 35 virtual void SetUp() OVERRIDE { | |
| 36 chromeos::CrosLibrary::Initialize(true); | |
| 37 } | |
| 38 | |
| 39 virtual void TearDown() OVERRIDE { | |
| 40 chromeos::CrosLibrary::Shutdown(); | |
| 41 } | |
| 42 | |
| 43 protected: | |
| 44 ScopedTestingLocalState scoped_testing_local_state_; | |
| 45 TestingPrefServiceSimple* local_state_; | |
| 46 MessageLoop message_loop_; | |
|
Mattias Nissler (ping if slow)
2013/04/04 13:11:11
message_loop_ and ui_thread_ should be first, so t
David Roche
2013/04/04 14:52:49
Done.
| |
| 47 content::TestBrowserThread ui_thread_; | |
| 48 }; | |
| 49 | |
| 50 TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) { | |
| 51 StrictMock<MockCertLibrary> mock_cert_library; | |
| 52 chromeos::CrosLibrary::Get()->GetTestApi()->SetCertLibrary( | |
| 53 &mock_cert_library, false); | |
| 54 | |
| 55 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq(""))) | |
| 56 .Times(1) | |
| 57 .WillOnce(Return("")); | |
| 58 EXPECT_CALL(mock_cert_library, EncryptWithSystemSalt(StrEq("test-token"))) | |
| 59 .Times(1) | |
| 60 .WillOnce(Return("encrypted")); | |
| 61 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("encrypted"))) | |
| 62 .Times(1) | |
| 63 .WillOnce(Return("test-token")); | |
| 64 | |
| 65 DeviceOAuth2TokenService oauth2_service( | |
| 66 new net::TestURLRequestContextGetter( | |
| 67 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 68 content::BrowserThread::IO)), | |
| 69 local_state_); | |
| 70 | |
| 71 ASSERT_EQ("", oauth2_service.GetRefreshToken()); | |
| 72 oauth2_service.SetAndSaveRefreshToken("test-token"); | |
| 73 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); | |
| 74 | |
| 75 // This call won't invoke decrypt again, since the value is cached. | |
| 76 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); | |
| 77 } | |
| 78 | |
| 79 } // namespace chromeos | |
| OLD | NEW |