| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/webcrypto/test/test_helpers.h" | 5 #include "components/webcrypto/test/test_helpers.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "content/child/webcrypto/algorithm_dispatch.h" | 18 #include "components/webcrypto/algorithm_dispatch.h" |
| 19 #include "content/child/webcrypto/crypto_data.h" | 19 #include "components/webcrypto/crypto_data.h" |
| 20 #include "content/child/webcrypto/generate_key_result.h" | 20 #include "components/webcrypto/generate_key_result.h" |
| 21 #include "content/child/webcrypto/jwk.h" | 21 #include "components/webcrypto/jwk.h" |
| 22 #include "content/child/webcrypto/status.h" | 22 #include "components/webcrypto/status.h" |
| 23 #include "content/child/webcrypto/webcrypto_util.h" | 23 #include "components/webcrypto/webcrypto_util.h" |
| 24 #include "content/public/common/content_paths.h" | |
| 25 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 24 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 26 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 25 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 27 #include "third_party/re2/re2/re2.h" | 26 #include "third_party/re2/re2/re2.h" |
| 28 | 27 |
| 29 #if !defined(USE_OPENSSL) | 28 #if !defined(USE_OPENSSL) |
| 30 #include <nss.h> | 29 #include <nss.h> |
| 31 #include <pk11pub.h> | 30 #include <pk11pub.h> |
| 32 | 31 |
| 33 #include "crypto/nss_util.h" | 32 #include "crypto/nss_util.h" |
| 34 #include "crypto/scoped_nss_types.h" | 33 #include "crypto/scoped_nss_types.h" |
| 35 #endif | 34 #endif |
| 36 | 35 |
| 37 namespace content { | 36 namespace components { |
| 38 | 37 |
| 39 namespace webcrypto { | 38 namespace webcrypto { |
| 40 | 39 |
| 41 void PrintTo(const Status& status, ::std::ostream* os) { | 40 void PrintTo(const Status& status, ::std::ostream* os) { |
| 42 *os << StatusToString(status); | 41 *os << StatusToString(status); |
| 43 } | 42 } |
| 44 | 43 |
| 45 bool operator==(const Status& a, const Status& b) { | 44 bool operator==(const Status& a, const Status& b) { |
| 46 if (a.IsSuccess() != b.IsSuccess()) | 45 if (a.IsSuccess() != b.IsSuccess()) |
| 47 return false; | 46 return false; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 170 |
| 172 std::vector<uint8_t> MakeJsonVector(const base::DictionaryValue& dict) { | 171 std::vector<uint8_t> MakeJsonVector(const base::DictionaryValue& dict) { |
| 173 std::string json; | 172 std::string json; |
| 174 base::JSONWriter::Write(&dict, &json); | 173 base::JSONWriter::Write(&dict, &json); |
| 175 return MakeJsonVector(json); | 174 return MakeJsonVector(json); |
| 176 } | 175 } |
| 177 | 176 |
| 178 ::testing::AssertionResult ReadJsonTestFile(const char* test_file_name, | 177 ::testing::AssertionResult ReadJsonTestFile(const char* test_file_name, |
| 179 scoped_ptr<base::Value>* value) { | 178 scoped_ptr<base::Value>* value) { |
| 180 base::FilePath test_data_dir; | 179 base::FilePath test_data_dir; |
| 181 if (!PathService::Get(DIR_TEST_DATA, &test_data_dir)) | 180 if (!PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)) |
| 182 return ::testing::AssertionFailure() << "Couldn't retrieve test dir"; | 181 return ::testing::AssertionFailure() << "Couldn't retrieve test dir"; |
| 183 | 182 |
| 184 base::FilePath file_path = | 183 base::FilePath file_path = test_data_dir.AppendASCII("components") |
| 185 test_data_dir.AppendASCII("webcrypto").AppendASCII(test_file_name); | 184 .AppendASCII("test") |
| 185 .AppendASCII("data") |
| 186 .AppendASCII("webcrypto") |
| 187 .AppendASCII(test_file_name); |
| 186 | 188 |
| 187 std::string file_contents; | 189 std::string file_contents; |
| 188 if (!base::ReadFileToString(file_path, &file_contents)) { | 190 if (!base::ReadFileToString(file_path, &file_contents)) { |
| 189 return ::testing::AssertionFailure() | 191 return ::testing::AssertionFailure() |
| 190 << "Couldn't read test file: " << file_path.value(); | 192 << "Couldn't read test file: " << file_path.value(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 // Strip C++ style comments out of the "json" file, otherwise it cannot be | 195 // Strip C++ style comments out of the "json" file, otherwise it cannot be |
| 194 // parsed. | 196 // parsed. |
| 195 re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), ""); | 197 re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), ""); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 return blink::WebCryptoNamedCurveP521; | 683 return blink::WebCryptoNamedCurveP521; |
| 682 else | 684 else |
| 683 ADD_FAILURE() << "Unrecognized curve name: " << curve_str; | 685 ADD_FAILURE() << "Unrecognized curve name: " << curve_str; |
| 684 | 686 |
| 685 return blink::WebCryptoNamedCurveP384; | 687 return blink::WebCryptoNamedCurveP384; |
| 686 } | 688 } |
| 687 | 689 |
| 688 } // namespace webcrypto | 690 } // namespace webcrypto |
| 689 | 691 |
| 690 } // namesapce content | 692 } // namesapce content |
| OLD | NEW |