| OLD | NEW |
| (Empty) |
| 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 <list> | |
| 6 | |
| 7 #include "chrome/browser/content_settings/content_settings_rule.h" | |
| 8 #include "components/content_settings/core/common/content_settings_pattern.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace content_settings { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class ListIterator : public RuleIterator { | |
| 16 public: | |
| 17 explicit ListIterator(const std::list<Rule>& rules) | |
| 18 : rules_(rules) {} | |
| 19 | |
| 20 virtual ~ListIterator() {} | |
| 21 | |
| 22 virtual bool HasNext() const OVERRIDE { | |
| 23 return !rules_.empty(); | |
| 24 } | |
| 25 | |
| 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(); | |
| 31 rules_.pop_front(); | |
| 32 return rule; | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 std::list<Rule> rules_; | |
| 37 }; | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 TEST(RuleTest, ConcatenationIterator) { | |
| 42 std::list<Rule> rules1; | |
| 43 rules1.push_back(Rule(ContentSettingsPattern::FromString("a"), | |
| 44 ContentSettingsPattern::Wildcard(), | |
| 45 new base::FundamentalValue(0))); | |
| 46 rules1.push_back(Rule(ContentSettingsPattern::FromString("b"), | |
| 47 ContentSettingsPattern::Wildcard(), | |
| 48 new base::FundamentalValue(0))); | |
| 49 std::list<Rule> rules2; | |
| 50 rules2.push_back(Rule(ContentSettingsPattern::FromString("c"), | |
| 51 ContentSettingsPattern::Wildcard(), | |
| 52 new base::FundamentalValue(0))); | |
| 53 rules2.push_back(Rule(ContentSettingsPattern::FromString("d"), | |
| 54 ContentSettingsPattern::Wildcard(), | |
| 55 new base::FundamentalValue(0))); | |
| 56 | |
| 57 ScopedVector<RuleIterator> iterators; | |
| 58 iterators.push_back(new ListIterator(rules1)); | |
| 59 iterators.push_back(new ListIterator(rules2)); | |
| 60 ConcatenationIterator concatenation_iterator(&iterators, NULL); | |
| 61 | |
| 62 Rule rule; | |
| 63 ASSERT_TRUE(concatenation_iterator.HasNext()); | |
| 64 rule = concatenation_iterator.Next(); | |
| 65 EXPECT_EQ(rule.primary_pattern, ContentSettingsPattern::FromString("a")); | |
| 66 | |
| 67 ASSERT_TRUE(concatenation_iterator.HasNext()); | |
| 68 rule = concatenation_iterator.Next(); | |
| 69 EXPECT_EQ(rule.primary_pattern, ContentSettingsPattern::FromString("b")); | |
| 70 | |
| 71 ASSERT_TRUE(concatenation_iterator.HasNext()); | |
| 72 rule = concatenation_iterator.Next(); | |
| 73 EXPECT_EQ(rule.primary_pattern, ContentSettingsPattern::FromString("c")); | |
| 74 | |
| 75 ASSERT_TRUE(concatenation_iterator.HasNext()); | |
| 76 rule = concatenation_iterator.Next(); | |
| 77 EXPECT_EQ(rule.primary_pattern, ContentSettingsPattern::FromString("d")); | |
| 78 | |
| 79 EXPECT_FALSE(concatenation_iterator.HasNext()); | |
| 80 } | |
| 81 | |
| 82 } // namespace content_settings | |
| OLD | NEW |