Chromium Code Reviews| Index: chrome/browser/web_bluetooth_browsertest.cc |
| diff --git a/chrome/browser/web_bluetooth_browsertest.cc b/chrome/browser/web_bluetooth_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6a94ea45e64b0bea1cb48c004943d62d35cf5405 |
| --- /dev/null |
| +++ b/chrome/browser/web_bluetooth_browsertest.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2016 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. |
| + |
| +// This file contains browsertests for Web Bluetooth that depend on behavior |
| +// defined in chrome/, not just in content/. |
| + |
| +#include "base/command_line.h" |
| +#include "base/metrics/field_trial.h" |
| +#include "chrome/browser/permissions/permission_context_base.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "components/variations/variations_associated_data.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "device/bluetooth/bluetooth_adapter_factory.h" |
| +#include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| + |
| +namespace { |
| + |
| +class WebBluetoothTest : public InProcessBrowserTest { |
| + protected: |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + // This is needed while Web Bluetooth is an Origin Trial, but can go away |
| + // once it ships globally. |
| + command_line->AppendSwitch(switches::kEnableWebBluetooth); |
| + InProcessBrowserTest::SetUpCommandLine(command_line); |
| + } |
| + |
| + void SetUpOnMainThread() override { |
| + // Navigate to a secure context. |
| + embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); |
| + ASSERT_TRUE(embedded_test_server()->Start()); |
| + ui_test_utils::NavigateToURL( |
| + browser(), |
| + embedded_test_server()->GetURL("localhost", "/simple_page.html")); |
| + web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| + EXPECT_THAT( |
| + web_contents_->GetMainFrame()->GetLastCommittedOrigin().Serialize(), |
| + testing::StartsWith("http://localhost:")); |
| + } |
| + |
| + content::WebContents* web_contents_ = nullptr; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(WebBluetoothTest, KillSwitchShouldBlock) { |
| + // Fake the BluetoothAdapter to say it's present. |
| + scoped_refptr<device::MockBluetoothAdapter> adapter = |
| + new testing::NiceMock<device::MockBluetoothAdapter>; |
| + EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true)); |
| + device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); |
| + |
| + // Turn on the global kill switch. |
|
kcarattini
2016/03/30 00:45:59
Can you also test that it works properly without t
Jeffrey Yasskin
2016/03/30 01:19:51
We test that in https://code.google.com/p/chromium
|
| + std::map<std::string, std::string> params; |
| + params["Bluetooth"] = |
| + PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| + variations::AssociateVariationParams( |
| + PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup", |
| + params); |
| + base::FieldTrialList::CreateFieldTrial( |
| + PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup"); |
| + |
| + std::string rejection; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + web_contents_, |
| + "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})" |
| + " .then(() => { domAutomationController.send('Success'); }," |
| + " reason => {" |
| + " domAutomationController.send(reason.name + ': ' + reason.message);" |
| + " });", |
| + &rejection)); |
| + EXPECT_THAT(rejection, |
| + testing::MatchesRegex("NotFoundError: .*globally disabled.*")); |
| +} |
| + |
| +} // namespace |