moduleloadcallback_test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. goog.provide('goog.module.ModuleLoadCallbackTest');
  15. goog.setTestOnly('goog.module.ModuleLoadCallbackTest');
  16. goog.require('goog.debug.ErrorHandler');
  17. goog.require('goog.debug.entryPointRegistry');
  18. goog.require('goog.functions');
  19. goog.require('goog.module.ModuleLoadCallback');
  20. goog.require('goog.testing.jsunit');
  21. goog.require('goog.testing.recordFunction');
  22. function testProtectEntryPoint() {
  23. // Test a callback created before the protect method is called.
  24. var callback1 =
  25. new goog.module.ModuleLoadCallback(goog.functions.error('callback1'));
  26. var errorFn = goog.testing.recordFunction();
  27. var errorHandler = new goog.debug.ErrorHandler(errorFn);
  28. goog.debug.entryPointRegistry.monitorAll(errorHandler);
  29. assertEquals(0, errorFn.getCallCount());
  30. assertThrows(goog.bind(callback1.execute, callback1));
  31. assertEquals(1, errorFn.getCallCount());
  32. assertContains('callback1', errorFn.getLastCall().getArguments()[0].message);
  33. // Test a callback created after the protect method is called.
  34. var callback2 =
  35. new goog.module.ModuleLoadCallback(goog.functions.error('callback2'));
  36. assertThrows(goog.bind(callback1.execute, callback2));
  37. assertEquals(2, errorFn.getCallCount());
  38. assertContains('callback2', errorFn.getLastCall().getArguments()[0].message);
  39. }