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

Side by Side Diff: cloud_print/service/win/service_state_unittest.cc

Issue 10414020: Service state file processing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
(Empty)
1 // Copyright (c) 2012 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 "cloud_print/service/win/service_state.h"
6
7 #include "base/string_util.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using ::testing::_;
12 using ::testing::Exactly;
13 using ::testing::Return;
14
15 TEST(ServiceStateTest, Empty) {
16 ServiceState state;
17 EXPECT_FALSE(state.IsValid());
18 }
19
20 TEST(ServiceStateTest, ToString) {
21 ServiceState state;
22 EXPECT_STREQ("{\"cloud_print\": {\"enabled\": true}}",
23 CollapseWhitespaceASCII(state.ToString(), true).c_str());
24 state.set_email("test@gmail.com");
25 state.set_password("123");
26 state.set_proxy_id("proxy");
27 state.set_robot_email("robot@gmail.com");
28 state.set_robot_token("abc");
29 state.set_auth_token("token1");
30 state.set_xmpp_auth_token("token2");
31 EXPECT_TRUE(state.IsValid());
32 EXPECT_STREQ("{\"cloud_print\": {\"auth_token\": \"token1\",\"email\": "
33 "\"test@gmail.com\",\"enabled\": true,\"proxy_id\": \"proxy\","
34 "\"robot_email\": \"robot@gmail.com\",\"robot_refresh_token\": "
35 "\"abc\",\"xmpp_auth_token\": \"token2\"}}",
36 CollapseWhitespaceASCII(state.ToString(), true).c_str());
37 }
38
39 TEST(ServiceStateTest, FromString) {
40 ServiceState state;
41 // Syntax error.
42 EXPECT_FALSE(state.FromString("<\"cloud_print\": {\"enabled\": true}}"));
43 // No data.
44 EXPECT_FALSE(state.FromString("{\"cloud_print\": {\"enabled\": true}}"));
45 EXPECT_FALSE(state.FromString(
46 "{\"cloud_print\": {\"email\": \"test@gmail.com\"}}"));
47 EXPECT_STREQ("test@gmail.com", state.email().c_str());
48
49 // Good state.
50 EXPECT_TRUE(state.FromString(
51 "{\"cloud_print\": {\"email\": \"test2@gmail.com\",\"enabled\": true,\""
52 "proxy_id\": \"proxy\",\"robot_email\": \"robot@gmail.com\",\""
53 "robot_refresh_token\": \"abc\"}}"));
54 EXPECT_STREQ("test2@gmail.com", state.email().c_str());
55 EXPECT_STREQ("proxy", state.proxy_id().c_str());
56 EXPECT_STREQ("robot@gmail.com", state.robot_email().c_str());
57 EXPECT_STREQ("abc", state.robot_token().c_str());
58 }
59
60 class OptionsDelegateMock : public ServiceState::OptionsDelegate {
61 public:
62 OptionsDelegateMock() {}
63
64 MOCK_METHOD3(GetOption,
65 std::string(const std::string& name,
66 const std::string& default,
67 bool secure));
68 private:
69 DISALLOW_COPY_AND_ASSIGN(OptionsDelegateMock);
70 };
71
72 class ServiceStateMock : public ServiceState {
73 public:
74 ServiceStateMock() {}
75
76 MOCK_METHOD3(LoginToGoogle,
77 std::string(const std::string& service,
78 const std::string& email,
79 const std::string& password));
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(ServiceStateMock);
83 };
84
85 TEST(ServiceStateTest, Configure) {
86 OptionsDelegateMock delegate;
87 ServiceStateMock state;
88 state.set_email("test1@gmail.com");
89 state.set_password("567");
90 state.set_proxy_id("id1");
91
92 EXPECT_CALL(delegate, GetOption("email", "test1@gmail.com", false))
93 .Times(Exactly(1))
94 .WillOnce(Return("test2@gmail.com"));
95 EXPECT_CALL(delegate, GetOption("password", "", true))
96 .Times(Exactly(1))
97 .WillOnce(Return("abc"));
98 EXPECT_CALL(delegate, GetOption("proxy_id", "id1", false))
99 .Times(Exactly(1))
100 .WillOnce(Return("id2"));
101
102 EXPECT_CALL(state, LoginToGoogle("cloudprint", "test2@gmail.com", "abc"))
103 .Times(Exactly(1))
104 .WillOnce(Return("auth1"));
105 EXPECT_CALL(state, LoginToGoogle("chromiumsync", "test2@gmail.com", "abc"))
106 .Times(Exactly(1))
107 .WillOnce(Return("auth2"));
108
109 EXPECT_TRUE(state.Configure(&delegate));
110
111 EXPECT_STREQ("id2", state.proxy_id().c_str());
112 EXPECT_STREQ("auth1", state.auth_token().c_str());
113 EXPECT_STREQ("auth2", state.xmpp_auth_token().c_str());
114 }
OLDNEW
« cloud_print/service/win/service_state.cc ('K') | « cloud_print/service/win/service_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698