Chromium Code Reviews| 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 "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 <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 main_instance = nullptr; | 834 main_instance = nullptr; |
| 835 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 835 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 836 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 836 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 837 | 837 |
| 838 // Free the subframe instance, which should free the browsing instance. | 838 // Free the subframe instance, which should free the browsing instance. |
| 839 subframe_instance = nullptr; | 839 subframe_instance = nullptr; |
| 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 841 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 841 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 TEST_F(SiteInstanceTest, IsolatedOrigins) { | |
| 845 GURL foo_url("http://www.foo.com"); | |
| 846 GURL isolated_foo_url("http://isolated.foo.com"); | |
| 847 GURL isolated_bar_url("http://isolated.bar.com"); | |
|
Charlie Reis
2017/05/05 23:18:51
Let's add tests for bar.isolated.foo.com, too.
alexmos
2017/05/16 17:26:38
I've built support for keeping those in isolated.f
Charlie Reis
2017/05/19 00:10:18
Sounds good!
| |
| 848 | |
| 849 EXPECT_FALSE( | |
| 850 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(isolated_foo_url))); | |
|
Charlie Reis
2017/05/05 23:18:51
Maybe check that IsSameWebsite for foo_url and iso
alexmos
2017/05/16 17:26:38
Done.
| |
| 851 | |
| 852 SiteInstanceImpl::AddIsolatedOrigin(url::Origin(isolated_foo_url)); | |
| 853 EXPECT_TRUE( | |
| 854 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(isolated_foo_url))); | |
| 855 EXPECT_FALSE(SiteInstanceImpl::IsIsolatedOrigin(url::Origin(foo_url))); | |
| 856 EXPECT_FALSE( | |
| 857 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(GURL("http://foo.com")))); | |
| 858 EXPECT_FALSE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 859 url::Origin(GURL("http://www.bar.com")))); | |
| 860 EXPECT_FALSE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 861 url::Origin(GURL("https://isolated.foo.com")))); | |
| 862 EXPECT_FALSE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 863 url::Origin(GURL("http://isolated.foo.com:12345")))); | |
| 864 EXPECT_FALSE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 865 url::Origin(GURL("http://bar.isolated.foo.com")))); | |
| 866 | |
| 867 SiteInstanceImpl::AddIsolatedOrigin(url::Origin(isolated_bar_url)); | |
| 868 EXPECT_TRUE( | |
| 869 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(isolated_bar_url))); | |
| 870 | |
| 871 // IsSameWebSite should compare origins rather than sites if either URL is an | |
| 872 // isolated origin. | |
| 873 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, foo_url, isolated_foo_url)); | |
| 874 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, isolated_foo_url, foo_url)); | |
| 875 EXPECT_FALSE( | |
| 876 SiteInstance::IsSameWebSite(nullptr, isolated_foo_url, isolated_bar_url)); | |
| 877 EXPECT_TRUE( | |
| 878 SiteInstance::IsSameWebSite(nullptr, isolated_foo_url, isolated_foo_url)); | |
| 879 | |
| 880 // Ensure blob and filesystem URLs with isolated origins are compared | |
| 881 // correctly. | |
| 882 GURL isolated_blob_foo_url("blob:http://isolated.foo.com/uuid"); | |
| 883 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, isolated_foo_url, | |
| 884 isolated_blob_foo_url)); | |
| 885 GURL isolated_filesystem_foo_url("filesystem:http://isolated.foo.com/bar/"); | |
| 886 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, isolated_foo_url, | |
| 887 isolated_filesystem_foo_url)); | |
| 888 | |
| 889 // The site URL for an isolated origin should be the full origin rather than | |
| 890 // eTLD+1. | |
| 891 EXPECT_EQ(isolated_foo_url, | |
| 892 SiteInstance::GetSiteForURL(nullptr, isolated_foo_url)); | |
| 893 EXPECT_EQ(isolated_bar_url, | |
| 894 SiteInstance::GetSiteForURL(nullptr, isolated_bar_url)); | |
| 895 EXPECT_EQ(isolated_foo_url, | |
| 896 SiteInstance::GetSiteForURL(nullptr, isolated_blob_foo_url)); | |
| 897 EXPECT_EQ(isolated_foo_url, | |
| 898 SiteInstance::GetSiteForURL(nullptr, isolated_filesystem_foo_url)); | |
| 899 | |
| 900 // Isolated origins always require a dedicated process. | |
| 901 EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess( | |
| 902 nullptr, isolated_foo_url)); | |
| 903 EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess( | |
| 904 nullptr, isolated_bar_url)); | |
| 905 EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess( | |
| 906 nullptr, isolated_blob_foo_url)); | |
| 907 EXPECT_TRUE(SiteInstanceImpl::DoesSiteRequireDedicatedProcess( | |
| 908 nullptr, isolated_filesystem_foo_url)); | |
| 909 } | |
| 910 | |
| 911 // Verifies parsing logic that extracts origins from --isolate-origins. | |
| 912 TEST_F(SiteInstanceTest, IsolateOriginsFromCommandLine) { | |
| 913 // Invalid and unique origins are not permitted. | |
| 914 SiteInstanceImpl::AddIsolatedOriginsFromCommandLine("foo"); | |
| 915 SiteInstanceImpl::AddIsolatedOriginsFromCommandLine(""); | |
| 916 SiteInstanceImpl::AddIsolatedOriginsFromCommandLine("about:blank"); | |
| 917 EXPECT_EQ(0U, SiteInstanceImpl::GetIsolatedOrigins()->size()); | |
| 918 | |
| 919 SiteInstanceImpl::AddIsolatedOriginsFromCommandLine( | |
| 920 "http://isolated.foo.com"); | |
| 921 EXPECT_EQ(1U, SiteInstanceImpl::GetIsolatedOrigins()->size()); | |
| 922 EXPECT_TRUE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 923 url::Origin(GURL("http://isolated.foo.com")))); | |
| 924 | |
| 925 SiteInstanceImpl::AddIsolatedOriginsFromCommandLine( | |
| 926 "http://a.com,https://b.com,,https://c.com:8000"); | |
| 927 EXPECT_EQ(4U, SiteInstanceImpl::GetIsolatedOrigins()->size()); | |
| 928 EXPECT_TRUE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 929 url::Origin(GURL("http://isolated.foo.com")))); | |
| 930 EXPECT_TRUE( | |
| 931 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(GURL("http://a.com")))); | |
| 932 EXPECT_TRUE( | |
| 933 SiteInstanceImpl::IsIsolatedOrigin(url::Origin(GURL("https://b.com")))); | |
| 934 EXPECT_TRUE(SiteInstanceImpl::IsIsolatedOrigin( | |
| 935 url::Origin(GURL("https://c.com:8000")))); | |
| 936 } | |
| 937 | |
| 844 } // namespace content | 938 } // namespace content |
| OLD | NEW |