| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 // Test of distinguishing URLs from different sites. Most of this logic is | 366 // Test of distinguishing URLs from different sites. Most of this logic is |
| 367 // tested in RegistryControlledDomainTest. This test focuses on URLs with | 367 // tested in RegistryControlledDomainTest. This test focuses on URLs with |
| 368 // different schemes or ports. | 368 // different schemes or ports. |
| 369 TEST_F(SiteInstanceTest, IsSameWebSite) { | 369 TEST_F(SiteInstanceTest, IsSameWebSite) { |
| 370 GURL url_foo = GURL("http://foo/a.html"); | 370 GURL url_foo = GURL("http://foo/a.html"); |
| 371 GURL url_foo2 = GURL("http://foo/b.html"); | 371 GURL url_foo2 = GURL("http://foo/b.html"); |
| 372 GURL url_foo_https = GURL("https://foo/a.html"); | 372 GURL url_foo_https = GURL("https://foo/a.html"); |
| 373 GURL url_foo_port = GURL("http://foo:8080/a.html"); | 373 GURL url_foo_port = GURL("http://foo:8080/a.html"); |
| 374 GURL url_javascript = GURL("javascript:alert(1);"); | 374 GURL url_javascript = GURL("javascript:alert(1);"); |
| 375 GURL url_blank = GURL(url::kAboutBlankURL); |
| 375 | 376 |
| 376 // Same scheme and port -> same site. | 377 // Same scheme and port -> same site. |
| 377 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); | 378 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); |
| 378 | 379 |
| 379 // Different scheme -> different site. | 380 // Different scheme -> different site. |
| 380 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); | 381 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); |
| 381 | 382 |
| 382 // Different port -> same site. | 383 // Different port -> same site. |
| 383 // (Changes to document.domain make renderer ignore the port.) | 384 // (Changes to document.domain make renderer ignore the port.) |
| 384 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); | 385 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); |
| 385 | 386 |
| 386 // JavaScript links should be considered same site for anything. | 387 // JavaScript links should be considered same site for anything. |
| 387 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); | 388 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); |
| 388 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); | 389 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); |
| 389 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); | 390 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); |
| 390 | 391 |
| 392 // Navigating to a blank page is considered the same site. |
| 393 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_blank)); |
| 394 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo_https, url_blank)); |
| 395 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo_port, url_blank)); |
| 396 |
| 397 // Navigating from a blank site is not considered to be the same site. |
| 398 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo)); |
| 399 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_https)); |
| 400 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_port)); |
| 401 |
| 391 DrainMessageLoops(); | 402 DrainMessageLoops(); |
| 392 } | 403 } |
| 393 | 404 |
| 394 // Test to ensure that there is only one SiteInstance per site in a given | 405 // Test to ensure that there is only one SiteInstance per site in a given |
| 395 // BrowsingInstance, when process-per-site is not in use. | 406 // BrowsingInstance, when process-per-site is not in use. |
| 396 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 407 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
| 397 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 408 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
| 398 switches::kProcessPerSite)); | 409 switches::kProcessPerSite)); |
| 399 int delete_counter = 0; | 410 int delete_counter = 0; |
| 400 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 411 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 776 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
| 766 host.reset(instance->GetProcess()); | 777 host.reset(instance->GetProcess()); |
| 767 | 778 |
| 768 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 779 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
| 769 browser_context.get(), GURL())); | 780 browser_context.get(), GURL())); |
| 770 | 781 |
| 771 DrainMessageLoops(); | 782 DrainMessageLoops(); |
| 772 } | 783 } |
| 773 | 784 |
| 774 } // namespace content | 785 } // namespace content |
| OLD | NEW |