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 <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/test/histogram_tester.h" |
17 #include "base/test/mock_entropy_provider.h" | 18 #include "base/test/mock_entropy_provider.h" |
18 #include "base/test/simple_test_tick_clock.h" | 19 #include "base/test/simple_test_tick_clock.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" | 24 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" |
24 #include "chrome/browser/resource_coordinator/tab_stats.h" | 25 #include "chrome/browser/resource_coordinator/tab_stats.h" |
25 #include "chrome/browser/sessions/tab_loader.h" | 26 #include "chrome/browser/sessions/tab_loader.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 595 |
595 TabLoader::RestoreTabs(restored_tabs, base::TimeTicks()); | 596 TabLoader::RestoreTabs(restored_tabs, base::TimeTicks()); |
596 EXPECT_TRUE(tab_manager->IsSessionRestoreLoadingTabs()); | 597 EXPECT_TRUE(tab_manager->IsSessionRestoreLoadingTabs()); |
597 | 598 |
598 WebContentsTester::For(test_contents.get()) | 599 WebContentsTester::For(test_contents.get()) |
599 ->NavigateAndCommit(GURL("about:blank")); | 600 ->NavigateAndCommit(GURL("about:blank")); |
600 WebContentsTester::For(test_contents.get())->TestSetIsLoading(false); | 601 WebContentsTester::For(test_contents.get())->TestSetIsLoading(false); |
601 EXPECT_FALSE(tab_manager->IsSessionRestoreLoadingTabs()); | 602 EXPECT_FALSE(tab_manager->IsSessionRestoreLoadingTabs()); |
602 } | 603 } |
603 | 604 |
| 605 TEST_F(TabManagerTest, HistogramsSessionRestoreSwitchToTab) { |
| 606 const char kHistogramName[] = "TabManager.SessionRestore.SwitchToTab"; |
| 607 |
| 608 TabManager tab_manager; |
| 609 WebContents* tab = CreateWebContents(); |
| 610 auto* data = tab_manager.GetWebContentsData(tab); |
| 611 |
| 612 base::HistogramTester histograms; |
| 613 histograms.ExpectTotalCount(kHistogramName, 0); |
| 614 |
| 615 data->SetTabLoadingState(TAB_IS_LOADING); |
| 616 tab_manager.RecordSwitchToTab(tab); |
| 617 tab_manager.RecordSwitchToTab(tab); |
| 618 |
| 619 // Nothing should happen until we're in a session restore |
| 620 histograms.ExpectTotalCount(kHistogramName, 0); |
| 621 |
| 622 tab_manager.OnSessionRestoreStartedLoadingTabs(); |
| 623 |
| 624 data->SetTabLoadingState(TAB_IS_NOT_LOADING); |
| 625 tab_manager.RecordSwitchToTab(tab); |
| 626 tab_manager.RecordSwitchToTab(tab); |
| 627 histograms.ExpectTotalCount(kHistogramName, 2); |
| 628 histograms.ExpectBucketCount(kHistogramName, TAB_IS_NOT_LOADING, 2); |
| 629 |
| 630 data->SetTabLoadingState(TAB_IS_LOADING); |
| 631 tab_manager.RecordSwitchToTab(tab); |
| 632 tab_manager.RecordSwitchToTab(tab); |
| 633 tab_manager.RecordSwitchToTab(tab); |
| 634 |
| 635 histograms.ExpectTotalCount(kHistogramName, 5); |
| 636 histograms.ExpectBucketCount(kHistogramName, TAB_IS_NOT_LOADING, 2); |
| 637 histograms.ExpectBucketCount(kHistogramName, TAB_IS_LOADING, 3); |
| 638 |
| 639 data->SetTabLoadingState(TAB_IS_LOADED); |
| 640 tab_manager.RecordSwitchToTab(tab); |
| 641 tab_manager.RecordSwitchToTab(tab); |
| 642 tab_manager.RecordSwitchToTab(tab); |
| 643 tab_manager.RecordSwitchToTab(tab); |
| 644 |
| 645 histograms.ExpectTotalCount(kHistogramName, 9); |
| 646 histograms.ExpectBucketCount(kHistogramName, TAB_IS_NOT_LOADING, 2); |
| 647 histograms.ExpectBucketCount(kHistogramName, TAB_IS_LOADING, 3); |
| 648 histograms.ExpectBucketCount(kHistogramName, TAB_IS_LOADED, 4); |
| 649 } |
| 650 |
604 } // namespace resource_coordinator | 651 } // namespace resource_coordinator |
OLD | NEW |