aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/module/moduleloadcallback_test.html
blob: 2fe5096bdf18e529f30bb643d468d99701118f55 (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
<!DOCTYPE html>
<html>

<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.

Author: nicksantos@google.com (Nick Santos)
-->

<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>JsUnit tests for goog.module.ModuleLoadCallback</title>
<script src="../base.js"></script>
<script>

goog.require('goog.debug.ErrorHandler');
goog.require('goog.debug.entryPointRegistry');
goog.require('goog.functions');
goog.require('goog.module.ModuleLoadCallback');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.recordFunction');


</script>
</head>
<body>
<script type='text/javascript'>

function testProtectEntryPoint() {
  // Test a callback created before the protect method is called.
  var callback1 = new goog.module.ModuleLoadCallback(
      goog.functions.error('callback1'));

  var errorFn = goog.testing.recordFunction();
  var errorHandler = new goog.debug.ErrorHandler(errorFn);
  goog.debug.entryPointRegistry.monitorAll(errorHandler);

  assertEquals(0, errorFn.getCallCount());
  assertThrows(goog.bind(callback1.execute, callback1));
  assertEquals(1, errorFn.getCallCount());
  assertContains('callback1', errorFn.getLastCall().getArguments()[0].message);

  // Test a callback created after the protect method is called.
  var callback2 = new goog.module.ModuleLoadCallback(
      goog.functions.error('callback2'));
  assertThrows(goog.bind(callback1.execute, callback2));
  assertEquals(2, errorFn.getCallCount());
  assertContains('callback2', errorFn.getLastCall().getArguments()[0].message);
}

</script>
</body>
</html>