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 RunUntilIdle(); |
| 382 EXPECT_FALSE(client.did_state_changed()); |
| 383 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
| 384 EXPECT_EQ(mojom::MemoryState::NORMAL, foreground_child->state()); |
| 385 EXPECT_EQ(mojom::MemoryState::THROTTLED, background_child->state()); |
| 386 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
| 387 } |
| 388 |
| 389 { |
| 390 // Transition happens (WARNING -> CRITICAL). |
| 391 // All processes should be in THROTTLED memory state. |
| 392 MockMemoryCoordinatorClient client; |
| 393 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
| 394 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
| 395 condition_observer->UpdateCondition(); |
384 RunUntilIdle(); | 396 RunUntilIdle(); |
385 EXPECT_TRUE(client.did_state_changed()); | 397 EXPECT_TRUE(client.did_state_changed()); |
386 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 398 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
| 399 EXPECT_EQ(mojom::MemoryState::THROTTLED, foreground_child->state()); |
| 400 EXPECT_EQ(mojom::MemoryState::THROTTLED, background_child->state()); |
387 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 401 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
388 } | 402 } |
389 | 403 |
390 { | 404 { |
391 // No transtion (NORMAL -> NORMAL). OnStateChange shouldn't be called. | 405 // No transtion (NORMAL -> NORMAL). OnStateChange shouldn't be called. |
392 MockMemoryCoordinatorClient client; | 406 MockMemoryCoordinatorClient client; |
393 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); | 407 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
394 coordinator_->current_state_ = base::MemoryState::NORMAL; | 408 coordinator_->memory_condition_ = MemoryCondition::NORMAL; |
395 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 409 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
396 state_updater->UpdateState(); | 410 condition_observer->UpdateCondition(); |
397 RunUntilIdle(); | 411 RunUntilIdle(); |
398 EXPECT_FALSE(client.did_state_changed()); | 412 EXPECT_FALSE(client.did_state_changed()); |
399 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); | 413 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
400 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 414 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
401 } | 415 } |
402 } | 416 } |
403 | 417 |
404 TEST_F(MemoryCoordinatorImplTest, SetMemoryStateForTesting) { | 418 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; | 419 MockMemoryCoordinatorClient client; |
414 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); | 420 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client); |
415 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); | 421 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetBrowserMemoryState()); |
416 EXPECT_EQ(base::MemoryState::NORMAL, | 422 EXPECT_EQ(base::MemoryState::NORMAL, |
417 base::MemoryCoordinatorProxy::GetInstance()-> | 423 base::MemoryCoordinatorProxy::GetInstance()-> |
418 GetCurrentMemoryState()); | 424 GetCurrentMemoryState()); |
419 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); | 425 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); |
420 | 426 |
421 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( | 427 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); | 428 base::MemoryState::THROTTLED); |
433 EXPECT_EQ(base::MemoryState::THROTTLED, | 429 EXPECT_EQ(base::MemoryState::THROTTLED, |
434 coordinator_->GetCurrentMemoryState()); | 430 coordinator_->GetBrowserMemoryState()); |
435 EXPECT_EQ(base::MemoryState::THROTTLED, | 431 EXPECT_EQ(base::MemoryState::THROTTLED, |
436 base::MemoryCoordinatorProxy::GetInstance()-> | 432 base::MemoryCoordinatorProxy::GetInstance()-> |
437 GetCurrentMemoryState()); | 433 GetCurrentMemoryState()); |
438 RunUntilIdle(); | 434 RunUntilIdle(); |
439 EXPECT_TRUE(client.did_state_changed()); | 435 EXPECT_TRUE(client.did_state_changed()); |
440 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 436 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
441 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 437 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
442 } | 438 } |
443 | 439 |
444 TEST_F(MemoryCoordinatorImplTest, ForceSetGlobalState) { | 440 TEST_F(MemoryCoordinatorImplTest, ForceSetMemoryCondition) { |
445 auto* state_updater = coordinator_->state_updater_.get(); | 441 auto* condition_observer = coordinator_->condition_observer_.get(); |
446 state_updater->expected_renderer_size_ = 10; | 442 condition_observer->expected_renderer_size_ = 10; |
447 state_updater->new_renderers_until_throttled_ = 4; | 443 condition_observer->new_renderers_until_warning_ = 4; |
448 state_updater->new_renderers_until_suspended_ = 2; | 444 condition_observer->new_renderers_until_critical_ = 2; |
449 state_updater->new_renderers_back_to_normal_ = 5; | 445 condition_observer->new_renderers_back_to_normal_ = 5; |
450 state_updater->new_renderers_back_to_throttled_ = 3; | 446 condition_observer->new_renderers_back_to_warning_ = 3; |
451 DCHECK(state_updater->ValidateParameters()); | 447 DCHECK(condition_observer->ValidateParameters()); |
452 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); | 448 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
453 | 449 |
454 base::TimeDelta interval = base::TimeDelta::FromSeconds(5); | 450 base::TimeDelta interval = base::TimeDelta::FromSeconds(5); |
455 base::TimeDelta minimum_transition = base::TimeDelta::FromSeconds(30); | 451 condition_observer->monitoring_interval_ = interval; |
456 state_updater->monitoring_interval_ = interval; | |
457 state_updater->minimum_transition_period_ = minimum_transition; | |
458 | 452 |
459 // Starts updating states. The initial state should be NORMAL with above | 453 // Starts updating memory condition. The initial condition should be NORMAL |
460 // configuration. | 454 // with above configuration. |
461 coordinator_->Start(); | 455 coordinator_->Start(); |
462 task_runner_->RunUntilIdle(); | 456 task_runner_->RunUntilIdle(); |
463 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetGlobalMemoryState()); | 457 EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition()); |
464 | 458 |
465 base::TimeDelta force_set_duration = interval * 3; | 459 base::TimeDelta force_set_duration = interval * 3; |
466 coordinator_->ForceSetGlobalState(base::MemoryState::SUSPENDED, | 460 coordinator_->ForceSetMemoryCondition(MemoryCondition::WARNING, |
467 force_set_duration); | 461 force_set_duration); |
468 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->GetGlobalMemoryState()); | 462 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
469 | 463 |
470 // The state should remain SUSPENDED even after some monitoring period are | 464 // The condition should remain SUSPENDED even after some monitoring period are |
471 // passed. | 465 // passed. |
472 task_runner_->FastForwardBy(interval * 2); | 466 task_runner_->FastForwardBy(interval * 2); |
473 task_runner_->RunUntilIdle(); | 467 task_runner_->RunUntilIdle(); |
474 EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->GetGlobalMemoryState()); | 468 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
475 | 469 |
476 // The state should be updated after |force_set_duration| is passed. | 470 // The condition should be updated after |force_set_duration| is passed. |
477 task_runner_->FastForwardBy(force_set_duration); | 471 task_runner_->FastForwardBy(force_set_duration); |
478 task_runner_->RunUntilIdle(); | 472 task_runner_->RunUntilIdle(); |
479 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetGlobalMemoryState()); | 473 EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition()); |
480 | 474 |
481 // Also make sure that the state is updated based on free avaiable memory. | 475 // 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); | 476 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
485 task_runner_->FastForwardBy(minimum_transition); | 477 task_runner_->FastForwardBy(interval * 2); |
486 task_runner_->RunUntilIdle(); | 478 task_runner_->RunUntilIdle(); |
487 EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->GetGlobalMemoryState()); | 479 EXPECT_EQ(MemoryCondition::WARNING, coordinator_->GetMemoryCondition()); |
488 } | 480 } |
489 | 481 |
490 TEST_F(MemoryCoordinatorImplTest, DiscardTab) { | 482 TEST_F(MemoryCoordinatorImplTest, DiscardTab) { |
491 coordinator_->DiscardTab(); | 483 coordinator_->DiscardTab(); |
492 EXPECT_TRUE(coordinator_->GetDelegate()->discard_tab_called()); | 484 EXPECT_TRUE(coordinator_->GetDelegate()->discard_tab_called()); |
493 } | 485 } |
494 | 486 |
495 #if defined(OS_ANDROID) | 487 #if defined(OS_ANDROID) |
496 // TODO(jcivelli): Broken on Android. http://crbug.com/678665 | 488 // TODO(jcivelli): Broken on Android. http://crbug.com/678665 |
497 #define MAYBE_GetStateForProcess DISABLED_GetStateForProcess | 489 #define MAYBE_GetStateForProcess DISABLED_GetStateForProcess |
(...skipping 22 matching lines...) Expand all Loading... |
520 | 512 |
521 EXPECT_TRUE( | 513 EXPECT_TRUE( |
522 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); | 514 coordinator_->SetChildMemoryState(1, MemoryState::THROTTLED)); |
523 EXPECT_EQ(base::MemoryState::THROTTLED, | 515 EXPECT_EQ(base::MemoryState::THROTTLED, |
524 coordinator_->GetStateForProcess(process1.Handle())); | 516 coordinator_->GetStateForProcess(process1.Handle())); |
525 EXPECT_EQ(base::MemoryState::NORMAL, | 517 EXPECT_EQ(base::MemoryState::NORMAL, |
526 coordinator_->GetStateForProcess(process2.Handle())); | 518 coordinator_->GetStateForProcess(process2.Handle())); |
527 } | 519 } |
528 | 520 |
529 } // namespace content | 521 } // namespace content |
OLD | NEW |