Chromium Code Reviews| 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 b0ed9c2c6a183d3adbddbcd62e1ed33800e76ae8..b4c7c85dcd36035d109e6608822a3f717a8535f6 100644 |
| --- a/content/browser/bluetooth/bluetooth_blacklist_unittest.cc |
| +++ b/content/browser/bluetooth/bluetooth_blacklist_unittest.cc |
| @@ -4,7 +4,6 @@ |
| #include "content/browser/bluetooth/bluetooth_blacklist.h" |
| -#include "content/common/bluetooth/bluetooth_scan_filter.h" |
| #include "device/bluetooth/bluetooth_uuid.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -218,92 +217,162 @@ TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { |
| list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); |
| list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); |
| { |
| - std::vector<BluetoothScanFilter> empty_filters; |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters; |
| EXPECT_FALSE(list_.IsExcluded(empty_filters)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> single_empty_filter(1); |
| - EXPECT_EQ(0u, single_empty_filter[0].services.size()); |
| + 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>(); |
| + |
| + EXPECT_EQ(0u, single_empty_filter[0]->services.size()); |
| EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> single_non_matching_filter(1); |
| - single_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> |
| + single_non_matching_filter(1); |
| + |
| + single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); |
| + single_non_matching_filter[0]->services.push_back( |
| + BluetoothUUID("0000").canonical_value()); |
| + |
| EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> multiple_non_matching_filter(2); |
| - multiple_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); |
| - multiple_non_matching_filter[0].services.push_back(BluetoothUUID("ee01")); |
| - multiple_non_matching_filter[1].services.push_back(BluetoothUUID("ee02")); |
| - multiple_non_matching_filter[1].services.push_back(BluetoothUUID("0003")); |
| - EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filter)); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> |
| + multiple_non_matching_filters(2); |
| + |
| + multiple_non_matching_filters[0] = |
| + blink::mojom::WebBluetoothScanFilter::New(); |
| + multiple_non_matching_filters[0]->services.push_back( |
| + BluetoothUUID("0000").canonical_value()); |
|
Jeffrey Yasskin
2016/05/13 04:41:58
Maybe write a local Canonicalize() function to get
ortuno
2016/05/13 20:11:17
Done.
|
| + multiple_non_matching_filters[0]->services.push_back( |
| + BluetoothUUID("ee01").canonical_value()); |
| + |
| + multiple_non_matching_filters[1] = |
| + blink::mojom::WebBluetoothScanFilter::New(); |
| + multiple_non_matching_filters[1]->services.push_back( |
| + BluetoothUUID("ee02").canonical_value()); |
| + multiple_non_matching_filters[1]->services.push_back( |
| + BluetoothUUID("0003").canonical_value()); |
| + |
| + EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters)); |
| } |
| } |
| TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { |
| list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); |
| { |
| - std::vector<BluetoothScanFilter> single_matching_filter(1); |
| - single_matching_filter[0].services.push_back(BluetoothUUID("eeee")); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter( |
| + 1); |
| + |
| + single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); |
| + single_matching_filter[0]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + |
| EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> first_matching_filter(2); |
| - first_matching_filter[0].services.push_back(BluetoothUUID("eeee")); |
| - first_matching_filter[0].services.push_back(BluetoothUUID("0001")); |
| - first_matching_filter[1].services.push_back(BluetoothUUID("0002")); |
| - first_matching_filter[1].services.push_back(BluetoothUUID("0003")); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter( |
| + 2); |
| + |
| + first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); |
| + first_matching_filter[0]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + first_matching_filter[0]->services.push_back( |
| + BluetoothUUID("0001").canonical_value()); |
| + |
| + first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); |
| + first_matching_filter[1]->services.push_back( |
| + BluetoothUUID("0002").canonical_value()); |
| + first_matching_filter[1]->services.push_back( |
| + BluetoothUUID("0003").canonical_value()); |
| + |
| EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> last_matching_filter(2); |
| - last_matching_filter[0].services.push_back(BluetoothUUID("0001")); |
| - last_matching_filter[0].services.push_back(BluetoothUUID("0001")); |
| - last_matching_filter[1].services.push_back(BluetoothUUID("0002")); |
| - last_matching_filter[1].services.push_back(BluetoothUUID("eeee")); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter( |
| + 2); |
| + |
| + last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); |
| + last_matching_filter[0]->services.push_back( |
| + BluetoothUUID("0001").canonical_value()); |
| + last_matching_filter[0]->services.push_back( |
| + BluetoothUUID("0001").canonical_value()); |
| + |
| + last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); |
| + last_matching_filter[1]->services.push_back( |
| + BluetoothUUID("0002").canonical_value()); |
| + last_matching_filter[1]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + |
| EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); |
| } |
| { |
| - std::vector<BluetoothScanFilter> multiple_matching_filter(2); |
| - multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); |
| - multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); |
| - multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); |
| - multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); |
| - EXPECT_TRUE(list_.IsExcluded(multiple_matching_filter)); |
| + mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> |
| + multiple_matching_filters(2); |
| + |
| + multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New(); |
| + multiple_matching_filters[0]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + multiple_matching_filters[0]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + |
| + multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New(); |
| + multiple_matching_filters[1]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + multiple_matching_filters[1]->services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + |
| + EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters)); |
| } |
| } |
| -TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_NonMatching) { |
| +TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) { |
| list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); |
| list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); |
| list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); |
| + |
| + // options.optional_services should be the same before and after |
| + // RemoveExcludedUUIDs(). |
| { |
| - std::vector<BluetoothUUID> empty; |
| - std::vector<BluetoothUUID> expected_empty; |
| - list_.RemoveExcludedUuids(&empty); |
| - EXPECT_EQ(expected_empty, empty); |
| - } |
| - { |
| - std::vector<BluetoothUUID> single_non_matching; |
| - single_non_matching.push_back(BluetoothUUID("0000")); |
| + // Empty optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services = mojo::Array<mojo::String>(); |
| - std::vector<BluetoothUUID> expected_copy(single_non_matching); |
| + mojo::Array<mojo::String> expected = options.optional_services.Clone(); |
| - list_.RemoveExcludedUuids(&single_non_matching); |
| - EXPECT_EQ(expected_copy, single_non_matching); |
| + list_.RemoveExcludedUUIDs(&options); |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| } |
| { |
| - std::vector<BluetoothUUID> multiple_non_matching; |
| - multiple_non_matching.push_back(BluetoothUUID("0000")); |
| - multiple_non_matching.push_back(BluetoothUUID("ee01")); |
| - multiple_non_matching.push_back(BluetoothUUID("ee02")); |
| - multiple_non_matching.push_back(BluetoothUUID("0003")); |
| + // One non-matching service in optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services.push_back( |
| + BluetoothUUID("0000").canonical_value()); |
| - std::vector<BluetoothUUID> expected_copy(multiple_non_matching); |
| + mojo::Array<mojo::String> expected = options.optional_services.Clone(); |
| - list_.RemoveExcludedUuids(&multiple_non_matching); |
| - EXPECT_EQ(expected_copy, multiple_non_matching); |
| + list_.RemoveExcludedUUIDs(&options); |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| + } |
| + { |
| + // Multiple non-matching services in optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services.push_back( |
| + BluetoothUUID("0000").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("ee01").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("ee02").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("0003").canonical_value()); |
| + |
| + mojo::Array<mojo::String> expected = options.optional_services.Clone(); |
| + |
| + list_.RemoveExcludedUUIDs(&options); |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| } |
| } |
| @@ -313,38 +382,50 @@ TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) { |
| list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE); |
| list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE); |
| { |
| - std::vector<BluetoothUUID> single_matching; |
| - single_matching.push_back(BluetoothUUID("eeee")); |
| + // Single matching service in optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| - std::vector<BluetoothUUID> expected_empty; |
| + mojo::Array<mojo::String> expected = mojo::Array<mojo::String>(); |
| - list_.RemoveExcludedUuids(&single_matching); |
| - EXPECT_EQ(expected_empty, single_matching); |
| + list_.RemoveExcludedUUIDs(&options); |
| + |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| } |
| { |
| - std::vector<BluetoothUUID> single_matching_of_many; |
| - single_matching_of_many.push_back(BluetoothUUID("0000")); |
| - single_matching_of_many.push_back(BluetoothUUID("eeee")); |
| - single_matching_of_many.push_back(BluetoothUUID("0001")); |
| - |
| - std::vector<BluetoothUUID> expected; |
| - expected.push_back(BluetoothUUID("0000")); |
| - expected.push_back(BluetoothUUID("0001")); |
| - |
| - list_.RemoveExcludedUuids(&single_matching_of_many); |
| - EXPECT_EQ(expected, single_matching_of_many); |
| + // Single matching of many services in optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services.push_back( |
| + BluetoothUUID("0000").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("0001").canonical_value()); |
| + |
| + mojo::Array<mojo::String> expected; |
| + expected.push_back(BluetoothUUID("0000").canonical_value()); |
| + expected.push_back(BluetoothUUID("0001").canonical_value()); |
| + |
| + list_.RemoveExcludedUUIDs(&options); |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| } |
| { |
| - std::vector<BluetoothUUID> all_matching_of_many; |
| - all_matching_of_many.push_back(BluetoothUUID("eee2")); |
| - all_matching_of_many.push_back(BluetoothUUID("eee4")); |
| - all_matching_of_many.push_back(BluetoothUUID("eee3")); |
| - all_matching_of_many.push_back(BluetoothUUID("eeee")); |
| - |
| - std::vector<BluetoothUUID> expected_empty; |
| - |
| - list_.RemoveExcludedUuids(&all_matching_of_many); |
| - EXPECT_EQ(expected_empty, all_matching_of_many); |
| + // All matching of many services in optional_services. |
| + blink::mojom::WebBluetoothRequestDeviceOptions options; |
| + options.optional_services.push_back( |
| + BluetoothUUID("eee2").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("eee4").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("eee3").canonical_value()); |
| + options.optional_services.push_back( |
| + BluetoothUUID("eeee").canonical_value()); |
| + |
| + mojo::Array<mojo::String> expected = mojo::Array<mojo::String>(); |
| + |
| + list_.RemoveExcludedUUIDs(&options); |
| + EXPECT_TRUE(options.optional_services.Equals(expected)); |
| } |
| } |