Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / test / status_unittest.cc
blobd04614e771ecc58463df8a448a34d764bd1209d6
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 "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"
15 namespace content {
17 namespace webcrypto {
19 namespace {
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());
31 EXPECT_EQ(Status::Success(), Status::Success());
32 EXPECT_EQ(Status::ErrorJwkMemberWrongType("kty", "string"),
33 Status::ErrorJwkMemberWrongType("kty", "string"));
35 Status status = Status::Success();
37 EXPECT_FALSE(status.IsError());
38 EXPECT_EQ("", status.error_details());
40 status = Status::OperationError();
41 EXPECT_TRUE(status.IsError());
42 EXPECT_EQ("", status.error_details());
43 EXPECT_EQ(blink::WebCryptoErrorTypeOperation, status.error_type());
45 status = Status::DataError();
46 EXPECT_TRUE(status.IsError());
47 EXPECT_EQ("", status.error_details());
48 EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type());
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());
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());
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());
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());
75 } // namespace
77 } // namespace webcrypto
79 } // namespace content