Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/renderer/extensions/json_schema_unittest.cc

Issue 9657026: Revert 125801 - Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class JsonSchemaTest : public V8UnitTest { 17 class JsonSchemaTest : public V8UnitTest {
18 public: 18 public:
19 JsonSchemaTest() {} 19 JsonSchemaTest() {}
20 20
21 virtual void SetUp() { 21 virtual void SetUp() {
22 V8UnitTest::SetUp(); 22 V8UnitTest::SetUp();
23 23
24 // Add the json schema code to the context. 24 // Add the json schema code to the context.
25 std::string code = ResourceBundle::GetSharedInstance().GetRawDataResource( 25 std::string code = ResourceBundle::GetSharedInstance().GetRawDataResource(
26 IDR_JSON_SCHEMA_JS).as_string(); 26 IDR_JSON_SCHEMA_JS).as_string();
27 27
28 // json_schema.js expects to have requireNative() defined. 28 // This is a nasty hack, but it is easier to test the code if we don't use
29 ExecuteScriptInContext( 29 // it as a v8 extension. So replace the only bit that relies on that with a
30 "function requireNative(id) {" 30 // more easily testable implementation.
31 " return {" 31 ReplaceFirstSubstringAfterOffset(&code, 0,
32 " GetChromeHidden: function() { return {}; }," 32 "native function GetChromeHidden();",
33 " };" 33 "function GetChromeHidden() {\n"
34 "}", 34 " if (!this.chromeHidden) this.chromeHidden = {};\n"
35 "test-code"); 35 " return this.chromeHidden;\n"
36 "}");
36 ExecuteScriptInContext(code, kJsonSchema); 37 ExecuteScriptInContext(code, kJsonSchema);
37 38
38 // Add the test functions to the context. 39 // Add the test functions to the context.
39 FilePath test_js_file_path; 40 FilePath test_js_file_path;
40 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_js_file_path)); 41 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_js_file_path));
41 test_js_file_path = test_js_file_path.AppendASCII("extensions"); 42 test_js_file_path = test_js_file_path.AppendASCII("extensions");
42 test_js_file_path = test_js_file_path.AppendASCII(kJsonSchemaTest); 43 test_js_file_path = test_js_file_path.AppendASCII(kJsonSchemaTest);
43 std::string test_js; 44 std::string test_js;
44 ASSERT_TRUE(file_util::ReadFileToString(test_js_file_path, &test_js)); 45 ASSERT_TRUE(file_util::ReadFileToString(test_js_file_path, &test_js));
45 ExecuteScriptInContext(test_js, kJsonSchemaTest); 46 ExecuteScriptInContext(test_js, kJsonSchemaTest);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 TestFunction("testGetAllTypesForSchema"); 99 TestFunction("testGetAllTypesForSchema");
99 } 100 }
100 101
101 TEST_F(JsonSchemaTest, TestIsValidSchemaType) { 102 TEST_F(JsonSchemaTest, TestIsValidSchemaType) {
102 TestFunction("testIsValidSchemaType"); 103 TestFunction("testIsValidSchemaType");
103 } 104 }
104 105
105 TEST_F(JsonSchemaTest, TestCheckSchemaOverlap) { 106 TEST_F(JsonSchemaTest, TestCheckSchemaOverlap) {
106 TestFunction("testCheckSchemaOverlap"); 107 TestFunction("testCheckSchemaOverlap");
107 } 108 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/i18n_custom_bindings.cc ('k') | chrome/renderer/extensions/miscellaneous_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698