Only send _NET_ACTIVE_WINDOW hint if the chromium window is not already active.
[chromium-blink-merge.git] / components / auto_login_parser / auto_login_parser_unittest.cc
blob442784c734f0153fb3b85499d89d885fe4b6aad8
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"
7 #include <string>
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace auto_login_parser {
13 class AutoLoginParserTest : public testing::Test {
14 protected:
15 static bool IsHeaderDataEmpty(const HeaderData& header) {
16 return header.realm.empty() && header.account.empty() &&
17 header.args.empty();
21 TEST_F(AutoLoginParserTest, ParseHeader) {
22 std::string header =
23 "realm=com.google&"
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) {
36 std::string header =
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) {
48 std::string header =
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) {
58 std::string header =
59 "realm=com.google&"
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) {
68 std::string header =
69 "realm=com.google&"
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) {
79 std::string header =
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