Commit f221eabf authored by michaelpg's avatar michaelpg Committed by Commit bot

Initialize BlueZ in app_shell on Linux

Whitelisted Linux apps can access chrome.bluetooth. Initialize Bluetooth so
we don't crash on those apps.

BUG=711142
R=rkc@chromium.org,rdevlin.cronin@chromium.org

Review-Url: https://codereview.chromium.org/2819593003
Cr-Commit-Position: refs/heads/master@{#469540}
parent 0f4c67a6
......@@ -313,6 +313,11 @@ source_set("browser_tests") {
testonly = true
sources = [
"api/audio/audio_apitest.cc",
# TODO(michaelpg): bluetooth_appshell_test.cc is a crutch until we have a
# better system for testing APIs in both app_shell and chrome. See
# crbug.com/650835.
"api/bluetooth/bluetooth_appshell_test.cc",
"api/bluetooth_socket/bluetooth_socket_apitest.cc",
"api/display_source/display_source_apitest.cc",
"api/display_source/display_source_apitestbase.cc",
......
// Copyright 2017 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 "extensions/shell/test/shell_apitest.h"
using BluetoothShellApiTest = extensions::ShellApiTest;
IN_PROC_BROWSER_TEST_F(BluetoothShellApiTest, ApiSanityCheck) {
ASSERT_TRUE(RunAppTest("api_test/bluetooth"));
}
......@@ -44,6 +44,7 @@ source_set("app_shell_lib") {
"//content",
"//content/shell:content_shell_lib",
"//device/base",
"//device/bluetooth",
"//device/hid",
"//extensions:extensions_resources",
"//extensions:shell_and_test_pak",
......
......@@ -47,15 +47,23 @@
#if defined(OS_CHROMEOS)
#include "chromeos/audio/audio_devices_pref_handler_impl.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "chromeos/network/network_handler.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "extensions/shell/browser/shell_audio_controller_chromeos.h"
#include "extensions/shell/browser/shell_network_controller_chromeos.h"
#endif
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#elif defined(OS_LINUX)
#include "device/bluetooth/dbus/dbus_thread_manager_linux.h"
#endif
#if defined(OS_MACOSX)
#include "extensions/shell/browser/shell_browser_main_parts_mac.h"
#endif
......@@ -122,8 +130,17 @@ void ShellBrowserMainParts::PostMainMessageLoopStart() {
switches::kAppShellAllowRoaming)) {
network_controller_->SetCellularAllowRoaming(true);
}
#elif defined(OS_LINUX)
// app_shell doesn't need GTK, so the fake input method context can work.
// See crbug.com/381852 and revision fb69f142.
// TODO(michaelpg): Verify this works for target environments.
ui::InitializeInputMethodForTesting();
bluez::DBusThreadManagerLinux::Initialize();
bluez::BluezDBusManager::Initialize(
bluez::DBusThreadManagerLinux::Get()->GetSystemBus(),
/*use_dbus_fakes=*/false);
#else
// Non-Chrome OS platforms are for developer convenience, so use a test IME.
ui::InitializeInputMethodForTesting();
#endif
}
......@@ -278,6 +295,10 @@ void ShellBrowserMainParts::PostDestroyThreads() {
device::BluetoothAdapterFactory::Shutdown();
bluez::BluezDBusManager::Shutdown();
chromeos::DBusThreadManager::Shutdown();
#elif defined(OS_LINUX)
device::BluetoothAdapterFactory::Shutdown();
bluez::BluezDBusManager::Shutdown();
bluez::DBusThreadManagerLinux::Shutdown();
#endif
}
......
{
"manifest_version": 2,
"name": "Test platform app with APIs",
"version": "1.0",
"description": "Tests loading an app that declares API keys and calls apps API functions",
"app": {
"background": {
"scripts": ["runtest.js"]
}
},
"bluetooth": {},
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqbc71rRrqz+62pGVmZGDzTK8P4IHTTyN4jBLBJasDTrRllQp4Pb6INnSr08HQM3aaZMYKWkAJTm4gbCDNzvHfIZMAMY6OZfnm0eqiZnxFFgKgIzdr4Z/EyAXVd1Rm1JKhncde2S/U3zWStDb5iYfWZJBIiWVT98q7cW6sstsMOmrHAIAKCzK+mzycFptlRWzAf+8NR9bq1jNZe+h1kJBgY0xnVlGZm+NIhZd/Ke8Y+G2vM4rtuDvp5971HVV294HD28hWbsoOqBf85gPa6tKE57FhLomi/aJVBVBiCfHExXjK1hB2QeM/r7e8P//ZZPoYszSzHJVBw/heRLFOMezIwIDAQAB"
}
// Copyright 2017 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.
/**
* @fileoverview Basic tests of API functions in a real (non-mocked) shell to
* ensure they can be called from a particular client or environment.
* Tests that verify specific behaviors should be in their own API tests.
*/
// Tests chrome.bluetooth availability.
function bluetoothSanityCheck() {
chrome.test.assertTrue(
!!chrome.bluetooth, 'chrome.bluetooth should be available');
chrome.bluetooth.getAdapterState(chrome.test.callback());
chrome.bluetooth.getDevice(
'AB:CD:EF:01:23:45', chrome.test.callbackFail('Invalid device'));
chrome.bluetooth.getDevices(chrome.test.callback());
// TODO(michaelpg): Re-enable on Chrome OS after crbug.com/711484 is fixed.
if (!/CrOS/.test(navigator.userAgent)) {
var startDiscoveryCallback = chrome.test.callbackAdded();
chrome.bluetooth.startDiscovery(function() {
// Ignore errors.
chrome.runtime.lastError;
startDiscoveryCallback();
});
var stopDiscoveryCallback = chrome.test.callbackAdded();
chrome.bluetooth.stopDiscovery(function() {
// Ignore errors.
chrome.runtime.lastError;
stopDiscoveryCallback();
});
}
}
chrome.app.runtime.onLaunched.addListener(function() {
chrome.test.runTests([bluetoothSanityCheck]);
});
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