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

Unified Diff: cloud_print/service/win/service_state_unittest.cc

Issue 10543021: Not all the files were added (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« no previous file with comments | « cloud_print/service/win/service_state.cc ('k') | cloud_print/service/win/service_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..00c651e01081fbda5a8be054e9fed24d4ff5d9cf
--- /dev/null
+++ b/cloud_print/service/win/service_state_unittest.cc
@@ -0,0 +1,89 @@
+// 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_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 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) {
+ ServiceStateMock state;
+ state.set_email("test1@gmail.com");
+ state.set_proxy_id("id1");
+
+ 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("test2@gmail.com", "abc", "id2"));
+
+ 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());
+}
« no previous file with comments | « cloud_print/service/win/service_state.cc ('k') | cloud_print/service/win/service_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698