Commit 741449bb authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

Specify a const for minimum channel requirement for Extension SW.

Update ExtensionsClient to use that constant.
Also, fix tests using channel overrides to use the more specific
channel: canary instead of trunk. This is done by providing an
override channel class called
ScopedExtensionAPIEnabledInServiceWorkersChannel.

Bug: None
Change-Id: I890a738c66522d4541e24c61761b82aa1bff1ad6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841932Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706142}
parent aceecfcd
......@@ -30,6 +30,7 @@
#include "extensions/browser/test_management_policy.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/dns/mock_host_resolver.h"
#include "ui/base/models/menu_model.h"
......@@ -46,11 +47,11 @@ class ExtensionContextMenuBrowserTest
public:
void SetUp() override {
extensions::ExtensionBrowserTest::SetUp();
// Service Workers are currently only available on the trunk, so set
// Service Workers are currently only available on certain channels, so set
// the channel for those tests.
if (GetParam() == ContextType::kServiceWorker) {
current_channel_ = std::make_unique<extensions::ScopedCurrentChannel>(
version_info::Channel::UNKNOWN);
current_channel_ =
std::make_unique<extensions::ScopedWorkerBasedExtensionsChannel>();
}
}
......@@ -273,7 +274,8 @@ class ExtensionContextMenuBrowserTest
EXPECT_EQ(should_be_checked, menu->IsCommandIdChecked(command_id));
}
std::unique_ptr<extensions::ScopedCurrentChannel> current_channel_;
std::unique_ptr<extensions::ScopedWorkerBasedExtensionsChannel>
current_channel_;
};
// Tests adding a simple context menu item.
......
......@@ -67,6 +67,7 @@
#include "extensions/common/extensions_client.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/common/value_builder.h"
#include "extensions/common/verifier_formats.h"
#include "extensions/test/background_page_watcher.h"
......@@ -226,13 +227,7 @@ class ServiceWorkerTest : public ExtensionApiTest {
class ServiceWorkerBasedBackgroundTest : public ServiceWorkerTest {
public:
ServiceWorkerBasedBackgroundTest()
: ServiceWorkerTest(
// Extensions APIs from SW are only enabled on trunk.
// It is important to set the channel early so that this change is
// visible in renderers running with service workers (and no
// extension).
version_info::Channel::UNKNOWN) {}
ServiceWorkerBasedBackgroundTest() = default;
~ServiceWorkerBasedBackgroundTest() override {}
void SetUpOnMainThread() override {
......@@ -274,6 +269,8 @@ class ServiceWorkerBasedBackgroundTest : public ServiceWorkerTest {
}
private:
ScopedWorkerBasedExtensionsChannel channel_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerBasedBackgroundTest);
};
......@@ -758,13 +755,7 @@ class ServiceWorkerPushMessagingTest : public ServiceWorkerTest {
class ServiceWorkerLazyBackgroundTest : public ServiceWorkerTest {
public:
ServiceWorkerLazyBackgroundTest()
: ServiceWorkerTest(
// Extensions APIs from SW are only enabled on trunk.
// It is important to set the channel early so that this change is
// visible in renderers running with service workers (and no
// extension).
version_info::Channel::UNKNOWN) {}
ServiceWorkerLazyBackgroundTest() = default;
~ServiceWorkerLazyBackgroundTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -783,6 +774,8 @@ class ServiceWorkerLazyBackgroundTest : public ServiceWorkerTest {
}
private:
ScopedWorkerBasedExtensionsChannel channel_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerLazyBackgroundTest);
};
......@@ -1197,9 +1190,8 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MAYBE_WebAccessibleResourcesFetch) {
// Tests that updating a packed extension with modified scripts works
// properly -- we expect that the new script will execute, rather than the
// previous one.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdatePackedExtension) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
UpdatePackedExtension) {
constexpr char kManifest1[] =
R"({
"name": "Test Extension",
......@@ -1286,9 +1278,8 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdatePackedExtension) {
// Tests that updating an unpacked extension with modified scripts works
// properly -- we expect that the new script will execute, rather than the
// previous one.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateUnpackedExtension) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
UpdateUnpackedExtension) {
constexpr char kManifest1[] =
R"({
"name": "Test Extension",
......@@ -1465,9 +1456,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) {
// Verifies that service workers that aren't specified as the background script
// for the extension do not have extension API bindings.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, VerifyNoApiBindings) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, VerifyNoApiBindings) {
const Extension* extension = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("service_worker/verify_no_api_bindings"),
kFlagNone);
......
......@@ -8,6 +8,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/version_info/version_info.h"
#include "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
......@@ -15,17 +16,11 @@ namespace extensions {
class ServiceWorkerMessagingTest : public ExtensionApiTest {
public:
ServiceWorkerMessagingTest()
: current_channel_(
// Extensions APIs from SW are only enabled on trunk.
// It is important to set the channel early so that this change is
// visible in renderers running with service workers (and no
// extension).
version_info::Channel::UNKNOWN) {}
ServiceWorkerMessagingTest() = default;
~ServiceWorkerMessagingTest() override = default;
private:
ScopedCurrentChannel current_channel_;
ScopedWorkerBasedExtensionsChannel current_channel_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerMessagingTest);
};
......
......@@ -215,7 +215,8 @@ std::set<base::FilePath> ChromeExtensionsClient::GetBrowserImagePaths(
bool ChromeExtensionsClient::ExtensionAPIEnabledInExtensionServiceWorkers()
const {
return GetCurrentChannel() <= version_info::Channel::CANARY;
return GetCurrentChannel() <=
extension_misc::kMinChannelForServiceWorkerBasedExtension;
}
void ChromeExtensionsClient::AddOriginAccessPermissions(
......
......@@ -23,6 +23,7 @@ source_set("common_constants") {
deps = [
"//base",
"//components/services/app_service/public/mojom",
"//components/version_info:channel",
"//ui/base",
]
......@@ -387,6 +388,8 @@ if (enable_extensions) {
"api/declarative_net_request/test_utils.h",
"file_test_util.cc",
"file_test_util.h",
"scoped_worker_based_extensions_channel.cc",
"scoped_worker_based_extensions_channel.h",
]
deps = [
......
......@@ -2,6 +2,7 @@ include_rules = [
"+components/crx_file",
"+components/url_formatter",
"+components/nacl/common/buildflags.h",
"+components/version_info/channel.h",
"+device/bluetooth", # For BluetoothPermission
"+grit/extensions_strings.h",
"+libxml",
......
......@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/strings/string_piece_forward.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "components/version_info/channel.h"
#include "ui/base/layout.h"
namespace extensions {
......@@ -252,6 +253,10 @@ extern const int kContentVerificationDefaultBlockSize;
// The minimum severity of a log or error in order to report it to the browser.
extern const logging::LogSeverity kMinimumSeverityToReportError;
// The minimum channel where Service Worker based extensions can run.
constexpr version_info::Channel kMinChannelForServiceWorkerBasedExtension =
version_info::Channel::CANARY;
} // namespace extension_misc
#endif // EXTENSIONS_COMMON_CONSTANTS_H_
......@@ -13,6 +13,7 @@
#include "extensions/common/manifest_handlers/content_scripts_handler.h"
#include "extensions/common/manifest_handlers/externally_connectable.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/common/user_script.h"
#include "extensions/common/value_builder.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -110,11 +111,9 @@ TEST(ExtensionBuilderTest, Background) {
EXPECT_FALSE(BackgroundInfo::IsServiceWorkerBased(extension.get()));
}
{
// Service Worker features are only available on the trunk.
// TODO(crbug.com/853378): Remove this when we open up support for
// service workers.
ScopedCurrentChannel current_channel_override(
version_info::Channel::UNKNOWN);
ScopedWorkerBasedExtensionsChannel current_channel_override;
scoped_refptr<const Extension> extension =
ExtensionBuilder("service worker")
.SetBackgroundContext(
......
// 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 "extensions/common/scoped_worker_based_extensions_channel.h"
#include "extensions/common/constants.h"
namespace extensions {
ScopedWorkerBasedExtensionsChannel::ScopedWorkerBasedExtensionsChannel()
: worker_based_extensions_channel_(
extension_misc::kMinChannelForServiceWorkerBasedExtension) {}
ScopedWorkerBasedExtensionsChannel::~ScopedWorkerBasedExtensionsChannel() =
default;
} // namespace extensions
// 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.
#ifndef EXTENSIONS_COMMON_SCOPED_WORKER_BASED_EXTENSIONS_CHANNEL_H_
#define EXTENSIONS_COMMON_SCOPED_WORKER_BASED_EXTENSIONS_CHANNEL_H_
#include "extensions/common/features/feature_channel.h"
namespace extensions {
// Sets the current channel so that Service Worker based extensions are enabled
// and also and extension APIs from those Service Workers are enabled.
//
// Note: It is important to set this override early in tests so that the
// channel change is visible to renderers running with service workers.
class ScopedWorkerBasedExtensionsChannel {
public:
ScopedWorkerBasedExtensionsChannel();
~ScopedWorkerBasedExtensionsChannel();
private:
ScopedCurrentChannel worker_based_extensions_channel_;
DISALLOW_COPY_AND_ASSIGN(ScopedWorkerBasedExtensionsChannel);
};
} // namespace extensions
#endif // EXTENSIONS_COMMON_SCOPED_WORKER_BASED_EXTENSIONS_CHANNEL_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