1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The tests in this file verify the behavior of variations safe mode. The tests
// should be kept in sync with those in ios/chrome/browser/variations/
// variations_safe_mode_egtest.mm.
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/browser_process.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/prefs/pref_service.h"
#include "components/variations/metrics.h"
#include "components/variations/pref_names.h"
#include "components/variations/service/variations_field_trial_creator.h"
#include "components/variations/variations_test_utils.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace variations {
class VariationsSafeModeBrowserTest : public InProcessBrowserTest {
public:
VariationsSafeModeBrowserTest() { DisableTestingConfig(); }
~VariationsSafeModeBrowserTest() override = default;
protected:
base::HistogramTester histogram_tester_;
};
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
PRE_PRE_PRE_ThreeCrashesTriggerSafeMode) {
// The PRE test mechanism is used to set prefs in the local state file before
// the next browser test runs. No InProcessBrowserTest functions allow this
// pref to be set early enough to be read by the variations code, which runs
// very early during startup.
PrefService* local_state = g_browser_process->local_state();
WriteSeedData(local_state, kTestSeedData, kSafeSeedPrefKeys);
SimulateCrash(local_state);
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
PRE_PRE_ThreeCrashesTriggerSafeMode) {
SimulateCrash(g_browser_process->local_state());
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
PRE_ThreeCrashesTriggerSafeMode) {
SimulateCrash(g_browser_process->local_state());
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
ThreeCrashesTriggerSafeMode) {
EXPECT_EQ(g_browser_process->local_state()->GetInteger(
prefs::kVariationsCrashStreak),
3);
histogram_tester_.ExpectUniqueSample("Variations.SafeMode.Streak.Crashes", 3,
1);
// Verify that Chrome fell back to a safe seed, which happens during browser
// test setup.
histogram_tester_.ExpectUniqueSample(
"Variations.SafeMode.LoadSafeSeed.Result", LoadSeedResult::kSuccess, 1);
histogram_tester_.ExpectUniqueSample("Variations.SeedUsage",
SeedUsage::kSafeSeedUsed, 1);
// Verify that |kTestSeedData| has been applied.
EXPECT_TRUE(FieldTrialListHasAllStudiesFrom(kTestSeedData));
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
PRE_FetchFailuresTriggerSafeMode) {
// The PRE test mechanism is used to set prefs in the local state file before
// the next browser test runs. No InProcessBrowserTest functions allow this
// pref to be set early enough to be read by the variations code, which runs
// very early during startup.
PrefService* local_state = g_browser_process->local_state();
local_state->SetInteger(prefs::kVariationsFailedToFetchSeedStreak, 25);
WriteSeedData(local_state, kTestSeedData, kSafeSeedPrefKeys);
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
FetchFailuresTriggerSafeMode) {
histogram_tester_.ExpectUniqueSample(
"Variations.SafeMode.Streak.FetchFailures", 25, 1);
// Verify that Chrome fell back to a safe seed, which happens during browser
// test setup.
histogram_tester_.ExpectUniqueSample(
"Variations.SafeMode.LoadSafeSeed.Result", LoadSeedResult::kSuccess, 1);
histogram_tester_.ExpectUniqueSample("Variations.SeedUsage",
SeedUsage::kSafeSeedUsed, 1);
// Verify that |kTestSeedData| has been applied.
EXPECT_TRUE(FieldTrialListHasAllStudiesFrom(kTestSeedData));
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest,
PRE_DoNotTriggerSafeMode) {
// The PRE test mechanism is used to set prefs in the local state file before
// the next browser test runs. No InProcessBrowserTest functions allow this
// pref to be set early enough to be read by the variations code, which runs
// very early during startup.
PrefService* local_state = g_browser_process->local_state();
local_state->SetInteger(prefs::kVariationsCrashStreak, 2);
local_state->SetInteger(prefs::kVariationsFailedToFetchSeedStreak, 24);
WriteSeedData(local_state, kTestSeedData, kRegularSeedPrefKeys);
}
IN_PROC_BROWSER_TEST_F(VariationsSafeModeBrowserTest, DoNotTriggerSafeMode) {
histogram_tester_.ExpectUniqueSample("Variations.SafeMode.Streak.Crashes", 2,
1);
histogram_tester_.ExpectUniqueSample(
"Variations.SafeMode.Streak.FetchFailures", 24, 1);
// Verify that Chrome applied the regular seed.
histogram_tester_.ExpectUniqueSample("Variations.SeedLoadResult",
LoadSeedResult::kSuccess, 1);
histogram_tester_.ExpectUniqueSample("Variations.SeedUsage",
SeedUsage::kRegularSeedUsed, 1);
}
} // namespace variations
|