 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, | |
| 
gab
2015/06/25 14:38:23
Add a comment about this fixture, explaining what
 | |
| 22 public testing::WithParamInterface<bool> { | |
| 23 public: | |
| 24 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {} | |
| 25 | |
| 26 bool SetUpUserDataDirectory() override { | |
| 27 // Setup normally in the PRE test and corrupt user profile in the main test. | |
| 28 if (IsPRETest()) | |
| 29 return InProcessBrowserTest::SetUpUserDataDirectory(); | |
| 30 if (do_corrupt_) | |
| 31 CorruptProfileOnDisk(); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 void SetUpInProcessBrowserTestFixture() override { | |
| 36 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 37 | |
| 38 // In the main test, skip showing the error message box in order to avoid | |
| 39 // freezing the main thread. | |
| 40 if (!IsPRETest()) | |
| 41 chrome::internal::g_should_skip_message_box_for_test = true; | |
| 42 } | |
| 43 | |
| 44 protected: | |
| 45 void CorruptProfileOnDisk() { | |
| 46 base::FilePath profile_dir; | |
| 47 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | |
| 48 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); | |
| 49 | |
| 50 const base::FilePath pref_file = | |
| 51 profile_dir.Append(chrome::kPreferencesFilename); | |
| 52 EXPECT_TRUE(base::PathExists(pref_file)); | |
| 53 | |
| 54 // Corrupt the user profile. | |
| 55 std::string junk("junk"); | |
| 56 EXPECT_TRUE(base::AppendToFile(pref_file, junk.c_str(), junk.size())); | |
| 57 } | |
| 58 | |
| 59 // Histogram value verifier. | |
| 60 const base::HistogramTester histogram_tester_; | |
| 61 | |
| 62 // Decide to corrupt or not depending on the params passed into the test | |
| 63 const bool do_corrupt_; | |
| 64 | |
| 65 private: | |
| 66 // Returns true if this is the PRE_ phase of the test. | |
| 67 bool IsPRETest() { | |
| 68 return base::StartsWithASCII( | |
| 69 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_", | |
| 70 true /* case_sensitive */); | |
| 71 } | |
| 72 }; | |
| 73 | |
| 74 #if defined(OS_CHROMEOS) | |
| 75 // Disable the test on chromos since kernel controls the user profile thus we | |
| 76 // won't be able to corrupt it. | |
| 77 #define MAYBE(test) DISABLED_##test | |
| 78 #else | |
| 79 #define MAYBE(test) test | |
| 80 #endif | |
| 81 | |
| 82 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) { | |
| 83 // Nothing to do, the purpose of this PRE test is only to bring up a default | |
| 84 // User Data directory. | |
| 85 } | |
| 86 | |
| 87 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) { | |
| 88 const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint"; | |
| 89 const char kFrameHistogram[] = "Startup.FirstWebContents.MainFrameLoad"; | |
| 
gab
2015/06/25 14:38:23
s/kFrameHistogram/kLoadHistogram/
I think is slig
 | |
| 90 | |
| 91 // Navigate to a URL so the first non-empty paint is registered. | |
| 92 ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/")); | |
| 93 if (do_corrupt_) { | |
| 94 histogram_tester_.ExpectTotalCount(kPaintHistogram, 0); | |
| 95 histogram_tester_.ExpectTotalCount(kFrameHistogram, 0); | |
| 96 } else { | |
| 97 histogram_tester_.ExpectTotalCount(kPaintHistogram, 1); | |
| 98 histogram_tester_.ExpectTotalCount(kFrameHistogram, 1); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance, | |
| 103 ProfileErrorBrowserTest, | |
| 104 testing::Bool()); | |
| 105 | |
| 106 } // namespace | |
| OLD | NEW |