| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "extensions/renderer/api_binding_test_util.h" | 7 #include "extensions/renderer/api_binding_test_util.h" |
| 8 #include "extensions/renderer/argument_spec.h" | 8 #include "extensions/renderer/argument_spec.h" |
| 9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 v8::Isolate* isolate = instance_->isolate(); | 64 v8::Isolate* isolate = instance_->isolate(); |
| 65 v8::HandleScope handle_scope(instance_->isolate()); | 65 v8::HandleScope handle_scope(instance_->isolate()); |
| 66 | 66 |
| 67 v8::Local<v8::Context> context = | 67 v8::Local<v8::Context> context = |
| 68 v8::Local<v8::Context>::New(instance_->isolate(), context_); | 68 v8::Local<v8::Context>::New(instance_->isolate(), context_); |
| 69 v8::TryCatch try_catch(isolate); | 69 v8::TryCatch try_catch(isolate); |
| 70 v8::Local<v8::Value> val = V8ValueFromScriptSource(context, script_source); | 70 v8::Local<v8::Value> val = V8ValueFromScriptSource(context, script_source); |
| 71 ASSERT_FALSE(val.IsEmpty()) << script_source; | 71 ASSERT_FALSE(val.IsEmpty()) << script_source; |
| 72 | 72 |
| 73 std::string error; | 73 std::string error; |
| 74 std::unique_ptr<base::Value> out_value = | 74 std::unique_ptr<base::Value> out_value; |
| 75 spec.ConvertArgument(context, val, type_refs_, &error); | 75 bool did_succeed = |
| 76 spec.ParseArgument(context, val, type_refs_, &out_value, &error); |
| 76 bool should_succeed = expected_result == TestResult::PASS; | 77 bool should_succeed = expected_result == TestResult::PASS; |
| 77 ASSERT_EQ(should_succeed, !!out_value) << script_source << ", " << error; | 78 ASSERT_EQ(should_succeed, did_succeed) << script_source << ", " << error; |
| 79 ASSERT_EQ(did_succeed, !!out_value); |
| 78 bool should_throw = expected_result == TestResult::THROW; | 80 bool should_throw = expected_result == TestResult::THROW; |
| 79 ASSERT_EQ(should_throw, try_catch.HasCaught()) << script_source; | 81 ASSERT_EQ(should_throw, try_catch.HasCaught()) << script_source; |
| 80 if (should_succeed) { | 82 if (should_succeed) { |
| 81 ASSERT_TRUE(out_value); | 83 ASSERT_TRUE(out_value); |
| 82 EXPECT_EQ(expected_json, ValueToString(*out_value)); | 84 EXPECT_EQ(expected_json, ValueToString(*out_value)); |
| 83 } else if (should_throw) { | 85 } else if (should_throw) { |
| 84 EXPECT_EQ(expected_thrown_message, | 86 EXPECT_EQ(expected_thrown_message, |
| 85 gin::V8ToString(try_catch.Message()->Get())); | 87 gin::V8ToString(try_catch.Message()->Get())); |
| 86 } | 88 } |
| 87 } | 89 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 ExpectSuccess(spec, "['alpha']", "['alpha']"); | 310 ExpectSuccess(spec, "['alpha']", "['alpha']"); |
| 309 ExpectSuccess(spec, "['alpha', 'beta']", "['alpha','beta']"); | 311 ExpectSuccess(spec, "['alpha', 'beta']", "['alpha','beta']"); |
| 310 ExpectSuccess(spec, "({prop1: 'alpha'})", "{'prop1':'alpha'}"); | 312 ExpectSuccess(spec, "({prop1: 'alpha'})", "{'prop1':'alpha'}"); |
| 311 ExpectFailure(spec, "({prop1: 1})"); | 313 ExpectFailure(spec, "({prop1: 1})"); |
| 312 ExpectFailure(spec, "'alpha'"); | 314 ExpectFailure(spec, "'alpha'"); |
| 313 ExpectFailure(spec, "42"); | 315 ExpectFailure(spec, "42"); |
| 314 } | 316 } |
| 315 } | 317 } |
| 316 | 318 |
| 317 } // namespace extensions | 319 } // namespace extensions |
| OLD | NEW |