Commit ed1756b9 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[BackgroundSync] Add background_sync component.

Introduces a new component for BackgroundSync so code can be shared with
WebLayer. Migrates BackgroundSyncPermissionContext and its unittest.

Bug: 1087486
Change-Id: Ib2968305dfa674eec81985f4ae19780ca5d6d9e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421491Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809874}
parent c7b9696e
......@@ -169,8 +169,6 @@ static_library("browser") {
"background_sync/background_sync_controller_impl.h",
"background_sync/background_sync_metrics.cc",
"background_sync/background_sync_metrics.h",
"background_sync/background_sync_permission_context.cc",
"background_sync/background_sync_permission_context.h",
"background_sync/periodic_background_sync_permission_context.cc",
"background_sync/periodic_background_sync_permission_context.h",
"bad_message.cc",
......@@ -1939,6 +1937,7 @@ static_library("browser") {
"//components/assist_ranker",
"//components/autofill/content/browser",
"//components/autofill/core/browser",
"//components/background_sync",
"//components/background_task_scheduler",
"//components/blocked_content",
"//components/blocklist/opt_out_blocklist",
......@@ -3128,6 +3127,7 @@ static_library("browser") {
"//components/assist_ranker/proto",
"//components/autofill_assistant/browser",
"//components/autofill_assistant/browser:proto",
"//components/background_sync",
"//components/bookmarks/common/android",
"//components/browser_ui/contacts_picker/android",
"//components/browser_ui/photo_picker/android",
......
......@@ -46,6 +46,7 @@ include_rules = [
"+components/autofill/core/browser",
"+components/autofill/core/common",
"+components/background_task_scheduler",
"+components/background_sync",
"+components/base32",
"+components/blocked_content",
"+components/blocklist/opt_out_blocklist",
......
iclelland@chromium.org
jkarlin@chromium.org
nator@chromium.org
peter@chromium.org
rayankans@chromium.org
per-file *permission_context*=file://components/permissions/PERMISSIONS_OWNERS
# COMPONENT: Blink>BackgroundSync
# TEAM: platform-capabilities@chromium.org
file://components/background_sync/OWNERS
......@@ -7,7 +7,6 @@
#include "build/build_config.h"
#include "chrome/browser/accessibility/accessibility_permission_context.h"
#include "chrome/browser/background_fetch/background_fetch_permission_context.h"
#include "chrome/browser/background_sync/background_sync_permission_context.h"
#include "chrome/browser/background_sync/periodic_background_sync_permission_context.h"
#include "chrome/browser/clipboard/clipboard_read_write_permission_context.h"
#include "chrome/browser/clipboard/clipboard_sanitized_write_permission_context.h"
......@@ -30,6 +29,7 @@
#include "chrome/common/buildflags.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "components/background_sync/background_sync_permission_context.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/permissions/contexts/font_access_permission_context.h"
#include "components/permissions/contexts/webxr_permission_context.h"
......
......@@ -3315,7 +3315,6 @@ test("unit_tests") {
"../browser/background_fetch/background_fetch_delegate_impl_unittest.cc",
"../browser/background_fetch/background_fetch_permission_context_unittest.cc",
"../browser/background_sync/background_sync_controller_impl_unittest.cc",
"../browser/background_sync/background_sync_permission_context_unittest.cc",
"../browser/background_sync/periodic_background_sync_permission_context_unittest.cc",
"../browser/banners/app_banner_settings_helper_unittest.cc",
"../browser/bitmap_fetcher/bitmap_fetcher_service_unittest.cc",
......
......@@ -224,6 +224,7 @@ test("components_unittests") {
"//components/autofill/content/browser:unit_tests",
"//components/autofill/content/renderer:unit_tests",
"//components/autofill/core/common/mojom:unit_tests",
"//components/background_sync:unit_tests",
"//components/blocked_content:unit_tests",
"//components/browsing_data/content:unit_tests",
"//components/captive_portal/content:unit_tests",
......
# 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.
static_library("background_sync") {
sources = [
"background_sync_permission_context.cc",
"background_sync_permission_context.h",
]
deps = [
"//components/content_settings/core/browser",
"//components/content_settings/core/common",
"//components/permissions",
"//third_party/blink/public/common:headers",
]
}
source_set("unit_tests") {
testonly = true
sources = [ "background_sync_permission_context_unittest.cc" ]
deps = [
":background_sync",
"//base",
"//components/content_settings/core/browser",
"//components/permissions",
"//components/permissions:test_support",
"//content/public/browser",
"//content/test:test_support",
"//testing/gtest",
"//url:url",
]
}
include_rules = [
"+components/content_settings/core",
"+components/permissions",
"+content/public/browser",
"+content/public/test",
"+third_party/blink/public/mojom",
]
iclelland@chromium.org
jkarlin@chromium.org
nator@chromium.org
peter@chromium.org
rayankans@chromium.org
per-file *permission_context*=file://components/permissions/PERMISSIONS_OWNERS
# COMPONENT: Blink>BackgroundSync
# TEAM: platform-capabilities@chromium.org
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/background_sync/background_sync_permission_context.h"
#include "components/background_sync/background_sync_permission_context.h"
#include "base/notreached.h"
#include "components/content_settings/core/common/content_settings_types.h"
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
#define CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
#ifndef COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
#define COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
#include "base/macros.h"
#include "components/permissions/permission_context_base.h"
......@@ -36,4 +36,4 @@ class BackgroundSyncPermissionContext
DISALLOW_COPY_AND_ASSIGN(BackgroundSyncPermissionContext);
};
#endif // CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
#endif // COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_PERMISSION_CONTEXT_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/background_sync/background_sync_permission_context.h"
#include "components/background_sync/background_sync_permission_context.h"
#include <string>
......@@ -10,25 +10,24 @@
#include "base/callback_helpers.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/permission_request_id.h"
#include "components/permissions/permissions_client.h"
#include "components/permissions/test/test_permissions_client.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
class BackgroundSyncPermissionContextTest
: public ChromeRenderViewHostTestHarness {
: public content::RenderViewHostTestHarness {
protected:
BackgroundSyncPermissionContextTest() = default;
~BackgroundSyncPermissionContextTest() override = default;
void NavigateAndRequestPermission(
......@@ -58,6 +57,9 @@ class BackgroundSyncPermissionContextTest
bool permission_granted() const { return permission_granted_; }
protected:
permissions::TestPermissionsClient client_;
private:
bool permission_granted_;
......@@ -67,7 +69,7 @@ class BackgroundSyncPermissionContextTest
// Background sync permission should be allowed by default for a secure origin.
TEST_F(BackgroundSyncPermissionContextTest, TestSecureRequestingUrl) {
GURL url("https://www.example.com");
BackgroundSyncPermissionContext permission_context(profile());
BackgroundSyncPermissionContext permission_context(browser_context());
NavigateAndRequestPermission(url, &permission_context);
......@@ -77,7 +79,7 @@ TEST_F(BackgroundSyncPermissionContextTest, TestSecureRequestingUrl) {
// Background sync permission should be denied for an insecure origin.
TEST_F(BackgroundSyncPermissionContextTest, TestInsecureRequestingUrl) {
GURL url("http://example.com");
BackgroundSyncPermissionContext permission_context(profile());
BackgroundSyncPermissionContext permission_context(browser_context());
NavigateAndRequestPermission(url, &permission_context);
......@@ -88,8 +90,9 @@ TEST_F(BackgroundSyncPermissionContextTest, TestInsecureRequestingUrl) {
TEST_F(BackgroundSyncPermissionContextTest, TestBlockOrigin) {
GURL url1("https://www.example1.com");
GURL url2("https://www.example2.com");
BackgroundSyncPermissionContext permission_context(profile());
HostContentSettingsMapFactory::GetForProfile(profile())
BackgroundSyncPermissionContext permission_context(browser_context());
permissions::PermissionsClient::Get()
->GetSettingsMap(browser_context())
->SetContentSettingDefaultScope(url1, GURL(),
ContentSettingsType::BACKGROUND_SYNC,
std::string(), CONTENT_SETTING_BLOCK);
......
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