[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/strings/stringprintf.h" |
thakis | 54f7dc9 | 2017-02-23 22:09:59 | [diff] [blame] | 6 | #include "extensions/grit/extensions_renderer_resources.h" |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 7 | #include "extensions/renderer/module_system_test.h" |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 8 | |
| 9 | namespace extensions { |
| 10 | namespace { |
| 11 | |
| 12 | class UtilsUnittest : public ModuleSystemTest { |
rdevlin.cronin | fedbe84 | 2017-06-24 02:12:03 | [diff] [blame] | 13 | public: |
dcheng | f9afb37 | 2014-10-27 21:43:14 | [diff] [blame] | 14 | void SetUp() override { |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 15 | ModuleSystemTest::SetUp(); |
| 16 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 17 | env()->RegisterModule("utils", IDR_UTILS_JS); |
[email protected] | ee92764 | 2014-08-20 03:38:32 | [diff] [blame] | 18 | env()->RegisterTestFile("utils_unittest", "utils_unittest.js"); |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 19 | env()->OverrideNativeHandler("schema_registry", |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 20 | "exports.$set('GetSchema', function() {});"); |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 21 | env()->OverrideNativeHandler("logging", |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 22 | "exports.$set('CHECK', function() {});\n" |
| 23 | "exports.$set('DCHECK', function() {});\n" |
| 24 | "exports.$set('WARNING', function() {});"); |
[email protected] | ee92764 | 2014-08-20 03:38:32 | [diff] [blame] | 25 | env()->OverrideNativeHandler("v8_context", ""); |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 26 | } |
rdevlin.cronin | fedbe84 | 2017-06-24 02:12:03 | [diff] [blame] | 27 | |
| 28 | void RunTest(const std::string& test_name) { RunTestImpl(test_name, false); } |
| 29 | |
| 30 | void RunTestWithPromises(const std::string& test_name) { |
| 31 | RunTestImpl(test_name, true); |
| 32 | } |
| 33 | |
| 34 | private: |
| 35 | void RunTestImpl(const std::string& test_name, bool run_promises) { |
| 36 | ModuleSystem::NativesEnabledScope natives_enabled_scope( |
| 37 | env()->module_system()); |
| 38 | ASSERT_FALSE(env() |
| 39 | ->module_system() |
| 40 | ->Require("utils_unittest") |
| 41 | .ToLocalChecked() |
| 42 | .IsEmpty()); |
| 43 | env()->module_system()->CallModuleMethodSafe("utils_unittest", test_name); |
| 44 | if (run_promises) |
| 45 | RunResolvedPromises(); |
| 46 | } |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | TEST_F(UtilsUnittest, TestNothing) { |
| 50 | ExpectNoAssertionsMade(); |
| 51 | } |
| 52 | |
| 53 | TEST_F(UtilsUnittest, SuperClass) { |
rdevlin.cronin | fedbe84 | 2017-06-24 02:12:03 | [diff] [blame] | 54 | RunTest("testSuperClass"); |
[email protected] | ee92764 | 2014-08-20 03:38:32 | [diff] [blame] | 55 | } |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 56 | |
[email protected] | ed51006d | 2014-06-10 18:37:14 | [diff] [blame] | 57 | } // namespace |
| 58 | } // namespace extensions |