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

Side by Side Diff: components/webcrypto/test/test_helpers.cc

Issue 1077273002: html_viewer: Move webcrypto to a place where html_viewer can use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « components/webcrypto/test/test_helpers.h ('k') | components/webcrypto/webcrypto.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
38
39 namespace webcrypto { 36 namespace webcrypto {
40 37
41 void PrintTo(const Status& status, ::std::ostream* os) { 38 void PrintTo(const Status& status, ::std::ostream* os) {
42 *os << StatusToString(status); 39 *os << StatusToString(status);
43 } 40 }
44 41
45 bool operator==(const Status& a, const Status& b) { 42 bool operator==(const Status& a, const Status& b) {
46 if (a.IsSuccess() != b.IsSuccess()) 43 if (a.IsSuccess() != b.IsSuccess())
47 return false; 44 return false;
48 if (a.IsSuccess()) 45 if (a.IsSuccess())
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 168
172 std::vector<uint8_t> MakeJsonVector(const base::DictionaryValue& dict) { 169 std::vector<uint8_t> MakeJsonVector(const base::DictionaryValue& dict) {
173 std::string json; 170 std::string json;
174 base::JSONWriter::Write(&dict, &json); 171 base::JSONWriter::Write(&dict, &json);
175 return MakeJsonVector(json); 172 return MakeJsonVector(json);
176 } 173 }
177 174
178 ::testing::AssertionResult ReadJsonTestFile(const char* test_file_name, 175 ::testing::AssertionResult ReadJsonTestFile(const char* test_file_name,
179 scoped_ptr<base::Value>* value) { 176 scoped_ptr<base::Value>* value) {
180 base::FilePath test_data_dir; 177 base::FilePath test_data_dir;
181 if (!PathService::Get(DIR_TEST_DATA, &test_data_dir)) 178 if (!PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir))
182 return ::testing::AssertionFailure() << "Couldn't retrieve test dir"; 179 return ::testing::AssertionFailure() << "Couldn't retrieve test dir";
183 180
184 base::FilePath file_path = 181 base::FilePath file_path = test_data_dir.AppendASCII("components")
185 test_data_dir.AppendASCII("webcrypto").AppendASCII(test_file_name); 182 .AppendASCII("test")
183 .AppendASCII("data")
184 .AppendASCII("webcrypto")
185 .AppendASCII(test_file_name);
186 186
187 std::string file_contents; 187 std::string file_contents;
188 if (!base::ReadFileToString(file_path, &file_contents)) { 188 if (!base::ReadFileToString(file_path, &file_contents)) {
189 return ::testing::AssertionFailure() 189 return ::testing::AssertionFailure()
190 << "Couldn't read test file: " << file_path.value(); 190 << "Couldn't read test file: " << file_path.value();
191 } 191 }
192 192
193 // Strip C++ style comments out of the "json" file, otherwise it cannot be 193 // Strip C++ style comments out of the "json" file, otherwise it cannot be
194 // parsed. 194 // parsed.
195 re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), ""); 195 re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), "");
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 return blink::WebCryptoNamedCurveP384; 679 return blink::WebCryptoNamedCurveP384;
680 if (curve_str == "P-521") 680 if (curve_str == "P-521")
681 return blink::WebCryptoNamedCurveP521; 681 return blink::WebCryptoNamedCurveP521;
682 else 682 else
683 ADD_FAILURE() << "Unrecognized curve name: " << curve_str; 683 ADD_FAILURE() << "Unrecognized curve name: " << curve_str;
684 684
685 return blink::WebCryptoNamedCurveP384; 685 return blink::WebCryptoNamedCurveP384;
686 } 686 }
687 687
688 } // namespace webcrypto 688 } // namespace webcrypto
689
690 } // namesapce content
OLDNEW
« no previous file with comments | « components/webcrypto/test/test_helpers.h ('k') | components/webcrypto/webcrypto.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698