Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: content/child/webcrypto/test/status_unittest.cc

Issue 489643002: [refactor] Split up a large (5k lines) unit-test into multiple files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error (by removing NSS ifdefed code) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/webcrypto/test/sha_unittest.cc ('k') | content/child/webcrypto/test/test_helpers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/test/status_unittest.cc
diff --git a/content/child/webcrypto/openssl/aes_gcm_openssl.cc b/content/child/webcrypto/test/status_unittest.cc
similarity index 18%
copy from content/child/webcrypto/openssl/aes_gcm_openssl.cc
copy to content/child/webcrypto/test/status_unittest.cc
index a3e1cd31a5591646b06a696aece119664f7a6e97..11d014e482532e803eb52394828217395a62c47a 100644
--- a/content/child/webcrypto/openssl/aes_gcm_openssl.cc
+++ b/content/child/webcrypto/test/status_unittest.cc
@@ -2,20 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <vector>
-#include <openssl/evp.h>
-
-#include "base/logging.h"
#include "base/stl_util.h"
+#include "content/child/webcrypto/algorithm_dispatch.h"
#include "content/child/webcrypto/crypto_data.h"
-#include "content/child/webcrypto/openssl/aes_key_openssl.h"
-#include "content/child/webcrypto/openssl/key_openssl.h"
-#include "content/child/webcrypto/openssl/util_openssl.h"
#include "content/child/webcrypto/status.h"
+#include "content/child/webcrypto/test/test_helpers.h"
#include "content/child/webcrypto/webcrypto_util.h"
-#include "crypto/openssl_util.h"
-#include "crypto/scoped_openssl_types.h"
+#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
#include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
+#include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
namespace content {
@@ -23,66 +18,61 @@ namespace webcrypto {
namespace {
-const EVP_AEAD* GetAesGcmAlgorithmFromKeySize(unsigned int key_size_bytes) {
- switch (key_size_bytes) {
- case 16:
- return EVP_aead_aes_128_gcm();
- case 32:
- return EVP_aead_aes_256_gcm();
- default:
- return NULL;
- }
-}
-
-Status AesGcmEncryptDecrypt(EncryptOrDecrypt mode,
- const blink::WebCryptoAlgorithm& algorithm,
- const blink::WebCryptoKey& key,
- const CryptoData& data,
- std::vector<uint8_t>* buffer) {
- const std::vector<uint8_t>& raw_key =
- SymKeyOpenSsl::Cast(key)->raw_key_data();
- const blink::WebCryptoAesGcmParams* params = algorithm.aesGcmParams();
-
- unsigned int tag_length_bits;
- Status status = GetAesGcmTagLengthInBits(params, &tag_length_bits);
- if (status.IsError())
- return status;
-
- return AeadEncryptDecrypt(mode,
- raw_key,
- data,
- tag_length_bits / 8,
- CryptoData(params->iv()),
- CryptoData(params->optionalAdditionalData()),
- GetAesGcmAlgorithmFromKeySize(raw_key.size()),
- buffer);
+// Tests several Status objects against their expected hard coded values, as
+// well as ensuring that comparison of Status objects works.
+// Comparison should take into account both the error details, as well as the
+// error type.
+TEST(WebCryptoStatusTest, Basic) {
+ // Even though the error message is the same, these should not be considered
+ // the same by the tests because the error type is different.
+ EXPECT_NE(Status::DataError(), Status::OperationError());
+ EXPECT_NE(Status::Success(), Status::OperationError());
+
+ EXPECT_EQ(Status::Success(), Status::Success());
+ EXPECT_EQ(Status::ErrorJwkPropertyWrongType("kty", "string"),
+ Status::ErrorJwkPropertyWrongType("kty", "string"));
+
+ Status status = Status::Success();
+
+ EXPECT_FALSE(status.IsError());
+ EXPECT_EQ("", status.error_details());
+
+ status = Status::OperationError();
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("", status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeOperation, status.error_type());
+
+ status = Status::DataError();
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("", status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type());
+
+ status = Status::ErrorUnsupported();
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("The requested operation is unsupported", status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeNotSupported, status.error_type());
+
+ status = Status::ErrorJwkPropertyMissing("kty");
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("The required JWK property \"kty\" was missing",
+ status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type());
+
+ status = Status::ErrorJwkPropertyWrongType("kty", "string");
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("The JWK property \"kty\" must be a string",
+ status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type());
+
+ status = Status::ErrorJwkBase64Decode("n");
+ EXPECT_TRUE(status.IsError());
+ EXPECT_EQ("The JWK property \"n\" could not be base64 decoded",
+ status.error_details());
+ EXPECT_EQ(blink::WebCryptoErrorTypeData, status.error_type());
}
-class AesGcmImplementation : public AesAlgorithm {
- public:
- AesGcmImplementation() : AesAlgorithm("GCM") {}
-
- virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
- const blink::WebCryptoKey& key,
- const CryptoData& data,
- std::vector<uint8_t>* buffer) const OVERRIDE {
- return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer);
- }
-
- virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
- const blink::WebCryptoKey& key,
- const CryptoData& data,
- std::vector<uint8_t>* buffer) const OVERRIDE {
- return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer);
- }
-};
-
} // namespace
-AlgorithmImplementation* CreatePlatformAesGcmImplementation() {
- return new AesGcmImplementation;
-}
-
} // namespace webcrypto
} // namespace content
« no previous file with comments | « content/child/webcrypto/test/sha_unittest.cc ('k') | content/child/webcrypto/test/test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698