| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include "base/stl_util.h" | |
| 6 #include "content/child/webcrypto/algorithm_dispatch.h" | |
| 7 #include "content/child/webcrypto/crypto_data.h" | |
| 8 #include "content/child/webcrypto/status.h" | |
| 9 #include "content/child/webcrypto/test/test_helpers.h" | |
| 10 #include "content/child/webcrypto/webcrypto_util.h" | |
| 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | |
| 12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | |
| 13 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace webcrypto { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Tests several Status objects against their expected hard coded values, as | |
| 22 // well as ensuring that comparison of Status objects works. | |
| 23 // Comparison should take into account both the error details, as well as the | |
| 24 // error type. | |
| 25 TEST(WebCryptoStatusTest, Basic) { | |
| 26 // Even though the error message is the same, these should not be considered | |
| 27 // the same by the tests because the error type is different. | |
| 28 EXPECT_NE(Status::DataError(), Status::OperationError()); | |
| 29 EXPECT_NE(Status::Success(), Status::OperationError()); | |
| 30 | |
| 31 EXPECT_EQ(Status::Success(), Status::Success()); | |
| 32 EXPECT_EQ(Status::ErrorJwkMemberWrongType("kty", "string"), | |
| 33 Status::ErrorJwkMemberWrongType("kty", "string")); | |
| 34 | |
| 35 Status status = Status::Success(); | |
| 36 | |
| 37 EXPECT_FALSE(status.IsError()); | |
| 38 EXPECT_EQ("", status.error_details()); | |
| 39 | |
| 40 status = Status::OperationError(); | |
| 41 EXPECT_TRUE(status.IsError()); | |
| 42 EXPECT_EQ("", status.error_details()); | |
| 43 EXPECT_EQ(blink::WebCryptoErrorTypeOperation, status.error_type()); | |
| 44 | |
| 45 status = Status::DataError(); | |
| 46 EXPECT_TRUE(status.IsError()); | |
| 47 EXPECT_EQ("", status.error_details()); | |
| 48 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); | |
| 49 | |
| 50 status = Status::ErrorUnsupported(); | |
| 51 EXPECT_TRUE(status.IsError()); | |
| 52 EXPECT_EQ("The requested operation is unsupported", status.error_details()); | |
| 53 EXPECT_EQ(blink::WebCryptoErrorTypeNotSupported, status.error_type()); | |
| 54 | |
| 55 status = Status::ErrorJwkMemberMissing("kty"); | |
| 56 EXPECT_TRUE(status.IsError()); | |
| 57 EXPECT_EQ("The required JWK member \"kty\" was missing", | |
| 58 status.error_details()); | |
| 59 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); | |
| 60 | |
| 61 status = Status::ErrorJwkMemberWrongType("kty", "string"); | |
| 62 EXPECT_TRUE(status.IsError()); | |
| 63 EXPECT_EQ("The JWK member \"kty\" must be a string", status.error_details()); | |
| 64 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); | |
| 65 | |
| 66 status = Status::ErrorJwkBase64Decode("n"); | |
| 67 EXPECT_TRUE(status.IsError()); | |
| 68 EXPECT_EQ( | |
| 69 "The JWK member \"n\" could not be base64url decoded or contained " | |
| 70 "padding", | |
| 71 status.error_details()); | |
| 72 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); | |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 | |
| 77 } // namespace webcrypto | |
| 78 | |
| 79 } // namespace content | |
| OLD | NEW |