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

Side by Side Diff: ios/web/web_state/js/credential_util_unittest.mm

Issue 1723583004: CREDENTIAL: Convert federations from URLs to origins throughout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iOS2 Created 4 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/web/public/web_state/js/credential_util.h" 5 #include "ios/web/public/web_state/js/credential_util.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "ios/web/public/web_state/credential.h" 10 #include "ios/web/public/web_state/credential.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gtest_mac.h" 13 #include "testing/gtest_mac.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 #include "url/origin.h"
16 17
17 namespace web { 18 namespace web {
18 namespace { 19 namespace {
19 20
20 // "type" value for a DictionaryValue representation of PasswordCredential. 21 // "type" value for a DictionaryValue representation of PasswordCredential.
21 const char* kTestCredentialTypePassword = "PasswordCredential"; 22 const char* kTestCredentialTypePassword = "PasswordCredential";
22 23
23 // "type" value for a DictionaryValue representation of FederatedCredential. 24 // "type" value for a DictionaryValue representation of FederatedCredential.
24 const char* kTestCredentialTypeFederated = "FederatedCredential"; 25 const char* kTestCredentialTypeFederated = "FederatedCredential";
25 26
(...skipping 23 matching lines...) Expand all
49 return credential; 50 return credential;
50 } 51 }
51 52
52 // Returns a credential with Federated type. 53 // Returns a credential with Federated type.
53 Credential GetTestFederatedCredential() { 54 Credential GetTestFederatedCredential() {
54 Credential credential; 55 Credential credential;
55 credential.type = CredentialType::CREDENTIAL_TYPE_FEDERATED; 56 credential.type = CredentialType::CREDENTIAL_TYPE_FEDERATED;
56 credential.id = base::ASCIIToUTF16(kTestCredentialID); 57 credential.id = base::ASCIIToUTF16(kTestCredentialID);
57 credential.name = base::ASCIIToUTF16(kTestCredentialName); 58 credential.name = base::ASCIIToUTF16(kTestCredentialName);
58 credential.avatar_url = GURL(kTestCredentialAvatarURL); 59 credential.avatar_url = GURL(kTestCredentialAvatarURL);
59 credential.federation_url = GURL(kTestCredentialFederationURL); 60 credential.federation_origin =
61 url::Origin(GURL(kTestCredentialFederationURL));
60 return credential; 62 return credential;
61 } 63 }
62 64
63 // Returns a value representing the credential returned by 65 // Returns a value representing the credential returned by
64 // |GetTestPasswordCredential()|. 66 // |GetTestPasswordCredential()|.
65 scoped_ptr<base::DictionaryValue> GetTestPasswordCredentialDictionaryValue() { 67 scoped_ptr<base::DictionaryValue> GetTestPasswordCredentialDictionaryValue() {
66 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); 68 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
67 value->SetString("type", kTestCredentialTypePassword); 69 value->SetString("type", kTestCredentialTypePassword);
68 value->SetString("id", kTestCredentialID); 70 value->SetString("id", kTestCredentialID);
69 value->SetString("name", kTestCredentialName); 71 value->SetString("name", kTestCredentialName);
70 value->SetString("avatarURL", kTestCredentialAvatarURL); 72 value->SetString("avatarURL", kTestCredentialAvatarURL);
71 value->SetString("password", kTestCredentialPassword); 73 value->SetString("password", kTestCredentialPassword);
72 return value; 74 return value;
73 } 75 }
74 76
75 // Returns a value representing the credential returned by 77 // Returns a value representing the credential returned by
76 // |GetTestFederatedCredentialDictionaryValue()|. 78 // |GetTestFederatedCredentialDictionaryValue()|.
77 scoped_ptr<base::DictionaryValue> GetTestFederatedCredentialDictionaryValue() { 79 scoped_ptr<base::DictionaryValue> GetTestFederatedCredentialDictionaryValue() {
78 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); 80 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
79 value->SetString("type", kTestCredentialTypeFederated); 81 value->SetString("type", kTestCredentialTypeFederated);
80 value->SetString("id", kTestCredentialID); 82 value->SetString("id", kTestCredentialID);
81 value->SetString("name", kTestCredentialName); 83 value->SetString("name", kTestCredentialName);
82 value->SetString("avatarURL", kTestCredentialAvatarURL); 84 value->SetString("avatarURL", kTestCredentialAvatarURL);
83 value->SetString("federation", kTestCredentialFederationURL); 85 value->SetString("federation",
86 url::Origin(GURL(kTestCredentialFederationURL)).Serialize());
84 return value; 87 return value;
85 } 88 }
86 89
87 // Tests that parsing an empty value fails. 90 // Tests that parsing an empty value fails.
88 TEST(CredentialUtilTest, ParsingEmptyValueFails) { 91 TEST(CredentialUtilTest, ParsingEmptyValueFails) {
89 base::DictionaryValue value; 92 base::DictionaryValue value;
90 Credential credential; 93 Credential credential;
91 EXPECT_FALSE(DictionaryValueToCredential(value, &credential)); 94 EXPECT_FALSE(DictionaryValueToCredential(value, &credential));
92 } 95 }
93 96
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TEST(CredentialUtilTest, SerializeEmptyCredentialIntoNonEmptyDictionary) { 219 TEST(CredentialUtilTest, SerializeEmptyCredentialIntoNonEmptyDictionary) {
217 base::DictionaryValue value; 220 base::DictionaryValue value;
218 value.SetString("foo", "bar"); 221 value.SetString("foo", "bar");
219 Credential credential; 222 Credential credential;
220 CredentialToDictionaryValue(credential, &value); 223 CredentialToDictionaryValue(credential, &value);
221 EXPECT_TRUE(make_scoped_ptr(new base::DictionaryValue)->Equals(&value)); 224 EXPECT_TRUE(make_scoped_ptr(new base::DictionaryValue)->Equals(&value));
222 } 225 }
223 226
224 } // namespace 227 } // namespace
225 } // namespace web 228 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698