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

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: Merge 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"
huangs 2015/06/16 17:50:52 Remove unused #includes. I don't see the followin
8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/histogram_samples.h"
12 #include "base/metrics/statistics_recorder.h"
13 #include "base/path_service.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_util.h"
16 #include "base/test/histogram_tester.h"
17 #include "base/values.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/simple_message_box_internal.h"
21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/ui_test_utils.h"
27
28 namespace {
29
30 class ProfileErrorBrowserTest : public InProcessBrowserTest,
31 public testing::WithParamInterface<bool> {
32 public:
33 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {}
34
35 void SetUp() override {
36 // Imitate the behavior but do not show the message box in the main test so
37 // it can terminate
38 if (!IsPRETest())
39 chrome::internal::g_should_skip_message_box_for_test = true;
40 InProcessBrowserTest::SetUp();
41 }
42
43 bool SetUpUserDataDirectory() override {
44 // Setup normally in the PRE test and corrupt user profile in the main test.
45 if (IsPRETest())
46 return InProcessBrowserTest::SetUpUserDataDirectory();
47
48 if (do_corrupt_)
49 CorruptProfileOnDisk();
50 return true;
51 }
52
53 protected:
54 void CorruptProfileOnDisk() {
55 base::FilePath profile_dir;
56 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
57 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
58
59 const base::FilePath pref_file =
60 profile_dir.Append(chrome::kPreferencesFilename);
61 EXPECT_TRUE(base::PathExists(pref_file));
62
63 // Corrupt the user profile.
64 std::string junk("junk");
65 EXPECT_TRUE(base::AppendToFile(pref_file, junk.c_str(), junk.size()));
66 }
67
68 base::HistogramTester& histograms() { return histograms_tester_; }
69
70 // Decide to corrupt or not depending on the params passed into the test
71 const bool do_corrupt_;
72
73 private:
74 // Returns true if this is the PRE_ phase of the test.
75 bool IsPRETest() {
76 return base::StartsWithASCII(
77 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_",
78 true /* case_sensitive */);
79 }
80
81 // Histogram value verifier.
82 base::HistogramTester histograms_tester_;
83 };
84
85 #if defined(OS_CHROMEOS)
86 // Disable the test on chromos since kernel controls the user profile thus we
87 // won't be able to corrupt it.
88 #define MAYBE(test) DISABLED_##test
89 #else
90 #define MAYBE(test) test
91 #endif
92
93 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(PRE_CorruptedProfile)) {
94 // Nothing to do, the purpose of this PRE test is only to bring up a default
95 // User Data directory.
96 }
97
98 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE(CorruptedProfile)) {
99 const char* kPaintHistogram = "Startup.FirstWebContents.NonEmptyPaint";
100 const char* kFrameHistogram = "Startup.FirstWebContents.MainFrameLoad";
101
102 // Navigate to a URL so the first non-empty paint is registered.
103 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/"));
104 if (do_corrupt_) {
105 histograms().ExpectTotalCount(kPaintHistogram, 0);
106 histograms().ExpectTotalCount(kFrameHistogram, 0);
107 } else {
108 histograms().ExpectTotalCount(kPaintHistogram, 1);
109 histograms().ExpectTotalCount(kFrameHistogram, 1);
110 }
111 }
112
113 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance,
114 ProfileErrorBrowserTest,
115 testing::Bool());
116
117 } // 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