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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/multiprocess_test.h" | 13 #include "base/test/multiprocess_test.h" |
14 #include "base/test/scoped_feature_list.h" | 14 #include "base/test/scoped_feature_list.h" |
15 #include "base/test/test_mock_time_task_runner.h" | 15 #include "base/test/test_mock_time_task_runner.h" |
| 16 #include "content/browser/memory/memory_condition_observer.h" |
16 #include "content/browser/memory/memory_monitor.h" | 17 #include "content/browser/memory/memory_monitor.h" |
17 #include "content/browser/memory/memory_state_updater.h" | |
18 #include "content/public/common/content_features.h" | 18 #include "content/public/common/content_features.h" |
19 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
20 #include "content/public/test/test_browser_context.h" | 20 #include "content/public/test/test_browser_context.h" |
21 #include "mojo/public/cpp/bindings/binding.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 render_process_host->IncrementServiceWorkerRefCount(); | 296 render_process_host->IncrementServiceWorkerRefCount(); |
297 EXPECT_TRUE( | 297 EXPECT_TRUE( |
298 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); | 298 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); |
299 EXPECT_EQ(mojom::MemoryState::THROTTLED, cmc->state()); | 299 EXPECT_EQ(mojom::MemoryState::THROTTLED, cmc->state()); |
300 EXPECT_FALSE( | 300 EXPECT_FALSE( |
301 coordinator_->SetChildMemoryState(1, MemoryState::SUSPENDED)); | 301 coordinator_->SetChildMemoryState(1, MemoryState::SUSPENDED)); |
302 EXPECT_EQ(mojom::MemoryState::THROTTLED, cmc->state()); | 302 EXPECT_EQ(mojom::MemoryState::THROTTLED, cmc->state()); |
303 render_process_host->DecrementSharedWorkerRefCount(); | 303 render_process_host->DecrementSharedWorkerRefCount(); |
304 } | 304 } |
305 | 305 |
306 TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { | 306 TEST_F(MemoryCoordinatorImplTest, CalculateNextCondition) { |
307 auto* state_updater = coordinator_->state_updater_.get(); | 307 auto* condition_observer = coordinator_->condition_observer_.get(); |
308 state_updater->expected_renderer_size_ = 10; | 308 condition_observer->expected_renderer_size_ = 10; |
309 state_updater->new_renderers_until_throttled_ = 4; | 309 condition_observer->new_renderers_until_warning_ = 4; |
310 state_updater->new_renderers_until_suspended_ = 2; | 310 condition_observer->new_renderers_until_critical_ = 2; |
311 state_updater->new_renderers_back_to_normal_ = 5; | 311 condition_observer->new_renderers_back_to_normal_ = 5; |
312 state_updater->new_renderers_back_to_throttled_ = 3; | 312 condition_observer->new_renderers_back_to_warning_ = 3; |
313 DCHECK(state_updater->ValidateParameters()); | 313 DCHECK(condition_observer->ValidateParameters()); |
314 | 314 |
315 // The default state is NORMAL. | 315 // The default condition is NORMAL. |
316 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); | 316 EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition()); |
317 EXPECT_EQ(base::MemoryState::NORMAL, | |
318 base::MemoryCoordinatorProxy::GetInstance()-> | |
319 GetCurrentMemoryState()); | |
320 | 317 |
321 // Transitions from NORMAL | 318 // Transitions from NORMAL |
322 coordinator_->current_state_ = base::MemoryState::NORMAL; | 319 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
323 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); | 320 EXPECT_EQ(MemoryCondition::NORMAL, |
324 EXPECT_EQ(base::MemoryState::NORMAL, | 321 condition_observer->CalculateNextCondition()); |
325 base::MemoryCoordinatorProxy::GetInstance()-> | 322 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
326 GetCurrentMemoryState()); | 323 EXPECT_EQ(MemoryCondition::WARNING, |
| 324 condition_observer->CalculateNextCondition()); |
| 325 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
| 326 EXPECT_EQ(MemoryCondition::CRITICAL, |
| 327 condition_observer->CalculateNextCondition()); |
327 | 328 |
328 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 329 // Transitions from WARNING |
329 EXPECT_EQ(base::MemoryState::NORMAL, state_updater->CalculateNextState()); | 330 coordinator_->memory_condition_ = MemoryCondition::WARNING; |
330 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); | 331 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
331 EXPECT_EQ(base::MemoryState::THROTTLED, state_updater->CalculateNextState()); | |
332 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); | |
333 EXPECT_EQ(base::MemoryState::SUSPENDED, state_updater->CalculateNextState()); | |
334 | |
335 // Transitions from THROTTLED | |
336 coordinator_->current_state_ = base::MemoryState::THROTTLED; | |
337 EXPECT_EQ(base::MemoryState::THROTTLED, | |
338 coordinator_->GetCurrentMemoryState()); | |
339 EXPECT_EQ(base::MemoryState::THROTTLED, | |
340 base::MemoryCoordinatorProxy::GetInstance()-> | |
341 GetCurrentMemoryState()); | |
342 | 332 |
343 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); | 333 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
344 EXPECT_EQ(base::MemoryState::THROTTLED, state_updater->CalculateNextState()); | 334 EXPECT_EQ(MemoryCondition::WARNING, |
| 335 condition_observer->CalculateNextCondition()); |
345 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 336 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
346 EXPECT_EQ(base::MemoryState::NORMAL, state_updater->CalculateNextState()); | 337 EXPECT_EQ(MemoryCondition::NORMAL, |
| 338 condition_observer->CalculateNextCondition()); |
347 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); | 339 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
348 EXPECT_EQ(base::MemoryState::SUSPENDED, state_updater->CalculateNextState()); | 340 EXPECT_EQ(MemoryCondition::CRITICAL, |
| 341 condition_observer->CalculateNextCondition()); |
349 | 342 |
350 // Transitions from SUSPENDED | 343 // Transitions from CRITICAL |
351 coordinator_->current_state_ = base::MemoryState::SUSPENDED; | 344 coordinator_->memory_condition_ = MemoryCondition::CRITICAL; |
352 // GetCurrentMemoryState() returns THROTTLED state for the browser process | 345 EXPECT_EQ(MemoryCondition::CRITICAL, coordinator_->GetMemoryCondition()); |
353 // when the global state is SUSPENDED. | |
354 EXPECT_EQ(base::MemoryState::THROTTLED, | |
355 coordinator_->GetCurrentMemoryState()); | |
356 EXPECT_EQ(base::MemoryState::THROTTLED, | |
357 base::MemoryCoordinatorProxy::GetInstance()-> | |
358 GetCurrentMemoryState()); | |
359 | 346 |
360 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); | 347 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
361 EXPECT_EQ(base::MemoryState::SUSPENDED, state_updater->CalculateNextState()); | 348 EXPECT_EQ(MemoryCondition::CRITICAL, |
| 349 condition_observer->CalculateNextCondition()); |
362 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(30); | 350 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(30); |
363 EXPECT_EQ(base::MemoryState::THROTTLED, state_updater->CalculateNextState()); | 351 EXPECT_EQ(MemoryCondition::WARNING, |
| 352 condition_observer->CalculateNextCondition()); |
364 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 353 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
365 EXPECT_EQ(base::MemoryState::NORMAL, state_updater->CalculateNextState()); | 354 EXPECT_EQ(MemoryCondition::NORMAL, |
| 355 condition_observer->CalculateNextCondition()); |
366 } | 356 } |
367 | 357 |
368 TEST_F(MemoryCoordinatorImplTest, UpdateState) { | 358 TEST_F(MemoryCoordinatorImplTest, UpdateCondition) { |
369 auto* state_updater = coordinator_->state_updater_.get(); | 359 auto* condition_observer = coordinator_->condition_observer_.get(); |
370 state_updater->expected_renderer_size_ = 10; | 360 condition_observer->expected_renderer_size_ = 10; |
371 state_updater->new_renderers_until_throttled_ = 4; | 361 condition_observer->new_renderers_until_warning_ = 4; |
372 state_updater->new_renderers_until_suspended_ = 2; | 362 condition_observer->new_renderers_until_critical_ = 2; |
373 state_updater->new_renderers_back_to_normal_ = 5; | 363 condition_observer->new_renderers_back_to_normal_ = 5; |
374 state_updater->new_renderers_back_to_throttled_ = 3; | 364 condition_observer->new_renderers_back_to_warning_ = 3; |
375 DCHECK(state_updater->ValidateParameters()); | 365 DCHECK(condition_observer->ValidateParameters()); |
| 366 |
| 367 auto* foreground_child = coordinator_->CreateChildMemoryCoordinator(1); |
| 368 auto* background_child = coordinator_->CreateChildMemoryCoordinator(2); |
| 369 auto iter = coordinator_->children().find(2); |
| 370 iter->second.is_visible = false; |
376 | 371 |
377 { | 372 { |
378 // Transition happens (NORMAL -> THROTTLED). | 373 // Transition happens (NORMAL -> WARNING). |
| 374 // Foreground processes should remain NORMAL state but background processes |
| 375 // should become THROTTLED state. |
379 MockMemoryCoordinatorClient client; | 376 MockMemoryCoordinatorClient client; |
380 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); | 377 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
381 coordinator_->current_state_ = base::MemoryState::NORMAL; | 378 coordinator_->memory_condition_ = MemoryCondition::NORMAL; |
382 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); | 379 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
383 state_updater->UpdateState(); | 380 condition_observer->UpdateCondition(); |
| 381 task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(40)); |
| 382 RunUntilIdle(); |
| 383 EXPECT_FALSE(client.did_state_changed()); |
| 384 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
| 385 EXPECT_EQ(mojom::MemoryState::NORMAL, foreground_child->state()); |
| 386 EXPECT_EQ(mojom::MemoryState::THROTTLED, background_child->state()); |
| 387 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
| 388 } |
| 389 |
| 390 { |
| 391 // Transition happens (WARNING -> CRITICAL). |
| 392 // All processes should be in THROTTLED memory state. |
| 393 MockMemoryCoordinatorClient client; |
| 394 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
| 395 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
| 396 condition_observer->UpdateCondition(); |
| 397 task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(40)); |
384 RunUntilIdle(); | 398 RunUntilIdle(); |
385 EXPECT_TRUE(client.did_state_changed()); | 399 EXPECT_TRUE(client.did_state_changed()); |
386 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 400 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
| 401 EXPECT_EQ(mojom::MemoryState::THROTTLED, foreground_child->state()); |
| 402 EXPECT_EQ(mojom::MemoryState::THROTTLED, background_child->state()); |
387 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 403 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
388 } | 404 } |
389 | 405 |
390 { | 406 { |
391 // No transtion (NORMAL -> NORMAL). OnStateChange shouldn't be called. | 407 // No transtion (NORMAL -> NORMAL). OnStateChange shouldn't be called. |
392 MockMemoryCoordinatorClient client; | 408 MockMemoryCoordinatorClient client; |
393 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); | 409 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
394 coordinator_->current_state_ = base::MemoryState::NORMAL; | 410 coordinator_->memory_condition_ = MemoryCondition::NORMAL; |
395 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 411 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
396 state_updater->UpdateState(); | 412 condition_observer->UpdateCondition(); |
397 RunUntilIdle(); | 413 RunUntilIdle(); |
398 EXPECT_FALSE(client.did_state_changed()); | 414 EXPECT_FALSE(client.did_state_changed()); |
399 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); | 415 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
400 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 416 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
401 } | 417 } |
402 } | 418 } |
403 | 419 |
404 TEST_F(MemoryCoordinatorImplTest, SetMemoryStateForTesting) { | 420 TEST_F(MemoryCoordinatorImplTest, SetMemoryStateForTesting) { |
405 auto* state_updater = coordinator_->state_updater_.get(); | |
406 state_updater->expected_renderer_size_ = 10; | |
407 state_updater->new_renderers_until_throttled_ = 4; | |
408 state_updater->new_renderers_until_suspended_ = 2; | |
409 state_updater->new_renderers_back_to_normal_ = 5; | |
410 state_updater->new_renderers_back_to_throttled_ = 3; | |
411 DCHECK(state_updater->ValidateParameters()); | |
412 | |
413 MockMemoryCoordinatorClient client; | 421 MockMemoryCoordinatorClient client; |
414 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); | 422 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
415 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); | 423 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetBrowserMemoryState()); |
416 EXPECT_EQ(base::MemoryState::NORMAL, | 424 EXPECT_EQ(base::MemoryState::NORMAL, |
417 base::MemoryCoordinatorProxy::GetInstance()-> | 425 base::MemoryCoordinatorProxy::GetInstance()-> |
418 GetCurrentMemoryState()); | 426 GetCurrentMemoryState()); |
419 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); | 427 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
420 | 428 |
421 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( | 429 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( |
422 base::MemoryState::SUSPENDED); | |
423 // GetCurrentMemoryState() returns THROTTLED state for the browser process | |
424 // when the global state is SUSPENDED. | |
425 EXPECT_EQ(base::MemoryState::THROTTLED, | |
426 coordinator_->GetCurrentMemoryState()); | |
427 EXPECT_EQ(base::MemoryState::THROTTLED, | |
428 base::MemoryCoordinatorProxy::GetInstance()-> | |
429 GetCurrentMemoryState()); | |
430 | |
431 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( | |
432 base::MemoryState::THROTTLED); | 430 base::MemoryState::THROTTLED); |
433 EXPECT_EQ(base::MemoryState::THROTTLED, | 431 EXPECT_EQ(base::MemoryState::THROTTLED, |
434 coordinator_->GetCurrentMemoryState()); | 432 coordinator_->GetBrowserMemoryState()); |
435 EXPECT_EQ(base::MemoryState::THROTTLED, | 433 EXPECT_EQ(base::MemoryState::THROTTLED, |
436 base::MemoryCoordinatorProxy::GetInstance()-> | 434 base::MemoryCoordinatorProxy::GetInstance()-> |
437 GetCurrentMemoryState()); | 435 GetCurrentMemoryState()); |
438 RunUntilIdle(); | 436 RunUntilIdle(); |
439 EXPECT_TRUE(client.did_state_changed()); | 437 EXPECT_TRUE(client.did_state_changed()); |
440 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 438 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
441 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 439 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
442 } | 440 } |
443 | 441 |
444 TEST_F(MemoryCoordinatorImplTest, ForceSetGlobalState) { | 442 TEST_F(MemoryCoordinatorImplTest, ForceSetMemoryCondition) { |
445 auto* state_updater = coordinator_->state_updater_.get(); | 443 auto* condition_observer = coordinator_->condition_observer_.get(); |
446 state_updater->expected_renderer_size_ = 10; | 444 condition_observer->expected_renderer_size_ = 10; |
447 state_updater->new_renderers_until_throttled_ = 4; | 445 condition_observer->new_renderers_until_warning_ = 4; |
448 state_updater->new_renderers_until_suspended_ = 2; | 446 condition_observer->new_renderers_until_critical_ = 2; |
449 state_updater->new_renderers_back_to_normal_ = 5; | 447 condition_observer->new_renderers_back_to_normal_ = 5; |
450 state_updater->new_renderers_back_to_throttled_ = 3; | 448 condition_observer->new_renderers_back_to_warning_ = 3; |
451 DCHECK(state_updater->ValidateParameters()); | 449 DCHECK(condition_observer->ValidateParameters()); |
452 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 450 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
453 | 451 |
454 base::TimeDelta interval = base::TimeDelta::FromSeconds(5); | 452 base::TimeDelta interval = base::TimeDelta::FromSeconds(5); |
455 base::TimeDelta minimum_transition = base::TimeDelta::FromSeconds(30); | 453 condition_observer->monitoring_interval_ = interval; |
456 state_updater->monitoring_interval_ = interval; | |
457 state_updater->minimum_transition_period_ = minimum_transition; | |
458 | 454 |
459 // Starts updating states. The initial state should be NORMAL with above | 455 // Starts updating memory condition. The initial condition should be NORMAL |
460 // configuration. | 456 // with above configuration. |
461 coordinator_->Start(); | 457 coordinator_->Start(); |
462 task_runner_->RunUntilIdle(); | 458 task_runner_->RunUntilIdle(); |
463 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetGlobalMemoryState()); | 459 EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition()); |
464 | 460 |
465 base::TimeDelta force_set_duration = interval * 3; | 461 base::TimeDelta force_set_duration = interval * 3; |
466 coordinator_->ForceSetGlobalState(base::MemoryState::SUSPENDED, | 462 coordinator_->ForceSetMemoryCondition(MemoryCondition::WARNING, |
467 force_set_duration); | 463 force_set_duration); |
468 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->GetGlobalMemoryState()); | 464 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
469 | 465 |
470 // The state should remain SUSPENDED even after some monitoring period are | 466 // The condition should remain SUSPENDED even after some monitoring period are |
471 // passed. | 467 // passed. |
472 task_runner_->FastForwardBy(interval * 2); | 468 task_runner_->FastForwardBy(interval * 2); |
473 task_runner_->RunUntilIdle(); | 469 task_runner_->RunUntilIdle(); |
474 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->GetGlobalMemoryState()); | 470 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
475 | 471 |
476 // The state should be updated after |force_set_duration| is passed. | 472 // The condition should be updated after |force_set_duration| is passed. |
477 task_runner_->FastForwardBy(force_set_duration); | 473 task_runner_->FastForwardBy(force_set_duration); |
478 task_runner_->RunUntilIdle(); | 474 task_runner_->RunUntilIdle(); |
479 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetGlobalMemoryState()); | 475 EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition()); |
480 | 476 |
481 // Also make sure that the state is updated based on free avaiable memory. | 477 // Also make sure that the condition is updated based on free avaiable memory. |
482 // Since the global state has changed in the previous task, we have to wait | |
483 // for |minimum_transition|. | |
484 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); | 478 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
485 task_runner_->FastForwardBy(minimum_transition); | 479 task_runner_->FastForwardBy(interval * 2); |
486 task_runner_->RunUntilIdle(); | 480 task_runner_->RunUntilIdle(); |
487 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->GetGlobalMemoryState()); | 481 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
488 } | 482 } |
489 | 483 |
490 TEST_F(MemoryCoordinatorImplTest, DiscardTab) { | 484 TEST_F(MemoryCoordinatorImplTest, DiscardTab) { |
491 coordinator_->DiscardTab(); | 485 coordinator_->DiscardTab(); |
492 EXPECT_TRUE(coordinator_->GetDelegate()->discard_tab_called()); | 486 EXPECT_TRUE(coordinator_->GetDelegate()->discard_tab_called()); |
493 } | 487 } |
494 | 488 |
495 #if defined(OS_ANDROID) | 489 #if defined(OS_ANDROID) |
496 // TODO(jcivelli): Broken on Android. http://crbug.com/678665 | 490 // TODO(jcivelli): Broken on Android. http://crbug.com/678665 |
497 #define MAYBE_GetStateForProcess DISABLED_GetStateForProcess | 491 #define MAYBE_GetStateForProcess DISABLED_GetStateForProcess |
(...skipping 22 matching lines...) Expand all Loading... |
520 | 514 |
521 EXPECT_TRUE( | 515 EXPECT_TRUE( |
522 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); | 516 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); |
523 EXPECT_EQ(base::MemoryState::THROTTLED, | 517 EXPECT_EQ(base::MemoryState::THROTTLED, |
524 coordinator_->GetStateForProcess(process1.Handle())); | 518 coordinator_->GetStateForProcess(process1.Handle())); |
525 EXPECT_EQ(base::MemoryState::NORMAL, | 519 EXPECT_EQ(base::MemoryState::NORMAL, |
526 coordinator_->GetStateForProcess(process2.Handle())); | 520 coordinator_->GetStateForProcess(process2.Handle())); |
527 } | 521 } |
528 | 522 |
529 } // namespace content | 523 } // namespace content |
OLD | NEW |