blob: e2e4e075d653c35038eb32a5964e021652ef42b8 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2018 The Chromium Authors
Nicolas Penac0299742018-06-27 18:49:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
danakj10f32372020-09-15 22:25:165#include "content/browser/renderer_host/frame_tree.h"
Nicolas Penac0299742018-06-27 18:49:116#include "content/browser/web_contents/web_contents_impl.h"
7#include "content/public/browser/web_contents.h"
Peter Kasting919ce652020-05-07 10:22:368#include "content/public/test/browser_test.h"
Nicolas Penac0299742018-06-27 18:49:119#include "content/public/test/browser_test_utils.h"
10#include "content/public/test/content_browser_test.h"
11#include "content/public/test/content_browser_test_utils.h"
12#include "content/shell/browser/shell.h"
13#include "content/test/content_browser_test_utils_internal.h"
14#include "net/dns/mock_host_resolver.h"
15
16namespace content {
17
18class PerformanceMemoryBrowserTest : public ContentBrowserTest {
19 public:
20 PerformanceMemoryBrowserTest() {}
21
22 protected:
23 void SetUpOnMainThread() override {
24 host_resolver()->AddRule("*", "127.0.0.1");
25 SetupCrossSiteRedirector(embedded_test_server());
26 ASSERT_TRUE(embedded_test_server()->Start());
27 }
28};
29
30// Verify that performance.memory is not bucketized when sites are isolated for
31// testing, and that it is bucketized when they are not.
32IN_PROC_BROWSER_TEST_F(PerformanceMemoryBrowserTest, PerformanceMemory) {
33 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
34 EXPECT_TRUE(NavigateToURL(shell(), main_url));
35
36 WebContents* contents = shell()->web_contents();
37 FrameTreeNode* root =
Carlos Caballero15caeeb2021-10-27 09:57:5538 static_cast<WebContentsImpl*>(contents)->GetPrimaryFrameTree().root();
Avi Drissmanc91bd8e2021-04-19 23:58:4439 int usedJSHeapSize =
40 EvalJs(root, "performance.memory.usedJSHeapSize;").ExtractInt();
Nicolas Penac0299742018-06-27 18:49:1141
42 EXPECT_GE(usedJSHeapSize, 0);
43 // There is no explicit way to check if the memory values are bucketized or
44 // not. As in third_party/blink/renderer/core/timing/memory_info_test.cc,
45 // check that the value mod 100000 is non-zero to verify that it is
46 // not bucketized. This should be the case when the renderer process is locked
47 // to a site (i.e. scheme plus eTLD+1).
48 if (AreAllSitesIsolatedForTesting())
49 EXPECT_NE(0, usedJSHeapSize % 100000);
50 else
51 EXPECT_EQ(0, usedJSHeapSize % 100000);
52}
53
54} // namespace content