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

Unified 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: Self-review fixes. Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/metrics_memory_details_browsertest.cc
diff --git a/chrome/browser/metrics/metrics_memory_details_browsertest.cc b/chrome/browser/metrics/metrics_memory_details_browsertest.cc
index d38bfda6c6ea11c221fc75ab99747acb8e6bde9d..4272a92cd13812adb71ca17adb770aea68f13a5b 100644
--- a/chrome/browser/metrics/metrics_memory_details_browsertest.cc
+++ b/chrome/browser/metrics/metrics_memory_details_browsertest.cc
@@ -6,9 +6,22 @@
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
#include "base/test/histogram_tester.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
+#include "net/dns/mock_host_resolver.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using base::Bucket;
+using testing::ContainerEq;
+using testing::ElementsAre;
namespace {
@@ -18,10 +31,15 @@ class TestMemoryDetails : public MetricsMemoryDetails {
: MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {}
void StartFetchAndWait() {
+ uma_.reset(new base::HistogramTester());
StartFetch(FROM_CHROME_ONLY);
content::RunMessageLoop();
}
+ // Returns a HistogramTester which observed the most recent call to
+ // StartFetchAndWait().
+ base::HistogramTester* uma() { return uma_.get(); }
+
private:
~TestMemoryDetails() override {}
@@ -31,6 +49,8 @@ class TestMemoryDetails : public MetricsMemoryDetails {
base::MessageLoop::current()->Quit();
}
+ scoped_ptr<base::HistogramTester> uma_;
+
DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails);
};
@@ -41,20 +61,241 @@ class MetricsMemoryDetailsBrowserTest : public InProcessBrowserTest {
MetricsMemoryDetailsBrowserTest() {}
~MetricsMemoryDetailsBrowserTest() override {}
+ void SetUpOnMainThread() override {
+ host_resolver()->AddRule("*", "127.0.0.1");
+
+ // Add content/test/data so we can use cross_site_iframe_factory.html
+ base::FilePath test_data_dir;
+ CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
+ embedded_test_server()->ServeFilesFromDirectory(
+ test_data_dir.AppendASCII("content/test/data/"));
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
dcheng 2015/07/30 23:35:04 Out of curiosity, why CHECK() above and ASSERT_TRU
ncarter (slow) 2015/08/04 23:51:21 Done.
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest);
};
IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestMemoryDetails) {
- base::HistogramTester histogram_tester;
-
scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails);
details->StartFetchAndWait();
// Memory.Browser histogram should have a single non-0 sample recorded.
- histogram_tester.ExpectTotalCount("Memory.Browser", 1);
+ details->uma()->ExpectTotalCount("Memory.Browser", 1);
scoped_ptr<base::HistogramSamples> samples(
- histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser"));
+ details->uma()->GetHistogramSamplesSinceCreation("Memory.Browser"));
ASSERT_TRUE(samples);
EXPECT_NE(0, samples->sum());
}
+
+IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest, TestSiteIsolation) {
+ // Page with 14 nested oopifs across 9 sites (a.com through i.com).
+ // None of these are https.
+ GURL abcdefghi_url = embedded_test_server()->GetURL(
+ "a.com",
+ "/cross_site_iframe_factory.html?a(b(a(b,c,d,e,f,g,h)),c,d,e,i(f))");
dcheng 2015/07/30 23:35:04 This is pretty neat, but the query string is a bit
ncarter (slow) 2015/07/31 17:16:01 I don't think the builder is necessary, at least n
dcheng 2015/08/04 00:14:41 I don't see myself using the ability to preview it
ncarter (slow) 2015/08/04 23:51:21 If we wind up adding any kind of per-node options
+ ui_test_utils::NavigateToURL(browser(), abcdefghi_url);
+
+ // Get the metrics.
+ scoped_refptr<TestMemoryDetails> details = new TestMemoryDetails();
+ details->StartFetchAndWait();
+
+ EXPECT_THAT(
+ details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.CurrentRendererProcessCount"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
+ ElementsAre(Bucket(9, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(9, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(9, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(11, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(3, 1)));
+
+ // Navigate to a different, disjoint set of 7 sites.
+ GURL pqrstuv_url = embedded_test_server()->GetURL(
+ "p.com",
+ "/cross_site_iframe_factory.html?p(q(r),r(s),s(t),t(q),u(u),v(p))");
+ ui_test_utils::NavigateToURL(browser(), pqrstuv_url);
+
+ details = new TestMemoryDetails();
+ details->StartFetchAndWait();
+
+ EXPECT_THAT(
+ details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.CurrentRendererProcessCount"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
+ ElementsAre(Bucket(7, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(7, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(7, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(9, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(1, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(3, 1)));
+
+ // Open a second tab (different browsing instance) with 4 sites (a through d).
+ GURL abcd_url = embedded_test_server()->GetURL(
+ "a.com", "/cross_site_iframe_factory.html?a(b(c(d())))");
+ AddTabAtIndex(1, abcd_url, ui::PAGE_TRANSITION_TYPED);
+
+ details = new TestMemoryDetails();
+ details->StartFetchAndWait();
+
+ EXPECT_THAT(
+ details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
+ ElementsAre(Bucket(2, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.CurrentRendererProcessCount"),
+ ElementsAre(Bucket(2, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
+ ElementsAre(Bucket(11, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(11, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(11, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(13, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
+ ElementsAre(Bucket(2, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 2.
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(2, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(4, 1)));
+
+ // Open a third tab (different browsing instance) with the same 4 sites.
+ AddTabAtIndex(2, abcd_url, ui::PAGE_TRANSITION_TYPED);
+
+ details = new TestMemoryDetails();
+ details->StartFetchAndWait();
+
+ EXPECT_THAT(
+ details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.CurrentRendererProcessCount"),
+ ElementsAre(Bucket(3, 1)));
+ // Could be 11 if subframe processes were reused across browsing instances.
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
+ ElementsAre(Bucket(15, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(11, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(15, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(17, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3.
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(5, 1)));
+
+ // From the third tab, window.open() a fourth tab in the same browsing
+ // instance, to a page using the same four sites "a-d" as third tab, plus an
+ // additional site "e". The estimated process counts should increase by one
+ // (not five) from the previous scenario, as the new tab can reuse the four
+ // processes already in the BrowsingInstance.
+ GURL dcbae_url = embedded_test_server()->GetURL(
+ "a.com", "/cross_site_iframe_factory.html?d(c(b(a(e))))");
+ ui_test_utils::UrlLoadObserver load_complete(
+ dcbae_url, content::NotificationService::AllSources());
+ ASSERT_EQ(3, browser()->tab_strip_model()->count());
+ ASSERT_TRUE(content::ExecuteScript(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ "window.open('" + dcbae_url.spec() + "');"));
+ ASSERT_EQ(4, browser()->tab_strip_model()->count());
+ load_complete.Wait();
+
+ details = new TestMemoryDetails();
+ details->StartFetchAndWait();
+
+ EXPECT_THAT(
+ details->uma()->GetAllSamples("SiteIsolation.BrowsingInstanceCount"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.CurrentRendererProcessCount"),
+ ElementsAre(Bucket(3, 1)));
+ // Could be 11 if subframe processes were reused across browsing instances.
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountEstimate"),
+ ElementsAre(Bucket(16, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(12, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(16, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(18, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountEstimate"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound"),
+ ElementsAre(Bucket(1, 1))); // TODO(nick): This should be 3.
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit"),
+ ElementsAre(Bucket(3, 1)));
+ EXPECT_THAT(details->uma()->GetAllSamples(
+ "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate"),
+ ElementsAre(Bucket(5, 1)));
+}
« no previous file with comments | « no previous file | content/test/data/cross_site_iframe_factory.html » ('j') | content/test/data/cross_site_iframe_factory.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698