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

Side by Side Diff: url/origin_unittest.cc

Issue 2287483002: Provide the equivalent of GURL::DomainIs for url::Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « url/origin.cc ('k') | url/url_util.h » ('j') | url/url_util.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 std::string(test.scheme, test.scheme_length), 245 std::string(test.scheme, test.scheme_length),
246 std::string(test.host, test.host_length), test.port); 246 std::string(test.host, test.host_length), test.port);
247 EXPECT_EQ("", origin.scheme()); 247 EXPECT_EQ("", origin.scheme());
248 EXPECT_EQ("", origin.host()); 248 EXPECT_EQ("", origin.host());
249 EXPECT_EQ(0, origin.port()); 249 EXPECT_EQ(0, origin.port());
250 EXPECT_TRUE(origin.unique()); 250 EXPECT_TRUE(origin.unique());
251 EXPECT_FALSE(origin.IsSameOriginWith(origin)); 251 EXPECT_FALSE(origin.IsSameOriginWith(origin));
252 } 252 }
253 } 253 }
254 254
255 TEST(OriginTest, DomainIs) {
engedy 2016/08/26 16:48:14 Could you please add an explicit test for a file:
pkalinnikov 2016/08/29 09:53:00 Done.
256 const struct {
257 const char* url;
258 const char* lower_ascii_domain;
259 bool expected_domain_is;
260 } kTestCases[] = {
261 {"http://google.com/foo", "google.com", true},
262 {"http://www.google.com:99/foo", "google.com", true},
263 {"http://www.google.com.cn/foo", "google.com", false},
264 {"http://www.google.comm", "google.com", false},
265 {"http://www.iamnotgoogle.com/foo", "google.com", false},
266 {"http://www.google.com/foo", "Google.com", false},
267
268 // If the host ends with a dot, it matches domains with or without a dot.
269 {"http://www.google.com./foo", "google.com", true},
270 {"http://www.google.com./foo", "google.com.", true},
271 {"http://www.google.com./foo", ".com", true},
272 {"http://www.google.com./foo", ".com.", true},
273
274 // But, if the host doesn't end with a dot and the input domain does, then
275 // it's considered to not match.
276 {"http://google.com/foo", "google.com.", false},
277
278 // If the host ends with two dots, it doesn't match.
279 {"http://www.google.com../foo", "google.com", false},
280
281 // Filesystem scheme.
282 {"filesystem:http://www.google.com:99/foo/", "google.com", true},
283 {"filesystem:http://www.iamnotgoogle.com/foo/", "google.com", false},
284 };
285
286 for (const auto& test_case : kTestCases) {
287 SCOPED_TRACE(testing::Message() << "(url, domain): (" << test_case.url
288 << ", " << test_case.lower_ascii_domain
289 << ")");
290 GURL url(test_case.url);
291 ASSERT_TRUE(url.is_valid());
292 url::Origin origin(url);
293
294 EXPECT_EQ(test_case.expected_domain_is,
295 origin.DomainIs(test_case.lower_ascii_domain));
296 }
297
298 // If the URL is invalid, DomainIs returns false.
299 GURL invalid_url("google.com");
300 ASSERT_FALSE(invalid_url.is_valid());
301 EXPECT_FALSE(url::Origin(invalid_url).DomainIs("google.com"));
302 }
303
255 } // namespace url 304 } // namespace url
OLDNEW
« no previous file with comments | « url/origin.cc ('k') | url/url_util.h » ('j') | url/url_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698