Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Nicolas Pena | c029974 | 2018-06-27 18:49:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
danakj | 10f3237 | 2020-09-15 22:25:16 | [diff] [blame] | 5 | #include "content/browser/renderer_host/frame_tree.h" |
Nicolas Pena | c029974 | 2018-06-27 18:49:11 | [diff] [blame] | 6 | #include "content/browser/web_contents/web_contents_impl.h" |
| 7 | #include "content/public/browser/web_contents.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 8 | #include "content/public/test/browser_test.h" |
Nicolas Pena | c029974 | 2018-06-27 18:49:11 | [diff] [blame] | 9 | #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 | |
| 16 | namespace content { |
| 17 | |
| 18 | class 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. |
| 32 | IN_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 Caballero | 15caeeb | 2021-10-27 09:57:55 | [diff] [blame] | 38 | static_cast<WebContentsImpl*>(contents)->GetPrimaryFrameTree().root(); |
Avi Drissman | c91bd8e | 2021-04-19 23:58:44 | [diff] [blame] | 39 | int usedJSHeapSize = |
| 40 | EvalJs(root, "performance.memory.usedJSHeapSize;").ExtractInt(); |
Nicolas Pena | c029974 | 2018-06-27 18:49:11 | [diff] [blame] | 41 | |
| 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 |