 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 2015 The Chromium Authors. All rights reserved. | |
| 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/path_service.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "base/test/histogram_tester.h" | |
| 12 #include "chrome/browser/ui/simple_message_box_internal.h" | |
| 13 #include "chrome/common/chrome_constants.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | |
| 16 #include "chrome/test/base/testing_profile.h" | |
| 17 #include "chrome/test/base/ui_test_utils.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class ProfileErrorBrowserTest : public InProcessBrowserTest, | |
| 22 public testing::WithParamInterface<bool> { | |
| 23 // A fixture that allows testing histograms reporting when faced with a | |
| 24 // corrupted profile. The boolean parameter forces the creation of an empty or | |
| 25 // corrupted profile, allowing to test both the corruption case and that what | |
| 26 // it is testing indeed happens differently when not under corruption. | |
| 27 public: | |
| 28 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {} | |
| 29 | |
| 30 bool SetUpUserDataDirectory() override { | |
| 31 CreateProfileOnDisk(); | |
| 32 return InProcessBrowserTest::SetUpUserDataDirectory(); | |
| 
gab
2015/07/06 15:52:54
Actually this doesn't do any setup (https://code.g
 
tiany
2015/07/06 21:49:54
Done.
 | |
| 33 } | |
| 34 | |
| 35 void SetUpInProcessBrowserTestFixture() override { | |
| 36 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 37 | |
| 38 // Skip showing the error message box in order to avoid freezing the main | |
| 39 // thread. | |
| 40 chrome::internal::g_should_skip_message_box_for_test = true; | |
| 41 } | |
| 42 | |
| 43 protected: | |
| 44 void CreateProfileOnDisk() { | |
| 45 base::FilePath profile_dir; | |
| 46 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | |
| 47 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); | |
| 48 EXPECT_TRUE(base::CreateDirectory(profile_dir)); | |
| 49 const base::FilePath pref_file = | |
| 50 profile_dir.Append(chrome::kPreferencesFilename); | |
| 51 | |
| 52 // Write either an empty or a invalid string to user profile, determined by | |
| 
gab
2015/07/06 15:52:53
s/,determined/as determined/
 
gab
2015/07/06 15:52:54
s/a invalid/an invalid/
 
gab
2015/07/06 15:52:54
s/to user profile/ to the user profile/
 
tiany
2015/07/06 21:49:54
Done.
 
tiany
2015/07/06 21:49:54
Done.
 
tiany
2015/07/06 21:49:54
Done.
 
tiany
2015/07/06 21:49:54
Done.
 | |
| 53 // the boolean parameter | |
| 
gab
2015/07/06 15:52:54
End sentence with '.'
 
tiany
2015/07/06 21:49:54
Done.
 | |
| 54 std::string data(do_corrupt_ ? "invalid json" : "{}"); | |
| 
gab
2015/07/06 15:52:54
const char[]
(instead of putting it in a string a
 
tiany
2015/07/06 21:49:54
Discussed with gab, used const std::string instead
 | |
| 55 EXPECT_TRUE(base::WriteFile(pref_file, data.c_str(), data.size())); | |
| 56 } | |
| 57 | |
| 58 // Histogram value verifier. | |
| 59 const base::HistogramTester histogram_tester_; | |
| 60 | |
| 61 // Decide to create an empty or a corrupted profile depending on the params | |
| 62 // passed into the test | |
| 
gab
2015/07/06 15:52:53
// Whether the test fixture and test should set up
 
tiany
2015/07/06 21:49:54
Done.
 | |
| 63 const bool do_corrupt_; | |
| 64 }; | |
| 65 | |
| 66 #if defined(OS_CHROMEOS) | |
| 67 // Disable the test on chromos since kernel controls the user profile thus we | |
| 68 // won't be able to corrupt it. | |
| 69 #define MAYBE(test) DISABLED_##test | |
| 
gab
2015/07/06 15:52:54
No need for advanced MAYBE macro anymore, i.e.:
M
 
tiany
2015/07/06 21:49:54
Done.
 | |
| 70 #else | |
| 71 #define MAYBE(test) test | |
| 72 #endif | |
| 73 | |
| 74 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) { | |
| 75 const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint"; | |
| 76 const char kLoadHistogram[] = "Startup.FirstWebContents.MainFrameLoad"; | |
| 77 | |
| 78 // Navigate to a URL so the first non-empty paint is registered. | |
| 79 ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/")); | |
| 80 if (do_corrupt_) { | |
| 81 histogram_tester_.ExpectTotalCount(kPaintHistogram, 0); | |
| 82 histogram_tester_.ExpectTotalCount(kLoadHistogram, 0); | |
| 83 } else { | |
| 84 histogram_tester_.ExpectTotalCount(kPaintHistogram, 1); | |
| 85 histogram_tester_.ExpectTotalCount(kLoadHistogram, 1); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance, | |
| 90 ProfileErrorBrowserTest, | |
| 91 testing::Bool()); | |
| 92 | |
| 93 } // namespace | |
| OLD | NEW |