| OLD | NEW |
| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "extensions/common/url_pattern.h" | 6 #include "extensions/common/url_pattern.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 { "http://", URLPattern::PARSE_ERROR_EMPTY_HOST }, | 32 { "http://", URLPattern::PARSE_ERROR_EMPTY_HOST }, |
| 33 { "http:///", URLPattern::PARSE_ERROR_EMPTY_HOST }, | 33 { "http:///", URLPattern::PARSE_ERROR_EMPTY_HOST }, |
| 34 { "http:// /", URLPattern::PARSE_ERROR_EMPTY_HOST }, | 34 { "http:// /", URLPattern::PARSE_ERROR_EMPTY_HOST }, |
| 35 { "http://*foo/bar", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 35 { "http://*foo/bar", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
| 36 { "http://foo.*.bar/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 36 { "http://foo.*.bar/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
| 37 { "http://fo.*.ba:123/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 37 { "http://fo.*.ba:123/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
| 38 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, | 38 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
| 39 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH }, | 39 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH }, |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidPatterns); ++i) { | 42 for (size_t i = 0; i < arraysize(kInvalidPatterns); ++i) { |
| 43 URLPattern pattern(URLPattern::SCHEME_ALL); | 43 URLPattern pattern(URLPattern::SCHEME_ALL); |
| 44 EXPECT_EQ(kInvalidPatterns[i].expected_result, | 44 EXPECT_EQ(kInvalidPatterns[i].expected_result, |
| 45 pattern.Parse(kInvalidPatterns[i].pattern)) | 45 pattern.Parse(kInvalidPatterns[i].pattern)) |
| 46 << kInvalidPatterns[i].pattern; | 46 << kInvalidPatterns[i].pattern; |
| 47 } | 47 } |
| 48 | 48 |
| 49 { | 49 { |
| 50 // Cannot use a C string, because this contains a null byte. | 50 // Cannot use a C string, because this contains a null byte. |
| 51 std::string null_host("http://\0www/", 12); | 51 std::string null_host("http://\0www/", 12); |
| 52 URLPattern pattern(URLPattern::SCHEME_ALL); | 52 URLPattern pattern(URLPattern::SCHEME_ALL); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 75 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
| 76 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" }, | 76 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" }, |
| 77 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 77 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
| 78 | 78 |
| 79 // Port-like strings in the path should not trigger a warning. | 79 // Port-like strings in the path should not trigger a warning. |
| 80 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" }, | 80 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" }, |
| 81 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" }, | 81 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" }, |
| 82 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS, "*" }, | 82 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS, "*" }, |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { | 85 for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { |
| 86 URLPattern pattern(URLPattern::SCHEME_ALL); | 86 URLPattern pattern(URLPattern::SCHEME_ALL); |
| 87 EXPECT_EQ(kTestPatterns[i].expected_result, | 87 EXPECT_EQ(kTestPatterns[i].expected_result, |
| 88 pattern.Parse(kTestPatterns[i].pattern)) | 88 pattern.Parse(kTestPatterns[i].pattern)) |
| 89 << "Got unexpected result for URL pattern: " | 89 << "Got unexpected result for URL pattern: " |
| 90 << kTestPatterns[i].pattern; | 90 << kTestPatterns[i].pattern; |
| 91 EXPECT_EQ(kTestPatterns[i].expected_port, pattern.port()) | 91 EXPECT_EQ(kTestPatterns[i].expected_port, pattern.port()) |
| 92 << "Got unexpected port for URL pattern: " << kTestPatterns[i].pattern; | 92 << "Got unexpected port for URL pattern: " << kTestPatterns[i].pattern; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 { "<all_urls>", | 656 { "<all_urls>", |
| 657 "<all_urls>", | 657 "<all_urls>", |
| 658 true | 658 true |
| 659 }, | 659 }, |
| 660 { "<all_urls>", | 660 { "<all_urls>", |
| 661 "http://*/*", | 661 "http://*/*", |
| 662 false | 662 false |
| 663 } | 663 } |
| 664 }; | 664 }; |
| 665 | 665 |
| 666 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEqualsTestCases); ++i) { | 666 for (size_t i = 0; i < arraysize(kEqualsTestCases); ++i) { |
| 667 std::string message = kEqualsTestCases[i].pattern1; | 667 std::string message = kEqualsTestCases[i].pattern1; |
| 668 message += " "; | 668 message += " "; |
| 669 message += kEqualsTestCases[i].pattern2; | 669 message += kEqualsTestCases[i].pattern2; |
| 670 | 670 |
| 671 URLPattern pattern1(URLPattern::SCHEME_ALL); | 671 URLPattern pattern1(URLPattern::SCHEME_ALL); |
| 672 URLPattern pattern2(URLPattern::SCHEME_ALL); | 672 URLPattern pattern2(URLPattern::SCHEME_ALL); |
| 673 | 673 |
| 674 pattern1.Parse(kEqualsTestCases[i].pattern1); | 674 pattern1.Parse(kEqualsTestCases[i].pattern1); |
| 675 pattern2.Parse(kEqualsTestCases[i].pattern2); | 675 pattern2.Parse(kEqualsTestCases[i].pattern2); |
| 676 EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2) | 676 EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 EXPECT_TRUE(URLPattern(URLPattern::SCHEME_HTTPS, "https://www.google.com/") | 835 EXPECT_TRUE(URLPattern(URLPattern::SCHEME_HTTPS, "https://www.google.com/") |
| 836 .MatchesSingleOrigin()); | 836 .MatchesSingleOrigin()); |
| 837 EXPECT_FALSE(URLPattern(URLPattern::SCHEME_HTTP, | 837 EXPECT_FALSE(URLPattern(URLPattern::SCHEME_HTTP, |
| 838 "http://*.google.com/foo/bar").MatchesSingleOrigin()); | 838 "http://*.google.com/foo/bar").MatchesSingleOrigin()); |
| 839 EXPECT_TRUE( | 839 EXPECT_TRUE( |
| 840 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/foo/bar") | 840 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/foo/bar") |
| 841 .MatchesSingleOrigin()); | 841 .MatchesSingleOrigin()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 } // namespace | 844 } // namespace |
| OLD | NEW |