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

Unified Diff: content/browser/memory/memory_coordinator_browsertest.cc

Issue 2552603002: Add tests for MemoryCoordinator::Can{Throttle,Suspend}Renderer() (Closed)
Patch Set: Fix unittests Created 4 years 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
« no previous file with comments | « content/browser/memory/memory_coordinator.cc ('k') | content/browser/memory/memory_coordinator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/memory/memory_coordinator_browsertest.cc
diff --git a/content/browser/memory/memory_coordinator_browsertest.cc b/content/browser/memory/memory_coordinator_browsertest.cc
index df22a9c4936be9abae338f13339191e82ba50fc4..4c80519e728a72ee9a6c656e59dc571b11b9dc4b 100644
--- a/content/browser/memory/memory_coordinator_browsertest.cc
+++ b/content/browser/memory/memory_coordinator_browsertest.cc
@@ -12,6 +12,19 @@
namespace content {
+class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate {
+ public:
+ TestMemoryCoordinatorDelegate() {}
+ ~TestMemoryCoordinatorDelegate() override {}
+
+ bool CanSuspendBackgroundedRenderer(int render_process_id) override {
+ return true;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate);
+};
+
class MemoryCoordinatorTest : public ContentBrowserTest {
public:
MemoryCoordinatorTest() {}
@@ -27,16 +40,40 @@ class MemoryCoordinatorTest : public ContentBrowserTest {
DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest);
};
-// TODO(bashi): Enable this test on macos when MemoryMonitorMac is implemented.
-#if defined(OS_MACOSX)
-#define MAYBE_HandleAdded DISABLED_HandleAdded
-#else
-#define MAYBE_HandleAdded HandleAdded
-#endif
-IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, MAYBE_HandleAdded) {
+// TODO(bashi): Enable these tests on macos when MemoryMonitorMac is
+// implemented.
+#if !defined(OS_MACOSX)
+
+IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, HandleAdded) {
GURL url = GetTestUrl("", "simple_page.html");
NavigateToURL(shell(), url);
- EXPECT_EQ(1u, MemoryCoordinator::GetInstance()->NumChildrenForTesting());
+ EXPECT_EQ(1u, MemoryCoordinator::GetInstance()->children().size());
}
+IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, CanSuspendRenderer) {
+ GURL url = GetTestUrl("", "simple_page.html");
+ NavigateToURL(shell(), url);
+ auto* memory_coordinator = MemoryCoordinator::GetInstance();
+ memory_coordinator->SetDelegateForTesting(
+ base::MakeUnique<TestMemoryCoordinatorDelegate>());
+ EXPECT_EQ(1u, memory_coordinator->children().size());
+ int render_process_id = memory_coordinator->children().begin()->first;
+ // Foreground tab cannot be suspended.
+ EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
+}
+
+IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, CanThrottleRenderer) {
+ GURL url = GetTestUrl("", "simple_page.html");
+ NavigateToURL(shell(), url);
+ auto* memory_coordinator = MemoryCoordinator::GetInstance();
+ memory_coordinator->SetDelegateForTesting(
+ base::MakeUnique<TestMemoryCoordinatorDelegate>());
+ EXPECT_EQ(1u, memory_coordinator->children().size());
+ int render_process_id = memory_coordinator->children().begin()->first;
+ // Foreground tab cannot be throttled.
+ EXPECT_FALSE(memory_coordinator->CanThrottleRenderer(render_process_id));
+}
+
+#endif // !defined(OS_MACOSX)
+
} // namespace content
« no previous file with comments | « content/browser/memory/memory_coordinator.cc ('k') | content/browser/memory/memory_coordinator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698