summaryrefslogtreecommitdiffstats
path: root/extensions/test/data/mojo_private_unittest.js
blob: f66b997d4cba11e76b08b8106780af6028825653 (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
// Copyright 2015 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.

'use strict';

let mojoPrivate = require('mojoPrivate').binding;
let test = require('test').binding;
let unittestBindings = require('test_environment_specific_bindings');

unittestBindings.exportTests([
  function testDefine() {
    mojoPrivate.define('testModule', [
      'mojo/public/js/codec',
    ], test.callbackPass(function(codec) {
      test.assertEq('function', typeof codec.Message);
    }));
  },

  function testDefineRegistersModule() {
    mojoPrivate.define('testModule', ['dependency'],
                       test.callbackPass(function(module) {
      test.assertEq(12345, module.result);
    }));
    mojoPrivate.define('dependency', test.callbackPass(function() {
      return {result: 12345};
    }));
  },

  function testDefineModuleDoesNotExist() {
    mojoPrivate.define('testModule', ['does not exist!'], test.fail);
    test.succeed();
  },

  function testRequireAsync() {
    mojoPrivate.requireAsync('mojo/public/js/codec').then(
        test.callbackPass(function(codec) {
          test.assertEq('function', typeof codec.Message);
        }));
  },

  function testDefineAndRequire() {
    mojoPrivate.define('testModule', ['dependency'],
                       test.callbackPass(function(module) {
      test.assertEq(12345, module.result);
    }));
    mojoPrivate.define('dependency', test.callbackPass(function() {
      return {result: 12345};
    }));
    mojoPrivate.requireAsync('dependency').then(
        test.callbackPass(),
        test.fail);
  }
], test.runTests, exports);