Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/browser/ui/profile_error_browsertest.cc

Issue 1169503002: Do not record startup metrics when non-browser UI was displayed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed wording. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 corruption to happen or not,
25 // allowing to test both the corruption case and that what it is testing indeed
26 // happens differently when not under corruption.
27 public:
28 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {}
29
30 bool SetUpUserDataDirectory() override {
31 // Setup normally in the PRE test and corrupt user profile in the main test.
32 if (IsPRETest())
33 return InProcessBrowserTest::SetUpUserDataDirectory();
34 if (do_corrupt_)
35 CorruptProfileOnDisk();
36 return true;
37 }
38
39 void SetUpInProcessBrowserTestFixture() override {
40 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
41
42 // In the main test, skip showing the error message box in order to avoid
43 // freezing the main thread.
44 if (!IsPRETest())
45 chrome::internal::g_should_skip_message_box_for_test = true;
46 }
47
48 protected:
49 void CorruptProfileOnDisk() {
50 base::FilePath profile_dir;
51 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
52 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
53
54 const base::FilePath pref_file =
55 profile_dir.Append(chrome::kPreferencesFilename);
56 EXPECT_TRUE(base::PathExists(pref_file));
57
58 // Corrupt the user profile.
59 std::string junk("junk");
60 EXPECT_TRUE(base::AppendToFile(pref_file, junk.c_str(), junk.size()));
61 }
62
63 // Histogram value verifier.
64 const base::HistogramTester histogram_tester_;
65
66 // Decide to corrupt or not depending on the params passed into the test
67 const bool do_corrupt_;
68
69 private:
70 // Returns true if this is the PRE_ phase of the test.
71 bool IsPRETest() {
72 return base::StartsWithASCII(
73 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_",
74 true /* case_sensitive */);
75 }
76 };
77
78 #if defined(OS_CHROMEOS)
79 // Disable the test on chromos since kernel controls the user profile thus we
80 // won't be able to corrupt it.
81 #define MAYBE(test) DISABLED_##test
82 #else
83 #define MAYBE(test) test
84 #endif
85
86 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) {
87 // 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
88 // User Data directory.
89 }
90
91 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) {
92 const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint";
93 const char kLoadHistogram[] = "Startup.FirstWebContents.MainFrameLoad";
94
95 // Navigate to a URL so the first non-empty paint is registered.
96 ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/"));
97 if (do_corrupt_) {
98 histogram_tester_.ExpectTotalCount(kPaintHistogram, 0);
99 histogram_tester_.ExpectTotalCount(kLoadHistogram, 0);
100 } else {
101 histogram_tester_.ExpectTotalCount(kPaintHistogram, 1);
102 histogram_tester_.ExpectTotalCount(kLoadHistogram, 1);
103 }
104 }
105
106 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance,
107 ProfileErrorBrowserTest,
108 testing::Bool());
109
110 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/simple_message_box_mac.mm ('k') | chrome/browser/ui/simple_message_box_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698