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

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

Issue 12647008: Refactor OAuth2TokenService to have profile- and device-based implementations. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase again 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
OLDNEW
(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 : ui_thread_(content::BrowserThread::UI, &message_loop_),
31 scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
32 virtual ~DeviceOAuth2TokenServiceTest() {}
33
34 virtual void SetUp() OVERRIDE {
35 chromeos::CrosLibrary::Initialize(true);
36 }
37
38 virtual void TearDown() OVERRIDE {
39 chromeos::CrosLibrary::Shutdown();
40 }
41
42 protected:
43 MessageLoop message_loop_;
44 content::TestBrowserThread ui_thread_;
45 ScopedTestingLocalState scoped_testing_local_state_;
46 };
47
48 TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) {
49 StrictMock<MockCertLibrary> mock_cert_library;
50 chromeos::CrosLibrary::Get()->GetTestApi()->SetCertLibrary(
51 &mock_cert_library, false);
52
53 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("")))
54 .Times(1)
55 .WillOnce(Return(""));
56 EXPECT_CALL(mock_cert_library, EncryptWithSystemSalt(StrEq("test-token")))
57 .Times(1)
58 .WillOnce(Return("encrypted"));
59 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("encrypted")))
60 .Times(1)
61 .WillOnce(Return("test-token"));
62
63 DeviceOAuth2TokenService oauth2_service(
64 new net::TestURLRequestContextGetter(
65 content::BrowserThread::GetMessageLoopProxyForThread(
66 content::BrowserThread::IO)),
67 scoped_testing_local_state_.Get());
68
69 ASSERT_EQ("", oauth2_service.GetRefreshToken());
70 oauth2_service.SetAndSaveRefreshToken("test-token");
71 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
72
73 // This call won't invoke decrypt again, since the value is cached.
74 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
75 }
76
77 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc ('k') | chrome/browser/history/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698