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