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 "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/files/file_path.h" | |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
12 #include "chrome/browser/extensions/extension_browsertest.h" | |
13 #include "chrome/browser/extensions/test_extension_dir.h" | |
11 #include "chrome/browser/metrics/metrics_memory_details.h" | 14 #include "chrome/browser/metrics/metrics_memory_details.h" |
12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/url_constants.h" | |
14 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
17 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
18 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
23 #include "extensions/common/value_builder.h" | |
19 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | |
22 | 28 |
23 using base::Bucket; | 29 using base::Bucket; |
30 using content::WebContents; | |
31 using extensions::DictionaryBuilder; | |
32 using extensions::Extension; | |
33 using extensions::ListBuilder; | |
34 using extensions::TestExtensionDir; | |
24 using testing::ContainerEq; | 35 using testing::ContainerEq; |
25 using testing::ElementsAre; | 36 using testing::ElementsAre; |
26 | 37 |
27 namespace { | 38 namespace { |
28 | 39 |
29 class TestMemoryDetails : public MetricsMemoryDetails { | 40 class TestMemoryDetails : public MetricsMemoryDetails { |
30 public: | 41 public: |
31 TestMemoryDetails() | 42 TestMemoryDetails() |
32 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} | 43 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} |
33 | 44 |
(...skipping 16 matching lines...) Expand all Loading... | |
50 base::MessageLoop::current()->Quit(); | 61 base::MessageLoop::current()->Quit(); |
51 } | 62 } |
52 | 63 |
53 scoped_ptr<base::HistogramTester> uma_; | 64 scoped_ptr<base::HistogramTester> uma_; |
54 | 65 |
55 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); | 66 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); |
56 }; | 67 }; |
57 | 68 |
58 } // namespace | 69 } // namespace |
59 | 70 |
60 class SiteDetailsBrowserTest : public InProcessBrowserTest { | 71 class SiteDetailsBrowserTest : public ExtensionBrowserTest { |
61 public: | 72 public: |
62 SiteDetailsBrowserTest() {} | 73 SiteDetailsBrowserTest() {} |
63 ~SiteDetailsBrowserTest() override {} | 74 ~SiteDetailsBrowserTest() override {} |
64 | 75 |
65 void SetUpOnMainThread() override { | 76 void SetUpOnMainThread() override { |
66 host_resolver()->AddRule("*", "127.0.0.1"); | 77 host_resolver()->AddRule("*", "127.0.0.1"); |
67 | 78 |
68 // Add content/test/data so we can use cross_site_iframe_factory.html | 79 // Add content/test/data so we can use cross_site_iframe_factory.html |
69 base::FilePath test_data_dir; | 80 base::FilePath test_data_dir; |
70 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); | 81 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); |
71 embedded_test_server()->ServeFilesFromDirectory( | 82 embedded_test_server()->ServeFilesFromDirectory( |
72 test_data_dir.AppendASCII("content/test/data/")); | 83 test_data_dir.AppendASCII("content/test/data/")); |
73 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 84 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
74 } | 85 } |
75 | 86 |
87 // Create and install an extension that has a couple of web-accessible | |
88 // resources and, optionally, a background process. | |
89 const Extension* CreateExtension(const std::string& name, | |
nasko
2015/09/04 22:19:43
Why create extension by writing it to the filesyst
ncarter (slow)
2015/09/10 19:08:59
First off: I'm using an established practice -- dy
nasko
2015/09/11 18:14:11
Thanks for the detailed answer!
| |
90 bool has_background_process) { | |
91 scoped_ptr<TestExtensionDir> dir(new TestExtensionDir); | |
92 | |
93 DictionaryBuilder manifest; | |
94 manifest.Set("name", name) | |
95 .Set("version", "1.0") | |
96 .Set("manifest_version", 2) | |
97 .Set("web_accessible_resources", ListBuilder() | |
98 .Append("blank_iframe.html") | |
99 .Append("http_iframe.html")); | |
100 | |
101 if (has_background_process) { | |
102 manifest.Set("background", | |
103 DictionaryBuilder().Set("scripts", | |
104 ListBuilder().Append("script.js"))); | |
105 dir->WriteFile(FILE_PATH_LITERAL("script.js"), | |
106 "console.log('" + name + " running');"); | |
107 } | |
108 | |
109 dir->WriteFile(FILE_PATH_LITERAL("blank_iframe.html"), | |
110 "<html><body>" + name + | |
111 ", blank iframe: " | |
112 "<iframe width=40 height=40></iframe></body></html>"); | |
113 GURL iframe_url = embedded_test_server()->GetURL("w.com", "/title1.html"); | |
114 dir->WriteFile(FILE_PATH_LITERAL("http_iframe.html"), | |
115 "<html><body>" + name + | |
116 ", http:// iframe: " | |
117 "<iframe width=40 height=40 src='" + | |
118 iframe_url.spec() + "'></iframe></body></html>"); | |
119 dir->WriteManifest(manifest.ToJSON()); | |
120 | |
121 const Extension* extension = LoadExtension(dir->unpacked_path()); | |
122 EXPECT_TRUE(extension); | |
123 temp_dirs_.push_back(dir.release()); | |
124 return extension; | |
125 } | |
126 | |
76 private: | 127 private: |
128 ScopedVector<TestExtensionDir> temp_dirs_; | |
77 DISALLOW_COPY_AND_ASSIGN(SiteDetailsBrowserTest); | 129 DISALLOW_COPY_AND_ASSIGN(SiteDetailsBrowserTest); |
78 }; | 130 }; |
79 | 131 |
80 // Test the accuracy of SiteDetails process estimation, in the presence of | 132 // Test the accuracy of SiteDetails process estimation, in the presence of |
81 // multiple iframes, navigation, multiple BrowsingInstances, and multiple tabs | 133 // multiple iframes, navigation, multiple BrowsingInstances, and multiple tabs |
82 // in the same BrowsingInstance. | 134 // in the same BrowsingInstance. |
83 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, ManyCrossSiteIframes) { | 135 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, ManyIframes) { |
84 // Page with 14 nested oopifs across 9 sites (a.com through i.com). | 136 // Page with 14 nested oopifs across 9 sites (a.com through i.com). |
85 // None of these are https. | 137 // None of these are https. |
86 GURL abcdefghi_url = embedded_test_server()->GetURL( | 138 GURL abcdefghi_url = embedded_test_server()->GetURL( |
87 "a.com", | 139 "a.com", |
88 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))"); | 140 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))"); |
89 ui_test_utils::NavigateToURL(browser(), abcdefghi_url); | 141 ui_test_utils::NavigateToURL(browser(), abcdefghi_url); |
90 | 142 |
91 // Get the metrics. | 143 // Get the metrics. |
92 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails(); | 144 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails(); |
93 details->StartFetchAndWait(); | 145 details->StartFetchAndWait(); |
(...skipping 15 matching lines...) Expand all Loading... | |
109 ElementsAre(Bucket(9, 1))); | 161 ElementsAre(Bucket(9, 1))); |
110 EXPECT_THAT(details->uma()->GetAllSamples( | 162 EXPECT_THAT(details->uma()->GetAllSamples( |
111 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), | 163 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), |
112 ElementsAre(Bucket(1, 1))); | 164 ElementsAre(Bucket(1, 1))); |
113 EXPECT_THAT(details->uma()->GetAllSamples( | 165 EXPECT_THAT(details->uma()->GetAllSamples( |
114 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), | 166 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), |
115 ElementsAre(Bucket(1, 1))); | 167 ElementsAre(Bucket(1, 1))); |
116 EXPECT_THAT(details->uma()->GetAllSamples( | 168 EXPECT_THAT(details->uma()->GetAllSamples( |
117 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), | 169 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), |
118 ElementsAre(Bucket(1, 1))); | 170 ElementsAre(Bucket(1, 1))); |
171 EXPECT_THAT(details->uma()->GetAllSamples( | |
172 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
173 ElementsAre(Bucket(1, 1))); | |
174 EXPECT_THAT(details->uma()->GetAllSamples( | |
175 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
176 ElementsAre(Bucket(1, 1))); | |
177 EXPECT_THAT(details->uma()->GetAllSamples( | |
178 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
179 ElementsAre(Bucket(1, 1))); | |
119 | 180 |
120 // Navigate to a different, disjoint set of 7 sites. | 181 // Navigate to a different, disjoint set of 7 sites. |
121 GURL pqrstuv_url = embedded_test_server()->GetURL( | 182 GURL pqrstuv_url = embedded_test_server()->GetURL( |
122 "p.com", | 183 "p.com", |
123 "/cross_site_iframe_factory.html?p(q(r),r(s),s(t),t(q),u(u),v(p))"); | 184 "/cross_site_iframe_factory.html?p(q(r),r(s),s(t),t(q),u(u),v(p))"); |
124 ui_test_utils::NavigateToURL(browser(), pqrstuv_url); | 185 ui_test_utils::NavigateToURL(browser(), pqrstuv_url); |
125 | 186 |
126 details = new TestMemoryDetails(); | 187 details = new TestMemoryDetails(); |
127 details->StartFetchAndWait(); | 188 details->StartFetchAndWait(); |
128 | 189 |
(...skipping 14 matching lines...) Expand all Loading... | |
143 ElementsAre(Bucket(7, 1))); | 204 ElementsAre(Bucket(7, 1))); |
144 EXPECT_THAT(details->uma()->GetAllSamples( | 205 EXPECT_THAT(details->uma()->GetAllSamples( |
145 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), | 206 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), |
146 ElementsAre(Bucket(1, 1))); | 207 ElementsAre(Bucket(1, 1))); |
147 EXPECT_THAT(details->uma()->GetAllSamples( | 208 EXPECT_THAT(details->uma()->GetAllSamples( |
148 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), | 209 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), |
149 ElementsAre(Bucket(1, 1))); | 210 ElementsAre(Bucket(1, 1))); |
150 EXPECT_THAT(details->uma()->GetAllSamples( | 211 EXPECT_THAT(details->uma()->GetAllSamples( |
151 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), | 212 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), |
152 ElementsAre(Bucket(1, 1))); | 213 ElementsAre(Bucket(1, 1))); |
214 EXPECT_THAT(details->uma()->GetAllSamples( | |
215 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
216 ElementsAre(Bucket(1, 1))); | |
217 EXPECT_THAT(details->uma()->GetAllSamples( | |
218 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
219 ElementsAre(Bucket(1, 1))); | |
220 EXPECT_THAT(details->uma()->GetAllSamples( | |
221 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
222 ElementsAre(Bucket(1, 1))); | |
153 | 223 |
154 // Open a second tab (different BrowsingInstance) with 4 sites (a through d). | 224 // Open a second tab (different BrowsingInstance) with 4 sites (a through d). |
155 GURL abcd_url = embedded_test_server()->GetURL( | 225 GURL abcd_url = embedded_test_server()->GetURL( |
156 "a.com", "/cross_site_iframe_factory.html?a(b(c(d())))"); | 226 "a.com", "/cross_site_iframe_factory.html?a(b(c(d())))"); |
157 AddTabAtIndex(1, abcd_url, ui::PAGE_TRANSITION_TYPED); | 227 AddTabAtIndex(1, abcd_url, ui::PAGE_TRANSITION_TYPED); |
158 | 228 |
159 details = new TestMemoryDetails(); | 229 details = new TestMemoryDetails(); |
160 details->StartFetchAndWait(); | 230 details->StartFetchAndWait(); |
161 | 231 |
162 EXPECT_THAT( | 232 EXPECT_THAT( |
(...skipping 13 matching lines...) Expand all Loading... | |
176 ElementsAre(Bucket(11, 1))); | 246 ElementsAre(Bucket(11, 1))); |
177 EXPECT_THAT(details->uma()->GetAllSamples( | 247 EXPECT_THAT(details->uma()->GetAllSamples( |
178 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), | 248 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), |
179 ElementsAre(Bucket(2, 1))); | 249 ElementsAre(Bucket(2, 1))); |
180 EXPECT_THAT(details->uma()->GetAllSamples( | 250 EXPECT_THAT(details->uma()->GetAllSamples( |
181 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), | 251 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), |
182 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 2. | 252 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 2. |
183 EXPECT_THAT(details->uma()->GetAllSamples( | 253 EXPECT_THAT(details->uma()->GetAllSamples( |
184 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), | 254 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), |
185 ElementsAre(Bucket(2, 1))); | 255 ElementsAre(Bucket(2, 1))); |
256 EXPECT_THAT(details->uma()->GetAllSamples( | |
257 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
258 ElementsAre(Bucket(2, 1))); | |
259 EXPECT_THAT(details->uma()->GetAllSamples( | |
260 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
261 ElementsAre(Bucket(1, 1))); | |
262 EXPECT_THAT(details->uma()->GetAllSamples( | |
263 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
264 ElementsAre(Bucket(2, 1))); | |
186 | 265 |
187 // Open a third tab (different BrowsingInstance) with the same 4 sites. | 266 // Open a third tab (different BrowsingInstance) with the same 4 sites. |
188 AddTabAtIndex(2, abcd_url, ui::PAGE_TRANSITION_TYPED); | 267 AddTabAtIndex(2, abcd_url, ui::PAGE_TRANSITION_TYPED); |
189 | 268 |
190 details = new TestMemoryDetails(); | 269 details = new TestMemoryDetails(); |
191 details->StartFetchAndWait(); | 270 details->StartFetchAndWait(); |
192 | 271 |
193 EXPECT_THAT( | 272 EXPECT_THAT( |
194 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"), | 273 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"), |
195 ElementsAre(Bucket(3, 1))); | 274 ElementsAre(Bucket(3, 1))); |
(...skipping 12 matching lines...) Expand all Loading... | |
208 ElementsAre(Bucket(15, 1))); | 287 ElementsAre(Bucket(15, 1))); |
209 EXPECT_THAT(details->uma()->GetAllSamples( | 288 EXPECT_THAT(details->uma()->GetAllSamples( |
210 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), | 289 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), |
211 ElementsAre(Bucket(3, 1))); | 290 ElementsAre(Bucket(3, 1))); |
212 EXPECT_THAT(details->uma()->GetAllSamples( | 291 EXPECT_THAT(details->uma()->GetAllSamples( |
213 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), | 292 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), |
214 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3. | 293 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3. |
215 EXPECT_THAT(details->uma()->GetAllSamples( | 294 EXPECT_THAT(details->uma()->GetAllSamples( |
216 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), | 295 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), |
217 ElementsAre(Bucket(3, 1))); | 296 ElementsAre(Bucket(3, 1))); |
297 EXPECT_THAT(details->uma()->GetAllSamples( | |
298 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
299 ElementsAre(Bucket(3, 1))); | |
300 EXPECT_THAT(details->uma()->GetAllSamples( | |
301 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
302 ElementsAre(Bucket(1, 1))); | |
303 EXPECT_THAT(details->uma()->GetAllSamples( | |
304 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
305 ElementsAre(Bucket(3, 1))); | |
218 | 306 |
219 // Do a window.open() to obtain a fourth tab in the same BrowsingInstance as | 307 // From the third tab, window.open() a fourth tab in the same |
220 // the third tab. The new page uses the same four sites "a-d" as third tab, | 308 // BrowsingInstance, to a page using the same four sites "a-d" as third tab, |
221 // plus an additional site "e". The estimated process counts should increase | 309 // plus an additional site "e". The estimated process counts should increase |
222 // by one (not five) from the previous result, since the new tab can reuse the | 310 // by one (not five) from the previous scenario, as the new tab can reuse the |
223 // four processes already in the BrowsingInstance. | 311 // four processes already in the BrowsingInstance. |
224 GURL dcbae_url = embedded_test_server()->GetURL( | 312 GURL dcbae_url = embedded_test_server()->GetURL( |
225 "a.com", "/cross_site_iframe_factory.html?d(c(b(a(e))))"); | 313 "a.com", "/cross_site_iframe_factory.html?d(c(b(a(e))))"); |
226 ui_test_utils::UrlLoadObserver load_complete( | 314 ui_test_utils::UrlLoadObserver load_complete( |
227 dcbae_url, content::NotificationService::AllSources()); | 315 dcbae_url, content::NotificationService::AllSources()); |
228 ASSERT_EQ(3, browser()->tab_strip_model()->count()); | 316 ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
229 ASSERT_TRUE(content::ExecuteScript( | 317 ASSERT_TRUE(content::ExecuteScript( |
230 browser()->tab_strip_model()->GetActiveWebContents(), | 318 browser()->tab_strip_model()->GetActiveWebContents(), |
231 "window.open('" + dcbae_url.spec() + "');")); | 319 "window.open('" + dcbae_url.spec() + "');")); |
232 ASSERT_EQ(4, browser()->tab_strip_model()->count()); | 320 ASSERT_EQ(4, browser()->tab_strip_model()->count()); |
(...skipping 20 matching lines...) Expand all Loading... | |
253 ElementsAre(Bucket(16, 1))); | 341 ElementsAre(Bucket(16, 1))); |
254 EXPECT_THAT(details->uma()->GetAllSamples( | 342 EXPECT_THAT(details->uma()->GetAllSamples( |
255 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), | 343 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"), |
256 ElementsAre(Bucket(3, 1))); | 344 ElementsAre(Bucket(3, 1))); |
257 EXPECT_THAT(details->uma()->GetAllSamples( | 345 EXPECT_THAT(details->uma()->GetAllSamples( |
258 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), | 346 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"), |
259 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3. | 347 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3. |
260 EXPECT_THAT(details->uma()->GetAllSamples( | 348 EXPECT_THAT(details->uma()->GetAllSamples( |
261 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), | 349 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"), |
262 ElementsAre(Bucket(3, 1))); | 350 ElementsAre(Bucket(3, 1))); |
351 EXPECT_THAT(details->uma()->GetAllSamples( | |
352 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
353 ElementsAre(Bucket(3, 1))); | |
354 EXPECT_THAT(details->uma()->GetAllSamples( | |
355 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
356 ElementsAre(Bucket(1, 1))); | |
357 EXPECT_THAT(details->uma()->GetAllSamples( | |
358 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
359 ElementsAre(Bucket(3, 1))); | |
263 } | 360 } |
361 | |
362 IN_PROC_BROWSER_TEST_F(SiteDetailsBrowserTest, IsolateExtensions) { | |
363 // We start on "about:blank", which should be credited with a process in this | |
364 // case. | |
365 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails(); | |
366 details->StartFetchAndWait(); | |
367 EXPECT_THAT(details->uma()->GetAllSamples( | |
368 "SiteIsolation.CurrentRendererProcessCount"), | |
369 ElementsAre(Bucket(1, 1))); | |
370 EXPECT_THAT(details->uma()->GetAllSamples( | |
371 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
372 ElementsAre(Bucket(1, 1))); | |
373 EXPECT_THAT(details->uma()->GetAllSamples( | |
374 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
375 ElementsAre(Bucket(1, 1))); | |
376 EXPECT_THAT(details->uma()->GetAllSamples( | |
377 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
378 ElementsAre(Bucket(1, 1))); | |
379 | |
380 // Install one script-injecting extension with background page, and an | |
381 // extension with web accessible resources. | |
382 const Extension* extension1 = CreateExtension("Extension One", true); | |
383 const Extension* extension2 = CreateExtension("Extension Two", false); | |
384 | |
385 // Open two a.com tabs (with cross site http iframes). IsolateExtensions mode | |
386 // should have no effect so far, since there are no frames straddling the | |
387 // extension/web boundary. | |
388 GURL tab1_url = embedded_test_server()->GetURL( | |
389 "a.com", "/cross_site_iframe_factory.html?a(b,c)"); | |
390 ui_test_utils::NavigateToURL(browser(), tab1_url); | |
391 WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(0); | |
392 GURL tab2_url = embedded_test_server()->GetURL( | |
393 "a.com", "/cross_site_iframe_factory.html?a(d,e)"); | |
394 AddTabAtIndex(1, tab2_url, ui::PAGE_TRANSITION_TYPED); | |
395 WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(1); | |
396 | |
397 details = new TestMemoryDetails(); | |
398 details->StartFetchAndWait(); | |
399 EXPECT_THAT(details->uma()->GetAllSamples( | |
400 "SiteIsolation.CurrentRendererProcessCount"), | |
401 ElementsAre(Bucket(3, 1))); | |
402 EXPECT_THAT(details->uma()->GetAllSamples( | |
403 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
404 ElementsAre(Bucket(3, 1))); | |
405 EXPECT_THAT(details->uma()->GetAllSamples( | |
406 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
407 ElementsAre(Bucket(2, 1))); | |
408 EXPECT_THAT(details->uma()->GetAllSamples( | |
409 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
410 ElementsAre(Bucket(3, 1))); | |
411 | |
412 // Test that "one process per extension" applies even when web content has an | |
413 // extension iframe. | |
414 | |
415 // Tab1 navigates its first iframe to a resource of extension1. This shouldn't | |
416 // result in a new extension process (it should share with extension1's | |
417 // background page). | |
418 content::NavigateIframeToURL( | |
419 tab1, "child-0", extension1->GetResourceURL("/blank_iframe.html")); | |
420 details = new TestMemoryDetails(); | |
421 details->StartFetchAndWait(); | |
422 EXPECT_THAT(details->uma()->GetAllSamples( | |
423 "SiteIsolation.CurrentRendererProcessCount"), | |
424 ElementsAre(Bucket(3, 1))); | |
425 EXPECT_THAT(details->uma()->GetAllSamples( | |
426 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
427 ElementsAre(Bucket(3, 1))); | |
428 EXPECT_THAT(details->uma()->GetAllSamples( | |
429 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
430 ElementsAre(Bucket(2, 1))); | |
431 EXPECT_THAT(details->uma()->GetAllSamples( | |
432 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
433 ElementsAre(Bucket(3, 1))); | |
434 | |
435 // Tab2 navigates its first iframe to a resource of extension1. This also | |
436 // shouldn't result in a new extension process (it should share with the | |
437 // background page and the other iframe). | |
438 content::NavigateIframeToURL( | |
439 tab2, "child-0", extension1->GetResourceURL("/blank_iframe.html")); | |
440 details = new TestMemoryDetails(); | |
441 details->StartFetchAndWait(); | |
442 EXPECT_THAT(details->uma()->GetAllSamples( | |
443 "SiteIsolation.CurrentRendererProcessCount"), | |
444 ElementsAre(Bucket(3, 1))); | |
445 EXPECT_THAT(details->uma()->GetAllSamples( | |
446 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
447 ElementsAre(Bucket(3, 1))); | |
448 EXPECT_THAT(details->uma()->GetAllSamples( | |
449 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
450 ElementsAre(Bucket(2, 1))); | |
451 EXPECT_THAT(details->uma()->GetAllSamples( | |
452 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
453 ElementsAre(Bucket(3, 1))); | |
454 | |
455 // Tab1 navigates its second iframe to a resource of extension2. This SHOULD | |
456 // result in a new process since extension2 had no existing process. | |
457 content::NavigateIframeToURL( | |
458 tab1, "child-1", extension2->GetResourceURL("/blank_iframe.html")); | |
459 details = new TestMemoryDetails(); | |
460 details->StartFetchAndWait(); | |
461 EXPECT_THAT(details->uma()->GetAllSamples( | |
462 "SiteIsolation.CurrentRendererProcessCount"), | |
463 ElementsAre(Bucket(3, 1))); | |
464 EXPECT_THAT(details->uma()->GetAllSamples( | |
465 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
466 ElementsAre(Bucket(4, 1))); | |
467 EXPECT_THAT(details->uma()->GetAllSamples( | |
468 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
469 ElementsAre(Bucket(3, 1))); | |
470 EXPECT_THAT(details->uma()->GetAllSamples( | |
471 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
472 ElementsAre(Bucket(4, 1))); | |
473 | |
474 // Tab2 navigates its second iframe to a resource of extension2. This should | |
475 // share the existing extension2 process. | |
476 content::NavigateIframeToURL( | |
477 tab2, "child-1", extension2->GetResourceURL("/blank_iframe.html")); | |
478 details = new TestMemoryDetails(); | |
479 details->StartFetchAndWait(); | |
480 EXPECT_THAT(details->uma()->GetAllSamples( | |
481 "SiteIsolation.CurrentRendererProcessCount"), | |
482 ElementsAre(Bucket(3, 1))); | |
483 EXPECT_THAT(details->uma()->GetAllSamples( | |
484 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
485 ElementsAre(Bucket(4, 1))); | |
486 EXPECT_THAT(details->uma()->GetAllSamples( | |
487 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
488 ElementsAre(Bucket(3, 1))); | |
489 EXPECT_THAT(details->uma()->GetAllSamples( | |
490 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
491 ElementsAre(Bucket(4, 1))); | |
492 | |
493 // Install extension3 (identical config to extension2) | |
494 const Extension* extension3 = CreateExtension("Extension Three", false); | |
495 | |
496 // Navigate Tab2 to a top-level page from extension3. | |
nasko
2015/09/04 22:19:43
It is useful to state verbally what we expect to c
ncarter (slow)
2015/09/10 19:08:59
Done.
| |
497 ui_test_utils::NavigateToURL(browser(), | |
498 extension3->GetResourceURL("blank_iframe.html")); | |
499 details = new TestMemoryDetails(); | |
500 details->StartFetchAndWait(); | |
501 EXPECT_THAT(details->uma()->GetAllSamples( | |
502 "SiteIsolation.CurrentRendererProcessCount"), | |
503 ElementsAre(Bucket(3, 1))); | |
504 EXPECT_THAT(details->uma()->GetAllSamples( | |
505 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
506 ElementsAre(Bucket(4, 1))); | |
507 EXPECT_THAT(details->uma()->GetAllSamples( | |
508 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
509 ElementsAre(Bucket(4, 1))); | |
510 EXPECT_THAT(details->uma()->GetAllSamples( | |
511 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
512 ElementsAre(Bucket(4, 1))); | |
513 | |
514 // Add a web iframe to the chrome-extension:// page. This should create a new | |
nasko
2015/09/04 22:19:43
You aren't really adding it to a page, rather navi
ncarter (slow)
2015/09/10 19:08:59
Done.
| |
515 // process. | |
516 ui_test_utils::NavigateToURL(browser(), | |
517 extension3->GetResourceURL("http_iframe.html")); | |
518 details = new TestMemoryDetails(); | |
519 details->StartFetchAndWait(); | |
520 EXPECT_THAT(details->uma()->GetAllSamples( | |
521 "SiteIsolation.CurrentRendererProcessCount"), | |
522 ElementsAre(Bucket(3, 1))); | |
523 EXPECT_THAT(details->uma()->GetAllSamples( | |
524 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
525 ElementsAre(Bucket(5, 1))); | |
526 EXPECT_THAT(details->uma()->GetAllSamples( | |
527 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
528 ElementsAre(Bucket(4, 1))); | |
529 EXPECT_THAT(details->uma()->GetAllSamples( | |
530 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
531 ElementsAre(Bucket(5, 1))); | |
532 | |
533 // Navigate tab1 to the extension3 page. There should be 3 processes estimated | |
534 // by IsolateExtensions: one for extension3, one for extension1's background | |
535 // page, and one for the web iframe in tab2. | |
536 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
537 ui_test_utils::NavigateToURL(browser(), | |
538 extension3->GetResourceURL("blank_iframe.html")); | |
539 details = new TestMemoryDetails(); | |
540 details->StartFetchAndWait(); | |
541 | |
nasko
2015/09/04 22:19:43
No need for empty line, to stay consistent with co
ncarter (slow)
2015/09/10 19:08:59
Done.
| |
542 EXPECT_THAT(details->uma()->GetAllSamples( | |
543 "SiteIsolation.CurrentRendererProcessCount"), | |
544 ElementsAre(Bucket(2, 1))); | |
545 EXPECT_THAT(details->uma()->GetAllSamples( | |
546 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
547 ElementsAre(Bucket(3, 1))); | |
548 EXPECT_THAT(details->uma()->GetAllSamples( | |
549 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
550 ElementsAre(Bucket(3, 1))); | |
551 EXPECT_THAT(details->uma()->GetAllSamples( | |
552 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
553 ElementsAre(Bucket(3, 1))); | |
554 | |
555 // Put a web iframe in tab1 as well. This could share a process with tab2's | |
556 // iframe (the LowerBound number), or it could get its own process (the | |
557 // Estimate number). | |
558 ui_test_utils::NavigateToURL(browser(), | |
559 extension3->GetResourceURL("http_iframe.html")); | |
560 details = new TestMemoryDetails(); | |
561 details->StartFetchAndWait(); | |
562 | |
nasko
2015/09/04 22:19:43
No need for empty line, to stay consistent with co
ncarter (slow)
2015/09/10 19:08:59
Done.
| |
563 EXPECT_THAT(details->uma()->GetAllSamples( | |
564 "SiteIsolation.CurrentRendererProcessCount"), | |
565 ElementsAre(Bucket(2, 1))); | |
566 EXPECT_THAT(details->uma()->GetAllSamples( | |
567 "SiteIsolation.IsolateExtensionsProcessCountEstimate"), | |
568 ElementsAre(Bucket(4, 1))); | |
569 EXPECT_THAT(details->uma()->GetAllSamples( | |
570 "SiteIsolation.IsolateExtensionsProcessCountLowerBound"), | |
571 ElementsAre(Bucket(3, 1))); | |
572 EXPECT_THAT(details->uma()->GetAllSamples( | |
573 "SiteIsolation.IsolateExtensionsProcessCountNoLimit"), | |
574 ElementsAre(Bucket(4, 1))); | |
575 } | |
OLD | NEW |