Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 1720263002: Add a policy_browsertest for the DefaultWebBluetoothGuardSetting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@policy-disable-bt
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/DEPS ('k') | chrome/browser/prefs/command_line_pref_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index 6817c64effadeedef78139e1ed77c65f9fed9c6f..533dcfe90fa9857ad73c08d739b2ce2359ed697b 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -119,6 +119,8 @@
#include "components/translate/core/browser/translate_infobar_delegate.h"
#include "components/variations/service/variations_service.h"
#include "components/version_info/version_info.h"
+#include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
+#include "content/common/bluetooth/bluetooth_messages.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
@@ -150,6 +152,8 @@
#include "content/public/test/mock_notification_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
+#include "content/public/test/web_contents_tester.h"
+#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
@@ -162,6 +166,8 @@
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/shared_module_info.h"
+#include "ipc/ipc_test_sink.h"
+#include "ipc/message_filter.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/base/url_util.h"
@@ -3654,6 +3660,106 @@ INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance,
MediaStreamDevicesControllerBrowserTest,
testing::Bool());
+class OriginTest : public InProcessBrowserTest {
+ void SetUpOnMainThread() override {
+ ASSERT_TRUE(embedded_test_server()->Start());
+ }
+};
+IN_PROC_BROWSER_TEST_F(OriginTest, CanNavigate) {
+ ui_test_utils::NavigateToURL(
+ browser(),
+ embedded_test_server()->GetURL("localhost", "/simple_page.html"));
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ ASSERT_EQ("http://localhost:33158",
+ web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize());
+}
+
+class WebBluetoothPolicyTest : public PolicyTest {
+ void SetUpOnMainThread() override {
+ PolicyTest::SetUpOnMainThread();
+ ASSERT_TRUE(embedded_test_server()->Start());
+ }
+};
+
+class WaitForRequestDeviceMessage : public IPC::Listener {
+ public:
+ explicit WaitForRequestDeviceMessage(
+ scoped_refptr<content::MessageLoopRunner> runner)
+ : runner_(runner) {}
+
+ bool OnMessageReceived(const IPC::Message& msg) override {
+ if (msg.type() == BluetoothMsg_RequestDeviceError::ID ||
+ msg.type() == BluetoothMsg_RequestDeviceSuccess::ID) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&content::MessageLoopRunner::Quit, runner_));
+ }
+ return false; // Store the message in the sink.
+ }
+
+ private:
+ scoped_refptr<content::MessageLoopRunner> runner_;
+};
+
+IN_PROC_BROWSER_TEST_F(WebBluetoothPolicyTest, Block) {
+ PolicyMap policies;
+ policies.Set(key::kDefaultWebBluetoothGuardSetting, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ new base::FundamentalValue(2), nullptr);
+ UpdateProviderPolicy(policies);
+
+ ui_test_utils::NavigateToURL(
+ browser(),
+ embedded_test_server()->GetURL("localhost", "/simple_page.html"));
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_THAT(
+ web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
+ testing::StartsWith("http://localhost:"));
+
+ IPC::TestSink sink;
+ scoped_refptr<content::BluetoothDispatcherHost> bluetooth =
+ new content::BluetoothDispatcherHost(
+ web_contents->GetRenderProcessHost()->GetID());
+ bluetooth->GetFilter()->OnFilterAdded(&sink);
+
+ scoped_refptr<device::MockBluetoothAdapter> adapter =
+ new testing::NiceMock<device::MockBluetoothAdapter>;
+ EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true));
+ bluetooth->SetBluetoothAdapterForTesting(adapter);
+
+ std::vector<content::BluetoothScanFilter> scan_filters;
+ content::BluetoothScanFilter scan_filter;
+ scan_filter.name = "Hello";
+ scan_filters.push_back(scan_filter);
+
+ scoped_refptr<content::MessageLoopRunner> request_device_runner =
+ new content::MessageLoopRunner;
+ WaitForRequestDeviceMessage waiter(request_device_runner);
+ sink.AddFilter(&waiter);
+
+ bluetooth->OnMessageReceived(BluetoothHostMsg_RequestDevice(
+ 1, 1, web_contents->GetMainFrame()->GetRoutingID(), scan_filters,
+ std::vector<device::BluetoothUUID>()));
+
+ request_device_runner->Run();
+
+ // Make sure no more IPCs arrive in the TestSink.
+ web_contents = nullptr;
+ browser()->tab_strip_model()->CloseAllTabs();
+
+ const IPC::Message* response_msg =
+ sink.GetUniqueMessageMatching(BluetoothMsg_RequestDeviceError::ID);
+ ASSERT_TRUE(response_msg);
+ BluetoothMsg_RequestDeviceError::Param response;
+ BluetoothMsg_RequestDeviceError::Read(response_msg, &response);
+ EXPECT_EQ(blink::WebBluetoothError::ChooserDisabled, base::get<2>(response));
+
+ bluetooth->SetBluetoothAdapterForTesting(nullptr);
+}
+
// Test that when extended reporting opt-in is disabled by policy, the
// opt-in checkbox does not appear on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingExtendedReportingOptInAllowed) {
« no previous file with comments | « chrome/browser/policy/DEPS ('k') | chrome/browser/prefs/command_line_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698