Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/common/content_settings_pattern_parser_unittest.cc

Issue 440423003: Clean content_settings_pattern_parser.* from unnecessary dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CrOS tests Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/content_settings_pattern.h"
6 #include "chrome/common/content_settings_pattern_parser.h" 5 #include "chrome/common/content_settings_pattern_parser.h"
7 6
7 #include "chrome/common/content_settings_component.h"
8 #include "chrome/common/content_settings_pattern.h"
8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace { 12 namespace {
12 typedef ContentSettingsPattern::BuilderInterface BuilderInterface; 13 typedef ContentSettingsPattern::BuilderInterface BuilderInterface;
13 } // namespace 14 } // namespace
14 15
15 class MockBuilder : public ContentSettingsPattern::BuilderInterface { 16 class MockBuilder : public ContentSettingsPattern::BuilderInterface {
16 public: 17 public:
17 MOCK_METHOD0(WithSchemeWildcard, BuilderInterface*()); 18 MOCK_METHOD0(WithSchemeWildcard, BuilderInterface*());
18 MOCK_METHOD0(WithDomainWildcard, BuilderInterface*()); 19 MOCK_METHOD0(WithDomainWildcard, BuilderInterface*());
19 MOCK_METHOD0(WithPortWildcard, BuilderInterface*()); 20 MOCK_METHOD0(WithPortWildcard, BuilderInterface*());
20 MOCK_METHOD1(WithScheme, BuilderInterface*(const std::string& scheme)); 21 MOCK_METHOD1(WithScheme, BuilderInterface*(const std::string& scheme));
21 MOCK_METHOD1(WithHost, BuilderInterface*(const std::string& host)); 22 MOCK_METHOD1(WithHost, BuilderInterface*(const std::string& host));
22 MOCK_METHOD1(WithPort, BuilderInterface*(const std::string& port)); 23 MOCK_METHOD1(WithPort, BuilderInterface*(const std::string& port));
23 MOCK_METHOD1(WithPath, BuilderInterface*(const std::string& path)); 24 MOCK_METHOD1(WithPath, BuilderInterface*(const std::string& path));
24 MOCK_METHOD0(WithPathWildcard, BuilderInterface*()); 25 MOCK_METHOD0(WithPathWildcard, BuilderInterface*());
25 MOCK_METHOD0(Invalid, BuilderInterface*()); 26 MOCK_METHOD0(Invalid, BuilderInterface*());
26 MOCK_METHOD0(Build, ContentSettingsPattern()); 27 MOCK_METHOD0(Build, ContentSettingsPattern());
27 }; 28 };
28 29
29 TEST(ContentSettingsPatternParserTest, ParsePatterns) { 30 TEST(ContentSettingsPatternParserTest, ParsePatterns) {
31 InitContentSettingsComponent();
Bernhard Bauer 2014/08/18 15:55:13 I would add this to ChromeTestSuite::Initialize()
vasilii 2014/08/20 08:44:06 Done.
30 // Test valid patterns 32 // Test valid patterns
31 ::testing::StrictMock<MockBuilder> builder; 33 ::testing::StrictMock<MockBuilder> builder;
32 34
33 // WithPathWildcard() is not called for "*". (Need a strict Mock for this 35 // WithPathWildcard() is not called for "*". (Need a strict Mock for this
34 // case.) 36 // case.)
35 EXPECT_CALL(builder, WithSchemeWildcard()).Times(1).WillOnce( 37 EXPECT_CALL(builder, WithSchemeWildcard()).Times(1).WillOnce(
36 ::testing::Return(&builder)); 38 ::testing::Return(&builder));
37 EXPECT_CALL(builder, WithDomainWildcard()).Times(1).WillOnce( 39 EXPECT_CALL(builder, WithDomainWildcard()).Times(1).WillOnce(
38 ::testing::Return(&builder)); 40 ::testing::Return(&builder));
39 EXPECT_CALL(builder, WithPortWildcard()).Times(1).WillOnce( 41 EXPECT_CALL(builder, WithPortWildcard()).Times(1).WillOnce(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 147
146 EXPECT_CALL(builder, WithSchemeWildcard()).Times(1).WillOnce( 148 EXPECT_CALL(builder, WithSchemeWildcard()).Times(1).WillOnce(
147 ::testing::Return(&builder)); 149 ::testing::Return(&builder));
148 EXPECT_CALL(builder, Invalid()).Times(1).WillOnce( 150 EXPECT_CALL(builder, Invalid()).Times(1).WillOnce(
149 ::testing::Return(&builder)); 151 ::testing::Return(&builder));
150 content_settings::PatternParser::Parse("www.youtube.com*", &builder); 152 content_settings::PatternParser::Parse("www.youtube.com*", &builder);
151 ::testing::Mock::VerifyAndClear(&builder); 153 ::testing::Mock::VerifyAndClear(&builder);
152 } 154 }
153 155
154 TEST(ContentSettingsPatternParserTest, ParseFilePatterns) { 156 TEST(ContentSettingsPatternParserTest, ParseFilePatterns) {
157 InitContentSettingsComponent();
155 ::testing::StrictMock<MockBuilder> builder; 158 ::testing::StrictMock<MockBuilder> builder;
156 159
157 EXPECT_CALL(builder, WithScheme("file")).Times(1).WillOnce( 160 EXPECT_CALL(builder, WithScheme("file")).Times(1).WillOnce(
158 ::testing::Return(&builder)); 161 ::testing::Return(&builder));
159 EXPECT_CALL(builder, WithPath("/foo/bar/test.html")).Times(1).WillOnce( 162 EXPECT_CALL(builder, WithPath("/foo/bar/test.html")).Times(1).WillOnce(
160 ::testing::Return(&builder)); 163 ::testing::Return(&builder));
161 content_settings::PatternParser::Parse( 164 content_settings::PatternParser::Parse(
162 "file:///foo/bar/test.html", &builder); 165 "file:///foo/bar/test.html", &builder);
163 ::testing::Mock::VerifyAndClear(&builder); 166 ::testing::Mock::VerifyAndClear(&builder);
164 167
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 EXPECT_CALL(builder, WithScheme("file")).Times(1).WillOnce( 205 EXPECT_CALL(builder, WithScheme("file")).Times(1).WillOnce(
203 ::testing::Return(&builder)); 206 ::testing::Return(&builder));
204 EXPECT_CALL(builder, Invalid()).Times(1).WillOnce( 207 EXPECT_CALL(builder, Invalid()).Times(1).WillOnce(
205 ::testing::Return(&builder)); 208 ::testing::Return(&builder));
206 content_settings::PatternParser::Parse( 209 content_settings::PatternParser::Parse(
207 "file://**", &builder); 210 "file://**", &builder);
208 ::testing::Mock::VerifyAndClear(&builder); 211 ::testing::Mock::VerifyAndClear(&builder);
209 } 212 }
210 213
211 TEST(ContentSettingsPatternParserTest, SerializePatterns) { 214 TEST(ContentSettingsPatternParserTest, SerializePatterns) {
215 InitContentSettingsComponent();
212 ContentSettingsPattern::PatternParts parts; 216 ContentSettingsPattern::PatternParts parts;
213 parts.scheme = "http"; 217 parts.scheme = "http";
214 parts.host = "www.youtube.com"; 218 parts.host = "www.youtube.com";
215 parts.port = "8080"; 219 parts.port = "8080";
216 EXPECT_STREQ("http://www.youtube.com:8080", 220 EXPECT_STREQ("http://www.youtube.com:8080",
217 content_settings::PatternParser::ToString(parts).c_str()); 221 content_settings::PatternParser::ToString(parts).c_str());
218 222
219 parts = ContentSettingsPattern::PatternParts(); 223 parts = ContentSettingsPattern::PatternParts();
220 parts.scheme = "file"; 224 parts.scheme = "file";
221 parts.path = "/foo/bar/test.html"; 225 parts.path = "/foo/bar/test.html";
222 EXPECT_STREQ("file:///foo/bar/test.html", 226 EXPECT_STREQ("file:///foo/bar/test.html",
223 content_settings::PatternParser::ToString(parts).c_str()); 227 content_settings::PatternParser::ToString(parts).c_str());
224 228
225 parts = ContentSettingsPattern::PatternParts(); 229 parts = ContentSettingsPattern::PatternParts();
226 parts.scheme = "file"; 230 parts.scheme = "file";
227 parts.path = ""; 231 parts.path = "";
228 parts.is_path_wildcard = true; 232 parts.is_path_wildcard = true;
229 EXPECT_EQ("file:///*", content_settings::PatternParser::ToString(parts)); 233 EXPECT_EQ("file:///*", content_settings::PatternParser::ToString(parts));
230 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698