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

Unified Diff: components/web_bluetooth/web_bluetooth_device_id_unittest.cc

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Fix build Created 4 years, 5 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
« no previous file with comments | « components/web_bluetooth/web_bluetooth_device_id.cc ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/web_bluetooth/web_bluetooth_device_id_unittest.cc
diff --git a/components/web_bluetooth/web_bluetooth_device_id_unittest.cc b/components/web_bluetooth/web_bluetooth_device_id_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35c9bd09f0d8b53889c918922d04196350fd0b15
--- /dev/null
+++ b/components/web_bluetooth/web_bluetooth_device_id_unittest.cc
@@ -0,0 +1,81 @@
+// 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.
+
+#include "components/web_bluetooth/web_bluetooth_device_id.h"
+
+#include "base/base64.h"
+#include "base/strings/string_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using web_bluetooth::WebBluetoothDeviceId;
+
+namespace {
+
+const char kValidDeviceId1[] = "123456789012345678901A==";
+const char kValidDeviceId2[] = "AbCdEfGhIjKlMnOpQrS+/Q==";
+const char kInvalidLongDeviceId[] = "12345678901234567890123=";
+const char kInvalidShortDeviceId[] = "12345678901234567890";
+const char kInvalidCharacterDeviceId[] = "123456789012345678901*==";
+// A base64 string should have a length of a multiple of 4.
+const char kInvalidLengthDeviceId[] = "123456789012345678901";
+
+} // namespace
+
+TEST(WebBluetoothDeviceIdTest, DefaulConstructor) {
palmer 2016/07/11 18:34:49 Typo: DefaultConstructor
ortuno 2016/07/13 22:53:03 Done.
+ WebBluetoothDeviceId default_id1;
+ WebBluetoothDeviceId default_id2;
+ WebBluetoothDeviceId valid_id(kValidDeviceId1);
+
+ ASSERT_DEATH_IF_SUPPORTED(default_id1.str(), "");
+ ASSERT_DEATH_IF_SUPPORTED(default_id2.str(), "");
+ ASSERT_TRUE(WebBluetoothDeviceId::IsValid(valid_id.str()));
+
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == default_id2; }(), "");
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != default_id2; }(), "");
+
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == valid_id; }(), "");
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id == default_id1; }(), "");
+
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != valid_id; }(), "");
+ EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id != default_id1; }(), "");
+}
+
+TEST(WebBluetoothDeviceIdTest, StrConstructor) {
+ WebBluetoothDeviceId valid1(kValidDeviceId1);
+ WebBluetoothDeviceId valid2(kValidDeviceId2);
+
+ EXPECT_TRUE(valid1 == valid1);
+ EXPECT_TRUE(valid2 == valid2);
+
+ EXPECT_TRUE(valid1 != valid2);
+
+ EXPECT_DEATH_IF_SUPPORTED(WebBluetoothDeviceId(""), "");
+ EXPECT_DEATH_IF_SUPPORTED(
+ [&]() { return WebBluetoothDeviceId(kInvalidLongDeviceId); }(), "");
+ EXPECT_DEATH_IF_SUPPORTED(
+ [&]() { return WebBluetoothDeviceId(kInvalidShortDeviceId); }(), "");
+ EXPECT_DEATH_IF_SUPPORTED(
+ [&]() { return WebBluetoothDeviceId(kInvalidCharacterDeviceId); }(), "");
+ EXPECT_DEATH_IF_SUPPORTED(
+ [&]() { return WebBluetoothDeviceId(kInvalidLengthDeviceId); }(), "");
+}
+
+TEST(WebBluetoothDeviceIdTest, IsValid_Valid) {
+ EXPECT_TRUE(WebBluetoothDeviceId::IsValid(kValidDeviceId1));
+ EXPECT_TRUE(WebBluetoothDeviceId::IsValid(kValidDeviceId2));
+}
+
+TEST(WebBluetoothDeviceIdTest, IsValid_Invalid) {
+ EXPECT_FALSE(WebBluetoothDeviceId::IsValid(""));
+ EXPECT_FALSE(WebBluetoothDeviceId::IsValid(kInvalidLongDeviceId));
+ EXPECT_FALSE(WebBluetoothDeviceId::IsValid(kInvalidShortDeviceId));
+ EXPECT_FALSE(WebBluetoothDeviceId::IsValid(kInvalidCharacterDeviceId));
+ EXPECT_FALSE(WebBluetoothDeviceId::IsValid(kInvalidLengthDeviceId));
+}
+
+TEST(WebBluetoothDeviceIdTest, Create) {
+ // Tests that Create generates a valid Device Id.
+ EXPECT_TRUE(
+ WebBluetoothDeviceId::IsValid(WebBluetoothDeviceId::Create().str()));
+}
« no previous file with comments | « components/web_bluetooth/web_bluetooth_device_id.cc ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698