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

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

Issue 816403002: [WebCrypto] Cleanup in LoadTestKeys() in ecdh unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows build fix Created 5 years, 12 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 | « no previous file | content/test/data/webcrypto/ecdh.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/test/ecdh_unittest.cc
diff --git a/content/child/webcrypto/test/ecdh_unittest.cc b/content/child/webcrypto/test/ecdh_unittest.cc
index 822013f6cc5058755f5d1c7e73bfbadfa6c3f8d6..7d33e18ec96c3de0bf819ee4c69804163188c2c5 100644
--- a/content/child/webcrypto/test/ecdh_unittest.cc
+++ b/content/child/webcrypto/test/ecdh_unittest.cc
@@ -126,19 +126,32 @@ TEST(WebCryptoEcdhTest, DeriveBitsKnownAnswer) {
// Loads up a test ECDH public and private key for P-521. The keys
// come from different key pairs, and can be used for key derivation of up to
// 528 bits.
-void LoadTestKeys(blink::WebCryptoKey* public_key,
- blink::WebCryptoKey* private_key) {
- // Assume that the 7th key in the test data is for P-521.
+::testing::AssertionResult LoadTestKeys(blink::WebCryptoKey* public_key,
+ blink::WebCryptoKey* private_key) {
scoped_ptr<base::ListValue> tests;
- ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests));
+ if (!ReadJsonTestFileToList("ecdh.json", &tests))
+ return ::testing::AssertionFailure() << "Failed loading ecdh.json";
- const base::DictionaryValue* test;
- ASSERT_TRUE(tests->GetDictionary(6, &test));
+ const base::DictionaryValue* test = NULL;
+ bool valid_p521_keys = false;
+ for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) {
+ SCOPED_TRACE(test_index);
+ EXPECT_TRUE(tests->GetDictionary(test_index, &test));
+ test->GetBoolean("valid_p521_keys", &valid_p521_keys);
+ if (valid_p521_keys)
+ break;
+ }
+ if (!valid_p521_keys) {
+ return ::testing::AssertionFailure()
+ << "The P-521 test are missing in ecdh.json";
+ }
ImportKeysFromTest(test, public_key, private_key);
- ASSERT_EQ(blink::WebCryptoNamedCurveP521,
+ EXPECT_EQ(blink::WebCryptoNamedCurveP521,
public_key->algorithm().ecParams()->namedCurve());
+
+ return ::testing::AssertionSuccess();
}
// Try deriving an AES key of length 129 bits.
@@ -148,7 +161,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyBadAesLength) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -166,7 +179,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyUnsupportedAesLength) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -184,7 +197,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyZeroLengthHmac) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -204,7 +217,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyHmac19Bits) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -237,7 +250,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyHmacSha256NoLength) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -276,7 +289,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyHmacSha512NoLength) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
@@ -296,7 +309,7 @@ TEST(WebCryptoEcdhTest, DeriveKeyAes128) {
blink::WebCryptoKey public_key;
blink::WebCryptoKey base_key;
- LoadTestKeys(&public_key, &base_key);
+ ASSERT_TRUE(LoadTestKeys(&public_key, &base_key));
blink::WebCryptoKey derived_key;
« no previous file with comments | « no previous file | content/test/data/webcrypto/ecdh.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698