| 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 27 matching lines...) Expand all Loading... |
| 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_UNSAFE(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 |
| 49 { |
| 50 // Cannot use a C string, because this contains a null byte. |
| 51 std::string null_host("http://\0www/", 12); |
| 52 URLPattern pattern(URLPattern::SCHEME_ALL); |
| 53 EXPECT_EQ(URLPattern::PARSE_ERROR_INVALID_HOST, |
| 54 pattern.Parse(null_host)) |
| 55 << null_host; |
| 56 } |
| 48 }; | 57 }; |
| 49 | 58 |
| 50 TEST(ExtensionURLPatternTest, Ports) { | 59 TEST(ExtensionURLPatternTest, Ports) { |
| 51 const struct { | 60 const struct { |
| 52 const char* pattern; | 61 const char* pattern; |
| 53 URLPattern::ParseResult expected_result; | 62 URLPattern::ParseResult expected_result; |
| 54 const char* expected_port; | 63 const char* expected_port; |
| 55 } kTestPatterns[] = { | 64 } kTestPatterns[] = { |
| 56 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, | 65 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, |
| 57 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, | 66 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 EXPECT_TRUE(StrictlyContains(pattern10, pattern12)); | 804 EXPECT_TRUE(StrictlyContains(pattern10, pattern12)); |
| 796 EXPECT_TRUE(StrictlyContains(pattern10, pattern13)); | 805 EXPECT_TRUE(StrictlyContains(pattern10, pattern13)); |
| 797 | 806 |
| 798 // More... | 807 // More... |
| 799 EXPECT_TRUE(StrictlyContains(pattern12, pattern11)); | 808 EXPECT_TRUE(StrictlyContains(pattern12, pattern11)); |
| 800 EXPECT_TRUE(NeitherContains(pattern11, pattern13)); | 809 EXPECT_TRUE(NeitherContains(pattern11, pattern13)); |
| 801 EXPECT_TRUE(StrictlyContains(pattern12, pattern13)); | 810 EXPECT_TRUE(StrictlyContains(pattern12, pattern13)); |
| 802 } | 811 } |
| 803 | 812 |
| 804 } // namespace | 813 } // namespace |
| OLD | NEW |