Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1131)

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc

Issue 14179007: Move cryptohome_library to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/testing_pref_service.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" 9 #include "chrome/test/base/scoped_testing_local_state.h"
12 #include "chrome/test/base/testing_browser_process.h" 10 #include "chrome/test/base/testing_browser_process.h"
11 #include "chromeos/cryptohome/mock_cryptohome_library.h"
13 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
14 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
15 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
16 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 using ::testing::_; 18 using ::testing::_;
20 using ::testing::AnyNumber; 19 using ::testing::AnyNumber;
21 using ::testing::Return; 20 using ::testing::Return;
22 using ::testing::StrEq; 21 using ::testing::StrEq;
23 using ::testing::StrictMock; 22 using ::testing::StrictMock;
24 23
25 namespace chromeos { 24 namespace chromeos {
26 25
27 class DeviceOAuth2TokenServiceTest : public testing::Test { 26 class DeviceOAuth2TokenServiceTest : public testing::Test {
28 public: 27 public:
29 DeviceOAuth2TokenServiceTest() 28 DeviceOAuth2TokenServiceTest()
30 : ui_thread_(content::BrowserThread::UI, &message_loop_), 29 : ui_thread_(content::BrowserThread::UI, &message_loop_),
31 scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()) {} 30 scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
32 virtual ~DeviceOAuth2TokenServiceTest() {} 31 virtual ~DeviceOAuth2TokenServiceTest() {}
33 32
34 virtual void SetUp() OVERRIDE { 33 virtual void SetUp() OVERRIDE {
35 chromeos::CrosLibrary::Initialize(true);
36 } 34 }
37 35
38 virtual void TearDown() OVERRIDE { 36 virtual void TearDown() OVERRIDE {
39 chromeos::CrosLibrary::Shutdown();
40 } 37 }
41 38
42 protected: 39 protected:
43 MessageLoop message_loop_; 40 MessageLoop message_loop_;
44 content::TestBrowserThread ui_thread_; 41 content::TestBrowserThread ui_thread_;
45 ScopedTestingLocalState scoped_testing_local_state_; 42 ScopedTestingLocalState scoped_testing_local_state_;
46 }; 43 };
47 44
48 TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) { 45 TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) {
49 StrictMock<MockCertLibrary> mock_cert_library; 46 StrictMock<MockCryptohomeLibrary> mock_cryptohome_library;
50 chromeos::CrosLibrary::Get()->GetTestApi()->SetCertLibrary( 47 CryptohomeLibrary::SetForTest(&mock_cryptohome_library);
51 &mock_cert_library, false);
52 48
53 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq(""))) 49 EXPECT_CALL(mock_cryptohome_library, DecryptWithSystemSalt(StrEq("")))
54 .Times(1) 50 .Times(1)
55 .WillOnce(Return("")); 51 .WillOnce(Return(""));
56 EXPECT_CALL(mock_cert_library, EncryptWithSystemSalt(StrEq("test-token"))) 52 EXPECT_CALL(mock_cryptohome_library,
53 EncryptWithSystemSalt(StrEq("test-token")))
57 .Times(1) 54 .Times(1)
58 .WillOnce(Return("encrypted")); 55 .WillOnce(Return("encrypted"));
59 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("encrypted"))) 56 EXPECT_CALL(mock_cryptohome_library,
57 DecryptWithSystemSalt(StrEq("encrypted")))
60 .Times(1) 58 .Times(1)
61 .WillOnce(Return("test-token")); 59 .WillOnce(Return("test-token"));
62 60
63 DeviceOAuth2TokenService oauth2_service( 61 DeviceOAuth2TokenService oauth2_service(
64 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()), 62 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()),
65 scoped_testing_local_state_.Get()); 63 scoped_testing_local_state_.Get());
66 64
67 ASSERT_EQ("", oauth2_service.GetRefreshToken()); 65 ASSERT_EQ("", oauth2_service.GetRefreshToken());
68 oauth2_service.SetAndSaveRefreshToken("test-token"); 66 oauth2_service.SetAndSaveRefreshToken("test-token");
69 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); 67 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
70 68
71 // This call won't invoke decrypt again, since the value is cached. 69 // This call won't invoke decrypt again, since the value is cached.
72 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken()); 70 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
73 } 71 }
74 72
75 } // namespace chromeos 73 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698