Commit ad676e5c authored by Swapnil's avatar Swapnil Committed by Commit Bot

Split policy statistics collector browsertest

The browsertests of statistics collector policy are moved from
policy_browsertests to a separate file.

Bug: 1128322
Change-Id: Ie35643f650c86d710ae470ec51745f8d227a07c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410063
Commit-Queue: Swapnil Gupta <swapnilgupta@google.com>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807853}
parent 8f9fa594
...@@ -39,9 +39,6 @@ ...@@ -39,9 +39,6 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -1423,48 +1420,6 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, WaitForInitialUserActivitySatisfied) { ...@@ -1423,48 +1420,6 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, WaitForInitialUserActivitySatisfied) {
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Similar to PolicyTest but sets a couple of policies before the browser is
// started.
class PolicyStatisticsCollectorTest : public PolicyTest {
public:
PolicyStatisticsCollectorTest() {}
~PolicyStatisticsCollectorTest() override {}
void SetUpInProcessBrowserTestFixture() override {
PolicyTest::SetUpInProcessBrowserTestFixture();
PolicyMap policies;
policies.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(true),
nullptr);
policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value("http://chromium.org"), nullptr);
provider_.UpdateChromePolicy(policies);
}
};
IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) {
// Verifies that policy usage histograms are collected at startup.
// BrowserPolicyConnector::Init() has already been called. Make sure the
// CompleteInitialization() task has executed as well.
content::RunAllPendingInMessageLoop();
base::HistogramBase* histogram =
base::StatisticsRecorder::FindHistogram("Enterprise.Policies");
std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
// HomepageLocation has policy ID 1.
EXPECT_GT(samples->GetCount(1), 0);
// ShowHomeButton has policy ID 35.
EXPECT_GT(samples->GetCount(35), 0);
// BookmarkBarEnabled has policy ID 82.
EXPECT_GT(samples->GetCount(82), 0);
}
// Test that when SSL error overriding is allowed by policy (default), the // Test that when SSL error overriding is allowed by policy (default), the
// proceed link appears on SSL blocking pages. // proceed link appears on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(PolicyTest, SSLErrorOverridingAllowed) { IN_PROC_BROWSER_TEST_F(PolicyTest, SSLErrorOverridingAllowed) {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/values.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
namespace policy {
// Similar to PolicyTest but sets a couple of policies before the browser is
// started.
class PolicyStatisticsCollectorTest : public PolicyTest {
public:
PolicyStatisticsCollectorTest() = default;
~PolicyStatisticsCollectorTest() override = default;
void SetUpInProcessBrowserTestFixture() override {
PolicyTest::SetUpInProcessBrowserTestFixture();
PolicyMap policies;
policies.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(true),
nullptr);
policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value("http://chromium.org"), nullptr);
provider_.UpdateChromePolicy(policies);
}
};
IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) {
// Verifies that policy usage histograms are collected at startup.
// BrowserPolicyConnector::Init() has already been called. Make sure the
// CompleteInitialization() task has executed as well.
content::RunAllPendingInMessageLoop();
base::HistogramBase* histogram =
base::StatisticsRecorder::FindHistogram("Enterprise.Policies");
std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
// HomepageLocation has policy ID 1.
EXPECT_GT(samples->GetCount(1), 0);
// ShowHomeButton has policy ID 35.
EXPECT_GT(samples->GetCount(35), 0);
// BookmarkBarEnabled has policy ID 82.
EXPECT_GT(samples->GetCount(82), 0);
}
} // namespace policy
...@@ -1192,6 +1192,7 @@ if (!is_android) { ...@@ -1192,6 +1192,7 @@ if (!is_android) {
"../browser/policy/policy_network_browsertest.cc", "../browser/policy/policy_network_browsertest.cc",
"../browser/policy/policy_prefs_browsertest.cc", "../browser/policy/policy_prefs_browsertest.cc",
"../browser/policy/policy_startup_browsertest.cc", "../browser/policy/policy_startup_browsertest.cc",
"../browser/policy/policy_statistics_collector_browsertest.cc",
"../browser/policy/policy_test_google_browsertest.cc", "../browser/policy/policy_test_google_browsertest.cc",
"../browser/policy/policy_test_utils.cc", "../browser/policy/policy_test_utils.cc",
"../browser/policy/policy_test_utils.h", "../browser/policy/policy_test_utils.h",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment