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