summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/utils_unittest.cc
blob: 485c214ea66feab21cd8157b82cfa31be2d10f98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/strings/stringprintf.h"
#include "extensions/renderer/module_system_test.h"
#include "gin/dictionary.h"
#include "grit/extensions_renderer_resources.h"

namespace extensions {
namespace {

class UtilsUnittest : public ModuleSystemTest {
 private:
  void SetUp() override {
    ModuleSystemTest::SetUp();

    env()->RegisterModule("utils", IDR_UTILS_JS);
    env()->RegisterTestFile("utils_unittest", "utils_unittest.js");
    env()->OverrideNativeHandler("schema_registry",
                                 "exports.$set('GetSchema', function() {});");
    env()->OverrideNativeHandler("logging",
                                 "exports.$set('CHECK', function() {});\n"
                                 "exports.$set('DCHECK', function() {});\n"
                                 "exports.$set('WARNING', function() {});");
    env()->OverrideNativeHandler("v8_context", "");
    gin::Dictionary chrome(env()->isolate(), env()->CreateGlobal("chrome"));
    gin::Dictionary chrome_runtime(
        gin::Dictionary::CreateEmpty(env()->isolate()));
    chrome.Set("runtime", chrome_runtime);
  }
};

TEST_F(UtilsUnittest, TestNothing) {
  ExpectNoAssertionsMade();
}

TEST_F(UtilsUnittest, SuperClass) {
  ModuleSystem::NativesEnabledScope natives_enabled_scope(
      env()->module_system());
  env()->module_system()->CallModuleMethod("utils_unittest", "testSuperClass");
}

TEST_F(UtilsUnittest, PromiseNoResult) {
  ModuleSystem::NativesEnabledScope natives_enabled_scope(
      env()->module_system());
  env()->module_system()->CallModuleMethod("utils_unittest",
                                           "testPromiseNoResult");
  RunResolvedPromises();
}

TEST_F(UtilsUnittest, PromiseOneResult) {
  ModuleSystem::NativesEnabledScope natives_enabled_scope(
      env()->module_system());
  env()->module_system()->CallModuleMethod("utils_unittest",
                                           "testPromiseOneResult");
  RunResolvedPromises();
}

TEST_F(UtilsUnittest, PromiseTwoResults) {
  ModuleSystem::NativesEnabledScope natives_enabled_scope(
      env()->module_system());
  env()->module_system()->CallModuleMethod("utils_unittest",
                                           "testPromiseTwoResults");
  RunResolvedPromises();
}

TEST_F(UtilsUnittest, PromiseError) {
  ModuleSystem::NativesEnabledScope natives_enabled_scope(
      env()->module_system());
  env()->module_system()->CallModuleMethod("utils_unittest",
                                           "testPromiseError");
  RunResolvedPromises();
}

}  // namespace
}  // namespace extensions