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/resource_coordinator/tab_manager.h" | 5 #include "chrome/browser/resource_coordinator/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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/test/mock_entropy_provider.h" | 16 #include "base/test/mock_entropy_provider.h" |
17 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" | 22 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" |
22 #include "chrome/browser/resource_coordinator/tab_stats.h" | 23 #include "chrome/browser/resource_coordinator/tab_stats.h" |
| 24 #include "chrome/browser/sessions/tab_loader.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" | 26 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" |
25 #include "chrome/common/chrome_features.h" | 27 #include "chrome/common/chrome_features.h" |
26 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
28 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
29 #include "components/variations/variations_associated_data.h" | 31 #include "components/variations/variations_associated_data.h" |
30 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
32 #include "content/public/test/mock_render_process_host.h" | 34 #include "content/public/test/mock_render_process_host.h" |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 tab_manager.PurgeBackgroundedTabsIfNeeded(); | 487 tab_manager.PurgeBackgroundedTabsIfNeeded(); |
486 // Since tab2 is kept inactive and background for more than time-to-purge, | 488 // Since tab2 is kept inactive and background for more than time-to-purge, |
487 // tab2 should be purged. | 489 // tab2 should be purged. |
488 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged()); | 490 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged()); |
489 | 491 |
490 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. | 492 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. |
491 tabstrip.ActivateTabAt(1, true /* user_gesture */); | 493 tabstrip.ActivateTabAt(1, true /* user_gesture */); |
492 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged()); | 494 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged()); |
493 } | 495 } |
494 | 496 |
| 497 TEST_F(TabManagerTest, OnSessionRestoreStartedAndEnded) { |
| 498 content::WebContents* test_contents = |
| 499 WebContentsTester::CreateTestWebContents(browser_context(), nullptr); |
| 500 |
| 501 std::vector<SessionRestoreDelegate::RestoredTab> restored_tabs{ |
| 502 SessionRestoreDelegate::RestoredTab(test_contents, true, false, false)}; |
| 503 |
| 504 TabManager* tab_manager = g_browser_process->GetTabManager(); |
| 505 EXPECT_FALSE(tab_manager->IsInSessionRestore()); |
| 506 |
| 507 TabLoader::RestoreTabs(restored_tabs, base::TimeTicks()); |
| 508 EXPECT_TRUE(tab_manager->IsInSessionRestore()); |
| 509 |
| 510 WebContentsTester::For(test_contents)->NavigateAndCommit(GURL("about:blank")); |
| 511 WebContentsTester::For(test_contents)->TestSetIsLoading(false); |
| 512 // Session restore ends when all restored tabs finish loading |
| 513 EXPECT_FALSE(tab_manager->IsInSessionRestore()); |
| 514 } |
| 515 |
495 } // namespace resource_coordinator | 516 } // namespace resource_coordinator |
OLD | NEW |