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

Unified Diff: content/browser/bluetooth/bluetooth_blacklist_unittest.cc

Issue 2015463004: bluetooth: Use BluetoothUUID instead of string when sending uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo-request-device
Patch Set: Lint Created 4 years, 7 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
Index: content/browser/bluetooth/bluetooth_blacklist_unittest.cc
diff --git a/content/browser/bluetooth/bluetooth_blacklist_unittest.cc b/content/browser/bluetooth/bluetooth_blacklist_unittest.cc
index a62a3fed549f63b9e4599da43545f1affb3092a6..c8aa12f39057d49c790ce4c6bdd53e0651c3f050 100644
--- a/content/browser/bluetooth/bluetooth_blacklist_unittest.cc
+++ b/content/browser/bluetooth/bluetooth_blacklist_unittest.cc
@@ -13,8 +13,22 @@ namespace content {
namespace {
-std::string Canonicalize(const std::string& string) {
- return device::BluetoothUUID(string).canonical_value();
+std::unique_ptr<BluetoothUUID> Canonicalize(const std::string& string) {
+ return base::WrapUnique(new device::BluetoothUUID(string));
+}
+
+bool OptionalServicesEqual(
Jeffrey Yasskin 2016/05/28 04:38:06 Write this to return an AssertionResult, and then
ortuno 2016/05/31 17:30:47 Now that we are using Optional we can just use the
Jeffrey Yasskin 2016/05/31 21:52:57 SGTM
+ const mojo::Array<std::unique_ptr<BluetoothUUID>>& optional_services,
+ const mojo::Array<std::unique_ptr<BluetoothUUID>>& expected) {
+ if (optional_services.size() != expected.size()) {
+ return false;
+ }
+ for (size_t i = 0; i < optional_services.size(); i++) {
+ if (*(optional_services[0]) != *(expected[0])) {
+ return false;
+ }
+ }
+ return true;
}
} // namespace
@@ -232,7 +246,8 @@ TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) {
mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1);
single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
- single_empty_filter[0]->services = mojo::Array<mojo::String>();
+ single_empty_filter[0]->services =
+ mojo::Array<std::unique_ptr<BluetoothUUID>>();
EXPECT_EQ(0u, single_empty_filter[0]->services.size());
EXPECT_FALSE(list_.IsExcluded(single_empty_filter));
@@ -329,22 +344,24 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) {
{
// Empty optional_services.
blink::mojom::WebBluetoothRequestDeviceOptions options;
- options.optional_services = mojo::Array<mojo::String>();
+ options.optional_services = mojo::Array<std::unique_ptr<BluetoothUUID>>();
- mojo::Array<mojo::String> expected = options.optional_services.Clone();
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected =
+ mojo::Array<std::unique_ptr<BluetoothUUID>>();
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
{
// One non-matching service in optional_services.
blink::mojom::WebBluetoothRequestDeviceOptions options;
options.optional_services.push_back(Canonicalize("0000"));
- mojo::Array<mojo::String> expected = options.optional_services.Clone();
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected;
+ expected.push_back(Canonicalize("0000"));
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
{
// Multiple non-matching services in optional_services.
@@ -354,10 +371,14 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) {
options.optional_services.push_back(Canonicalize("ee02"));
options.optional_services.push_back(Canonicalize("0003"));
- mojo::Array<mojo::String> expected = options.optional_services.Clone();
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected;
+ expected.push_back(Canonicalize("0000"));
+ expected.push_back(Canonicalize("ee01"));
+ expected.push_back(Canonicalize("ee02"));
+ expected.push_back(Canonicalize("0003"));
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
}
@@ -371,11 +392,12 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
blink::mojom::WebBluetoothRequestDeviceOptions options;
options.optional_services.push_back(Canonicalize("eeee"));
- mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected =
+ mojo::Array<std::unique_ptr<BluetoothUUID>>();
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
{
// Single matching of many services in optional_services.
@@ -384,12 +406,12 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
options.optional_services.push_back(Canonicalize("eeee"));
options.optional_services.push_back(Canonicalize("0001"));
- mojo::Array<mojo::String> expected;
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected;
expected.push_back(Canonicalize("0000"));
expected.push_back(Canonicalize("0001"));
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
{
// All matching of many services in optional_services.
@@ -399,10 +421,11 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
options.optional_services.push_back(Canonicalize("eee3"));
options.optional_services.push_back(Canonicalize("eeee"));
- mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
+ mojo::Array<std::unique_ptr<BluetoothUUID>> expected =
+ mojo::Array<std::unique_ptr<BluetoothUUID>>();
list_.RemoveExcludedUUIDs(&options);
- EXPECT_TRUE(options.optional_services.Equals(expected));
+ EXPECT_TRUE(OptionalServicesEqual(options.optional_services, expected));
}
}

Powered by Google App Engine
This is Rietveld 408576698