OLD | NEW |
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, | 89 url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, |
90 &new_parsed); | 90 &new_parsed); |
91 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, | 91 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, |
92 &new_parsed); | 92 &new_parsed); |
93 url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, | 93 url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, |
94 &new_parsed); | 94 &new_parsed); |
95 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, | 95 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, |
96 &new_parsed); | 96 &new_parsed); |
97 } | 97 } |
98 | 98 |
| 99 static std::string CheckReplaceScheme(const char* base_url, |
| 100 const char* scheme) { |
| 101 // Make sure the input is canonicalized. |
| 102 url_canon::RawCanonOutput<32> original; |
| 103 url_parse::Parsed original_parsed; |
| 104 url_util::Canonicalize(base_url, strlen(base_url), NULL, |
| 105 &original, &original_parsed); |
| 106 |
| 107 url_canon::Replacements<char> replacements; |
| 108 replacements.SetScheme(scheme, url_parse::Component(0, strlen(scheme))); |
| 109 |
| 110 std::string output_string; |
| 111 url_canon::StdStringCanonOutput output(&output_string); |
| 112 url_parse::Parsed output_parsed; |
| 113 url_util::ReplaceComponents(original.data(), original.length(), |
| 114 original_parsed, replacements, NULL, |
| 115 &output, &output_parsed); |
| 116 |
| 117 output.Complete(); |
| 118 return output_string; |
| 119 } |
| 120 |
| 121 TEST(URLUtilTest, ReplaceScheme) { |
| 122 EXPECT_EQ("https://google.com/", |
| 123 CheckReplaceScheme("http://google.com/", "https")); |
| 124 EXPECT_EQ("file://google.com/", |
| 125 CheckReplaceScheme("http://google.com/", "file")); |
| 126 EXPECT_EQ("http://home/Build", |
| 127 CheckReplaceScheme("file:///Home/Build", "http")); |
| 128 EXPECT_EQ("javascript:foo", |
| 129 CheckReplaceScheme("about:foo", "javascript")); |
| 130 EXPECT_EQ("://google.com/", |
| 131 CheckReplaceScheme("http://google.com/", "")); |
| 132 EXPECT_EQ("http://google.com/", |
| 133 CheckReplaceScheme("about:google.com", "http")); |
| 134 EXPECT_EQ("http:", CheckReplaceScheme("", "http")); |
| 135 |
| 136 #ifdef WIN32 |
| 137 // Magic Windows drive letter behavior when converting to a file URL. |
| 138 EXPECT_EQ("file:///E:/foo/", |
| 139 CheckReplaceScheme("http://localhost/e:foo/", "file")); |
| 140 #endif |
| 141 |
| 142 // This will probably change to "about://google.com/" when we fix |
| 143 // http://crbug.com/160 which should also be an acceptable result. |
| 144 EXPECT_EQ("about://google.com/", |
| 145 CheckReplaceScheme("http://google.com/", "about")); |
| 146 } |
OLD | NEW |