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

Side by Side Diff: base/test/launcher/test_results_tracker.cc

Issue 1312923003: Fix test launcher crash on non-UTF-8 output snippets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/test/launcher/test_results_tracker.h" 5 #include "base/test/launcher/test_results_tracker.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 for (size_t k = 0; k < j->second.test_results.size(); k++) { 255 for (size_t k = 0; k < j->second.test_results.size(); k++) {
256 const TestResult& test_result = j->second.test_results[k]; 256 const TestResult& test_result = j->second.test_results[k];
257 257
258 scoped_ptr<DictionaryValue> test_result_value(new DictionaryValue); 258 scoped_ptr<DictionaryValue> test_result_value(new DictionaryValue);
259 259
260 test_result_value->SetString("status", test_result.StatusAsString()); 260 test_result_value->SetString("status", test_result.StatusAsString());
261 test_result_value->SetInteger( 261 test_result_value->SetInteger(
262 "elapsed_time_ms", 262 "elapsed_time_ms",
263 static_cast<int>(test_result.elapsed_time.InMilliseconds())); 263 static_cast<int>(test_result.elapsed_time.InMilliseconds()));
264 264
265 // There are no guarantees about character encoding of the output 265 bool lossless_snippet = false;
266 // snippet. Escape it and record whether it was losless. 266 if (IsStringUTF8(test_result.output_snippet)) {
267 // It's useful to have the output snippet as string in the summary 267 test_result_value->SetString(
268 // for easy viewing. 268 "output_snippet", test_result.output_snippet);
269 std::string escaped_output_snippet; 269 lossless_snippet = true;
270 bool losless_snippet = EscapeJSONString( 270 } else {
271 test_result.output_snippet, false, &escaped_output_snippet); 271 test_result_value->SetString(
272 test_result_value->SetString("output_snippet", 272 "output_snippet",
273 escaped_output_snippet); 273 "<non-UTF-8 snippet, see output_snippet_base64>");
sky 2015/08/27 16:51:56 Actually, one question here, can we escape the str
Paweł Hajdan Jr. 2015/08/28 08:04:24 That's what the previous code was trying to do. Ap
274 test_result_value->SetBoolean("losless_snippet", losless_snippet); 274 }
275
276 // TODO(phajdan.jr): Fix typo in JSON key (losless -> lossless)
277 // making sure not to break any consumers of this data.
278 test_result_value->SetBoolean("losless_snippet", lossless_snippet);
275 279
276 // Also include the raw version (base64-encoded so that it can be safely 280 // Also include the raw version (base64-encoded so that it can be safely
277 // JSON-serialized - there are no guarantees about character encoding 281 // JSON-serialized - there are no guarantees about character encoding
278 // of the snippet). This can be very useful piece of information when 282 // of the snippet). This can be very useful piece of information when
279 // debugging a test failure related to character encoding. 283 // debugging a test failure related to character encoding.
280 std::string base64_output_snippet; 284 std::string base64_output_snippet;
281 Base64Encode(test_result.output_snippet, &base64_output_snippet); 285 Base64Encode(test_result.output_snippet, &base64_output_snippet);
282 test_result_value->SetString("output_snippet_base64", 286 test_result_value->SetString("output_snippet_base64",
283 base64_output_snippet); 287 base64_output_snippet);
284 test_results->Append(test_result_value.Pass()); 288 test_results->Append(test_result_value.Pass());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 TestResultsTracker::AggregateTestResult::~AggregateTestResult() { 358 TestResultsTracker::AggregateTestResult::~AggregateTestResult() {
355 } 359 }
356 360
357 TestResultsTracker::PerIterationData::PerIterationData() { 361 TestResultsTracker::PerIterationData::PerIterationData() {
358 } 362 }
359 363
360 TestResultsTracker::PerIterationData::~PerIterationData() { 364 TestResultsTracker::PerIterationData::~PerIterationData() {
361 } 365 }
362 366
363 } // namespace base 367 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698