status_unittest.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/webcrypto/status.h"
  5. #include "components/webcrypto/algorithm_dispatch.h"
  6. #include "components/webcrypto/algorithms/test_helpers.h"
  7. #include "third_party/blink/public/platform/web_crypto_algorithm.h"
  8. #include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
  9. #include "third_party/blink/public/platform/web_crypto_key_algorithm.h"
  10. namespace webcrypto {
  11. namespace {
  12. // Tests several Status objects against their expected hard coded values, as
  13. // well as ensuring that comparison of Status objects works.
  14. // Comparison should take into account both the error details, as well as the
  15. // error type.
  16. TEST(WebCryptoStatusTest, Basic) {
  17. // Even though the error message is the same, these should not be considered
  18. // the same by the tests because the error type is different.
  19. EXPECT_NE(Status::DataError(), Status::OperationError());
  20. EXPECT_NE(Status::Success(), Status::OperationError());
  21. EXPECT_EQ(Status::Success(), Status::Success());
  22. EXPECT_EQ(Status::ErrorJwkMemberWrongType("kty", "string"),
  23. Status::ErrorJwkMemberWrongType("kty", "string"));
  24. Status status = Status::Success();
  25. EXPECT_FALSE(status.IsError());
  26. EXPECT_EQ("", status.error_details());
  27. status = Status::OperationError();
  28. EXPECT_TRUE(status.IsError());
  29. EXPECT_EQ("", status.error_details());
  30. EXPECT_EQ(blink::kWebCryptoErrorTypeOperation, status.error_type());
  31. status = Status::DataError();
  32. EXPECT_TRUE(status.IsError());
  33. EXPECT_EQ("", status.error_details());
  34. EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
  35. status = Status::ErrorUnsupported();
  36. EXPECT_TRUE(status.IsError());
  37. EXPECT_EQ("The requested operation is unsupported", status.error_details());
  38. EXPECT_EQ(blink::kWebCryptoErrorTypeNotSupported, status.error_type());
  39. status = Status::ErrorJwkMemberMissing("kty");
  40. EXPECT_TRUE(status.IsError());
  41. EXPECT_EQ("The required JWK member \"kty\" was missing",
  42. status.error_details());
  43. EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
  44. status = Status::ErrorJwkMemberWrongType("kty", "string");
  45. EXPECT_TRUE(status.IsError());
  46. EXPECT_EQ("The JWK member \"kty\" must be a string", status.error_details());
  47. EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
  48. status = Status::ErrorJwkBase64Decode("n");
  49. EXPECT_TRUE(status.IsError());
  50. EXPECT_EQ(
  51. "The JWK member \"n\" could not be base64url decoded or contained "
  52. "padding",
  53. status.error_details());
  54. EXPECT_EQ(blink::kWebCryptoErrorTypeData, status.error_type());
  55. }
  56. } // namespace
  57. } // namespace webcrypto