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

Side by Side Diff: chrome/browser/site_details_browsertest.cc

Issue 1492033002: Add UMA histogram for the number of SiteInstances per BrowsingInstance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 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 "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 group = "IsolateExtensionsFlag"; 1028 group = "IsolateExtensionsFlag";
1029 } else { 1029 } else {
1030 group = "FieldTrial"; 1030 group = "FieldTrial";
1031 } 1031 }
1032 } else { 1032 } else {
1033 group = "Default"; 1033 group = "Default";
1034 } 1034 }
1035 1035
1036 EXPECT_TRUE(IsInTrialGroup("SiteIsolationExtensionsActive", group)); 1036 EXPECT_TRUE(IsInTrialGroup("SiteIsolationExtensionsActive", group));
1037 } 1037 }
1038
1039 // Verifies that the UMA counter for SiteInstances in a BrowsingInstance is
1040 // correct when using tabs with web pages.
1041 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest,
1042 VerifySiteInstanceCountInBrowsingInstance) {
1043 // Page with 14 nested oopifs across 9 sites (a.com through i.com).
1044 GURL abcdefghi_url = embedded_test_server()->GetURL(
1045 "a.com",
1046 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))");
1047 ui_test_utils::NavigateToURL(browser(), abcdefghi_url);
1048
1049 // Get the metrics.
1050 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails();
1051 details->StartFetchAndWait();
1052 if (content::AreAllSitesIsolatedForTesting()) {
1053 EXPECT_THAT(details->uma()->GetAllSamples(
1054 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1055 ElementsAre(Bucket(9, 1)));
1056 } else {
1057 // Since there are no extensions involved, the results in the default case
1058 // and extensions::IsIsolateExtensionsEnabled() are the same.
1059 EXPECT_THAT(details->uma()->GetAllSamples(
1060 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1061 ElementsAre(Bucket(1, 1)));
1062 }
1063
1064 // Open another tab through window.open(), which will be in the same
1065 // BrowsingInstance.
1066 GURL dcbae_url = embedded_test_server()->GetURL(
1067 "a.com", "/cross_site_iframe_factory.html?d(c(b(j(k))))");
1068 ui_test_utils::UrlLoadObserver load_complete(
1069 dcbae_url, content::NotificationService::AllSources());
1070 ASSERT_EQ(1, browser()->tab_strip_model()->count());
1071 ASSERT_TRUE(content::ExecuteScript(
1072 browser()->tab_strip_model()->GetActiveWebContents(),
1073 "window.open('" + dcbae_url.spec() + "');"));
1074 ASSERT_EQ(2, browser()->tab_strip_model()->count());
1075 load_complete.Wait();
1076
1077 details = new TestMemoryDetails();
1078 details->StartFetchAndWait();
1079 if (content::AreAllSitesIsolatedForTesting()) {
1080 EXPECT_THAT(details->uma()->GetAllSamples(
1081 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1082 ElementsAre(Bucket(11, 1)));
1083 } else {
1084 EXPECT_THAT(details->uma()->GetAllSamples(
1085 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1086 ElementsAre(Bucket(1, 1)));
1087 }
1088
1089 // Open a tab, which will be in a different BrowsingInstance.
1090 GURL abcd_url = embedded_test_server()->GetURL(
1091 "a.com", "/cross_site_iframe_factory.html?a(b(c(d())))");
1092 AddTabAtIndex(1, abcd_url, ui::PAGE_TRANSITION_TYPED);
1093
1094 details = new TestMemoryDetails();
1095 details->StartFetchAndWait();
1096 if (content::AreAllSitesIsolatedForTesting()) {
1097 EXPECT_THAT(details->uma()->GetAllSamples(
1098 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1099 ElementsAre(Bucket(4, 1), Bucket(11, 1)));
1100 } else {
1101 EXPECT_THAT(details->uma()->GetAllSamples(
1102 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1103 ElementsAre(Bucket(1, 2)));
1104 }
1105 }
1106
1107 // Verifies that the UMA counter for SiteInstances in a BrowsingInstance is
1108 // correct when extensions and web pages are mixed together.
1109 IN_PROC_BROWSER_TEST_F(
1110 SiteDetailsBrowserTest,
1111 VerifySiteInstanceCountInBrowsingInstanceWithExtensions) {
1112 // Open two a.com tabs (with cross site http iframes). IsolateExtensions mode
1113 // should have no effect so far, since there are no frames straddling the
1114 // extension/web boundary.
1115 GURL tab_url = embedded_test_server()->GetURL(
1116 "a.com", "/cross_site_iframe_factory.html?a(b,c,d(e))");
1117 ui_test_utils::NavigateToURL(browser(), tab_url);
1118 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0);
1119 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails();
1120 details->StartFetchAndWait();
1121 if (content::AreAllSitesIsolatedForTesting()) {
1122 EXPECT_THAT(details->uma()->GetAllSamples(
1123 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1124 ElementsAre(Bucket(5, 1)));
1125 } else {
1126 // Since there are no extensions loaded yet, the results in the default case
1127 // and extensions::IsIsolateExtensionsEnabled() are the same.
1128 EXPECT_THAT(details->uma()->GetAllSamples(
1129 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1130 ElementsAre(Bucket(1, 1)));
1131 }
1132
1133 // Load an extension without a background page, which will avoid creating a
1134 // BrowsingInstance for it.
1135 const Extension* extension1 = CreateExtension("Extension One", false);
1136
1137 // Navigate the tab's first iframe to a resource of the extension. The
1138 // extension iframe will be put in a separate BrowsingInstance (see
1139 // https://crbug.com/522302) unless in the default process model.
1140 content::NavigateIframeToURL(
1141 tab, "child-0", extension1->GetResourceURL("/blank_iframe.html"));
1142 details = new TestMemoryDetails();
1143 details->StartFetchAndWait();
1144 if (content::AreAllSitesIsolatedForTesting()) {
1145 EXPECT_THAT(details->uma()->GetAllSamples(
1146 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1147 ElementsAre(Bucket(1, 1), Bucket(4, 1)));
1148 } else if (extensions::IsIsolateExtensionsEnabled()) {
1149 EXPECT_THAT(details->uma()->GetAllSamples(
1150 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1151 ElementsAre(Bucket(1, 2)));
1152 } else {
1153 EXPECT_THAT(details->uma()->GetAllSamples(
1154 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1155 ElementsAre(Bucket(1, 1)));
1156 }
1157
1158 // Now load an extension with a background page. This will result in a
1159 // BrowsingInstance for the background page.
1160 const Extension* extension2 = CreateExtension("Extension One", true);
1161 details = new TestMemoryDetails();
1162 details->StartFetchAndWait();
1163 if (content::AreAllSitesIsolatedForTesting()) {
1164 EXPECT_THAT(details->uma()->GetAllSamples(
1165 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1166 ElementsAre(Bucket(1, 2), Bucket(4, 1)));
1167 } else if (extensions::IsIsolateExtensionsEnabled()) {
1168 EXPECT_THAT(details->uma()->GetAllSamples(
1169 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1170 ElementsAre(Bucket(1, 3)));
1171 } else {
1172 EXPECT_THAT(details->uma()->GetAllSamples(
1173 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1174 ElementsAre(Bucket(1, 2)));
1175 }
1176
1177 // Navigate the second iframe of the tab to the second extension. This will
1178 // create a new BrowsingInstance again due to https://crbug.com/522302 for
1179 // --site-per-process and --isolate-extensions.
1180 content::NavigateIframeToURL(
1181 tab, "child-1", extension2->GetResourceURL("/blank_iframe.html"));
1182 details = new TestMemoryDetails();
1183 details->StartFetchAndWait();
1184 if (content::AreAllSitesIsolatedForTesting()) {
1185 EXPECT_THAT(details->uma()->GetAllSamples(
1186 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1187 ElementsAre(Bucket(1, 3), Bucket(3, 1)));
1188 } else if (extensions::IsIsolateExtensionsEnabled()) {
1189 EXPECT_THAT(details->uma()->GetAllSamples(
1190 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1191 ElementsAre(Bucket(1, 4)));
1192 } else {
1193 EXPECT_THAT(details->uma()->GetAllSamples(
1194 "SiteIsolation.SiteInstancesPerBrowsingInstance"),
1195 ElementsAre(Bucket(1, 2)));
1196 }
1197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698