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

Side by Side Diff: chrome/browser/metrics/metrics_memory_details_browsertest.cc

Issue 1264923002: Introduce cross_site_iframe_factory.html, and use it in a test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unittest.html, since I don't know how to hook it up. Created 5 years, 4 months 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/metrics/metrics_memory_details.h" 5 #include "chrome/browser/metrics/metrics_memory_details.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
9 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
18 #include "net/dns/mock_host_resolver.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21
22 using base::Bucket;
23 using testing::ContainerEq;
24 using testing::ElementsAre;
12 25
13 namespace { 26 namespace {
14 27
15 class TestMemoryDetails : public MetricsMemoryDetails { 28 class TestMemoryDetails : public MetricsMemoryDetails {
16 public: 29 public:
17 TestMemoryDetails() 30 TestMemoryDetails()
18 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} 31 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {}
19 32
20 void StartFetchAndWait() { 33 void StartFetchAndWait() {
34 uma_.reset(new base::HistogramTester());
21 StartFetch(FROM_CHROME_ONLY); 35 StartFetch(FROM_CHROME_ONLY);
22 content::RunMessageLoop(); 36 content::RunMessageLoop();
23 } 37 }
24 38
39 // Returns a HistogramTester which observed the most recent call to
40 // StartFetchAndWait().
41 base::HistogramTester* uma() { return uma_.get(); }
42
25 private: 43 private:
26 ~TestMemoryDetails() override {} 44 ~TestMemoryDetails() override {}
27 45
28 void OnDetailsAvailable() override { 46 void OnDetailsAvailable() override {
29 MetricsMemoryDetails::OnDetailsAvailable(); 47 MetricsMemoryDetails::OnDetailsAvailable();
30 // Exit the loop initiated by StartFetchAndWait(). 48 // Exit the loop initiated by StartFetchAndWait().
31 base::MessageLoop::current()->Quit(); 49 base::MessageLoop::current()->Quit();
32 } 50 }
33 51
52 scoped_ptr<base::HistogramTester> uma_;
53
34 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); 54 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails);
35 }; 55 };
36 56
37 } // namespace 57 } // namespace
38 58
39 class MetricsMemoryDetailsBrowserTest : public InProcessBrowserTest { 59 class MetricsMemoryDetailsBrowserTest : public InProcessBrowserTest {
40 public: 60 public:
41 MetricsMemoryDetailsBrowserTest() {} 61 MetricsMemoryDetailsBrowserTest() {}
42 ~MetricsMemoryDetailsBrowserTest() override {} 62 ~MetricsMemoryDetailsBrowserTest() override {}
43 63
64 void SetUpOnMainThread() override {
65 host_resolver()->AddRule("*", "127.0.0.1");
66
67 // Add content/test/data so we can use cross_site_iframe_factory.html
68 base::FilePath test_data_dir;
69 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
70 embedded_test_server()->ServeFilesFromDirectory(
71 test_data_dir.AppendASCII("content/test/data/"));
72 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
73 }
74
44 private: 75 private:
45 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest); 76 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest);
46 }; 77 };
47 78
48 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestMemoryDetails) { 79 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestMemoryDetails) {
49 base::HistogramTester histogram_tester;
50
51 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); 80 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails);
52 details->StartFetchAndWait(); 81 details->StartFetchAndWait();
53 82
54 // Memory.Browser histogram should have a single non-0 sample recorded. 83 // Memory.Browser histogram should have a single non-0 sample recorded.
55 histogram_tester.ExpectTotalCount("Memory.Browser", 1); 84 details->uma()->ExpectTotalCount("Memory.Browser", 1);
56 scoped_ptr<base::HistogramSamples> samples( 85 scoped_ptr<base::HistogramSamples> samples(
57 histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser")); 86 details->uma()->GetHistogramSamplesSinceCreation("Memory.Browser"));
58 ASSERT_TRUE(samples); 87 ASSERT_TRUE(samples);
59 EXPECT_NE(0, samples->sum()); 88 EXPECT_NE(0, samples->sum());
60 } 89 }
90
91 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestSiteIsolation) {
92 // Page with 14 nested oopifs across 9 sites (a.com through i.com).
93 // None of these are https.
94 GURL abcdefghi_url = embedded_test_server()->GetURL(
95 "a.com",
96 "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))");
97 ui_test_utils::NavigateToURL(browser(), abcdefghi_url);
98
99 // Get the metrics.
100 scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails();
101 details->StartFetchAndWait();
102
103 EXPECT_THAT(
104 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
Alexei Svitkine (slow) 2015/08/05 18:46:47 These histograms are logged by site_details.cc. Pe
ncarter (slow) 2015/08/05 22:52:03 This is as much a test of what MemoryMetricsDetail
Alexei Svitkine (slow) 2015/08/06 14:45:03 So one issue is that we'll likely want to componen
105 ElementsAre(Bucket(1, 1)));
106 EXPECT_THAT(details->uma()->GetAllSamples(
107 "SiteIsolation.CurrentRendererProcessCount"),
108 ElementsAre(Bucket(1, 1)));
109 EXPECT_THAT(details->uma()->GetAllSamples(
110 "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
111 ElementsAre(Bucket(9, 1)));
112 EXPECT_THAT(details->uma()->GetAllSamples(
113 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
114 ElementsAre(Bucket(9, 1)));
115 EXPECT_THAT(details->uma()->GetAllSamples(
116 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
117 ElementsAre(Bucket(9, 1)));
118 EXPECT_THAT(details->uma()->GetAllSamples(
119 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
120 ElementsAre(Bucket(11, 1)));
121 EXPECT_THAT(details->uma()->GetAllSamples(
122 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
123 ElementsAre(Bucket(1, 1)));
124 EXPECT_THAT(details->uma()->GetAllSamples(
125 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
126 ElementsAre(Bucket(1, 1)));
127 EXPECT_THAT(details->uma()->GetAllSamples(
128 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
129 ElementsAre(Bucket(1, 1)));
130 EXPECT_THAT(details->uma()->GetAllSamples(
131 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
132 ElementsAre(Bucket(3, 1)));
133
134 // Navigate to a different, disjoint set of 7 sites.
135 GURL pqrstuv_url = embedded_test_server()->GetURL(
136 "p.com",
137 "/cross_site_iframe_factory.html?p(q(r),r(s),s(t),t(q),u(u),v(p))");
138 ui_test_utils::NavigateToURL(browser(), pqrstuv_url);
139
140 details = new TestMemoryDetails();
141 details->StartFetchAndWait();
142
143 EXPECT_THAT(
144 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
145 ElementsAre(Bucket(1, 1)));
146 EXPECT_THAT(details->uma()->GetAllSamples(
147 "SiteIsolation.CurrentRendererProcessCount"),
148 ElementsAre(Bucket(1, 1)));
149 EXPECT_THAT(details->uma()->GetAllSamples(
150 "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
151 ElementsAre(Bucket(7, 1)));
152 EXPECT_THAT(details->uma()->GetAllSamples(
153 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
154 ElementsAre(Bucket(7, 1)));
155 EXPECT_THAT(details->uma()->GetAllSamples(
156 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
157 ElementsAre(Bucket(7, 1)));
158 EXPECT_THAT(details->uma()->GetAllSamples(
159 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
160 ElementsAre(Bucket(9, 1)));
161 EXPECT_THAT(details->uma()->GetAllSamples(
162 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
163 ElementsAre(Bucket(1, 1)));
164 EXPECT_THAT(details->uma()->GetAllSamples(
165 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
166 ElementsAre(Bucket(1, 1)));
167 EXPECT_THAT(details->uma()->GetAllSamples(
168 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
169 ElementsAre(Bucket(1, 1)));
170 EXPECT_THAT(details->uma()->GetAllSamples(
171 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
172 ElementsAre(Bucket(3, 1)));
173
174 // Open a second tab (different browsing instance) with 4 sites (a through d).
175 GURL abcd_url = embedded_test_server()->GetURL(
176 "a.com", "/cross_site_iframe_factory.html?a(b(c(d())))");
177 AddTabAtIndex(1, abcd_url, ui::PAGE_TRANSITION_TYPED);
178
179 details = new TestMemoryDetails();
180 details->StartFetchAndWait();
181
182 EXPECT_THAT(
183 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
184 ElementsAre(Bucket(2, 1)));
185 EXPECT_THAT(details->uma()->GetAllSamples(
186 "SiteIsolation.CurrentRendererProcessCount"),
187 ElementsAre(Bucket(2, 1)));
188 EXPECT_THAT(details->uma()->GetAllSamples(
189 "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
190 ElementsAre(Bucket(11, 1)));
191 EXPECT_THAT(details->uma()->GetAllSamples(
192 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
193 ElementsAre(Bucket(11, 1)));
194 EXPECT_THAT(details->uma()->GetAllSamples(
195 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
196 ElementsAre(Bucket(11, 1)));
197 EXPECT_THAT(details->uma()->GetAllSamples(
198 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
199 ElementsAre(Bucket(13, 1)));
200 EXPECT_THAT(details->uma()->GetAllSamples(
201 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
202 ElementsAre(Bucket(2, 1)));
203 EXPECT_THAT(details->uma()->GetAllSamples(
204 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
205 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 2.
206 EXPECT_THAT(details->uma()->GetAllSamples(
207 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
208 ElementsAre(Bucket(2, 1)));
209 EXPECT_THAT(details->uma()->GetAllSamples(
210 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
211 ElementsAre(Bucket(4, 1)));
212
213 // Open a third tab (different browsing instance) with the same 4 sites.
214 AddTabAtIndex(2, abcd_url, ui::PAGE_TRANSITION_TYPED);
215
216 details = new TestMemoryDetails();
217 details->StartFetchAndWait();
218
219 EXPECT_THAT(
220 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
221 ElementsAre(Bucket(3, 1)));
222 EXPECT_THAT(details->uma()->GetAllSamples(
223 "SiteIsolation.CurrentRendererProcessCount"),
224 ElementsAre(Bucket(3, 1)));
225 // Could be 11 if subframe processes were reused across browsing instances.
226 EXPECT_THAT(details->uma()->GetAllSamples(
227 "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
228 ElementsAre(Bucket(15, 1)));
229 EXPECT_THAT(details->uma()->GetAllSamples(
230 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
231 ElementsAre(Bucket(11, 1)));
232 EXPECT_THAT(details->uma()->GetAllSamples(
233 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
234 ElementsAre(Bucket(15, 1)));
235 EXPECT_THAT(details->uma()->GetAllSamples(
236 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
237 ElementsAre(Bucket(17, 1)));
238 EXPECT_THAT(details->uma()->GetAllSamples(
239 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
240 ElementsAre(Bucket(3, 1)));
241 EXPECT_THAT(details->uma()->GetAllSamples(
242 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
243 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3.
244 EXPECT_THAT(details->uma()->GetAllSamples(
245 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
246 ElementsAre(Bucket(3, 1)));
247 EXPECT_THAT(details->uma()->GetAllSamples(
248 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
249 ElementsAre(Bucket(5, 1)));
250
251 // From the third tab, window.open() a fourth tab in the same browsing
252 // instance, to a page using the same four sites "a-d" as third tab, plus an
253 // additional site "e". The estimated process counts should increase by one
254 // (not five) from the previous scenario, as the new tab can reuse the four
255 // processes already in the BrowsingInstance.
256 GURL dcbae_url = embedded_test_server()->GetURL(
257 "a.com", "/cross_site_iframe_factory.html?d(c(b(a(e))))");
258 ui_test_utils::UrlLoadObserver load_complete(
259 dcbae_url, content::NotificationService::AllSources());
260 ASSERT_EQ(3, browser()->tab_strip_model()->count());
261 ASSERT_TRUE(content::ExecuteScript(
262 browser()->tab_strip_model()->GetActiveWebContents(),
263 "window.open('" + dcbae_url.spec() + "');"));
264 ASSERT_EQ(4, browser()->tab_strip_model()->count());
265 load_complete.Wait();
266
267 details = new TestMemoryDetails();
268 details->StartFetchAndWait();
269
270 EXPECT_THAT(
271 details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
272 ElementsAre(Bucket(3, 1)));
273 EXPECT_THAT(details->uma()->GetAllSamples(
274 "SiteIsolation.CurrentRendererProcessCount"),
275 ElementsAre(Bucket(3, 1)));
276 // Could be 11 if subframe processes were reused across browsing instances.
277 EXPECT_THAT(details->uma()->GetAllSamples(
278 "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
279 ElementsAre(Bucket(16, 1)));
280 EXPECT_THAT(details->uma()->GetAllSamples(
281 "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
282 ElementsAre(Bucket(12, 1)));
283 EXPECT_THAT(details->uma()->GetAllSamples(
284 "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
285 ElementsAre(Bucket(16, 1)));
286 EXPECT_THAT(details->uma()->GetAllSamples(
287 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
288 ElementsAre(Bucket(18, 1)));
289 EXPECT_THAT(details->uma()->GetAllSamples(
290 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
291 ElementsAre(Bucket(3, 1)));
292 EXPECT_THAT(details->uma()->GetAllSamples(
293 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
294 ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3.
295 EXPECT_THAT(details->uma()->GetAllSamples(
296 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
297 ElementsAre(Bucket(3, 1)));
298 EXPECT_THAT(details->uma()->GetAllSamples(
299 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
300 ElementsAre(Bucket(5, 1)));
301 }
OLDNEW
« no previous file with comments | « no previous file | content/test/data/cross_site_iframe_factory.html » ('j') | content/test/data/tree_parser_util.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698