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

Unified Diff: chrome/browser/permissions/permission_uma_util_unittest.cc

Issue 2047253002: Add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-reporter-implementation
Patch Set: Refactor tests Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/permissions/permission_uma_util.cc ('k') | chrome/browser/permissions/permission_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/permissions/permission_uma_util_unittest.cc
diff --git a/chrome/browser/permissions/permission_uma_util_unittest.cc b/chrome/browser/permissions/permission_uma_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ad3da9aa8d9850e5a1282c2eafd1f7ff7fdd997
--- /dev/null
+++ b/chrome/browser/permissions/permission_uma_util_unittest.cc
@@ -0,0 +1,131 @@
+// Copyright 2016 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 "chrome/browser/permissions/permission_uma_util.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/signin/fake_signin_manager_builder.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/sync/profile_sync_service_factory.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/browser_sync/browser/profile_sync_service.h"
+#include "components/browser_sync/common/browser_sync_switches.h"
+#include "components/prefs/pref_service.h"
+#include "components/signin/core/browser/fake_signin_manager.h"
+#include "components/sync_driver/glue/sync_backend_host_mock.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+const char* kTestingGaiaId = "gaia_id";
+const char* kTestingUsername = "fake_username";
+} // namespace
+
+class PermissionUmaUtilTest : public testing::Test {
+ protected:
+ PermissionUmaUtilTest() : profile_(new TestingProfile()) {}
+
+ static bool IsOptedInPermissionActionReporting(Profile* profile) {
+ return PermissionUmaUtil::IsOptedInPermissionActionReporting(profile);
+ }
+
+ void SetUp() override {
+ profile_.reset(new TestingProfile());
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, NULL);
+ }
+
+ void FakeSignIn() {
+ SigninManagerBase* signin_manager = static_cast<FakeSigninManager*>(
+ SigninManagerFactory::GetForProfile(profile()));
+ signin_manager->SetAuthenticatedAccountInfo(kTestingGaiaId,
+ kTestingUsername);
+ // Attach a sync backend to the profile sync service.
+ GetProfileSyncService()->backend_.reset(
+ new browser_sync::SyncBackendHostMock());
+ GetProfileSyncService()->backend_initialized_ = true;
+ }
+
+ void SetSafeBrowsing(bool enabled) {
+ PrefService* preferences = profile_->GetPrefs();
+ preferences->SetBoolean(prefs::kSafeBrowsingEnabled, enabled);
+ }
+
+ ProfileSyncService* GetProfileSyncService() {
+ return ProfileSyncServiceFactory::GetForProfile(profile());
+ }
+
+ Profile* profile() { return profile_.get(); }
+
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
+ std::unique_ptr<Profile> profile_;
+};
+
+TEST_F(PermissionUmaUtilTest, IsOptedInPermissionActionReporting) {
raymes 2016/06/23 00:38:55 IsOptedInPermissionActionReportingSignIn ?
stefanocs 2016/06/23 01:04:15 Done.
+ SetSafeBrowsing(true);
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePermissionActionReporting);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+
+ FakeSignIn();
+ EXPECT_FALSE(
+ IsOptedInPermissionActionReporting(profile()->GetOffTheRecordProfile()));
+ EXPECT_TRUE(IsOptedInPermissionActionReporting(profile()));
+}
+
+TEST_F(PermissionUmaUtilTest, IsOptedInPermissionActionReportingFlagCheck) {
+ SetSafeBrowsing(true);
+ FakeSignIn();
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kDisablePermissionActionReporting);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+}
+
+TEST_F(PermissionUmaUtilTest,
+ IsOptedInPermissionActionReportingSafeBrowsingCheck) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePermissionActionReporting);
+ FakeSignIn();
+ SetSafeBrowsing(false);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+}
+
+TEST_F(PermissionUmaUtilTest,
+ IsOptedInPermissionActionReportingProfileSyncServiceCheck) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePermissionActionReporting);
+ SetSafeBrowsing(true);
+ FakeSignIn();
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+}
+
+TEST_F(PermissionUmaUtilTest,
+ IsOptedInPermissionActionReportingSyncPreferenceCheck) {
stefanocs 2016/06/22 04:36:03 Is the right way to do the sync preference test?
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePermissionActionReporting);
+ SetSafeBrowsing(true);
+ FakeSignIn();
+
+ syncer::ModelTypeSet selectable_data_types = syncer::UserSelectableTypes();
raymes 2016/06/23 00:38:55 Maybe we should start with an empty set of sync ty
stefanocs 2016/06/23 01:04:15 Done.
+
+ selectable_data_types.Remove(syncer::PROXY_TABS);
+ GetProfileSyncService()->OnUserChoseDatatypes(false, selectable_data_types);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+ selectable_data_types.Put(syncer::PROXY_TABS);
+
+ selectable_data_types.Remove(syncer::PREFERENCES);
+ GetProfileSyncService()->OnUserChoseDatatypes(false, selectable_data_types);
+ EXPECT_FALSE(IsOptedInPermissionActionReporting(profile()));
+ selectable_data_types.Put(syncer::PREFERENCES);
+
+ GetProfileSyncService()->OnUserChoseDatatypes(true, selectable_data_types);
+ EXPECT_TRUE(IsOptedInPermissionActionReporting(profile()));
+}
« no previous file with comments | « chrome/browser/permissions/permission_uma_util.cc ('k') | chrome/browser/permissions/permission_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698