 Chromium Code Reviews
 Chromium Code Reviews Issue 1169503002:
  Do not record startup metrics when non-browser UI was displayed  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1169503002:
  Do not record startup metrics when non-browser UI was displayed  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 
huangs
2015/06/12 18:16:14
2015
 
tiany
2015/06/16 14:37:18
Done.
 | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/files/file_util.h" | |
| 9 #include "base/metrics/histogram_base.h" | |
| 
huangs
2015/06/12 18:16:14
#include "base/memory/scoped_ptr.h"
 
tiany
2015/06/16 14:37:18
good catch! thanks.
 | |
| 10 #include "base/metrics/histogram_samples.h" | |
| 11 #include "base/metrics/statistics_recorder.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/prefs/pref_service.h" | |
| 14 #include "base/strings/string_util.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/ui/browser.h" | |
| 18 #include "chrome/browser/ui/simple_message_box_internal.h" | |
| 19 #include "chrome/common/chrome_constants.h" | |
| 20 #include "chrome/common/chrome_paths.h" | |
| 21 #include "chrome/common/pref_names.h" | |
| 22 #include "chrome/test/base/in_process_browser_test.h" | |
| 23 #include "chrome/test/base/testing_profile.h" | |
| 24 #include "chrome/test/base/ui_test_utils.h" | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 
huangs
2015/06/12 18:16:14
Nit: End sentence with "."
 
tiany
2015/06/16 14:37:18
Done.
 | |
| 28 // Returns the number of times |histogram_name| was reported so far; | |
| 29 bool StartupHistogramRecorded(const char* histogram_name) { | |
| 30 const base::HistogramBase* histogram = | |
| 31 base::StatisticsRecorder::FindHistogram(histogram_name); | |
| 32 if (!histogram) | |
| 33 return false; | |
| 34 | |
| 35 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | |
| 36 return (samples->TotalCount() > 0); | |
| 
gab
2015/06/12 18:12:38
@asvitkine: it's not clear to me from the base::St
 
Alexei Svitkine (slow)
2015/06/15 20:06:40
Chatted with Alex offline - suggested to use Histo
 | |
| 37 } | |
| 38 | |
| 39 class ProfileErrorBrowserTest : public InProcessBrowserTest, | |
| 40 public testing::WithParamInterface<bool> { | |
| 41 public: | |
| 42 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {} | |
| 43 | |
| 44 void SetUp() override { | |
| 45 // Imitate the behavior but do not show the message box so the test can | |
| 46 // terminate | |
| 47 chrome::internal::g_should_skip_message_box_for_test = true; | |
| 
gab
2015/06/12 18:12:38
Only do this if !IsPRETest(); it shouldn't matter
 | |
| 48 InProcessBrowserTest::SetUp(); | |
| 
gab
2015/06/12 18:12:38
Do this first (i.e. in general when overriding Set
 | |
| 49 } | |
| 50 | |
| 51 bool SetUpUserDataDirectory() override { | |
| 52 // Setup normally in the PRE test and corrupt user profile in the main test. | |
| 53 if (IsPRETest()) | |
| 54 return InProcessBrowserTest::SetUpUserDataDirectory(); | |
| 55 | |
| 56 if (do_corrupt_) | |
| 57 CorruptProfileOnDisk(); | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 protected: | |
| 62 void CorruptProfileOnDisk() { | |
| 63 base::FilePath profile_dir; | |
| 64 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | |
| 65 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); | |
| 66 | |
| 67 const base::FilePath pref_file = | |
| 68 profile_dir.Append(chrome::kPreferencesFilename); | |
| 69 EXPECT_TRUE(base::PathExists(pref_file)); | |
| 70 | |
| 71 // Corrupt the user profile. | |
| 72 std::string junk("junk"); | |
| 73 EXPECT_TRUE(base::AppendToFile(pref_file, junk.c_str(), junk.size())); | |
| 74 } | |
| 75 | |
| 76 bool do_corrupt_; | |
| 
gab
2015/06/12 18:12:38
Make this const and add a comment.
 | |
| 77 | |
| 78 private: | |
| 79 // Returns true if this is the PRE_ phase of the test. | |
| 80 bool IsPRETest() { | |
| 81 return StartsWithASCII( | |
| 82 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_", | |
| 83 true /* case_sensitive */); | |
| 84 } | |
| 85 }; | |
| 86 | |
| 87 #if defined(OS_CHROMEOS) | |
| 88 // Disable the test on chromos since kernel controls the user profile thus we | |
| 89 // won't be able to corrupt it. | |
| 90 #define MAYBE(test) DISABLED_##test | |
| 91 #else | |
| 92 #define MAYBE(test) test | |
| 93 #endif | |
| 94 | |
| 95 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) { | |
| 96 } | |
| 
gab
2015/06/12 18:12:38
Add a comment in the body to explain the purpose t
 | |
| 97 | |
| 98 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) { | |
| 99 // Navigate to a URL so the first non-empty paint is registered. | |
| 100 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); | |
| 101 if (do_corrupt_) { | |
| 102 EXPECT_FALSE(StartupHistogramRecorded( | |
| 103 "Startup.FirstWebContents.NonEmptyPaint")); | |
| 104 EXPECT_FALSE(StartupHistogramRecorded( | |
| 105 "Startup.FirstWebContents.MainFrameLoad")); | |
| 106 } else { | |
| 107 EXPECT_TRUE(StartupHistogramRecorded( | |
| 108 "Startup.FirstWebContents.NonEmptyPaint")); | |
| 109 EXPECT_TRUE(StartupHistogramRecorded( | |
| 110 "Startup.FirstWebContents.MainFrameLoad")); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance, | |
| 115 ProfileErrorBrowserTest, testing::Bool()); | |
| 116 | |
| 117 } // namespace | |
| OLD | NEW |