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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 | 674 |
675 TEST_F(TabManagerTest, NextPurgeAndSuspendState) { | 675 TEST_F(TabManagerTest, NextPurgeAndSuspendState) { |
676 TabManager tab_manager; | 676 TabManager tab_manager; |
677 TabStripDummyDelegate delegate; | 677 TabStripDummyDelegate delegate; |
678 TabStripModel tabstrip(&delegate, profile()); | 678 TabStripModel tabstrip(&delegate, profile()); |
679 tabstrip.AddObserver(&tab_manager); | 679 tabstrip.AddObserver(&tab_manager); |
680 | 680 |
681 WebContents* test_contents = CreateWebContents(); | 681 WebContents* test_contents = CreateWebContents(); |
682 tabstrip.AppendWebContents(test_contents, false); | 682 tabstrip.AppendWebContents(test_contents, false); |
683 | 683 |
684 base::TimeDelta threshold = base::TimeDelta::FromSeconds(180); | 684 // Use default time-to-first-purge defined in TabManager. |
| 685 base::TimeDelta threshold = TabManager::kDefaultTimeToFirstPurge; |
685 base::SimpleTestTickClock test_clock; | 686 base::SimpleTestTickClock test_clock; |
686 | 687 |
687 tab_manager.GetWebContentsData(test_contents) | 688 tab_manager.GetWebContentsData(test_contents) |
688 ->SetPurgeAndSuspendState(TabManager::RUNNING); | 689 ->SetPurgeAndSuspendState(TabManager::RUNNING); |
689 tab_manager.GetWebContentsData(test_contents) | 690 tab_manager.GetWebContentsData(test_contents) |
690 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | 691 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
691 | 692 |
692 test_clock.Advance(base::TimeDelta::FromSeconds(180)); | 693 // Wait 30 minutes and verify that the tab is still RUNNING. |
| 694 test_clock.Advance(base::TimeDelta::FromMinutes(30)); |
693 EXPECT_EQ(TabManager::RUNNING, | 695 EXPECT_EQ(TabManager::RUNNING, |
694 tab_manager.GetNextPurgeAndSuspendState( | 696 tab_manager.GetNextPurgeAndSuspendState( |
695 test_contents, test_clock.NowTicks(), threshold)); | 697 test_contents, test_clock.NowTicks(), threshold)); |
696 | 698 |
| 699 // Wait another second and verify that it is now SUSPENDED. |
697 test_clock.Advance(base::TimeDelta::FromSeconds(1)); | 700 test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
698 EXPECT_EQ(TabManager::SUSPENDED, | 701 EXPECT_EQ(TabManager::SUSPENDED, |
699 tab_manager.GetNextPurgeAndSuspendState( | 702 tab_manager.GetNextPurgeAndSuspendState( |
700 test_contents, test_clock.NowTicks(), threshold)); | 703 test_contents, test_clock.NowTicks(), threshold)); |
701 | 704 |
702 tab_manager.GetWebContentsData(test_contents) | 705 tab_manager.GetWebContentsData(test_contents) |
703 ->SetPurgeAndSuspendState(TabManager::SUSPENDED); | 706 ->SetPurgeAndSuspendState(TabManager::SUSPENDED); |
704 tab_manager.GetWebContentsData(test_contents) | 707 tab_manager.GetWebContentsData(test_contents) |
705 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); | 708 ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
706 | 709 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 tabstrip.ActivateTabAt(0, true /* user_gesture */); | 773 tabstrip.ActivateTabAt(0, true /* user_gesture */); |
771 EXPECT_EQ(TabManager::RUNNING, | 774 EXPECT_EQ(TabManager::RUNNING, |
772 tab_manager.GetWebContentsData(tab1)->GetPurgeAndSuspendState()); | 775 tab_manager.GetWebContentsData(tab1)->GetPurgeAndSuspendState()); |
773 | 776 |
774 // Clean up the tabstrip. | 777 // Clean up the tabstrip. |
775 tabstrip.CloseAllTabs(); | 778 tabstrip.CloseAllTabs(); |
776 EXPECT_TRUE(tabstrip.empty()); | 779 EXPECT_TRUE(tabstrip.empty()); |
777 } | 780 } |
778 | 781 |
779 } // namespace memory | 782 } // namespace memory |
OLD | NEW |