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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cloud_print/service/win/service_state_unittest.cc
diff --git a/cloud_print/service/win/service_state_unittest.cc b/cloud_print/service/win/service_state_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e3eecb3cf7226e8be4e64476b168b37c2ca2ffed
--- /dev/null
+++ b/cloud_print/service/win/service_state_unittest.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2012 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 "cloud_print/service/win/service_state.h"
+
+#include "base/string_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::Exactly;
+using ::testing::Return;
+
+TEST(ServiceStateTest, Empty) {
+ ServiceState state;
+ EXPECT_FALSE(state.IsValid());
+}
+
+TEST(ServiceStateTest, ToString) {
+ ServiceState state;
+ EXPECT_STREQ("{\"cloud_print\": {\"enabled\": true}}",
+ CollapseWhitespaceASCII(state.ToString(), true).c_str());
+ state.set_email("test@gmail.com");
+ state.set_password("123");
+ state.set_proxy_id("proxy");
+ state.set_robot_email("robot@gmail.com");
+ state.set_robot_token("abc");
+ state.set_auth_token("token1");
+ state.set_xmpp_auth_token("token2");
+ EXPECT_TRUE(state.IsValid());
+ EXPECT_STREQ("{\"cloud_print\": {\"auth_token\": \"token1\",\"email\": "
+ "\"test@gmail.com\",\"enabled\": true,\"proxy_id\": \"proxy\","
+ "\"robot_email\": \"robot@gmail.com\",\"robot_refresh_token\": "
+ "\"abc\",\"xmpp_auth_token\": \"token2\"}}",
+ CollapseWhitespaceASCII(state.ToString(), true).c_str());
+}
+
+TEST(ServiceStateTest, FromString) {
+ ServiceState state;
+ // Syntax error.
+ EXPECT_FALSE(state.FromString("<\"cloud_print\": {\"enabled\": true}}"));
+ // No data.
+ EXPECT_FALSE(state.FromString("{\"cloud_print\": {\"enabled\": true}}"));
+ EXPECT_FALSE(state.FromString(
+ "{\"cloud_print\": {\"email\": \"test@gmail.com\"}}"));
+ EXPECT_STREQ("test@gmail.com", state.email().c_str());
+
+ // Good state.
+ EXPECT_TRUE(state.FromString(
+ "{\"cloud_print\": {\"email\": \"test2@gmail.com\",\"enabled\": true,\""
+ "proxy_id\": \"proxy\",\"robot_email\": \"robot@gmail.com\",\""
+ "robot_refresh_token\": \"abc\"}}"));
+ EXPECT_STREQ("test2@gmail.com", state.email().c_str());
+ EXPECT_STREQ("proxy", state.proxy_id().c_str());
+ EXPECT_STREQ("robot@gmail.com", state.robot_email().c_str());
+ EXPECT_STREQ("abc", state.robot_token().c_str());
+}
+
+class OptionsDelegateMock : public ServiceState::OptionsDelegate {
+ public:
+ OptionsDelegateMock() {}
+
+ MOCK_METHOD3(GetOption,
+ std::string(const std::string& name,
+ const std::string& default,
+ bool secure));
+ private:
+ DISALLOW_COPY_AND_ASSIGN(OptionsDelegateMock);
+};
+
+class ServiceStateMock : public ServiceState {
+ public:
+ ServiceStateMock() {}
+
+ MOCK_METHOD3(LoginToGoogle,
+ std::string(const std::string& service,
+ const std::string& email,
+ const std::string& password));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ServiceStateMock);
+};
+
+TEST(ServiceStateTest, Configure) {
+ OptionsDelegateMock delegate;
+ ServiceStateMock state;
+ state.set_email("test1@gmail.com");
+ state.set_password("567");
+ state.set_proxy_id("id1");
+
+ EXPECT_CALL(delegate, GetOption("email", "test1@gmail.com", false))
+ .Times(Exactly(1))
+ .WillOnce(Return("test2@gmail.com"));
+ EXPECT_CALL(delegate, GetOption("password", "", true))
+ .Times(Exactly(1))
+ .WillOnce(Return("abc"));
+ EXPECT_CALL(delegate, GetOption("proxy_id", "id1", false))
+ .Times(Exactly(1))
+ .WillOnce(Return("id2"));
+
+ EXPECT_CALL(state, LoginToGoogle("cloudprint", "test2@gmail.com", "abc"))
+ .Times(Exactly(1))
+ .WillOnce(Return("auth1"));
+ EXPECT_CALL(state, LoginToGoogle("chromiumsync", "test2@gmail.com", "abc"))
+ .Times(Exactly(1))
+ .WillOnce(Return("auth2"));
+
+ EXPECT_TRUE(state.Configure(&delegate));
+
+ EXPECT_STREQ("id2", state.proxy_id().c_str());
+ EXPECT_STREQ("auth1", state.auth_token().c_str());
+ EXPECT_STREQ("auth2", state.xmpp_auth_token().c_str());
+}
« 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