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

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: Reverted g_browser_process integration and re-instated factory, with added initialize/shutdown. 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 using ::testing::InSequence;
25
26 namespace chromeos {
27
28 class DeviceOAuth2TokenServiceTest : public testing::Test {
29 public:
30 DeviceOAuth2TokenServiceTest()
31 : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()),
32 local_state_(scoped_testing_local_state_.Get()),
33 ui_thread_(content::BrowserThread::UI, &message_loop_) {}
34 virtual ~DeviceOAuth2TokenServiceTest() {}
35
36 virtual void SetUp() OVERRIDE {
37 chromeos::CrosLibrary::Initialize(true);
38 }
39
40 virtual void TearDown() OVERRIDE {
41 chromeos::CrosLibrary::Shutdown();
42 }
43
44 protected:
45 ScopedTestingLocalState scoped_testing_local_state_;
46 TestingPrefServiceSimple* local_state_;
47 MessageLoop message_loop_;
48 content::TestBrowserThread ui_thread_;
49
Mattias Nissler (ping if slow) 2013/04/03 11:33:16 remove stray blank line.
David Roche 2013/04/03 16:34:09 Done.
50 };
51
52 TEST_F(DeviceOAuth2TokenServiceTest, SaveEncryptedToken) {
53 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.
54 StrictMock<MockCertLibrary> mock_cert_library;
55 chromeos::CrosLibrary::Get()->GetTestApi()->SetCertLibrary(
56 &mock_cert_library, false);
57
58 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("")))
59 .Times(1)
60 .WillOnce(Return(""));
61 EXPECT_CALL(mock_cert_library, EncryptWithSystemSalt(StrEq("test-token")))
62 .Times(1)
63 .WillOnce(Return("encrypted"));
64 EXPECT_CALL(mock_cert_library, DecryptWithSystemSalt(StrEq("encrypted")))
65 .Times(1)
66 .WillOnce(Return("test-token"));
67
68 DeviceOAuth2TokenService oauth2_service(
Mattias Nissler (ping if slow) 2013/04/03 11:33:16 indentation
David Roche 2013/04/03 16:34:09 Done.
69 new net::TestURLRequestContextGetter(
70 content::BrowserThread::GetMessageLoopProxyForThread(
71 content::BrowserThread::IO)),
72 local_state_);
73
74 ASSERT_EQ("", oauth2_service.GetRefreshToken());
75 oauth2_service.SetAndSaveRefreshToken("test-token");
76 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
77
78 // This call won't invoke decrypt again, since the value is cached.
79 ASSERT_EQ("test-token", oauth2_service.GetRefreshToken());
80 }
81
82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698