OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/test/base/module_system_test.h" | 6 #include "chrome/test/base/module_system_test.h" |
7 #include "grit/extensions_renderer_resources.h" | 7 #include "grit/extensions_renderer_resources.h" |
8 | 8 |
9 namespace extensions { | 9 namespace extensions { |
10 namespace { | 10 namespace { |
11 | 11 |
12 class UtilsUnittest : public ModuleSystemTest { | 12 class UtilsUnittest : public ModuleSystemTest { |
13 protected: | 13 protected: |
14 void RegisterTestModule(const char* code) { | 14 void RegisterTestModule(const char* code) { |
15 RegisterModule("test", | 15 env()->RegisterModule("test", |
16 base::StringPrintf( | 16 base::StringPrintf( |
17 "var assert = requireNative('assert');\n" | 17 "var assert = requireNative('assert');\n" |
18 "var AssertTrue = assert.AssertTrue;\n" | 18 "var AssertTrue = assert.AssertTrue;\n" |
19 "var AssertFalse = assert.AssertFalse;\n" | 19 "var AssertFalse = assert.AssertFalse;\n" |
20 "var utils = require('utils');\n" | 20 "var utils = require('utils');\n" |
21 "%s", | 21 "%s", |
22 code)); | 22 code)); |
23 } | 23 } |
24 | 24 |
25 private: | 25 private: |
26 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
27 ModuleSystemTest::SetUp(); | 27 ModuleSystemTest::SetUp(); |
28 | 28 |
29 RegisterModule("utils", IDR_UTILS_JS); | 29 env()->RegisterModule("utils", IDR_UTILS_JS); |
30 OverrideNativeHandler("schema_registry", | 30 env()->OverrideNativeHandler("schema_registry", |
31 "exports.GetSchema = function() {};"); | 31 "exports.GetSchema = function() {};"); |
32 OverrideNativeHandler("logging", | 32 env()->OverrideNativeHandler("logging", |
33 "exports.CHECK = function() {};\n" | 33 "exports.CHECK = function() {};\n" |
34 "exports.WARNING = function() {};"); | 34 "exports.WARNING = function() {};"); |
35 } | 35 } |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(UtilsUnittest, TestNothing) { | 38 TEST_F(UtilsUnittest, TestNothing) { |
39 ExpectNoAssertionsMade(); | 39 ExpectNoAssertionsMade(); |
40 } | 40 } |
41 | 41 |
42 TEST_F(UtilsUnittest, SuperClass) { | 42 TEST_F(UtilsUnittest, SuperClass) { |
43 ModuleSystem::NativesEnabledScope natives_enabled_scope( | 43 ModuleSystem::NativesEnabledScope natives_enabled_scope( |
44 context_->module_system()); | 44 env()->module_system()); |
45 RegisterTestModule( | 45 RegisterTestModule( |
46 "function SuperClassImpl() {}\n" | 46 "function SuperClassImpl() {}\n" |
47 "\n" | 47 "\n" |
48 "SuperClassImpl.prototype = {\n" | 48 "SuperClassImpl.prototype = {\n" |
49 " attrA: 'aSuper',\n" | 49 " attrA: 'aSuper',\n" |
50 " attrB: 'bSuper',\n" | 50 " attrB: 'bSuper',\n" |
51 " func: function() { return 'func'; },\n" | 51 " func: function() { return 'func'; },\n" |
52 " superFunc: function() { return 'superFunc'; }\n" | 52 " superFunc: function() { return 'superFunc'; }\n" |
53 "};\n" | 53 "};\n" |
54 "\n" | 54 "\n" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 "AssertTrue(subsub.attrB == 'bSuper');\n" | 109 "AssertTrue(subsub.attrB == 'bSuper');\n" |
110 "AssertTrue(subsub.attrC == 'cSub');\n" | 110 "AssertTrue(subsub.attrC == 'cSub');\n" |
111 "AssertTrue(subsub.func() == 'overridden');\n" | 111 "AssertTrue(subsub.func() == 'overridden');\n" |
112 "AssertTrue(subsub.superFunc() == 'superFunc');\n" | 112 "AssertTrue(subsub.superFunc() == 'superFunc');\n" |
113 "AssertTrue(subsub.subFunc() == 'subFunc');\n" | 113 "AssertTrue(subsub.subFunc() == 'subFunc');\n" |
114 "AssertTrue(subsub.subSubFunc() == 'subsub');\n" | 114 "AssertTrue(subsub.subSubFunc() == 'subsub');\n" |
115 "AssertTrue(subsub instanceof SuperClass);\n" | 115 "AssertTrue(subsub instanceof SuperClass);\n" |
116 "AssertTrue(subsub instanceof SubClass);\n" | 116 "AssertTrue(subsub instanceof SubClass);\n" |
117 "AssertTrue(subsub instanceof SubSubClass);\n"); | 117 "AssertTrue(subsub instanceof SubSubClass);\n"); |
118 | 118 |
119 context_->module_system()->Require("test"); | 119 env()->module_system()->Require("test"); |
120 } | 120 } |
121 | 121 |
122 } // namespace | 122 } // namespace |
123 } // namespace extensions | 123 } // namespace extensions |
OLD | NEW |