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..f1815a41807dd82245d7e619bf27d0b0f92db8bf |
--- /dev/null |
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc |
@@ -0,0 +1,82 @@ |
+// 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; |
+using ::testing::InSequence; |
+ |
+namespace chromeos { |
+ |
+class DeviceOAuth2TokenServiceTest : public testing::Test { |
+ public: |
+ DeviceOAuth2TokenServiceTest() |
+ : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()), |
+ local_state_(scoped_testing_local_state_.Get()), |
+ 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_; |
+ content::TestBrowserThread ui_thread_; |
+ |
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
remove stray blank line.
David Roche
2013/04/03 16:34:09
Done.
|
+}; |
+ |
+TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) { |
+ InSequence s; // Enforces that expected calls are in order. |
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
Is this really necessary? I think this makes the t
David Roche
2013/04/03 16:34:09
Done.
|
+ 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( |
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
indentation
David Roche
2013/04/03 16:34:09
Done.
|
+ 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 |