| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/memory/tab_manager.h" | 5 #include "chrome/browser/memory/tab_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 EXPECT_FALSE(tm.under_memory_pressure_); | 664 EXPECT_FALSE(tm.under_memory_pressure_); |
| 665 EXPECT_EQ(0u, task_runner->size()); | 665 EXPECT_EQ(0u, task_runner->size()); |
| 666 EXPECT_EQ(0u, tm.notified_renderers_.size()); | 666 EXPECT_EQ(0u, tm.notified_renderers_.size()); |
| 667 | 667 |
| 668 | 668 |
| 669 // Clean up the tabstrip. | 669 // Clean up the tabstrip. |
| 670 tabstrip.CloseAllTabs(); | 670 tabstrip.CloseAllTabs(); |
| 671 ASSERT_TRUE(tabstrip.empty()); | 671 ASSERT_TRUE(tabstrip.empty()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 TEST_F(TabManagerTest, NextPurgeAndSuspendState) { | |
| 675 TabManager tab_manager; | |
| 676 TabStripDummyDelegate delegate; | |
| 677 TabStripModel tabstrip(&delegate, profile()); | |
| 678 tabstrip.AddObserver(&tab_manager); | |
| 679 | |
| 680 WebContents* test_contents = CreateWebContents(); | |
| 681 tabstrip.AppendWebContents(test_contents, false); | |
| 682 | |
| 683 base::TimeDelta threshold = base::TimeDelta::FromSeconds(180); | |
| 684 base::SimpleTestTickClock test_clock; | |
| 685 | |
| 686 tab_manager.GetWebContentsData(test_contents) | |
| 687 ->SetPurgeAndSuspendState(TabManager::RUNNING); | |
| 688 tab_manager.GetWebContentsData(test_contents) | |
| 689 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | |
| 690 | |
| 691 test_clock.Advance(base::TimeDelta::FromSeconds(180)); | |
| 692 EXPECT_EQ(TabManager::RUNNING, | |
| 693 tab_manager.GetNextPurgeAndSuspendState( | |
| 694 test_contents, test_clock.NowTicks(), threshold)); | |
| 695 | |
| 696 test_clock.Advance(base::TimeDelta::FromSeconds(1)); | |
| 697 EXPECT_EQ(TabManager::SUSPENDED, | |
| 698 tab_manager.GetNextPurgeAndSuspendState( | |
| 699 test_contents, test_clock.NowTicks(), threshold)); | |
| 700 | |
| 701 tab_manager.GetWebContentsData(test_contents) | |
| 702 ->SetPurgeAndSuspendState(TabManager::SUSPENDED); | |
| 703 tab_manager.GetWebContentsData(test_contents) | |
| 704 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | |
| 705 | |
| 706 test_clock.Advance(base::TimeDelta::FromSeconds(120)); | |
| 707 EXPECT_EQ(TabManager::SUSPENDED, | |
| 708 tab_manager.GetNextPurgeAndSuspendState( | |
| 709 test_contents, test_clock.NowTicks(), threshold)); | |
| 710 | |
| 711 test_clock.Advance(base::TimeDelta::FromSeconds(1)); | |
| 712 EXPECT_EQ(TabManager::RESUMED, | |
| 713 tab_manager.GetNextPurgeAndSuspendState( | |
| 714 test_contents, test_clock.NowTicks(), threshold)); | |
| 715 | |
| 716 tab_manager.GetWebContentsData(test_contents) | |
| 717 ->SetPurgeAndSuspendState(TabManager::RESUMED); | |
| 718 tab_manager.GetWebContentsData(test_contents) | |
| 719 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | |
| 720 | |
| 721 test_clock.Advance(base::TimeDelta::FromSeconds(10)); | |
| 722 EXPECT_EQ(TabManager::RESUMED, | |
| 723 tab_manager.GetNextPurgeAndSuspendState( | |
| 724 test_contents, test_clock.NowTicks(), threshold)); | |
| 725 | |
| 726 test_clock.Advance(base::TimeDelta::FromSeconds(1)); | |
| 727 EXPECT_EQ(TabManager::SUSPENDED, | |
| 728 tab_manager.GetNextPurgeAndSuspendState( | |
| 729 test_contents, test_clock.NowTicks(), threshold)); | |
| 730 | |
| 731 // Clean up the tabstrip. | |
| 732 tabstrip.CloseAllTabs(); | |
| 733 EXPECT_TRUE(tabstrip.empty()); | |
| 734 } | |
| 735 | |
| 736 TEST_F(TabManagerTest, ActivateTabResetPurgeAndSuspendState) { | |
| 737 TabManager tab_manager; | |
| 738 TabStripDummyDelegate delegate; | |
| 739 TabStripModel tabstrip(&delegate, profile()); | |
| 740 tabstrip.AddObserver(&tab_manager); | |
| 741 | |
| 742 WebContents* tab1 = CreateWebContents(); | |
| 743 WebContents* tab2 = CreateWebContents(); | |
| 744 tabstrip.AppendWebContents(tab1, true); | |
| 745 tabstrip.AppendWebContents(tab2, false); | |
| 746 | |
| 747 base::SimpleTestTickClock test_clock; | |
| 748 | |
| 749 // Initially PurgeAndSuspend state should be RUNNING. | |
| 750 EXPECT_EQ(TabManager::RUNNING, | |
| 751 tab_manager.GetWebContentsData(tab2)->GetPurgeAndSuspendState()); | |
| 752 | |
| 753 tab_manager.GetWebContentsData(tab2)->SetPurgeAndSuspendState( | |
| 754 TabManager::SUSPENDED); | |
| 755 tab_manager.GetWebContentsData(tab2) | |
| 756 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | |
| 757 | |
| 758 // Activate tab2. Tab2's PurgeAndSuspend state should be RUNNING. | |
| 759 tabstrip.ActivateTabAt(1, true /* user_gesture */); | |
| 760 EXPECT_EQ(TabManager::RUNNING, | |
| 761 tab_manager.GetWebContentsData(tab2)->GetPurgeAndSuspendState()); | |
| 762 | |
| 763 tab_manager.GetWebContentsData(tab1)->SetPurgeAndSuspendState( | |
| 764 TabManager::RESUMED); | |
| 765 tab_manager.GetWebContentsData(tab1) | |
| 766 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | |
| 767 | |
| 768 // Activate tab1. Tab1's PurgeAndSuspend state should be RUNNING. | |
| 769 tabstrip.ActivateTabAt(0, true /* user_gesture */); | |
| 770 EXPECT_EQ(TabManager::RUNNING, | |
| 771 tab_manager.GetWebContentsData(tab1)->GetPurgeAndSuspendState()); | |
| 772 | |
| 773 // Clean up the tabstrip. | |
| 774 tabstrip.CloseAllTabs(); | |
| 775 EXPECT_TRUE(tabstrip.empty()); | |
| 776 } | |
| 777 | |
| 778 } // namespace memory | 674 } // namespace memory |
| OLD | NEW |