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/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/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "net/dns/mock_host_resolver.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 class TestMemoryDetails : public MetricsMemoryDetails { | 17 class TestMemoryDetails : public MetricsMemoryDetails { |
16 public: | 18 public: |
17 TestMemoryDetails() | 19 TestMemoryDetails() |
18 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} | 20 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} |
19 | 21 |
20 void StartFetchAndWait() { | 22 void StartFetchAndWait() { |
21 StartFetch(FROM_CHROME_ONLY); | 23 StartFetch(FROM_CHROME_ONLY); |
(...skipping 12 matching lines...) Expand all Loading... |
34 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); | 36 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails); |
35 }; | 37 }; |
36 | 38 |
37 } // namespace | 39 } // namespace |
38 | 40 |
39 class MetricsMemoryDetailsBrowserTest : public InProcessBrowserTest { | 41 class MetricsMemoryDetailsBrowserTest : public InProcessBrowserTest { |
40 public: | 42 public: |
41 MetricsMemoryDetailsBrowserTest() {} | 43 MetricsMemoryDetailsBrowserTest() {} |
42 ~MetricsMemoryDetailsBrowserTest() override {} | 44 ~MetricsMemoryDetailsBrowserTest() override {} |
43 | 45 |
| 46 void SetUpOnMainThread() override { |
| 47 host_resolver()->AddRule("*", "127.0.0.1"); |
| 48 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 49 } |
| 50 |
44 private: | 51 private: |
45 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest); | 52 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest); |
46 }; | 53 }; |
47 | 54 |
48 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestMemoryDetails) { | 55 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestMemoryDetails) { |
49 base::HistogramTester histogram_tester; | 56 base::HistogramTester histogram_tester; |
50 | 57 |
51 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); | 58 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); |
52 details->StartFetchAndWait(); | 59 details->StartFetchAndWait(); |
53 | 60 |
54 // Memory.Browser histogram should have a single non-0 sample recorded. | 61 // Memory.Browser histogram should have a single non-0 sample recorded. |
55 histogram_tester.ExpectTotalCount("Memory.Browser", 1); | 62 histogram_tester.ExpectTotalCount("Memory.Browser", 1); |
56 scoped_ptr<base::HistogramSamples> samples( | 63 scoped_ptr<base::HistogramSamples> samples( |
57 histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser")); | 64 histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser")); |
58 ASSERT_TRUE(samples); | 65 ASSERT_TRUE(samples); |
59 EXPECT_NE(0, samples->sum()); | 66 EXPECT_NE(0, samples->sum()); |
60 } | 67 } |
| 68 |
| 69 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestSiteIsolation) { |
| 70 // One page, with a buttload of oopifs. |
| 71 GURL url1 = test_server()->GetUrl("a.com", |
| 72 "cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,f,g,h)"); |
| 73 |
| 74 ui_test_utils::NavigateToURL(browser(), url1); |
| 75 |
| 76 // Get the metrics. |
| 77 base::HistogramTester histogram_tester; |
| 78 |
| 79 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); |
| 80 details->StartFetchAndWait(); |
| 81 |
| 82 base::HistogramTester::CountsMap expected_metrics; |
| 83 expected_metrics["SiteIsolation.BrowsingInstanceCount"] = 1; |
| 84 expected_metrics["SiteIsolation.CurrentRendererProcessCount"] = 1; |
| 85 expected_metrics["SiteIsolation.IsolateAllSitesProcessCountEstimate"] = 1; |
| 86 expected_metrics["SiteIsolation.IsolateAllSitesProcessCountLowerBound"] = 1; |
| 87 expected_metrics["SiteIsolation.IsolateAllSitesProcessCountNoLimit"] = 1; |
| 88 expected_metrics["SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"] = 1
; |
| 89 expected_metrics["SiteIsolation.IsolateHttpsSitesProcessCountEstimate"] = 1; |
| 90 expected_metrics["SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"] = 1; |
| 91 expected_metrics["SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"] = 1; |
| 92 expected_metrics["SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"] =
1; |
| 93 |
| 94 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("SiteIsolation."), |
| 95 testing::ContainerEq(expected_metrics)); |
| 96 } |
OLD | NEW |