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::ErrorJwkPropertyWrongType("kty", "string"), 33 Status::ErrorJwkPropertyWrongType("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::ErrorJwkPropertyMissing("kty"); 56 EXPECT_TRUE(status.IsError()); 57 EXPECT_EQ("The required JWK property \"kty\" was missing", 58 status.error_details()); 59 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); 60 61 status = Status::ErrorJwkPropertyWrongType("kty", "string"); 62 EXPECT_TRUE(status.IsError()); 63 EXPECT_EQ("The JWK property \"kty\" must be a string", 64 status.error_details()); 65 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); 66 67 status = Status::ErrorJwkBase64Decode("n"); 68 EXPECT_TRUE(status.IsError()); 69 EXPECT_EQ("The JWK property \"n\" could not be base64 decoded", 70 status.error_details()); 71 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type()); 72 } 73 74 } // namespace 75 76 } // namespace webcrypto 77 78 } // namespace content 79