OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/safe_json/testing_json_parser.h" | 5 #include "components/safe_json/testing_json_parser.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace safe_json { | 16 namespace safe_json { |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 10 matching lines...) Expand all Loading... |
27 run_loop.QuitClosure())); | 29 run_loop.QuitClosure())); |
28 run_loop.Run(); | 30 run_loop.Run(); |
29 } | 31 } |
30 | 32 |
31 bool did_success() { return did_success_; } | 33 bool did_success() { return did_success_; } |
32 bool did_error() { return did_error_; } | 34 bool did_error() { return did_error_; } |
33 | 35 |
34 private: | 36 private: |
35 static void SuccessCallback(TestingJsonParserTest* test, | 37 static void SuccessCallback(TestingJsonParserTest* test, |
36 base::Closure quit_closure, | 38 base::Closure quit_closure, |
37 scoped_ptr<base::Value> value) { | 39 std::unique_ptr<base::Value> value) { |
38 test->did_success_ = true; | 40 test->did_success_ = true; |
39 quit_closure.Run(); | 41 quit_closure.Run(); |
40 | 42 |
41 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 43 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
42 base::DictionaryValue* dict; | 44 base::DictionaryValue* dict; |
43 ASSERT_TRUE(value->GetAsDictionary(&dict)); | 45 ASSERT_TRUE(value->GetAsDictionary(&dict)); |
44 int key_value = 0; | 46 int key_value = 0; |
45 EXPECT_TRUE(dict->GetInteger("key", &key_value)); | 47 EXPECT_TRUE(dict->GetInteger("key", &key_value)); |
46 EXPECT_EQ(2, key_value); | 48 EXPECT_EQ(2, key_value); |
47 } | 49 } |
(...skipping 20 matching lines...) Expand all Loading... |
68 } | 70 } |
69 | 71 |
70 TEST_F(TestingJsonParserTest, QuitLoopInErrorCallback) { | 72 TEST_F(TestingJsonParserTest, QuitLoopInErrorCallback) { |
71 Parse(&kTestJson[1]); | 73 Parse(&kTestJson[1]); |
72 EXPECT_FALSE(did_success()); | 74 EXPECT_FALSE(did_success()); |
73 EXPECT_TRUE(did_error()); | 75 EXPECT_TRUE(did_error()); |
74 } | 76 } |
75 | 77 |
76 } // namespace | 78 } // namespace |
77 } // namespace safe_json | 79 } // namespace safe_json |
OLD | NEW |