| 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/bindings/api_binding_test_util.h" | 7 #include "extensions/renderer/bindings/api_binding_test_util.h" |
| 8 #include "extensions/renderer/bindings/api_invocation_errors.h" | 8 #include "extensions/renderer/bindings/api_invocation_errors.h" |
| 9 #include "extensions/renderer/bindings/api_type_reference_map.h" | 9 #include "extensions/renderer/bindings/api_type_reference_map.h" |
| 10 #include "extensions/renderer/bindings/argument_spec.h" | 10 #include "extensions/renderer/bindings/argument_spec.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 476 } |
| 477 | 477 |
| 478 TEST_F(ArgumentSpecUnitTest, TypeChoicesTest) { | 478 TEST_F(ArgumentSpecUnitTest, TypeChoicesTest) { |
| 479 using namespace api_errors; | 479 using namespace api_errors; |
| 480 { | 480 { |
| 481 const char kSimpleChoices[] = | 481 const char kSimpleChoices[] = |
| 482 "{'choices': [{'type': 'string'}, {'type': 'integer'}]}"; | 482 "{'choices': [{'type': 'string'}, {'type': 'integer'}]}"; |
| 483 ArgumentSpec spec(*ValueFromString(kSimpleChoices)); | 483 ArgumentSpec spec(*ValueFromString(kSimpleChoices)); |
| 484 ExpectSuccess(spec, "'alpha'", "'alpha'"); | 484 ExpectSuccess(spec, "'alpha'", "'alpha'"); |
| 485 ExpectSuccess(spec, "42", "42"); | 485 ExpectSuccess(spec, "42", "42"); |
| 486 ExpectFailure(spec, "true", InvalidChoice()); | 486 const char kChoicesType[] = "[string|integer]"; |
| 487 ExpectFailure(spec, "true", InvalidType(kChoicesType, kTypeBoolean)); |
| 487 } | 488 } |
| 488 | 489 |
| 489 { | 490 { |
| 490 const char kComplexChoices[] = | 491 const char kComplexChoices[] = |
| 491 "{" | 492 "{" |
| 492 " 'choices': [" | 493 " 'choices': [" |
| 493 " {'type': 'array', 'items': {'type': 'string'}}," | 494 " {'type': 'array', 'items': {'type': 'string'}}," |
| 494 " {'type': 'object', 'properties': {'prop1': {'type': 'string'}}}" | 495 " {'type': 'object', 'properties': {'prop1': {'type': 'string'}}}" |
| 495 " ]" | 496 " ]" |
| 496 "}"; | 497 "}"; |
| 497 ArgumentSpec spec(*ValueFromString(kComplexChoices)); | 498 ArgumentSpec spec(*ValueFromString(kComplexChoices)); |
| 498 ExpectSuccess(spec, "['alpha']", "['alpha']"); | 499 ExpectSuccess(spec, "['alpha']", "['alpha']"); |
| 499 ExpectSuccess(spec, "['alpha', 'beta']", "['alpha','beta']"); | 500 ExpectSuccess(spec, "['alpha', 'beta']", "['alpha','beta']"); |
| 500 ExpectSuccess(spec, "({prop1: 'alpha'})", "{'prop1':'alpha'}"); | 501 ExpectSuccess(spec, "({prop1: 'alpha'})", "{'prop1':'alpha'}"); |
| 502 |
| 503 const char kChoicesType[] = "[array|object]"; |
| 501 ExpectFailure(spec, "({prop1: 1})", InvalidChoice()); | 504 ExpectFailure(spec, "({prop1: 1})", InvalidChoice()); |
| 502 ExpectFailure(spec, "'alpha'", InvalidChoice()); | 505 ExpectFailure(spec, "'alpha'", InvalidType(kChoicesType, kTypeString)); |
| 503 ExpectFailure(spec, "42", InvalidChoice()); | 506 ExpectFailure(spec, "42", InvalidType(kChoicesType, kTypeInteger)); |
| 504 } | 507 } |
| 505 } | 508 } |
| 506 | 509 |
| 507 TEST_F(ArgumentSpecUnitTest, AdditionalPropertiesTest) { | 510 TEST_F(ArgumentSpecUnitTest, AdditionalPropertiesTest) { |
| 508 using namespace api_errors; | 511 using namespace api_errors; |
| 509 { | 512 { |
| 510 const char kOnlyAnyAdditionalProperties[] = | 513 const char kOnlyAnyAdditionalProperties[] = |
| 511 "{" | 514 "{" |
| 512 " 'type': 'object'," | 515 " 'type': 'object'," |
| 513 " 'additionalProperties': {'type': 'any'}" | 516 " 'additionalProperties': {'type': 'any'}" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 std::vector<std::unique_ptr<ArgumentSpec>> choices; | 811 std::vector<std::unique_ptr<ArgumentSpec>> choices; |
| 809 choices.push_back(base::MakeUnique<ArgumentSpec>(ArgumentType::INTEGER)); | 812 choices.push_back(base::MakeUnique<ArgumentSpec>(ArgumentType::INTEGER)); |
| 810 choices.push_back(base::MakeUnique<ArgumentSpec>(ArgumentType::STRING)); | 813 choices.push_back(base::MakeUnique<ArgumentSpec>(ArgumentType::STRING)); |
| 811 ArgumentSpec choices_spec(ArgumentType::CHOICES); | 814 ArgumentSpec choices_spec(ArgumentType::CHOICES); |
| 812 choices_spec.set_choices(std::move(choices)); | 815 choices_spec.set_choices(std::move(choices)); |
| 813 EXPECT_EQ("[integer|string]", choices_spec.GetTypeName()); | 816 EXPECT_EQ("[integer|string]", choices_spec.GetTypeName()); |
| 814 } | 817 } |
| 815 } | 818 } |
| 816 | 819 |
| 817 } // namespace extensions | 820 } // namespace extensions |
| OLD | NEW |