Roll src/third_party/WebKit 395ff9e:18c0088 (svn 192995:192997)
[chromium-blink-merge.git] / extensions / renderer / json_schema_unittest.cc
blob41a4b71142726056cfef66e756ec6672af9323fe
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
3 // found in the LICENSE file.
5 #include "extensions/renderer/module_system_test.h"
6 #include "extensions/renderer/v8_schema_registry.h"
7 #include "gin/dictionary.h"
8 #include "grit/extensions_renderer_resources.h"
10 namespace extensions {
12 class JsonSchemaTest : public ModuleSystemTest {
13 public:
14 void SetUp() override {
15 ModuleSystemTest::SetUp();
17 env()->RegisterModule("json_schema", IDR_JSON_SCHEMA_JS);
18 env()->RegisterModule("utils", IDR_UTILS_JS);
20 env()->module_system()->RegisterNativeHandler(
21 "schema_registry", schema_registry_.AsNativeHandler());
23 env()->RegisterTestFile("json_schema_test", "json_schema_test.js");
26 protected:
27 void TestFunction(const std::string& test_name) {
28 env()->module_system()->CallModuleMethod("json_schema_test", test_name);
31 private:
32 V8SchemaRegistry schema_registry_;
35 TEST_F(JsonSchemaTest, TestFormatError) {
36 TestFunction("testFormatError");
39 TEST_F(JsonSchemaTest, TestComplex) {
40 TestFunction("testComplex");
43 TEST_F(JsonSchemaTest, TestEnum) {
44 TestFunction("testEnum");
47 TEST_F(JsonSchemaTest, TestExtends) {
48 TestFunction("testExtends");
51 TEST_F(JsonSchemaTest, TestObject) {
52 TestFunction("testObject");
55 TEST_F(JsonSchemaTest, TestArrayTuple) {
56 TestFunction("testArrayTuple");
59 TEST_F(JsonSchemaTest, TestArrayNonTuple) {
60 TestFunction("testArrayNonTuple");
63 TEST_F(JsonSchemaTest, TestString) {
64 TestFunction("testString");
67 TEST_F(JsonSchemaTest, TestNumber) {
68 TestFunction("testNumber");
71 TEST_F(JsonSchemaTest, TestIntegerBounds) {
72 TestFunction("testIntegerBounds");
75 TEST_F(JsonSchemaTest, TestType) {
76 gin::Dictionary array_buffer_container(
77 env()->isolate(),
78 env()->CreateGlobal("otherContextArrayBufferContainer"));
80 // Create an ArrayBuffer in another v8 context and pass it to the test
81 // through a global.
82 scoped_ptr<ModuleSystemTestEnvironment> other_env(CreateEnvironment());
83 v8::Context::Scope scope(other_env->context()->v8_context());
84 v8::Handle<v8::ArrayBuffer> array_buffer(
85 v8::ArrayBuffer::New(env()->isolate(), 1));
86 array_buffer_container.Set("value", array_buffer);
88 TestFunction("testType");
91 TEST_F(JsonSchemaTest, TestTypeReference) {
92 TestFunction("testTypeReference");
95 TEST_F(JsonSchemaTest, TestGetAllTypesForSchema) {
96 TestFunction("testGetAllTypesForSchema");
99 TEST_F(JsonSchemaTest, TestIsValidSchemaType) {
100 TestFunction("testIsValidSchemaType");
103 TEST_F(JsonSchemaTest, TestCheckSchemaOverlap) {
104 TestFunction("testCheckSchemaOverlap");
107 TEST_F(JsonSchemaTest, TestInstanceOf) {
108 TestFunction("testInstanceOf");
111 } // namespace extensions