Commit 01958af7 authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Commit Bot

Api test for plugins wildcard matching

Bug: 1073883
Change-Id: I98964fe27b8a3f5bc247291e0b810e5e74c04a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2224863
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774575}
parent 3ee492cf
......@@ -18,15 +18,19 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "components/content_settings/core/browser/cookie_settings.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/features.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_manager.h"
#include "components/permissions/permission_result.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h"
......@@ -430,4 +434,42 @@ IN_PROC_BROWSER_TEST_F(
<< message_;
}
class ExtensionContentSettingsApiTestWithWildcardMatchingDisabled
: public ExtensionContentSettingsApiTest {
public:
ExtensionContentSettingsApiTestWithWildcardMatchingDisabled() {
scoped_feature_list_.InitAndEnableFeature(
content_settings::kDisallowWildcardsInPluginContentSettings);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(
ExtensionContentSettingsApiTestWithWildcardMatchingDisabled,
PluginTest) {
constexpr char kExtensionPath[] = "content_settings/pluginswildcardmatching";
EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_;
constexpr char kGoogleMailUrl[] = "http://mail.google.com:443";
constexpr char kGoogleDriveUrl[] = "http://drive.google.com:443";
permissions::PermissionManager* permission_manager =
PermissionManagerFactory::GetForProfile(browser()->profile());
EXPECT_EQ(
permission_manager
->GetPermissionStatus(ContentSettingsType::PLUGINS,
GURL(kGoogleMailUrl), GURL(kGoogleMailUrl))
.content_setting,
ContentSetting::CONTENT_SETTING_BLOCK);
EXPECT_EQ(
permission_manager
->GetPermissionStatus(ContentSettingsType::PLUGINS,
GURL(kGoogleDriveUrl), GURL(kGoogleDriveUrl))
.content_setting,
ContentSetting::CONTENT_SETTING_ALLOW);
}
} // namespace extensions
{
"name" : "Content Settings API Test Extension",
"version" : "0.1",
"manifest_version": 2,
"description" : "Sets and checks exceptions to allow flash, ensures wildcard patterns are not allowed",
"permissions": [ "contentSettings" ]
}
<!--
* 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.
-->
<script src="test.js"></script>
// 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.
var cs = chrome.contentSettings;
function expect(expected, message) {
return chrome.test.callbackPass(function(value) {
chrome.test.assertEq(expected, value, message);
});
}
chrome.test.runTests([function setAndCheckContentSettings() {
cs['plugins'].set({
'primaryPattern': 'http://drive.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'http://*.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].get(
{'primaryUrl': 'http://drive.google.com:443/'},
expect(
{'setting': 'allow'},
'Flash should be allowed on this ' +
'page'));
cs['plugins'].get(
{'primaryUrl': 'http://mail.google.com:443/'},
expect(
{'setting': 'block'},
'Flash should be blocked on this page' +
' because wildcards are not allowed'));
}]);
\ No newline at end of file
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