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.
5 #include "base/stl_util.h"
6 #include "components/webcrypto/algorithm_dispatch.h"
7 #include "components/webcrypto/crypto_data.h"
8 #include "components/webcrypto/status.h"
9 #include "components/webcrypto/test/test_helpers.h"
10 #include "components/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"
19 // Tests several Status objects against their expected hard coded values, as
20 // well as ensuring that comparison of Status objects works.
21 // Comparison should take into account both the error details, as well as the
23 TEST(WebCryptoStatusTest
, Basic
) {
24 // Even though the error message is the same, these should not be considered
25 // the same by the tests because the error type is different.
26 EXPECT_NE(Status::DataError(), Status::OperationError());
27 EXPECT_NE(Status::Success(), Status::OperationError());
29 EXPECT_EQ(Status::Success(), Status::Success());
30 EXPECT_EQ(Status::ErrorJwkMemberWrongType("kty", "string"),
31 Status::ErrorJwkMemberWrongType("kty", "string"));
33 Status status
= Status::Success();
35 EXPECT_FALSE(status
.IsError());
36 EXPECT_EQ("", status
.error_details());
38 status
= Status::OperationError();
39 EXPECT_TRUE(status
.IsError());
40 EXPECT_EQ("", status
.error_details());
41 EXPECT_EQ(blink::WebCryptoErrorTypeOperation
, status
.error_type());
43 status
= Status::DataError();
44 EXPECT_TRUE(status
.IsError());
45 EXPECT_EQ("", status
.error_details());
46 EXPECT_EQ(blink::WebCryptoErrorTypeData
, status
.error_type());
48 status
= Status::ErrorUnsupported();
49 EXPECT_TRUE(status
.IsError());
50 EXPECT_EQ("The requested operation is unsupported", status
.error_details());
51 EXPECT_EQ(blink::WebCryptoErrorTypeNotSupported
, status
.error_type());
53 status
= Status::ErrorJwkMemberMissing("kty");
54 EXPECT_TRUE(status
.IsError());
55 EXPECT_EQ("The required JWK member \"kty\" was missing",
56 status
.error_details());
57 EXPECT_EQ(blink::WebCryptoErrorTypeData
, status
.error_type());
59 status
= Status::ErrorJwkMemberWrongType("kty", "string");
60 EXPECT_TRUE(status
.IsError());
61 EXPECT_EQ("The JWK member \"kty\" must be a string", status
.error_details());
62 EXPECT_EQ(blink::WebCryptoErrorTypeData
, status
.error_type());
64 status
= Status::ErrorJwkBase64Decode("n");
65 EXPECT_TRUE(status
.IsError());
67 "The JWK member \"n\" could not be base64url decoded or contained "
69 status
.error_details());
70 EXPECT_EQ(blink::WebCryptoErrorTypeData
, status
.error_type());
75 } // namespace webcrypto