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

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: Removed unnecessary include statements, override SetUpInProcessBrowserTestFixture instead of Setup. Created 5 years, 6 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 public:
24 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {}
25
26 void SetUpInProcessBrowserTestFixture() override {
27 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
28 // Imitate the behavior in the main test but do not show the message box so
gab 2015/06/16 19:55:34 nit: +empty line above.
tiany 2015/06/23 18:36:35 Done.
29 // it can terminate
gab 2015/06/16 19:55:34 How about something like: // In the main test, sk
tiany 2015/06/23 18:36:35 Done.
30 if (!IsPRETest())
31 chrome::internal::g_should_skip_message_box_for_test = true;
32 }
33
34 bool SetUpUserDataDirectory() override {
gab 2015/06/16 19:55:34 nit: Put this override first (since it happens fir
tiany 2015/06/23 18:36:35 Done.
35 // Setup normally in the PRE test and corrupt user profile in the main test.
36 if (IsPRETest())
37 return InProcessBrowserTest::SetUpUserDataDirectory();
38
gab 2015/06/16 19:55:34 Remove empty line here (since the comment on line
tiany 2015/06/23 18:36:35 Done.
39 if (do_corrupt_)
40 CorruptProfileOnDisk();
41 return 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 base::HistogramTester& histograms() { return histograms_tester_; }
gab 2015/06/16 19:55:34 In Chromium we never (almost never) use non-const
tiany 2015/06/23 18:36:35 Done.
60
61 // Decide to corrupt or not depending on the params passed into the test
62 const bool do_corrupt_;
63
64 private:
65 // Returns true if this is the PRE_ phase of the test.
66 bool IsPRETest() {
67 return base::StartsWithASCII(
68 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_",
69 true /* case_sensitive */);
70 }
71
72 // Histogram value verifier.
73 base::HistogramTester histograms_tester_;
74 };
75
76 #if defined(OS_CHROMEOS)
77 // Disable the test on chromos since kernel controls the user profile thus we
78 // won't be able to corrupt it.
79 #define MAYBE(test) DISABLED_##test
80 #else
81 #define MAYBE(test) test
82 #endif
83
84 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) {
85 // Nothing to do, the purpose of this PRE test is only to bring up a default
86 // User Data directory.
87 }
88
89 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) {
90 const char* kPaintHistogram = "Startup.FirstWebContents.NonEmptyPaint";
gab 2015/06/16 19:55:34 const char kFoo[] instead of const char* kFoo for
tiany 2015/06/23 18:36:35 Done.
91 const char* kFrameHistogram = "Startup.FirstWebContents.MainFrameLoad";
92
93 // Navigate to a URL so the first non-empty paint is registered.
94 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/"));
gab 2015/06/16 19:55:34 Best practice is to use http://example.com as a du
tiany 2015/06/23 18:36:35 Done.
95 if (do_corrupt_) {
96 histograms().ExpectTotalCount(kPaintHistogram, 0);
97 histograms().ExpectTotalCount(kFrameHistogram, 0);
98 } else {
99 histograms().ExpectTotalCount(kPaintHistogram, 1);
100 histograms().ExpectTotalCount(kFrameHistogram, 1);
101 }
102 }
103
104 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance,
105 ProfileErrorBrowserTest,
106 testing::Bool());
107
108 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698