Commit 4d696ac8 authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Commit Bot

Clean up and extend plugin wildcard matching API tests.

JS parts of ExtensionContentSettingsApiTestWithWildcardMatchingDisabled
have been cleaned up, and an additional native test is added to verify
that trying to add a wildcarded pattern for `plugins` through the
chrome.contentSettings API will print a console warning.

Bug: 1073883
Change-Id: I010b1d3f25fb68110fc6f72b40ccf103c011731c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289423Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Auto-Submit: Ravjit Singh Uppal <ravjit@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799039}
parent f97ca58f
......@@ -17,6 +17,7 @@
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#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/api/content_settings/content_settings_api_constants.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
......@@ -519,25 +520,25 @@ IN_PROC_BROWSER_TEST_P(
PluginTest) {
constexpr char kExtensionPath[] = "content_settings/pluginswildcardmatching";
EXPECT_TRUE(RunLazyTest(kExtensionPath)) << 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);
IN_PROC_BROWSER_TEST_P(
ExtensionContentSettingsApiTestWithWildcardMatchingDisabled,
ConsoleErrorTest) {
constexpr char kExtensionPath[] = "content_settings/pluginswildcardmatching";
const extensions::Extension* extension =
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
ASSERT_TRUE(extension);
auto* web_contents = extensions::ProcessManager::Get(profile())
->GetBackgroundHostForExtension(extension->id())
->host_contents();
content::WebContentsConsoleObserver console_observer(web_contents);
console_observer.SetPattern(
content_settings_api_constants::kWildcardPatternsForPluginsDisallowed);
browsertest_util::ExecuteScriptInBackgroundPageNoWait(
profile(), extension->id(), "setWildcardedPatterns()");
console_observer.Wait();
EXPECT_EQ(1u, console_observer.messages().size());
}
} // namespace extensions
......@@ -4,59 +4,95 @@
var cs = chrome.contentSettings;
function setWildcardedPatterns() {
cs['plugins'].set({
'primaryPattern': '<all_urls>',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
}
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/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'http://docs.google.com:*/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': '*://drive.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': '*://*.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'http://*.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': '<all_urls>',
'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://docs.google.com:100/'},
expect({'setting': 'allow'}, 'Flash should be allowed on this page'));
cs['plugins'].get(
{'primaryUrl': 'https://drive.google.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'http://maps.google.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'http://example.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'http://mail.google.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
}]);
\ No newline at end of file
chrome.test.runTests([
function testSchemeWildcardMatching() {
cs['plugins'].set({
'primaryPattern': '*://drive.google.com:*/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'https://maps.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].get(
{'primaryUrl': 'https://drive.google.com:443/*'},
expect({'setting': 'allow'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'http://drive.google.com:80/*'},
expect({'setting': 'allow'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'https://maps.google.com:443/*'},
expect({'setting': 'allow'}, 'Flash should be blocked on this page'));
cs['plugins'].clear({});
},
function testPortWildcardMatching() {
cs['plugins'].set({
'primaryPattern': 'https://drive.google.com:*/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'https://maps.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].get(
{'primaryUrl': 'https://drive.google.com:100/'},
expect({'setting': 'allow'}, 'Flash should be allowed on this page'));
cs['plugins'].get(
{'primaryUrl': 'https://maps.google.com:443/'},
expect({'setting': 'allow'}, 'Flash should be allowed on this page'));
cs['plugins'].clear({});
},
function testSubdomainWildcardMatching() {
cs['plugins'].set({
'primaryPattern': 'https://*.google.com:443/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].get(
{'primaryUrl': 'http://drive.google.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].clear({});
},
function testFullWilcardMatching() {
cs['plugins'].set({
'primaryPattern': '<all_urls>',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': 'https://*/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].set({
'primaryPattern': '*://*/*',
'secondaryPattern': '<all_urls>',
'setting': 'allow'
});
cs['plugins'].get(
{'primaryUrl': 'https://drive.google.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].get(
{'primaryUrl': 'https://example.com:443/'},
expect({'setting': 'block'}, 'Flash should be blocked on this page'));
cs['plugins'].clear({});
},
]);
\ 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