OLD | NEW |
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/memory/memory_coordinator_client_registry.h" | 7 #include "base/memory/memory_coordinator_client_registry.h" |
8 #include "base/memory/memory_coordinator_proxy.h" | 8 #include "base/memory/memory_coordinator_proxy.h" |
9 #include "base/memory/memory_pressure_monitor.h" | 9 #include "base/memory/memory_pressure_monitor.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 // Also make sure that the state is updated based on free avaiable memory. | 467 // Also make sure that the state is updated based on free avaiable memory. |
468 // Since the global state has changed in the previous task, we have to wait | 468 // Since the global state has changed in the previous task, we have to wait |
469 // for |minimum_transition|. | 469 // for |minimum_transition|. |
470 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); | 470 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
471 task_runner_->FastForwardBy(minimum_transition); | 471 task_runner_->FastForwardBy(minimum_transition); |
472 task_runner_->RunUntilIdle(); | 472 task_runner_->RunUntilIdle(); |
473 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->GetGlobalMemoryState()); | 473 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->GetGlobalMemoryState()); |
474 } | 474 } |
475 | 475 |
476 | 476 TEST_F(MemoryCoordinatorImplTest, GetStateForProcess) { |
477 #if defined(OS_ANDROID) | |
478 // TODO(jcivelli): Broken on Android. http://crbug.com/678665 | |
479 #define MAYBE_GetStateForProcess DISABLED_GetStateForProcess | |
480 #else | |
481 #define MAYBE_GetStateForProcess GetStateForProcess | |
482 #endif | |
483 TEST_F(MemoryCoordinatorImplTest, MAYBE_GetStateForProcess) { | |
484 EXPECT_EQ(base::MemoryState::UNKNOWN, | 477 EXPECT_EQ(base::MemoryState::UNKNOWN, |
485 coordinator_->GetStateForProcess(base::kNullProcessHandle)); | 478 coordinator_->GetStateForProcess(base::kNullProcessHandle)); |
486 EXPECT_EQ(base::MemoryState::NORMAL, | 479 EXPECT_EQ(base::MemoryState::NORMAL, |
487 coordinator_->GetStateForProcess(base::GetCurrentProcessHandle())); | 480 coordinator_->GetStateForProcess(base::GetCurrentProcessHandle())); |
488 | 481 |
489 coordinator_->CreateChildMemoryCoordinator(1); | 482 coordinator_->CreateChildMemoryCoordinator(1); |
490 coordinator_->CreateChildMemoryCoordinator(2); | 483 coordinator_->CreateChildMemoryCoordinator(2); |
491 base::Process process1 = SpawnChild("process1"); | 484 base::Process process1 = SpawnChild("process1"); |
492 base::Process process2 = SpawnChild("process2"); | 485 base::Process process2 = SpawnChild("process2"); |
493 coordinator_->GetMockRenderProcessHost(1)->SetProcessHandle( | 486 coordinator_->GetMockRenderProcessHost(1)->SetProcessHandle( |
494 base::MakeUnique<base::ProcessHandle>(process1.Handle())); | 487 base::MakeUnique<base::ProcessHandle>(process1.Handle())); |
495 coordinator_->GetMockRenderProcessHost(2)->SetProcessHandle( | 488 coordinator_->GetMockRenderProcessHost(2)->SetProcessHandle( |
496 base::MakeUnique<base::ProcessHandle>(process2.Handle())); | 489 base::MakeUnique<base::ProcessHandle>(process2.Handle())); |
497 | 490 |
498 EXPECT_EQ(base::MemoryState::NORMAL, | 491 EXPECT_EQ(base::MemoryState::NORMAL, |
499 coordinator_->GetStateForProcess(process1.Handle())); | 492 coordinator_->GetStateForProcess(process1.Handle())); |
500 EXPECT_EQ(base::MemoryState::NORMAL, | 493 EXPECT_EQ(base::MemoryState::NORMAL, |
501 coordinator_->GetStateForProcess(process2.Handle())); | 494 coordinator_->GetStateForProcess(process2.Handle())); |
502 | 495 |
503 EXPECT_TRUE( | 496 EXPECT_TRUE( |
504 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); | 497 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); |
505 EXPECT_EQ(base::MemoryState::THROTTLED, | 498 EXPECT_EQ(base::MemoryState::THROTTLED, |
506 coordinator_->GetStateForProcess(process1.Handle())); | 499 coordinator_->GetStateForProcess(process1.Handle())); |
507 EXPECT_EQ(base::MemoryState::NORMAL, | 500 EXPECT_EQ(base::MemoryState::NORMAL, |
508 coordinator_->GetStateForProcess(process2.Handle())); | 501 coordinator_->GetStateForProcess(process2.Handle())); |
509 } | 502 } |
510 | 503 |
511 } // namespace content | 504 } // namespace content |
OLD | NEW |