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

Unified Diff: services/authentication/auth_data_unittest.cc

Issue 1466733002: Google OAuth Device Flow support for FNL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: updated demo namespaces Created 5 years 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: services/authentication/auth_data_unittest.cc
diff --git a/services/authentication/auth_data_unittest.cc b/services/authentication/auth_data_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..625028b5d948a8aee7c69e578246a8485c2672d7
--- /dev/null
+++ b/services/authentication/auth_data_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2015 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 "auth_data.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace authentication {
+namespace {
+
+AuthData* GetInputData() {
+ AuthData* auth_data = new AuthData();
+
+ auth_data->username = "test@google.com";
+ auth_data->auth_provider = "Google";
+ auth_data->persistent_credential_type = "RT";
+ auth_data->persistent_credential = "test_refresh_token";
+ auth_data->scopes = "profile email";
+
+ return auth_data;
+}
+
+std::string GetInputString(AuthData* auth_data) {
+ std::string expected_str;
+ expected_str += auth_data->username + ",";
+ expected_str += auth_data->auth_provider + ",";
+ expected_str += auth_data->persistent_credential_type + ",";
+ expected_str += auth_data->persistent_credential + ",";
+ expected_str += auth_data->scopes;
+
+ return expected_str;
+}
+
+TEST(AuthDataTest, ConvertToString) {
+ AuthData* auth_data = GetInputData();
+
+ std::string auth_data_str(authentication::GetAuthDataAsString(*auth_data));
+ EXPECT_EQ(auth_data_str.size(), GetInputString(auth_data).size());
+ EXPECT_TRUE(auth_data_str.find(auth_data->username) != std::string::npos);
+ EXPECT_TRUE(auth_data_str.find(auth_data->scopes) != std::string::npos);
+}
+
+TEST(AuthDataTest, ParseFromString) {
+ AuthData* auth_data = GetInputData();
+ AuthData* out =
+ authentication::GetAuthDataFromString(GetInputString(auth_data));
+
+ EXPECT_EQ(auth_data->username, out->username);
+ EXPECT_EQ(auth_data->auth_provider, out->auth_provider);
+ EXPECT_EQ(auth_data->persistent_credential_type,
+ out->persistent_credential_type);
+ EXPECT_EQ(auth_data->persistent_credential, out->persistent_credential);
+ EXPECT_EQ(auth_data->scopes, out->scopes);
+}
+
+TEST(AuthDataTest, InvalidInput) {
+ std::string empty_auth_data_str;
+ AuthData* out = authentication::GetAuthDataFromString(empty_auth_data_str);
+ EXPECT_TRUE(out == nullptr);
+
+ std::string auth_data_str_missing_components("a:b:c");
+ out = authentication::GetAuthDataFromString(auth_data_str_missing_components);
+ EXPECT_TRUE(out == nullptr);
+
+ std::string invalid_auth_data_str("a:b:c:d:e:f");
+ out = authentication::GetAuthDataFromString(invalid_auth_data_str);
+ EXPECT_TRUE(out == nullptr);
+}
+
+} // namespace
+} // namespace authentication

Powered by Google App Engine
This is Rietveld 408576698