| OLD | NEW |
| 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 "chrome/browser/site_details.h" | 5 #include "chrome/browser/site_details.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 std::unique_ptr<base::HistogramTester> uma_; | 97 std::unique_ptr<base::HistogramTester> uma_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); | 99 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 IsolationScenarioType GetCurrentPolicy() { | 102 IsolationScenarioType GetCurrentPolicy() { |
| 103 if (content::AreAllSitesIsolatedForTesting()) | 103 if (content::AreAllSitesIsolatedForTesting()) |
| 104 return ISOLATE_ALL_SITES; | 104 return ISOLATE_ALL_SITES; |
| 105 if (extensions::IsIsolateExtensionsEnabled()) | 105 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 106 return ISOLATE_EXTENSIONS; | 106 return ISOLATE_EXTENSIONS; |
| 107 #else |
| 107 return ISOLATE_NOTHING; | 108 return ISOLATE_NOTHING; |
| 109 #endif |
| 108 } | 110 } |
| 109 | 111 |
| 110 // This matcher takes three other matchers as arguments, and applies one of them | 112 // This matcher takes three other matchers as arguments, and applies one of them |
| 111 // depending on the current site isolation mode. The first applies if no site | 113 // depending on the current site isolation mode. The first applies if no site |
| 112 // isolation mode is active; the second applies under --isolate-extensions mode; | 114 // isolation mode is active; the second applies under --isolate-extensions mode; |
| 113 // and the third applies under --site-per-process mode. | 115 // and the third applies under --site-per-process mode. |
| 114 MATCHER_P3(DependingOnPolicy, | 116 MATCHER_P3(DependingOnPolicy, |
| 115 isolate_nothing, | 117 isolate_nothing, |
| 116 isolate_extensions, | 118 isolate_extensions, |
| 117 isolate_all_sites, | 119 isolate_all_sites, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 int GetRenderProcessCount() { | 315 int GetRenderProcessCount() { |
| 314 int count = 0; | 316 int count = 0; |
| 315 for (content::RenderProcessHost::iterator it( | 317 for (content::RenderProcessHost::iterator it( |
| 316 content::RenderProcessHost::AllHostsIterator()); | 318 content::RenderProcessHost::AllHostsIterator()); |
| 317 !it.IsAtEnd(); it.Advance()) { | 319 !it.IsAtEnd(); it.Advance()) { |
| 318 count++; | 320 count++; |
| 319 } | 321 } |
| 320 return count; | 322 return count; |
| 321 } | 323 } |
| 322 | 324 |
| 323 // Checks whether the test run is part of a field trial with |trial_name|. | |
| 324 bool IsInTrial(const std::string& trial_name) { | |
| 325 uint32_t trial = metrics::HashName(trial_name); | |
| 326 | |
| 327 std::vector<variations::ActiveGroupId> synthetic_trials; | |
| 328 g_browser_process->metrics_service() | |
| 329 ->GetCurrentSyntheticFieldTrialsForTesting(&synthetic_trials); | |
| 330 | |
| 331 for (const auto& entry : synthetic_trials) { | |
| 332 if (trial == entry.name) | |
| 333 return true; | |
| 334 } | |
| 335 | |
| 336 return false; | |
| 337 } | |
| 338 | |
| 339 // Similar to IsInTrial but checks that the correct group is present as well. | |
| 340 bool IsInTrialGroup(const std::string& trial_name, | |
| 341 const std::string& group_name) { | |
| 342 uint32_t trial = metrics::HashName(trial_name); | |
| 343 uint32_t group = metrics::HashName(group_name); | |
| 344 | |
| 345 std::vector<variations::ActiveGroupId> synthetic_trials; | |
| 346 g_browser_process->metrics_service() | |
| 347 ->GetCurrentSyntheticFieldTrialsForTesting(&synthetic_trials); | |
| 348 | |
| 349 for (const auto& entry : synthetic_trials) { | |
| 350 if (trial == entry.name && group == entry.group) | |
| 351 return true; | |
| 352 } | |
| 353 | |
| 354 return false; | |
| 355 } | |
| 356 | |
| 357 private: | 325 private: |
| 358 std::vector<std::unique_ptr<TestExtensionDir>> temp_dirs_; | 326 std::vector<std::unique_ptr<TestExtensionDir>> temp_dirs_; |
| 359 DISALLOW_COPY_AND_ASSIGN(SiteDetailsBrowserTest); | 327 DISALLOW_COPY_AND_ASSIGN(SiteDetailsBrowserTest); |
| 360 }; | 328 }; |
| 361 | 329 |
| 362 | 330 |
| 363 // Test the accuracy of SiteDetails process estimation, in the presence of | 331 // Test the accuracy of SiteDetails process estimation, in the presence of |
| 364 // multiple iframes, navigation, multiple BrowsingInstances, and multiple tabs | 332 // multiple iframes, navigation, multiple BrowsingInstances, and multiple tabs |
| 365 // in the same BrowsingInstance. | 333 // in the same BrowsingInstance. |
| 366 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, ManyIframes) { | 334 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, ManyIframes) { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(3, 3, 16)); | 613 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(3, 3, 16)); |
| 646 EXPECT_THAT(details->GetOutOfProcessIframeCount(), | 614 EXPECT_THAT(details->GetOutOfProcessIframeCount(), |
| 647 DependingOnPolicy(0, 0, 21)); | 615 DependingOnPolicy(0, 0, 21)); |
| 648 EXPECT_THAT(details->uma()->GetAllSamples("SiteIsolation.ProxyCount"), | 616 EXPECT_THAT(details->uma()->GetAllSamples("SiteIsolation.ProxyCount"), |
| 649 HasOneSample(DependingOnPolicy(0, 0, 114))); | 617 HasOneSample(DependingOnPolicy(0, 0, 114))); |
| 650 EXPECT_THAT(details->uma()->GetAllSamples( | 618 EXPECT_THAT(details->uma()->GetAllSamples( |
| 651 "SiteIsolation.ProxyCountPerBrowsingInstance"), | 619 "SiteIsolation.ProxyCountPerBrowsingInstance"), |
| 652 DependingOnPolicy( | 620 DependingOnPolicy( |
| 653 ElementsAre(Bucket(0, 3)), ElementsAre(Bucket(0, 3)), | 621 ElementsAre(Bucket(0, 3)), ElementsAre(Bucket(0, 3)), |
| 654 ElementsAre(Bucket(12, 1), Bucket(29, 1), Bucket(68, 1)))); | 622 ElementsAre(Bucket(12, 1), Bucket(29, 1), Bucket(68, 1)))); |
| 655 | |
| 656 // This test doesn't navigate to any extensions URLs, so it should not be | |
| 657 // in any of the field trial groups. | |
| 658 EXPECT_FALSE(IsInTrial("SiteIsolationExtensionsActive")); | |
| 659 } | 623 } |
| 660 | 624 |
| 661 // Flaky on Windows and Mac. crbug.com/671891 | 625 // Flaky on Windows and Mac. crbug.com/671891 |
| 662 #if defined(OS_WIN) || defined(OS_MACOSX) | 626 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 663 #define MAYBE_IsolateExtensions DISABLED_IsolateExtensions | 627 #define MAYBE_IsolateExtensions DISABLED_IsolateExtensions |
| 664 #else | 628 #else |
| 665 #define MAYBE_IsolateExtensions IsolateExtensions | 629 #define MAYBE_IsolateExtensions IsolateExtensions |
| 666 #endif | 630 #endif |
| 667 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, MAYBE_IsolateExtensions) { | 631 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, MAYBE_IsolateExtensions) { |
| 668 // We start on "about:blank", which should be credited with a process in this | 632 // We start on "about:blank", which should be credited with a process in this |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 HasOneSample(4)); | 895 HasOneSample(4)); |
| 932 EXPECT_THAT(details->uma()->GetAllSamples( | 896 EXPECT_THAT(details->uma()->GetAllSamples( |
| 933 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | 897 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), |
| 934 HasOneSample(3)); | 898 HasOneSample(3)); |
| 935 EXPECT_THAT(details->uma()->GetAllSamples( | 899 EXPECT_THAT(details->uma()->GetAllSamples( |
| 936 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | 900 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), |
| 937 HasOneSample(4)); | 901 HasOneSample(4)); |
| 938 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(2, 4, 4)); | 902 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(2, 4, 4)); |
| 939 EXPECT_THAT(details->GetOutOfProcessIframeCount(), | 903 EXPECT_THAT(details->GetOutOfProcessIframeCount(), |
| 940 DependingOnPolicy(0, 2, 2)); | 904 DependingOnPolicy(0, 2, 2)); |
| 941 | |
| 942 EXPECT_TRUE(IsInTrial("SiteIsolationExtensionsActive")); | |
| 943 } | 905 } |
| 944 | 906 |
| 945 // Due to http://crbug.com/612711, we are not isolating iframes from platform | 907 // Due to http://crbug.com/612711, we are not isolating iframes from platform |
| 946 // apps with --isolate-extenions. | 908 // apps with --isolate-extenions. |
| 947 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, PlatformAppsNotIsolated) { | 909 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, PlatformAppsNotIsolated) { |
| 948 // --site-per-process will still isolate iframes from platform apps, so skip | 910 // --site-per-process will still isolate iframes from platform apps, so skip |
| 949 // the test in that case. | 911 // the test in that case. |
| 950 if (content::AreAllSitesIsolatedForTesting()) | 912 if (content::AreAllSitesIsolatedForTesting()) |
| 951 return; | 913 return; |
| 952 CreateAppWithSandboxPage("Extension One"); | 914 CreateAppWithSandboxPage("Extension One"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 983 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | 945 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), |
| 984 HasOneSample(2)); | 946 HasOneSample(2)); |
| 985 EXPECT_THAT(details->uma()->GetAllSamples( | 947 EXPECT_THAT(details->uma()->GetAllSamples( |
| 986 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | 948 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), |
| 987 HasOneSample(2)); | 949 HasOneSample(2)); |
| 988 // TODO(nick): https://crbug.com/512560 Make the number below agree with the | 950 // TODO(nick): https://crbug.com/512560 Make the number below agree with the |
| 989 // estimates above, which assume consolidation of subframe processes. | 951 // estimates above, which assume consolidation of subframe processes. |
| 990 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(1, 3, 3)); | 952 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(1, 3, 3)); |
| 991 EXPECT_THAT(details->GetOutOfProcessIframeCount(), | 953 EXPECT_THAT(details->GetOutOfProcessIframeCount(), |
| 992 DependingOnPolicy(0, 2, 2)); | 954 DependingOnPolicy(0, 2, 2)); |
| 993 | |
| 994 EXPECT_TRUE(IsInTrial("SiteIsolationExtensionsActive")); | |
| 995 } | 955 } |
| 996 | 956 |
| 997 // Verifies that --isolate-extensions doesn't isolate hosted apps. | 957 // Verifies that --isolate-extensions doesn't isolate hosted apps. |
| 998 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, IsolateExtensionsHostedApps) { | 958 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, IsolateExtensionsHostedApps) { |
| 999 GURL app_with_web_iframe_url = embedded_test_server()->GetURL( | 959 GURL app_with_web_iframe_url = embedded_test_server()->GetURL( |
| 1000 "app.org", "/cross_site_iframe_factory.html?app.org(b.com)"); | 960 "app.org", "/cross_site_iframe_factory.html?app.org(b.com)"); |
| 1001 GURL app_in_web_iframe_url = embedded_test_server()->GetURL( | 961 GURL app_in_web_iframe_url = embedded_test_server()->GetURL( |
| 1002 "b.com", "/cross_site_iframe_factory.html?b.com(app.org)"); | 962 "b.com", "/cross_site_iframe_factory.html?b.com(app.org)"); |
| 1003 | 963 |
| 1004 // No hosted app is installed: app.org just behaves like a normal domain. | 964 // No hosted app is installed: app.org just behaves like a normal domain. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 HasOneSample(2)); | 1087 HasOneSample(2)); |
| 1128 EXPECT_THAT(details->uma()->GetAllSamples( | 1088 EXPECT_THAT(details->uma()->GetAllSamples( |
| 1129 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"), | 1089 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"), |
| 1130 HasOneSample(2)); | 1090 HasOneSample(2)); |
| 1131 EXPECT_THAT(details->uma()->GetAllSamples( | 1091 EXPECT_THAT(details->uma()->GetAllSamples( |
| 1132 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"), | 1092 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"), |
| 1133 HasOneSample(2)); | 1093 HasOneSample(2)); |
| 1134 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(1, 1, 2)); | 1094 EXPECT_THAT(GetRenderProcessCount(), DependingOnPolicy(1, 1, 2)); |
| 1135 EXPECT_THAT(details->GetOutOfProcessIframeCount(), | 1095 EXPECT_THAT(details->GetOutOfProcessIframeCount(), |
| 1136 DependingOnPolicy(0, 0, 1)); | 1096 DependingOnPolicy(0, 0, 1)); |
| 1137 | |
| 1138 // Since hosted apps are excluded from isolation, this test should not be | |
| 1139 // in any of the field trial groups. | |
| 1140 EXPECT_FALSE(IsInTrial("SiteIsolationExtensionsActive")); | |
| 1141 } | |
| 1142 | |
| 1143 // Verifies that the client is put in the appropriate field trial group. | |
| 1144 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, VerifyFieldTrialGroup) { | |
| 1145 const Extension* extension = CreateExtension("Extension", false); | |
| 1146 GURL tab1_url = embedded_test_server()->GetURL( | |
| 1147 "a.com", "/cross_site_iframe_factory.html?a(b,c)"); | |
| 1148 ui_test_utils::NavigateToURL(browser(), tab1_url); | |
| 1149 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 1150 | |
| 1151 // Tab navigates its second iframe to a page of the extension. | |
| 1152 content::NavigateIframeToURL(tab, "child-1", | |
| 1153 extension->GetResourceURL("/blank_iframe.html")); | |
| 1154 | |
| 1155 std::string group; | |
| 1156 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1157 switches::kSitePerProcess)) { | |
| 1158 group = "SitePerProcessFlag"; | |
| 1159 } else if (extensions::IsIsolateExtensionsEnabled()) { | |
| 1160 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1161 extensions::switches::kIsolateExtensions)) { | |
| 1162 group = "IsolateExtensionsFlag"; | |
| 1163 } else { | |
| 1164 group = "FieldTrial"; | |
| 1165 } | |
| 1166 } else { | |
| 1167 if (base::FieldTrialList::FindFullName("SiteIsolationExtensions").empty()) | |
| 1168 group = "Default"; | |
| 1169 else | |
| 1170 group = "Control"; | |
| 1171 } | |
| 1172 | |
| 1173 EXPECT_TRUE(IsInTrialGroup("SiteIsolationExtensionsActive", group)); | |
| 1174 } | 1097 } |
| 1175 | 1098 |
| 1176 // Verifies that the UMA counter for SiteInstances in a BrowsingInstance is | 1099 // Verifies that the UMA counter for SiteInstances in a BrowsingInstance is |
| 1177 // correct when using tabs with web pages. | 1100 // correct when using tabs with web pages. |
| 1178 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, | 1101 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, |
| 1179 VerifySiteInstanceCountInBrowsingInstance) { | 1102 VerifySiteInstanceCountInBrowsingInstance) { |
| 1180 // Page with 14 nested oopifs across 9 sites (a.com through i.com). | 1103 // Page with 14 nested oopifs across 9 sites (a.com through i.com). |
| 1181 GURL abcdefghi_url = embedded_test_server()->GetURL( | 1104 GURL abcdefghi_url = embedded_test_server()->GetURL( |
| 1182 "a.com", | 1105 "a.com", |
| 1183 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))"); | 1106 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))"); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 content::NavigateIframeToURL( | 1218 content::NavigateIframeToURL( |
| 1296 tab, "child-1", extension2->GetResourceURL("/blank_iframe.html")); | 1219 tab, "child-1", extension2->GetResourceURL("/blank_iframe.html")); |
| 1297 details = new TestMemoryDetails(); | 1220 details = new TestMemoryDetails(); |
| 1298 details->StartFetchAndWait(); | 1221 details->StartFetchAndWait(); |
| 1299 EXPECT_THAT(details->uma()->GetAllSamples( | 1222 EXPECT_THAT(details->uma()->GetAllSamples( |
| 1300 "SiteIsolation.SiteInstancesPerBrowsingInstance"), | 1223 "SiteIsolation.SiteInstancesPerBrowsingInstance"), |
| 1301 DependingOnPolicy(ElementsAre(Bucket(1, 2)), | 1224 DependingOnPolicy(ElementsAre(Bucket(1, 2)), |
| 1302 ElementsAre(Bucket(1, 1), Bucket(3, 1)), | 1225 ElementsAre(Bucket(1, 1), Bucket(3, 1)), |
| 1303 ElementsAre(Bucket(1, 1), Bucket(5, 1)))); | 1226 ElementsAre(Bucket(1, 1), Bucket(5, 1)))); |
| 1304 } | 1227 } |
| OLD | NEW |