Chromium Code Reviews| Index: chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc |
| diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..83b99c759d2d95b6724c544869c87e6b2d058d4c |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| + |
| +#include "base/message_loop.h" |
| +#include "base/prefs/testing_pref_service.h" |
| +#include "chrome/browser/chromeos/cros/cros_library.h" |
| +#include "chrome/browser/chromeos/cros/mock_cert_library.h" |
| +#include "chrome/test/base/scoped_testing_local_state.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "net/url_request/url_request_test_util.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::_; |
| +using ::testing::AnyNumber; |
| +using ::testing::Return; |
| +using ::testing::StrEq; |
| +using ::testing::StrictMock; |
| + |
| +namespace chromeos { |
| + |
| +class DeviceOAuth2TokenServiceTest : public testing::Test { |
| + public: |
| + DeviceOAuth2TokenServiceTest() |
| + : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()), |
| + 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.
|
| + ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| + virtual ~DeviceOAuth2TokenServiceTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + chromeos::CrosLibrary::Initialize(true); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + chromeos::CrosLibrary::Shutdown(); |
| + } |
| + |
| + protected: |
| + ScopedTestingLocalState scoped_testing_local_state_; |
| + TestingPrefServiceSimple* local_state_; |
| + 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.
|
| + content::TestBrowserThread ui_thread_; |
| +}; |
| + |
| +TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) { |
| + StrictMock<MockCertLibrary> mock_cert_library; |
| + chromeos::CrosLibrary::Get()->GetTestApi()->SetCertLibrary( |
| + &mock_cert_library, false); |
| + |
| + EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq(""))) |
| + .Times(1) |
| + .WillOnce(Return("")); |
| + EXPECT_CALL(mock_cert_library, EncryptWithSystemSalt(StrEq("test-token"))) |
| + .Times(1) |
| + .WillOnce(Return("encrypted")); |
| + EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("encrypted"))) |
| + .Times(1) |
| + .WillOnce(Return("test-token")); |
| + |
| + DeviceOAuth2TokenService oauth2_service( |
| + new net::TestURLRequestContextGetter( |
| + content::BrowserThread::GetMessageLoopProxyForThread( |
| + content::BrowserThread::IO)), |
| + local_state_); |
| + |
| + ASSERT_EQ("", oauth2_service.GetRefreshToken()); |
| + oauth2_service.SetAndSaveRefreshToken("test-token"); |
| + ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); |
| + |
| + // This call won't invoke decrypt again, since the value is cached. |
| + ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); |
| +} |
| + |
| +} // namespace chromeos |