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

Side by Side Diff: components/url_matcher/url_matcher_unittest.cc

Issue 219613002: Add support for matching query parameters in URLMatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Makes the changes backward compatible Created 6 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/url_matcher/url_matcher.h" 5 #include "components/url_matcher/url_matcher.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 TEST(URLMatcherConditionTest, IsFullURLCondition) { 63 TEST(URLMatcherConditionTest, IsFullURLCondition) {
64 StringPattern pattern("example.com", 1); 64 StringPattern pattern("example.com", 1);
65 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::HOST_SUFFIX, 65 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::HOST_SUFFIX,
66 &pattern).IsFullURLCondition()); 66 &pattern).IsFullURLCondition());
67 67
68 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::HOST_CONTAINS, 68 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::HOST_CONTAINS,
69 &pattern).IsFullURLCondition()); 69 &pattern).IsFullURLCondition());
70 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::PATH_CONTAINS, 70 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::PATH_CONTAINS,
71 &pattern).IsFullURLCondition()); 71 &pattern).IsFullURLCondition());
72 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::QUERY_CONTAINS, 72 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::QUERY_CONTAINS,
73 &pattern).IsFullURLCondition()); 73 &pattern).IsFullURLCondition());
74 74
75 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_PREFIX, 75 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_PREFIX,
76 &pattern).IsFullURLCondition()); 76 &pattern).IsFullURLCondition());
77 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_SUFFIX, 77 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_SUFFIX,
78 &pattern).IsFullURLCondition()); 78 &pattern).IsFullURLCondition());
79 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_CONTAINS, 79 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_CONTAINS,
80 &pattern).IsFullURLCondition()); 80 &pattern).IsFullURLCondition());
81 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_EQUALS, 81 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_EQUALS,
82 &pattern).IsFullURLCondition()); 82 &pattern).IsFullURLCondition());
83 } 83 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_FALSE(Matches(factory.CreateQueryEqualsCondition( 319 EXPECT_FALSE(Matches(factory.CreateQueryEqualsCondition(
320 "sourceid=chrome-instant&ie=UTF-8&ion="), url)); 320 "sourceid=chrome-instant&ie=UTF-8&ion="), url));
321 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( 321 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition(
322 "sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); 322 "sourceid=chrome-instant&ie=UTF-8&ion=1"), url));
323 // The '?' at the beginning is just ignored. 323 // The '?' at the beginning is just ignored.
324 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( 324 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition(
325 "?sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); 325 "?sourceid=chrome-instant&ie=UTF-8&ion=1"), url));
326 EXPECT_FALSE( 326 EXPECT_FALSE(
327 Matches(factory.CreateQueryEqualsCondition("www.google.com"), url)); 327 Matches(factory.CreateQueryEqualsCondition("www.google.com"), url));
328 328
329 EXPECT_TRUE(Matches(
330 factory.CreateQueryContainsCondition("sourceid=chrome-instant"), url));
331 // The '?' at the beginning is just ignored.
332 EXPECT_TRUE(Matches(
333 factory.CreateQueryContainsCondition("?sourceid=chrome-instant"), url));
334 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("?ie=UTF-8"), url));
335 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("ie=UTF-8"), url));
336 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("t&ie=UTF-8"), url));
337 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("e=UTF-8"), url));
338 // Multiple key value pairs are supported (though not very useful)
339 EXPECT_TRUE(Matches(
340 factory.CreateQueryContainsCondition("sourceid=chrome-instant&ie=UTF-8"),
341 url));
342
343 EXPECT_TRUE(Matches(
344 factory.CreateQueryContainsExactCondition("sourceid=chrome-instant"),
345 url));
346 // The '?' at the beginning is just ignored.
347 EXPECT_TRUE(Matches(
348 factory.CreateQueryContainsExactCondition("?sourceid=chrome-instant"),
349 url));
350 EXPECT_TRUE(
351 Matches(factory.CreateQueryContainsExactCondition("?ie=UTF-8"), url));
352 EXPECT_TRUE(
353 Matches(factory.CreateQueryContainsExactCondition("ie=UTF-8"), url));
354 // Partial key value pairs not supported
355 EXPECT_FALSE(
356 Matches(factory.CreateQueryContainsExactCondition("t&ie=UTF-8"), url));
357 // Looks for an exact match, i.e., looks for "&e=UTF-8" or "?e=UTF-8" below
358 // and fails.
359 EXPECT_FALSE(
360 Matches(factory.CreateQueryContainsExactCondition("e=UTF-8"), url));
361 // Multiple key value pairs are supported (though not very useful)
362 EXPECT_TRUE(Matches(factory.CreateQueryContainsExactCondition(
363 "sourceid=chrome-instant&ie=UTF-8"),
364 url));
329 365
330 // Test adjacent components 366 // Test adjacent components
331 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( 367 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
332 "google.com", "/webhp"), url)); 368 "google.com", "/webhp"), url));
333 EXPECT_TRUE(Matches( 369 EXPECT_TRUE(Matches(
334 factory.CreateHostSuffixPathPrefixCondition(std::string(), "/webhp"), 370 factory.CreateHostSuffixPathPrefixCondition(std::string(), "/webhp"),
335 url)); 371 url));
336 EXPECT_TRUE(Matches( 372 EXPECT_TRUE(Matches(
337 factory.CreateHostSuffixPathPrefixCondition("google.com", std::string()), 373 factory.CreateHostSuffixPathPrefixCondition("google.com", std::string()),
338 url)); 374 url));
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 conditions.insert(factory->CreateOriginAndPathMatchesCondition("val")); 709 conditions.insert(factory->CreateOriginAndPathMatchesCondition("val"));
674 const int kConditionSetId = 1; 710 const int kConditionSetId = 1;
675 URLMatcherConditionSet::Vector insert; 711 URLMatcherConditionSet::Vector insert;
676 insert.push_back(make_scoped_refptr( 712 insert.push_back(make_scoped_refptr(
677 new URLMatcherConditionSet(kConditionSetId, conditions))); 713 new URLMatcherConditionSet(kConditionSetId, conditions)));
678 matcher.AddConditionSets(insert); 714 matcher.AddConditionSets(insert);
679 EXPECT_EQ(0u, matcher.MatchURL(url).size()); 715 EXPECT_EQ(0u, matcher.MatchURL(url).size());
680 } 716 }
681 717
682 } // namespace url_matcher 718 } // namespace url_matcher
OLDNEW
« components/url_matcher/url_matcher.cc ('K') | « components/url_matcher/url_matcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698