| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/safe_json_parser.h" | 10 #include "chrome/browser/safe_json_parser.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 std::string MaybeToJson(const base::Value* value) { | 17 std::string MaybeToJson(const base::Value* value) { |
| 18 if (!value) | 18 if (!value) |
| 19 return "(null)"; | 19 return "(null)"; |
| 20 | 20 |
| 21 std::string json; | 21 std::string json; |
| 22 if (!base::JSONWriter::Write(value, &json)) | 22 if (!base::JSONWriter::Write(*value, &json)) |
| 23 return "(invalid value)"; | 23 return "(invalid value)"; |
| 24 | 24 |
| 25 return json; | 25 return json; |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 class SafeJsonParserTest : public InProcessBrowserTest { | 30 class SafeJsonParserTest : public InProcessBrowserTest { |
| 31 protected: | 31 protected: |
| 32 void TestParse(const std::string& json) { | 32 void TestParse(const std::string& json) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 TestParse("\"laser\""); | 95 TestParse("\"laser\""); |
| 96 TestParse("false"); | 96 TestParse("false"); |
| 97 TestParse("null"); | 97 TestParse("null"); |
| 98 TestParse("3.14"); | 98 TestParse("3.14"); |
| 99 TestParse("["); | 99 TestParse("["); |
| 100 TestParse("\""); | 100 TestParse("\""); |
| 101 TestParse(std::string()); | 101 TestParse(std::string()); |
| 102 TestParse("☃"); | 102 TestParse("☃"); |
| 103 TestParse("\"☃\""); | 103 TestParse("\"☃\""); |
| 104 } | 104 } |
| OLD | NEW |