Commit 21095442 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: Add resources to device_unittests

This change adds the ability for device_unittests to run with resource
strings in order to test the
BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() method.

Bug: 506415
Change-Id: I598181822d5b7101b6f2a3dc04d7e39a605c87f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1497323Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638196}
parent 9f446613
...@@ -118,6 +118,7 @@ test("device_unittests") { ...@@ -118,6 +118,7 @@ test("device_unittests") {
} }
deps = [ deps = [
"//base",
"//base/test:test_support", "//base/test:test_support",
"//base/third_party/dynamic_annotations:dynamic_annotations", "//base/third_party/dynamic_annotations:dynamic_annotations",
"//components/apdu", "//components/apdu",
...@@ -142,9 +143,15 @@ test("device_unittests") { ...@@ -142,9 +143,15 @@ test("device_unittests") {
"//testing/gtest", "//testing/gtest",
"//third_party/blink/public:blink_headers", "//third_party/blink/public:blink_headers",
"//tools/usb_gadget", "//tools/usb_gadget",
"//ui/base",
"//url", "//url",
] ]
data_deps = [
"bluetooth/strings:bluetooth_test_strings",
"//ui/resources:ui_test_pak_data",
]
# U2F: # U2F:
# Android doesn't compile. # Android doesn't compile.
# Linux, requires udev. # Linux, requires udev.
......
...@@ -1154,14 +1154,17 @@ TEST_F(BluetoothTest, MAYBE_GetName_NullName) { ...@@ -1154,14 +1154,17 @@ TEST_F(BluetoothTest, MAYBE_GetName_NullName) {
BluetoothDevice* device = SimulateLowEnergyDevice(5); BluetoothDevice* device = SimulateLowEnergyDevice(5);
EXPECT_FALSE(device->GetName()); EXPECT_FALSE(device->GetName());
}
// TODO(506415): Test GetNameForDisplay with a device with no name. // The check below is not currently working on Android and Mac because the
// BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which // GetAppearance() method is not implemented on those platforms.
// requires string resources to be loaded. For that, something like // TODO(https://crbug.com/588083): Enable the check below when GetAppearance()
// InitSharedInstance must be run. See unittest files that call that. It will // is implemented for Android and Mac.
// also require build configuration to generate string resources into a .pak #if !defined(OS_ANDROID) && !defined(OS_MACOSX)
// file. EXPECT_EQ(
device->GetNameForDisplay(),
base::UTF8ToUTF16("Unknown or Unsupported Device (01:00:00:90:1E:BE)"));
#endif
}
#if defined(OS_ANDROID) || defined(OS_MACOSX) #if defined(OS_ANDROID) || defined(OS_MACOSX)
#define MAYBE_CreateGattConnection CreateGattConnection #define MAYBE_CreateGattConnection CreateGattConnection
......
...@@ -4,4 +4,6 @@ include_rules = [ ...@@ -4,4 +4,6 @@ include_rules = [
"+net/proxy_resolution", "+net/proxy_resolution",
"+net/traffic_annotation", "+net/traffic_annotation",
"+net/url_request", "+net/url_request",
# The test runner needs to initialize various parts of the UI stack.
"+ui",
] ]
...@@ -3,17 +3,67 @@ ...@@ -3,17 +3,67 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/test/launcher/unit_test_launcher.h" #include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h" #include "base/test/test_suite.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/scale_factor.h"
#include "ui/base/ui_base_paths.h"
namespace {
class DeviceTestSuite : public base::TestSuite {
public:
DeviceTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
~DeviceTestSuite() override = default;
protected:
void Initialize() override {
base::TestSuite::Initialize();
#if !defined(OS_IOS)
ui::RegisterPathProvider();
base::FilePath ui_test_pak_path;
ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
base::FilePath path;
#if defined(OS_ANDROID)
ASSERT_TRUE(base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path));
#else
ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &path));
#endif // defined(OS_ANDROID)
base::FilePath bluetooth_test_strings =
path.Append(FILE_PATH_LITERAL("bluetooth_test_strings.pak"));
ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
bluetooth_test_strings, ui::SCALE_FACTOR_NONE);
#endif // !defined(OS_IOS)
}
void Shutdown() override {
#if !defined(OS_IOS)
ui::ResourceBundle::CleanupSharedInstance();
#endif
base::TestSuite::Shutdown();
}
private:
DISALLOW_COPY_AND_ASSIGN(DeviceTestSuite);
};
} // namespace
int main(int argc, char** argv) { int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv); DeviceTestSuite test_suite(argc, argv);
mojo::core::Init(); mojo::core::Init();
return base::LaunchUnitTests( return base::LaunchUnitTests(
argc, argc, argv,
argv, base::BindOnce(&DeviceTestSuite::Run, base::Unretained(&test_suite)));
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
} }
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