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.
7 #include "chrome/common/content_settings_pattern.h"
8 #include "chrome/browser/content_settings/content_settings_rule.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace content_settings
{
15 class ListIterator
: public RuleIterator
{
17 explicit ListIterator(const std::list
<Rule
>& rules
)
20 virtual ~ListIterator() {}
22 virtual bool HasNext() const OVERRIDE
{
23 return !rules_
.empty();
26 virtual Rule
Next() OVERRIDE
{
27 EXPECT_FALSE(rules_
.empty());
28 // |front()| returns a reference but we're going to discard the object
29 // referred to; force copying here.
30 Rule rule
= rules_
.front();
36 std::list
<Rule
> rules_
;
41 TEST(RuleTest
, ConcatenationIterator
) {
42 std::list
<Rule
> rules1
;
43 rules1
.push_back(Rule(ContentSettingsPattern::FromString("a"),
44 ContentSettingsPattern::Wildcard(),
45 base::Value::CreateIntegerValue(0)));
46 rules1
.push_back(Rule(ContentSettingsPattern::FromString("b"),
47 ContentSettingsPattern::Wildcard(),
48 base::Value::CreateIntegerValue(0)));
49 std::list
<Rule
> rules2
;
50 rules2
.push_back(Rule(ContentSettingsPattern::FromString("c"),
51 ContentSettingsPattern::Wildcard(),
52 base::Value::CreateIntegerValue(0)));
53 rules2
.push_back(Rule(ContentSettingsPattern::FromString("d"),
54 ContentSettingsPattern::Wildcard(),
55 base::Value::CreateIntegerValue(0)));
57 ScopedVector
<RuleIterator
> iterators
;
58 iterators
.push_back(new ListIterator(rules1
));
59 iterators
.push_back(new ListIterator(rules2
));
60 ConcatenationIterator
concatenation_iterator(&iterators
, NULL
);
63 ASSERT_TRUE(concatenation_iterator
.HasNext());
64 rule
= concatenation_iterator
.Next();
65 EXPECT_EQ(rule
.primary_pattern
, ContentSettingsPattern::FromString("a"));
67 ASSERT_TRUE(concatenation_iterator
.HasNext());
68 rule
= concatenation_iterator
.Next();
69 EXPECT_EQ(rule
.primary_pattern
, ContentSettingsPattern::FromString("b"));
71 ASSERT_TRUE(concatenation_iterator
.HasNext());
72 rule
= concatenation_iterator
.Next();
73 EXPECT_EQ(rule
.primary_pattern
, ContentSettingsPattern::FromString("c"));
75 ASSERT_TRUE(concatenation_iterator
.HasNext());
76 rule
= concatenation_iterator
.Next();
77 EXPECT_EQ(rule
.primary_pattern
, ContentSettingsPattern::FromString("d"));
79 EXPECT_FALSE(concatenation_iterator
.HasNext());
82 } // namespace content_settings