summaryrefslogtreecommitdiffstats
path: root/base/test
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 18:00:41 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 18:00:41 +0000
commitdd2cb504afa07f30ce1e6f73066d0c8575c4ac0a (patch)
tree1f4dfda2f2fa315616a0dc6e165f718e6a1257cd /base/test
parentcb502c7ad085f0d6737eea7de9b98621d62f4c0b (diff)
downloadchromium_src-dd2cb504afa07f30ce1e6f73066d0c8575c4ac0a.zip
chromium_src-dd2cb504afa07f30ce1e6f73066d0c8575c4ac0a.tar.gz
chromium_src-dd2cb504afa07f30ce1e6f73066d0c8575c4ac0a.tar.bz2
GTTF: Fix the test launcher's JSON output for non-UTF8-encoded snippets.
There are no guarantees about the encoding of test output. StringValue requires valid UTF-8. This change escapes the easily readable snippet and even adds a base64-encoded field in case a deeper debugging is needed. We shouldn't lose the raw string because it may be critical for debugging tricky bugs related to character encoding. BUG=236893 R=sky@chromium.org Review URL: https://codereview.chromium.org/102673005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/test')
-rw-r--r--base/test/launcher/test_results_tracker.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/base/test/launcher/test_results_tracker.cc b/base/test/launcher/test_results_tracker.cc
index 7b8dbeb..3e68093 100644
--- a/base/test/launcher/test_results_tracker.cc
+++ b/base/test/launcher/test_results_tracker.cc
@@ -4,11 +4,13 @@
#include "base/test/launcher/test_results_tracker.h"
+#include "base/base64.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/format_macros.h"
#include "base/json/json_file_value_serializer.h"
+#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/test/launcher/test_launcher.h"
@@ -273,8 +275,26 @@ bool TestResultsTracker::SaveSummaryAsJSON(const FilePath& path) const {
test_result_value->SetString("status", test_result.StatusAsString());
test_result_value->SetInteger(
"elapsed_time_ms", test_result.elapsed_time.InMilliseconds());
+
+ // There are no guarantees about character encoding of the output
+ // snippet. Escape it and record whether it was losless.
+ // It's useful to have the output snippet as string in the summary
+ // for easy viewing.
+ std::string escaped_output_snippet;
+ bool losless_snippet = EscapeJSONString(
+ test_result.output_snippet, false, &escaped_output_snippet);
test_result_value->SetString("output_snippet",
- test_result.output_snippet);
+ escaped_output_snippet);
+ test_result_value->SetBoolean("losless_snippet", losless_snippet);
+
+ // Also include the raw version (base64-encoded so that it can be safely
+ // JSON-serialized - there are no guarantees about character encoding
+ // of the snippet). This can be very useful piece of information when
+ // debugging a test failure related to character encoding.
+ std::string base64_output_snippet;
+ Base64Encode(test_result.output_snippet, &base64_output_snippet);
+ test_result_value->SetString("output_snippet_base64",
+ base64_output_snippet);
}
}
}