summaryrefslogtreecommitdiffstats
path: root/extensions/test/data/api_test_base_unittest.js
blob: 46641ba5ccfdc23877797a583800421f0309be84 (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
// 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.

var test = require('test').binding;
var unittestBindings = require('test_environment_specific_bindings');

unittestBindings.exportTests([
  function testEnvironment() {
    test.assertTrue(!!$Array);
    test.assertTrue(!!$Function);
    test.assertTrue(!!$JSON);
    test.assertTrue(!!$Object);
    test.assertTrue(!!$RegExp);
    test.assertTrue(!!$String);
    test.assertTrue(!!privates);
    test.assertTrue(!!define);
    test.assertTrue(!!require);
    test.assertTrue(!!requireNative);
    test.assertTrue(!!requireAsync);
    test.assertEq(undefined, chrome.runtime.lastError);
    test.assertEq(undefined, chrome.extension.lastError);
    test.succeed();
  },
  function testPromisesRun() {
    Promise.resolve().then(test.callbackPass());
  },
  function testCommonModulesAreAvailable() {
    var binding = require('binding');
    var sendRequest = require('sendRequest');
    var lastError = require('lastError');
    test.assertTrue(!!binding);
    test.assertTrue(!!sendRequest);
    test.assertTrue(!!lastError);
    test.succeed();
  },
  function testMojoModulesAreAvailable() {
    Promise.all([
      requireAsync('mojo/public/js/connection'),
      requireAsync('mojo/public/js/core'),
      requireAsync('content/public/renderer/service_provider'),
    ]).then(test.callback(function(modules) {
      var connection = modules[0];
      var core = modules[1];
      var serviceProvider = modules[2];
      test.assertTrue(!!connection.Connection);
      test.assertTrue(!!core.createMessagePipe);
      test.assertTrue(!!serviceProvider.connectToService);
    }));
  },
  function testTestBindings() {
    var counter = 0;
    function increment() {
      counter++;
    }
    test.runWithUserGesture(increment);
    test.runWithoutUserGesture(increment);
    test.runWithModuleSystem(increment);
    test.assertEq(3, counter);
    test.assertFalse(test.isProcessingUserGesture());
    test.assertTrue(!!test.getApiFeatures());
    test.assertEq(0, test.getApiDefinitions().length);
    test.succeed();
  }
], test.runTests, exports);