Commit 21a0e18b authored by Swapnil's avatar Swapnil Committed by Commit Bot

Split native messaging policy browsertests

The browsertests related to native messaging policy are moved to
a separated file.

Bug: 1128467
Change-Id: Ie07028d38b58fad47ebe0c23363359b4b732c10f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412487
Commit-Queue: Swapnil Gupta <swapnilgupta@google.com>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807888}
parent 55a9fcc8
// 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.
#include "base/values.h"
#include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/api/messaging/messaging_delegate.h"
namespace policy {
namespace {
extensions::MessagingDelegate::PolicyPermission IsNativeMessagingHostAllowed(
content::BrowserContext* browser_context,
const std::string& native_host_name) {
extensions::MessagingDelegate* messaging_delegate =
extensions::ExtensionsAPIClient::Get()->GetMessagingDelegate();
EXPECT_NE(messaging_delegate, nullptr);
return messaging_delegate->IsNativeMessagingHostAllowed(browser_context,
native_host_name);
}
} // namespace
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlocklistSelective) {
base::ListValue blacklist;
blacklist.AppendString("host.name");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlocklistWildcard) {
base::ListValue blacklist;
blacklist.AppendString("*");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingAllowlist) {
base::ListValue blacklist;
blacklist.AppendString("*");
base::ListValue allowlist;
allowlist.AppendString("host.name");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
policies.Set(key::kNativeMessagingAllowlist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, allowlist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
} // namespace policy
...@@ -336,18 +336,6 @@ class TestAudioObserver : public chromeos::CrasAudioHandler::AudioObserver { ...@@ -336,18 +336,6 @@ class TestAudioObserver : public chromeos::CrasAudioHandler::AudioObserver {
}; };
#endif #endif
#if !defined(OS_CHROMEOS)
extensions::MessagingDelegate::PolicyPermission IsNativeMessagingHostAllowed(
content::BrowserContext* browser_context,
const std::string& native_host_name) {
extensions::MessagingDelegate* messaging_delegate =
extensions::ExtensionsAPIClient::Get()->GetMessagingDelegate();
EXPECT_NE(messaging_delegate, nullptr);
return messaging_delegate->IsNativeMessagingHostAllowed(browser_context,
native_host_name);
}
#endif
} // namespace } // namespace
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -1511,60 +1499,6 @@ IN_PROC_BROWSER_TEST_F(PolicyVariationsServiceTest, VariationsURLIsValid) { ...@@ -1511,60 +1499,6 @@ IN_PROC_BROWSER_TEST_F(PolicyVariationsServiceTest, VariationsURLIsValid) {
EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
EXPECT_EQ("restricted", value); EXPECT_EQ("restricted", value);
} }
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlocklistSelective) {
base::ListValue blacklist;
blacklist.AppendString("host.name");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlocklistWildcard) {
base::ListValue blacklist;
blacklist.AppendString("*");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingAllowlist) {
base::ListValue blacklist;
blacklist.AppendString("*");
base::ListValue allowlist;
allowlist.AppendString("host.name");
PolicyMap policies;
policies.Set(key::kNativeMessagingBlocklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.Clone(),
nullptr);
policies.Set(key::kNativeMessagingAllowlist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, allowlist.Clone(),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL,
IsNativeMessagingHostAllowed(browser()->profile(), "host.name"));
EXPECT_EQ(
extensions::MessagingDelegate::PolicyPermission::DISALLOW,
IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name"));
}
#endif // !defined(CHROME_OS) #endif // !defined(CHROME_OS)
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
......
...@@ -1659,7 +1659,10 @@ if (!is_android) { ...@@ -1659,7 +1659,10 @@ if (!is_android) {
} }
if (!is_chromeos) { if (!is_chromeos) {
sources += [ "../browser/ui/views/accessibility/accessibility_focus_highlight_browsertest.cc" ] sources += [
"../browser/policy/native_messaging_policy_browsertest.cc",
"../browser/ui/views/accessibility/accessibility_focus_highlight_browsertest.cc",
]
} }
if (include_js_tests) { if (include_js_tests) {
......
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