 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| Index: chrome/browser/ui/profile_error_browsertest.cc | 
| diff --git a/chrome/browser/ui/profile_error_browsertest.cc b/chrome/browser/ui/profile_error_browsertest.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..7d042fab482b1003268d0e70405cebfa7d0d1659 | 
| --- /dev/null | 
| +++ b/chrome/browser/ui/profile_error_browsertest.cc | 
| @@ -0,0 +1,110 @@ | 
| +// Copyright 2015 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include <string> | 
| + | 
| +#include "base/files/file_path.h" | 
| +#include "base/files/file_util.h" | 
| +#include "base/path_service.h" | 
| +#include "base/strings/string_util.h" | 
| +#include "base/test/histogram_tester.h" | 
| +#include "chrome/browser/ui/simple_message_box_internal.h" | 
| +#include "chrome/common/chrome_constants.h" | 
| +#include "chrome/common/chrome_paths.h" | 
| +#include "chrome/test/base/in_process_browser_test.h" | 
| +#include "chrome/test/base/testing_profile.h" | 
| +#include "chrome/test/base/ui_test_utils.h" | 
| + | 
| +namespace { | 
| + | 
| +class ProfileErrorBrowserTest : public InProcessBrowserTest, | 
| + public testing::WithParamInterface<bool> { | 
| + // A fixture that allows testing histograms reporting when faced with a | 
| + // corrupted profile. The boolean parameter forces corruption to happen or not, | 
| + // allowing to test both the corruption case and that what it is testing indeed | 
| + // happens differently when not under corruption. | 
| + public: | 
| + ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {} | 
| + | 
| + bool SetUpUserDataDirectory() override { | 
| + // Setup normally in the PRE test and corrupt user profile in the main test. | 
| + if (IsPRETest()) | 
| + return InProcessBrowserTest::SetUpUserDataDirectory(); | 
| + if (do_corrupt_) | 
| + CorruptProfileOnDisk(); | 
| + return true; | 
| + } | 
| + | 
| + void SetUpInProcessBrowserTestFixture() override { | 
| + InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 
| + | 
| + // In the main test, skip showing the error message box in order to avoid | 
| + // freezing the main thread. | 
| + if (!IsPRETest()) | 
| + chrome::internal::g_should_skip_message_box_for_test = true; | 
| + } | 
| + | 
| + protected: | 
| + void CorruptProfileOnDisk() { | 
| + base::FilePath profile_dir; | 
| + EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | 
| + profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); | 
| + | 
| + const base::FilePath pref_file = | 
| + profile_dir.Append(chrome::kPreferencesFilename); | 
| + EXPECT_TRUE(base::PathExists(pref_file)); | 
| + | 
| + // Corrupt the user profile. | 
| + std::string junk("junk"); | 
| + EXPECT_TRUE(base::AppendToFile(pref_file, junk.c_str(), junk.size())); | 
| + } | 
| + | 
| + // Histogram value verifier. | 
| + const base::HistogramTester histogram_tester_; | 
| + | 
| + // Decide to corrupt or not depending on the params passed into the test | 
| + const bool do_corrupt_; | 
| + | 
| + private: | 
| + // Returns true if this is the PRE_ phase of the test. | 
| + bool IsPRETest() { | 
| + return base::StartsWithASCII( | 
| + testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_", | 
| + true /* case_sensitive */); | 
| + } | 
| +}; | 
| + | 
| +#if defined(OS_CHROMEOS) | 
| +// Disable the test on chromos since kernel controls the user profile thus we | 
| +// won't be able to corrupt it. | 
| +#define MAYBE(test) DISABLED_##test | 
| +#else | 
| +#define MAYBE(test) test | 
| +#endif | 
| + | 
| +IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) { | 
| + // Nothing to do, the purpose of this PRE test is only to bring up a default | 
| 
sky
2015/06/30 22:16:59
I'm confused by this. Don't we nuke the directory
 
tiany
2015/06/30 22:33:50
For the pre tests, InProcessBrowserTest::SetUpUser
 
sky
2015/06/30 22:38:57
AFAICT SetUpUserDataDirectory() is always called.
 
gab
2015/07/01 00:35:33
I don't think SetUpUserDataDirectory() sets up a f
 | 
| + // User Data directory. | 
| +} | 
| + | 
| +IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) { | 
| + const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint"; | 
| + const char kLoadHistogram[] = "Startup.FirstWebContents.MainFrameLoad"; | 
| + | 
| + // Navigate to a URL so the first non-empty paint is registered. | 
| + ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/")); | 
| + if (do_corrupt_) { | 
| + histogram_tester_.ExpectTotalCount(kPaintHistogram, 0); | 
| + histogram_tester_.ExpectTotalCount(kLoadHistogram, 0); | 
| + } else { | 
| + histogram_tester_.ExpectTotalCount(kPaintHistogram, 1); | 
| + histogram_tester_.ExpectTotalCount(kLoadHistogram, 1); | 
| + } | 
| +} | 
| + | 
| +INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance, | 
| + ProfileErrorBrowserTest, | 
| + testing::Bool()); | 
| + | 
| +} // namespace |