Commit 6a867dfe authored by Archana Simha's avatar Archana Simha Committed by Commit Bot

[Extensions Checkup] Modifies extensions_checkup and adds unit test.

extensions_checkup verifies that the user has an extension installed
that is not policy installed, is not a component extension, and was
not installed by default.

Bug: 1019296
Change-Id: I1665bac06a33c1015db2637a0426ad9f023ff2dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922187
Commit-Queue: Archana Simha <archanasimha@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719363}
parent 23be23f9
...@@ -41,7 +41,11 @@ bool ShouldShowExtensionsCheckup(content::BrowserContext* context) { ...@@ -41,7 +41,11 @@ bool ShouldShowExtensionsCheckup(content::BrowserContext* context) {
// are policy-installed (even if they can be disabled), then do not show the // are policy-installed (even if they can be disabled), then do not show the
// extensions checkup experiment. // extensions checkup experiment.
for (const auto& extension : *extension_set) { for (const auto& extension : *extension_set) {
if (!extensions::Manifest::IsPolicyLocation(extension->location())) { if (extension->is_extension() &&
!extensions::Manifest::IsPolicyLocation(extension->location()) &&
!extensions::Manifest::IsComponentLocation(extension->location()) &&
!(extension->creation_flags() &
extensions::Extension::WAS_INSTALLED_BY_DEFAULT)) {
return true; return true;
} }
} }
...@@ -52,6 +56,9 @@ bool ShouldShowExtensionsCheckup(content::BrowserContext* context) { ...@@ -52,6 +56,9 @@ bool ShouldShowExtensionsCheckup(content::BrowserContext* context) {
namespace extensions { namespace extensions {
const char kNtpPromoExperiment[] = "promo";
const char kStartupExperiment[] = "startup";
bool ShouldShowExtensionsCheckupOnStartup(content::BrowserContext* context) { bool ShouldShowExtensionsCheckupOnStartup(content::BrowserContext* context) {
ExtensionPrefs* prefs = ExtensionPrefs::Get(context); ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
if (ShouldShowExtensionsCheckup(context) && if (ShouldShowExtensionsCheckup(context) &&
......
...@@ -10,6 +10,8 @@ class BrowserContext; ...@@ -10,6 +10,8 @@ class BrowserContext;
} }
namespace extensions { namespace extensions {
extern const char kNtpPromoExperiment[];
extern const char kStartupExperiment[];
// The type of message the extensions checkup banner will convey. // The type of message the extensions checkup banner will convey.
enum class CheckupMessage { enum class CheckupMessage {
......
// Copyright 2019 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/extensions/extension_checkup.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
class ExtensionCheckupTest : public ExtensionServiceTestBase,
public testing::WithParamInterface<const char*> {
public:
ExtensionCheckupTest() {}
~ExtensionCheckupTest() override {}
void SetUp() override {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
extensions_features::kExtensionsCheckupTool,
{{extensions_features::kExtensionsCheckupToolEntryPointParameter,
GetParam()}});
ExtensionServiceTestBase::SetUp();
InitializeEmptyExtensionService();
service()->Init();
}
// Adds a user installed extension.
void AddUserInstalledExtension() {
scoped_refptr<const Extension> extension = ExtensionBuilder("foo").Build();
service()->AddExtension(extension.get());
}
void AddExemptExtensions() {
// Install policy extension.
scoped_refptr<const Extension> policy_extension =
ExtensionBuilder("policy")
.SetLocation(Manifest::EXTERNAL_POLICY)
.Build();
service()->AddExtension(policy_extension.get());
// Install component extension.
scoped_refptr<const Extension> component_extension =
ExtensionBuilder("component").SetLocation(Manifest::COMPONENT).Build();
service()->AddExtension(component_extension.get());
// Load a default installed extension.
int creation_flags = Extension::WAS_INSTALLED_BY_DEFAULT;
scoped_refptr<const Extension> default_install_extension =
ExtensionBuilder("default").AddFlags(creation_flags).Build();
service()->AddExtension(default_install_extension.get());
ASSERT_TRUE(default_install_extension);
}
// Verify the extensions checkup behavior.
bool ShouldShowExperimentCheckup() {
if (GetParam() == kNtpPromoExperiment)
return ShouldShowExtensionsCheckupPromo(browser_context());
return ShouldShowExtensionsCheckupOnStartup(browser_context());
}
// Verify that the opposite entry point will always return false (i.e if the
// user is supposed to see the middle slot promo entry point they should never
// see the extensions checkup upon startup).
void VerifyNonExperimentCheckupDisabled() {
if (GetParam() == kNtpPromoExperiment)
EXPECT_FALSE(ShouldShowExtensionsCheckupOnStartup(browser_context()));
else
EXPECT_FALSE(ShouldShowExtensionsCheckupPromo(browser_context()));
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ExtensionCheckupTest);
};
// Checkup is not shown if no extensions are installed.
TEST_P(ExtensionCheckupTest, NoInstalledExtensions) {
VerifyNonExperimentCheckupDisabled();
EXPECT_FALSE(ShouldShowExperimentCheckup());
}
// Checkup is not shown if the only extensions installed are policy
// installed, component extensions, or installed by default.
TEST_P(ExtensionCheckupTest, NoUserInstalledExtensions) {
AddExemptExtensions();
VerifyNonExperimentCheckupDisabled();
EXPECT_FALSE(ShouldShowExperimentCheckup());
}
// Checkup is shown if at least one non policy extension is installed.
TEST_P(ExtensionCheckupTest, OnlyOneUserInstalledExtension) {
AddUserInstalledExtension();
VerifyNonExperimentCheckupDisabled();
EXPECT_TRUE(ShouldShowExperimentCheckup());
}
TEST_P(ExtensionCheckupTest, UserAndNonUserInstalledExtensions) {
AddUserInstalledExtension();
AddExemptExtensions();
VerifyNonExperimentCheckupDisabled();
EXPECT_TRUE(ShouldShowExperimentCheckup());
}
INSTANTIATE_TEST_SUITE_P(,
ExtensionCheckupTest,
::testing::Values(kNtpPromoExperiment,
kStartupExperiment));
} // namespace extensions
...@@ -4385,6 +4385,7 @@ test("unit_tests") { ...@@ -4385,6 +4385,7 @@ test("unit_tests") {
"../browser/extensions/extension_action_unittest.cc", "../browser/extensions/extension_action_unittest.cc",
"../browser/extensions/extension_api_unittest.cc", "../browser/extensions/extension_api_unittest.cc",
"../browser/extensions/extension_api_unittest.h", "../browser/extensions/extension_api_unittest.h",
"../browser/extensions/extension_checkup_unittest.cc",
"../browser/extensions/extension_context_menu_model_unittest.cc", "../browser/extensions/extension_context_menu_model_unittest.cc",
"../browser/extensions/extension_error_controller_unittest.cc", "../browser/extensions/extension_error_controller_unittest.cc",
"../browser/extensions/extension_error_ui_default_unittest.cc", "../browser/extensions/extension_error_ui_default_unittest.cc",
......
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