 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 base::FilePath profile_dir; | |
| 32 if (!PathService::Get(chrome::DIR_USER_DATA, &profile_dir)) { | |
| 33 ADD_FAILURE(); | |
| 34 return false; | |
| 35 } | |
| 36 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); | |
| 37 if (!base::CreateDirectory(profile_dir)) { | |
| 38 ADD_FAILURE(); | |
| 39 return false; | |
| 40 } | |
| 41 const base::FilePath pref_file = | |
| 42 profile_dir.Append(chrome::kPreferencesFilename); | |
| 43 | |
| 44 // Write either an empty or an invalid string to the user profile as | |
| 45 // determined by the boolean parameter. | |
| 46 const std::string kUserProfileData(do_corrupt_ ? "invalid json" : "{}"); | |
| 47 if (!base::WriteFile(pref_file, kUserProfileData.c_str(), | |
| 48 kUserProfileData.size())) { | |
| 49 ADD_FAILURE(); | |
| 50 return false; | |
| 51 } | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 void SetUpInProcessBrowserTestFixture() override { | |
| 56 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 57 | |
| 58 // Skip showing the error message box in order to avoid freezing the main | |
| 59 // thread. | |
| 60 chrome::internal::g_should_skip_message_box_for_test = true; | |
| 61 } | |
| 62 | |
| 63 protected: | |
| 64 // Histogram value verifier. | |
| 65 const base::HistogramTester histogram_tester_; | |
| 66 | |
| 67 // Whether the test fixture and test should set up a corrupted profile and | |
| 68 // expect a reaction to one. | |
| 69 const bool do_corrupt_; | |
| 70 }; | |
| 71 | |
| 72 #if defined(OS_CHROMEOS) | |
| 73 // Disable the test on chromos since kernel controls the user profile thus we | |
| 74 // won't be able to corrupt it. | |
| 75 #define MAYBE_CorruptedProfile DISABLED_CorruptedProfile | |
| 76 #else | |
| 77 #define MAYBE_CorruptedProfile CorruptedProfile | |
| 78 #endif | |
| 79 | |
| 80 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE_CorruptedProfile) { | |
| 81 const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint"; | |
| 82 const char kLoadHistogram[] = "Startup.FirstWebContents.MainFrameLoad"; | |
| 83 | |
| 84 // Navigate to a URL so the first non-empty paint is registered. | |
| 85 ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/")); | |
| 86 if (do_corrupt_) { | |
| 87 histogram_tester_.ExpectTotalCount(kPaintHistogram, 0); | |
| 88 histogram_tester_.ExpectTotalCount(kLoadHistogram, 0); | |
| 89 } else { | |
| 
Nico
2015/07/08 18:49:06
Since over 50% of the test body is this if, it see
 
gab
2015/07/08 18:55:01
The test fixture also sets things up differently b
 | |
| 90 histogram_tester_.ExpectTotalCount(kPaintHistogram, 1); | |
| 91 histogram_tester_.ExpectTotalCount(kLoadHistogram, 1); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance, | |
| 96 ProfileErrorBrowserTest, | |
| 97 testing::Bool()); | |
| 98 | |
| 99 } // namespace | |
| OLD | NEW |