Debian Codegraph @

closure-library/closure/goog/module/moduleloadcallback_test.js

raw
1 // Copyright 2010 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.module.ModuleLoadCallbackTest');
16 goog.setTestOnly('goog.module.ModuleLoadCallbackTest');
17
18 goog.require('goog.debug.ErrorHandler');
19 goog.require('goog.debug.entryPointRegistry');
20 goog.require('goog.functions');
21 goog.require('goog.module.ModuleLoadCallback');
22 goog.require('goog.testing.jsunit');
23 goog.require('goog.testing.recordFunction');
24
25 function testProtectEntryPoint() {
26 // Test a callback created before the protect method is called.
27 var callback1 =
28 new goog.module.ModuleLoadCallback(goog.functions.error('callback1'));
29
30 var errorFn = goog.testing.recordFunction();
31 var errorHandler = new goog.debug.ErrorHandler(errorFn);
32 goog.debug.entryPointRegistry.monitorAll(errorHandler);
33
34 assertEquals(0, errorFn.getCallCount());
35 assertThrows(goog.bind(callback1.execute, callback1));
36 assertEquals(1, errorFn.getCallCount());
37 assertContains('callback1', errorFn.getLastCall().getArguments()[0].message);
38
39 // Test a callback created after the protect method is called.
40 var callback2 =
41 new goog.module.ModuleLoadCallback(goog.functions.error('callback2'));
42 assertThrows(goog.bind(callback1.execute, callback2));
43 assertEquals(2, errorFn.getCallCount());
44 assertContains('callback2', errorFn.getLastCall().getArguments()[0].message);
45 }