[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / chrome / browser / ui / profile_error_browsertest.cc
blobbc9d3073d92e208d3f1032c6e2f45d0fbb764bc3
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.
5 #include <string>
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"
19 namespace {
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 the creation of an empty or
25 // corrupted profile, allowing to test both the corruption case and that what
26 // it is testing indeed happens differently when not under corruption.
27 public:
28 ProfileErrorBrowserTest() : do_corrupt_(GetParam()) {}
30 bool SetUpUserDataDirectory() override {
31 base::FilePath profile_dir;
32 if (!PathService::Get(chrome::DIR_USER_DATA, &profile_dir)) {
33 ADD_FAILURE();
34 return false;
36 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
37 if (!base::CreateDirectory(profile_dir)) {
38 ADD_FAILURE();
39 return false;
41 const base::FilePath pref_file =
42 profile_dir.Append(chrome::kPreferencesFilename);
44 // Write either an empty or an invalid string to the user profile as
45 // determined by the boolean parameter.
46 const std::string kUserProfileData(do_corrupt_ ? "invalid json" : "{}");
47 if (!base::WriteFile(pref_file, kUserProfileData.c_str(),
48 kUserProfileData.size())) {
49 ADD_FAILURE();
50 return false;
52 return true;
55 void SetUpInProcessBrowserTestFixture() override {
56 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
58 // Skip showing the error message box in order to avoid freezing the main
59 // thread.
60 chrome::internal::g_should_skip_message_box_for_test = true;
63 protected:
64 // Histogram value verifier.
65 const base::HistogramTester histogram_tester_;
67 // Whether the test fixture and test should set up a corrupted profile and
68 // expect a reaction to one.
69 const bool do_corrupt_;
72 #if defined(OS_CHROMEOS)
73 // Disable the test on chromos since kernel controls the user profile thus we
74 // won't be able to corrupt it.
75 #define MAYBE_CorruptedProfile DISABLED_CorruptedProfile
76 #else
77 #define MAYBE_CorruptedProfile CorruptedProfile
78 #endif
80 IN_PROC_BROWSER_TEST_P(ProfileErrorBrowserTest, MAYBE_CorruptedProfile) {
81 const char kPaintHistogram[] = "Startup.FirstWebContents.NonEmptyPaint";
82 const char kLoadHistogram[] = "Startup.FirstWebContents.MainFrameLoad";
84 // Navigate to a URL so the first non-empty paint is registered.
85 ui_test_utils::NavigateToURL(browser(), GURL("http://www.example.com/"));
86 if (do_corrupt_) {
87 histogram_tester_.ExpectTotalCount(kPaintHistogram, 0);
88 histogram_tester_.ExpectTotalCount(kLoadHistogram, 0);
89 } else {
90 histogram_tester_.ExpectTotalCount(kPaintHistogram, 1);
91 histogram_tester_.ExpectTotalCount(kLoadHistogram, 1);
95 INSTANTIATE_TEST_CASE_P(ProfileErrorBrowserTestInstance,
96 ProfileErrorBrowserTest,
97 testing::Bool());
99 } // namespace