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.
5 #include "components/auto_login_parser/auto_login_parser.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace auto_login_parser
{
13 class AutoLoginParserTest
: public testing::Test
{
15 static bool IsHeaderDataEmpty(const HeaderData
& header
) {
16 return header
.realm
.empty() && header
.account
.empty() &&
21 TEST_F(AutoLoginParserTest
, ParseHeader
) {
24 "account=fred.example%40gmail.com&"
25 "args=kfdshfwoeriudslkfsdjfhdskjfhsdkr";
27 HeaderData header_data
;
28 EXPECT_TRUE(ParseHeader(header
, ONLY_GOOGLE_COM
, &header_data
));
30 ASSERT_EQ("com.google", header_data
.realm
);
31 ASSERT_EQ("fred.example@gmail.com", header_data
.account
);
32 ASSERT_EQ("kfdshfwoeriudslkfsdjfhdskjfhsdkr", header_data
.args
);
35 TEST_F(AutoLoginParserTest
, ParseHeaderOnlySupportsComGoogle
) {
37 "realm=com.microsoft&"
38 "account=fred.example%40gmail.com&"
39 "args=kfdshfwoeriudslkfsdjfhdskjfhsdkr";
41 HeaderData header_data
;
42 EXPECT_FALSE(ParseHeader(header
, ONLY_GOOGLE_COM
, &header_data
));
43 // |header| should not be touched when parsing fails.
44 EXPECT_TRUE(IsHeaderDataEmpty(header_data
));
47 TEST_F(AutoLoginParserTest
, ParseHeaderWithMissingRealm
) {
49 "account=fred.example%40gmail.com&"
50 "args=kfdshfwoeriudslkfsdjfhdskjfhsdkr";
52 HeaderData header_data
;
53 EXPECT_FALSE(ParseHeader(header
, ONLY_GOOGLE_COM
, &header_data
));
54 EXPECT_TRUE(IsHeaderDataEmpty(header_data
));
57 TEST_F(AutoLoginParserTest
, ParseHeaderWithMissingArgs
) {
60 "account=fred.example%40gmail.com&";
62 HeaderData header_data
;
63 EXPECT_FALSE(ParseHeader(header
, ONLY_GOOGLE_COM
, &header_data
));
64 EXPECT_TRUE(IsHeaderDataEmpty(header_data
));
67 TEST_F(AutoLoginParserTest
, ParseHeaderWithoutOptionalAccount
) {
70 "args=kfdshfwoeriudslkfsdjfhdskjfhsdkr";
72 HeaderData header_data
;
73 EXPECT_TRUE(ParseHeader(header
, ONLY_GOOGLE_COM
, &header_data
));
74 ASSERT_EQ("com.google", header_data
.realm
);
75 ASSERT_EQ("kfdshfwoeriudslkfsdjfhdskjfhsdkr", header_data
.args
);
78 TEST_F(AutoLoginParserTest
, ParseHeaderAllowsAnyRealmWithOption
) {
80 "realm=com.microsoft&"
81 "account=fred.example%40gmail.com&"
82 "args=kfdshfwoeriudslkfsdjfhdskjfhsdkr";
84 HeaderData header_data
;
85 EXPECT_TRUE(ParseHeader(header
, ALLOW_ANY_REALM
, &header_data
));
87 ASSERT_EQ("com.microsoft", header_data
.realm
);
88 ASSERT_EQ("fred.example@gmail.com", header_data
.account
);
89 ASSERT_EQ("kfdshfwoeriudslkfsdjfhdskjfhsdkr", header_data
.args
);
92 } // namespace auto_login_parser