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

Side by Side Diff: content/browser/memory/memory_coordinator_impl_unittest.cc

Issue 2412413002: WIP: Add MemoryCoordinator::GetCurrentMemoryState (Closed)
Patch Set: (rebase) Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/memory/memory_coordinator_impl.h" 5 #include "content/browser/memory/memory_coordinator_impl.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/memory/memory_monitor.h" 8 #include "content/browser/memory/memory_monitor.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 }; 64 };
65 65
66 TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { 66 TEST_F(MemoryCoordinatorImplTest, CalculateNextState) {
67 coordinator_->expected_renderer_size_ = 10; 67 coordinator_->expected_renderer_size_ = 10;
68 coordinator_->new_renderers_until_throttled_ = 4; 68 coordinator_->new_renderers_until_throttled_ = 4;
69 coordinator_->new_renderers_until_suspended_ = 2; 69 coordinator_->new_renderers_until_suspended_ = 2;
70 coordinator_->new_renderers_back_to_normal_ = 5; 70 coordinator_->new_renderers_back_to_normal_ = 5;
71 coordinator_->new_renderers_back_to_throttled_ = 3; 71 coordinator_->new_renderers_back_to_throttled_ = 3;
72 DCHECK(coordinator_->ValidateParameters()); 72 DCHECK(coordinator_->ValidateParameters());
73 73
74 // The default state is NORMAL.
75 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState());
76
74 // Transitions from NORMAL 77 // Transitions from NORMAL
75 coordinator_->current_state_ = base::MemoryState::NORMAL; 78 coordinator_->current_state_ = base::MemoryState::NORMAL;
79 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState());
76 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); 80 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
77 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState()); 81 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState());
78 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); 82 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40);
79 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState()); 83 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState());
80 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); 84 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20);
81 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState()); 85 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState());
82 86
83 // Transitions from THROTTLED 87 // Transitions from THROTTLED
84 coordinator_->current_state_ = base::MemoryState::THROTTLED; 88 coordinator_->current_state_ = base::MemoryState::THROTTLED;
89 EXPECT_EQ(base::MemoryState::THROTTLED,
90 coordinator_->GetCurrentMemoryState());
85 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); 91 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40);
86 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState()); 92 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState());
87 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); 93 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
88 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState()); 94 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState());
89 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); 95 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20);
90 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState()); 96 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState());
91 97
92 // Transitions from SUSPENDED 98 // Transitions from SUSPENDED
93 coordinator_->current_state_ = base::MemoryState::SUSPENDED; 99 coordinator_->current_state_ = base::MemoryState::SUSPENDED;
100 EXPECT_EQ(base::MemoryState::SUSPENDED,
101 coordinator_->GetCurrentMemoryState());
94 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); 102 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20);
95 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState()); 103 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState());
96 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(30); 104 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(30);
97 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState()); 105 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState());
98 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); 106 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
99 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState()); 107 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState());
100 } 108 }
101 109
102 TEST_F(MemoryCoordinatorImplTest, UpdateState) { 110 TEST_F(MemoryCoordinatorImplTest, UpdateState) {
103 coordinator_->expected_renderer_size_ = 10; 111 coordinator_->expected_renderer_size_ = 10;
(...skipping 26 matching lines...) Expand all
130 coordinator_->UpdateState(); 138 coordinator_->UpdateState();
131 base::RunLoop loop; 139 base::RunLoop loop;
132 loop.RunUntilIdle(); 140 loop.RunUntilIdle();
133 EXPECT_FALSE(client.is_called()); 141 EXPECT_FALSE(client.is_called());
134 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); 142 EXPECT_EQ(base::MemoryState::NORMAL, client.state());
135 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); 143 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
136 } 144 }
137 } 145 }
138 146
139 } // namespace content 147 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698