1// Copyright (c) 2011 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.
4
5#include "chrome/browser/content_settings/content_settings_utils.h"
6
7#include <string>
8
9#include "testing/gtest/include/gtest/gtest.h"
10
11TEST(ContentSettingsUtilsTest, ParsePatternString) {
12  content_settings::PatternPair pattern_pair;
13
14  pattern_pair = content_settings::ParsePatternString(std::string());
15  EXPECT_FALSE(pattern_pair.first.IsValid());
16  EXPECT_FALSE(pattern_pair.second.IsValid());
17
18  pattern_pair = content_settings::ParsePatternString(",");
19  EXPECT_FALSE(pattern_pair.first.IsValid());
20  EXPECT_FALSE(pattern_pair.second.IsValid());
21
22  pattern_pair = content_settings::ParsePatternString("http://www.foo.com");
23  EXPECT_TRUE(pattern_pair.first.IsValid());
24  EXPECT_EQ(pattern_pair.second, ContentSettingsPattern::Wildcard());
25
26  // This inconsistency is to recover from some broken code.
27  pattern_pair = content_settings::ParsePatternString("http://www.foo.com,");
28  EXPECT_TRUE(pattern_pair.first.IsValid());
29  EXPECT_FALSE(pattern_pair.second.IsValid());
30
31  pattern_pair = content_settings::ParsePatternString(
32      "http://www.foo.com,http://www.bar.com");
33  EXPECT_TRUE(pattern_pair.first.IsValid());
34  EXPECT_TRUE(pattern_pair.second.IsValid());
35
36  pattern_pair = content_settings::ParsePatternString(
37      "http://www.foo.com,http://www.bar.com,");
38  EXPECT_FALSE(pattern_pair.first.IsValid());
39  EXPECT_FALSE(pattern_pair.second.IsValid());
40
41  pattern_pair = content_settings::ParsePatternString(
42      "http://www.foo.com,http://www.bar.com,http://www.error.com");
43  EXPECT_FALSE(pattern_pair.first.IsValid());
44  EXPECT_FALSE(pattern_pair.second.IsValid());
45}
46