| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/test/base/v8_unit_test.h" | 9 #include "chrome/test/base/v8_unit_test.h" |
| 10 #include "grit/renderer_resources.h" | 10 #include "grit/renderer_resources.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 | 13 |
| 14 static const char kJsonSchema[] = "json_schema.js"; | 14 static const char kJsonSchema[] = "json_schema.js"; |
| 15 static const char kJsonSchemaTest[] = "json_schema_test.js"; | 15 static const char kJsonSchemaTest[] = "json_schema_test.js"; |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 class JsonSchemaTest : public V8UnitTest { | 19 class JsonSchemaTest : public V8UnitTest { |
| 20 public: | 20 public: |
| 21 JsonSchemaTest() {} | 21 JsonSchemaTest() {} |
| 22 | 22 |
| 23 virtual void SetUp() { | 23 virtual void SetUp() { |
| 24 V8UnitTest::SetUp(); | 24 V8UnitTest::SetUp(); |
| 25 | 25 |
| 26 // Add the json schema code to the context. | 26 // Add the json schema code to the context. |
| 27 std::string code = ResourceBundle::GetSharedInstance().GetRawDataResource( | 27 std::string code = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 28 IDR_JSON_SCHEMA_JS).as_string(); | 28 IDR_JSON_SCHEMA_JS).as_string(); |
| 29 | 29 |
| 30 // json_schema.js expects to have require() and requireNative() defined. | 30 // json_schema.js expects to have requireNative() defined. |
| 31 ExecuteScriptInContext( | 31 ExecuteScriptInContext( |
| 32 "function requireNative(id) {" | 32 "function requireNative(id) {" |
| 33 " return {" | 33 " return {" |
| 34 " GetChromeHidden: function() { return {}; }," | 34 " GetChromeHidden: function() { return {}; }," |
| 35 " };" | 35 " };" |
| 36 "}" | |
| 37 "function require(id) {" | |
| 38 " return {" | |
| 39 " loadRefDependency: function(foo) { return {}; }," | |
| 40 " };" | |
| 41 "}", | 36 "}", |
| 42 "test-code"); | 37 "test-code"); |
| 43 ExecuteScriptInContext(code, kJsonSchema); | 38 ExecuteScriptInContext(code, kJsonSchema); |
| 44 | 39 |
| 45 // Add the test functions to the context. | 40 // Add the test functions to the context. |
| 46 base::FilePath test_js_file_path; | 41 base::FilePath test_js_file_path; |
| 47 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_js_file_path)); | 42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_js_file_path)); |
| 48 test_js_file_path = test_js_file_path.AppendASCII("extensions"); | 43 test_js_file_path = test_js_file_path.AppendASCII("extensions"); |
| 49 test_js_file_path = test_js_file_path.AppendASCII(kJsonSchemaTest); | 44 test_js_file_path = test_js_file_path.AppendASCII(kJsonSchemaTest); |
| 50 std::string test_js; | 45 std::string test_js; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 102 |
| 108 TEST_F(JsonSchemaTest, TestIsValidSchemaType) { | 103 TEST_F(JsonSchemaTest, TestIsValidSchemaType) { |
| 109 TestFunction("testIsValidSchemaType"); | 104 TestFunction("testIsValidSchemaType"); |
| 110 } | 105 } |
| 111 | 106 |
| 112 TEST_F(JsonSchemaTest, TestCheckSchemaOverlap) { | 107 TEST_F(JsonSchemaTest, TestCheckSchemaOverlap) { |
| 113 TestFunction("testCheckSchemaOverlap"); | 108 TestFunction("testCheckSchemaOverlap"); |
| 114 } | 109 } |
| 115 | 110 |
| 116 } // namespace extensions | 111 } // namespace extensions |
| OLD | NEW |