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

Side by Side Diff: content/browser/site_instance_impl_unittest.cc

Issue 1911573002: Teach SiteInstance::GetSiteForURL() about blob and filesystem URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mark two layout tests fixed Created 4 years, 8 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
OLDNEW
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 "content/browser/site_instance_impl.h" 5 #include "content/browser/site_instance_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 // Test to ensure GetSiteForURL properly returns sites for URLs. 283 // Test to ensure GetSiteForURL properly returns sites for URLs.
284 TEST_F(SiteInstanceTest, GetSiteForURL) { 284 TEST_F(SiteInstanceTest, GetSiteForURL) {
285 // Pages are irrelevant. 285 // Pages are irrelevant.
286 GURL test_url = GURL("http://www.google.com/index.html"); 286 GURL test_url = GURL("http://www.google.com/index.html");
287 GURL site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 287 GURL site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
288 EXPECT_EQ(GURL("http://google.com"), site_url); 288 EXPECT_EQ(GURL("http://google.com"), site_url);
289 EXPECT_EQ("http", site_url.scheme()); 289 EXPECT_EQ("http", site_url.scheme());
290 EXPECT_EQ("google.com", site_url.host()); 290 EXPECT_EQ("google.com", site_url.host());
291 291
292 // Ports are irrlevant. 292 // Ports are irrelevant.
293 test_url = GURL("https://www.google.com:8080"); 293 test_url = GURL("https://www.google.com:8080");
294 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 294 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
295 EXPECT_EQ(GURL("https://google.com"), site_url); 295 EXPECT_EQ(GURL("https://google.com"), site_url);
296 296
297 // Hostnames without TLDs are ok. 297 // Punycode is canonicalized.
298 test_url = GURL("http://☃snowperson☃.net:333/");
299 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
300 EXPECT_EQ(GURL("http://xn--snowperson-di0gka.net"), site_url);
301
302 // Username and password are stripped out.
303 test_url = GURL("ftp://username:password@ftp.chromium.org/files/README");
304 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
305 EXPECT_EQ(GURL("ftp://chromium.org"), site_url);
306
307 // Literal IP addresses of any flavor are okay.
308 test_url = GURL("http://127.0.0.1/a.html");
309 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
310 EXPECT_EQ(GURL("http://127.0.0.1"), site_url);
311 EXPECT_EQ("127.0.0.1", site_url.host());
312
313 test_url = GURL("http://2130706433/a.html");
314 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
315 EXPECT_EQ(GURL("http://127.0.0.1"), site_url);
316 EXPECT_EQ("127.0.0.1", site_url.host());
317
318 test_url = GURL("http://[::1]:2/page.html");
319 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
320 EXPECT_EQ(GURL("http://[::1]"), site_url);
321 EXPECT_EQ("[::1]", site_url.host());
ncarter (slow) 2016/04/20 23:06:00 These are added just for good measure, and pass be
322
323 // Hostnames without TLDs are okay.
298 test_url = GURL("http://foo/a.html"); 324 test_url = GURL("http://foo/a.html");
299 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 325 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
300 EXPECT_EQ(GURL("http://foo"), site_url); 326 EXPECT_EQ(GURL("http://foo"), site_url);
301 EXPECT_EQ("foo", site_url.host()); 327 EXPECT_EQ("foo", site_url.host());
302 328
303 // File URLs should include the scheme. 329 // File URLs should include the scheme.
304 test_url = GURL("file:///C:/Downloads/"); 330 test_url = GURL("file:///C:/Downloads/");
305 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 331 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
306 EXPECT_EQ(GURL("file:"), site_url); 332 EXPECT_EQ(GURL("file:"), site_url);
307 EXPECT_EQ("file", site_url.scheme()); 333 EXPECT_EQ("file", site_url.scheme());
(...skipping 12 matching lines...) Expand all
320 EXPECT_EQ("data", site_url.scheme()); 346 EXPECT_EQ("data", site_url.scheme());
321 EXPECT_FALSE(site_url.has_host()); 347 EXPECT_FALSE(site_url.has_host());
322 348
323 // Javascript URLs should include the scheme. 349 // Javascript URLs should include the scheme.
324 test_url = GURL("javascript:foo();"); 350 test_url = GURL("javascript:foo();");
325 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 351 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
326 EXPECT_EQ(GURL("javascript:"), site_url); 352 EXPECT_EQ(GURL("javascript:"), site_url);
327 EXPECT_EQ("javascript", site_url.scheme()); 353 EXPECT_EQ("javascript", site_url.scheme());
328 EXPECT_FALSE(site_url.has_host()); 354 EXPECT_FALSE(site_url.has_host());
329 355
356 // Blob URLs extract the site from the origin.
357 test_url = GURL(
358 "blob:gopher://www.ftp.chromium.org/"
359 "4d4ff040-6d61-4446-86d3-13ca07ec9ab9");
360 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
361 EXPECT_EQ(GURL("gopher://chromium.org"), site_url);
362
363 // Private domains are preserved, appspot being such a site.
364 test_url = GURL(
365 "blob:http://www.example.appspot.com:44/"
366 "4d4ff040-6d61-4446-86d3-13ca07ec9ab9");
367 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
368 EXPECT_EQ(GURL("http://example.appspot.com"), site_url);
369
370 // The site of filesystem URLs is determined by the inner URL.
371 test_url = GURL("filesystem:http://www.google.com/foo/bar.html?foo#bar");
372 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
373 EXPECT_EQ(GURL("http://google.com"), site_url);
ncarter (slow) 2016/04/20 23:06:00 These 3 tests would have failed prior to this chan
374
330 // Guest URLs are special and need to have the path in the site as well, 375 // Guest URLs are special and need to have the path in the site as well,
331 // since it affects the StoragePartition configuration. 376 // since it affects the StoragePartition configuration.
332 std::string guest_url(kGuestScheme); 377 std::string guest_url(kGuestScheme);
333 guest_url.append("://abc123/path"); 378 guest_url.append("://abc123/path");
334 test_url = GURL(guest_url); 379 test_url = GURL(guest_url);
335 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); 380 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url);
336 EXPECT_EQ(test_url, site_url); 381 EXPECT_EQ(test_url, site_url);
337 382
338 DrainMessageLoops(); 383 DrainMessageLoops();
339 } 384 }
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount());
796 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); 841 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount());
797 842
798 // Free the subframe instance, which should free the browsing instance. 843 // Free the subframe instance, which should free the browsing instance.
799 subframe_instance = nullptr; 844 subframe_instance = nullptr;
800 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); 845 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount());
801 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); 846 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount());
802 } 847 }
803 848
804 } // namespace content 849 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/site_instance_impl.cc ('k') | testing/buildbot/filters/site-per-process.content_browsertests.filter » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698