| 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..61c8c578d45296115e0194585d3668068f0e9dcd
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc
|
| @@ -0,0 +1,77 @@
|
| +// 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()
|
| + : ui_thread_(content::BrowserThread::UI, &message_loop_),
|
| + scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
|
| + virtual ~DeviceOAuth2TokenServiceTest() {}
|
| +
|
| + virtual void SetUp() OVERRIDE {
|
| + chromeos::CrosLibrary::Initialize(true);
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + chromeos::CrosLibrary::Shutdown();
|
| + }
|
| +
|
| + protected:
|
| + MessageLoop message_loop_;
|
| + content::TestBrowserThread ui_thread_;
|
| + ScopedTestingLocalState scoped_testing_local_state_;
|
| +};
|
| +
|
| +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)),
|
| + scoped_testing_local_state_.Get());
|
| +
|
| + 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
|
|
|