| 1 |
// Copyright 2009 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 |
/** |
| 16 |
* @fileoverview Tests for goog.module.ModuleLoader. |
| 17 |
* @author [email protected] (Nick Santos) |
| 18 |
*/ |
| 19 |
|
| 20 |
goog.provide('goog.module.ModuleLoaderTest'); |
| 21 |
|
| 22 |
goog.require('goog.Promise'); |
| 23 |
goog.require('goog.array'); |
| 24 |
goog.require('goog.dom'); |
| 25 |
goog.require('goog.dom.TagName'); |
| 26 |
goog.require('goog.events'); |
| 27 |
goog.require('goog.functions'); |
| 28 |
goog.require('goog.html.TrustedResourceUrl'); |
| 29 |
goog.require('goog.module.ModuleLoader'); |
| 30 |
goog.require('goog.module.ModuleManager'); |
| 31 |
goog.require('goog.net.BulkLoader'); |
| 32 |
goog.require('goog.net.XmlHttp'); |
| 33 |
goog.require('goog.object'); |
| 34 |
goog.require('goog.string.Const'); |
| 35 |
goog.require('goog.testing.PropertyReplacer'); |
| 36 |
goog.require('goog.testing.TestCase'); |
| 37 |
goog.require('goog.testing.events.EventObserver'); |
| 38 |
goog.require('goog.testing.jsunit'); |
| 39 |
goog.require('goog.userAgent'); |
| 40 |
|
| 41 |
goog.setTestOnly('goog.module.ModuleLoaderTest'); |
| 42 |
|
| 43 |
|
| 44 |
var modA1Loaded = false; |
| 45 |
var modA2Loaded = false; |
| 46 |
var modB1Loaded = false; |
| 47 |
|
| 48 |
var moduleLoader = null; |
| 49 |
var moduleManager = null; |
| 50 |
var stubs = new goog.testing.PropertyReplacer(); |
| 51 |
var modA1 = goog.html.TrustedResourceUrl.fromConstant( |
| 52 |
goog.string.Const.from('testdata/modA_1.js')); |
| 53 |
var modA2 = goog.html.TrustedResourceUrl.fromConstant( |
| 54 |
goog.string.Const.from('testdata/modA_2.js')); |
| 55 |
var modB1 = goog.html.TrustedResourceUrl.fromConstant( |
| 56 |
goog.string.Const.from('testdata/modB_1.js')); |
| 57 |
|
| 58 |
var EventType = goog.module.ModuleLoader.EventType; |
| 59 |
var observer; |
| 60 |
|
| 61 |
function setUpPage() { |
| 62 |
goog.testing.TestCase.getActiveTestCase().promiseTimeout = 10000; // 10s |
| 63 |
} |
| 64 |
|
| 65 |
function setUp() { |
| 66 |
modA1Loaded = false; |
| 67 |
modA2Loaded = false; |
| 68 |
modB1Loaded = false; |
| 69 |
|
| 70 |
goog.provide = goog.nullFunction; |
| 71 |
moduleManager = goog.module.ModuleManager.getInstance(); |
| 72 |
stubs.replace(moduleManager, 'getBackOff_', goog.functions.constant(0)); |
| 73 |
|
| 74 |
moduleLoader = new goog.module.ModuleLoader(); |
| 75 |
observer = new goog.testing.events.EventObserver(); |
| 76 |
|
| 77 |
goog.events.listen(moduleLoader, goog.object.getValues(EventType), observer); |
| 78 |
|
| 79 |
moduleManager.setLoader(moduleLoader); |
| 80 |
moduleManager.setAllModuleInfo({'modA': [], 'modB': ['modA']}); |
| 81 |
moduleManager.setModuleTrustedUris({'modA': [modA1, modA2], 'modB': [modB1]}); |
| 82 |
|
| 83 |
assertNotLoaded('modA'); |
| 84 |
assertNotLoaded('modB'); |
| 85 |
assertFalse(modA1Loaded); |
| 86 |
} |
| 87 |
|
| 88 |
function tearDown() { |
| 89 |
stubs.reset(); |
| 90 |
goog.dispose(moduleLoader); |
| 91 |
|
| 92 |
// Ensure that the module manager was created. |
| 93 |
assertNotNull(goog.module.ModuleManager.getInstance()); |
| 94 |
moduleManager = goog.module.ModuleManager.instance_ = null; |
| 95 |
|
| 96 |
// tear down the module loaded flag. |
| 97 |
modA1Loaded = false; |
| 98 |
|
| 99 |
// Remove all the fake scripts. |
| 100 |
var scripts = |
| 101 |
goog.array.clone(goog.dom.getElementsByTagName(goog.dom.TagName.SCRIPT)); |
| 102 |
for (var i = 0; i < scripts.length; i++) { |
| 103 |
if (scripts[i].src.indexOf('testdata') != -1) { |
| 104 |
goog.dom.removeNode(scripts[i]); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
function testLoadModuleA() { |
| 110 |
return new goog |
| 111 |
.Promise(function(resolve, reject) { |
| 112 |
moduleManager.execOnLoad('modA', function() { |
| 113 |
assertLoaded('modA'); |
| 114 |
assertNotLoaded('modB'); |
| 115 |
assertTrue(modA1Loaded); |
| 116 |
|
| 117 |
// The code is not evaluated immediately, but only after a browser |
| 118 |
// yield. |
| 119 |
assertEquals( |
| 120 |
'EVALUATE_CODE', 0, |
| 121 |
observer.getEvents(EventType.EVALUATE_CODE).length); |
| 122 |
assertEquals( |
| 123 |
'REQUEST_SUCCESS', 1, |
| 124 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 125 |
assertArrayEquals( |
| 126 |
['modA'], |
| 127 |
observer.getEvents(EventType.REQUEST_SUCCESS)[0].moduleIds); |
| 128 |
assertEquals( |
| 129 |
'REQUEST_ERROR', 0, |
| 130 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 131 |
resolve(); |
| 132 |
}); |
| 133 |
}) |
| 134 |
.then(function() { |
| 135 |
assertEquals( |
| 136 |
'EVALUATE_CODE after tick', 1, |
| 137 |
observer.getEvents(EventType.EVALUATE_CODE).length); |
| 138 |
assertEquals( |
| 139 |
'REQUEST_SUCCESS after tick', 1, |
| 140 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 141 |
assertEquals( |
| 142 |
'REQUEST_ERROR after tick', 0, |
| 143 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 144 |
}); |
| 145 |
} |
| 146 |
|
| 147 |
function testLoadModuleB() { |
| 148 |
return new goog |
| 149 |
.Promise(function(resolve, reject) { |
| 150 |
moduleManager.execOnLoad('modB', resolve); |
| 151 |
}) |
| 152 |
.then(function() { |
| 153 |
assertLoaded('modA'); |
| 154 |
assertLoaded('modB'); |
| 155 |
assertTrue(modA1Loaded); |
| 156 |
}); |
| 157 |
} |
| 158 |
|
| 159 |
function testLoadDebugModuleA() { |
| 160 |
moduleLoader.setDebugMode(true); |
| 161 |
return new goog |
| 162 |
.Promise(function(resolve, reject) { |
| 163 |
moduleManager.execOnLoad('modA', resolve); |
| 164 |
}) |
| 165 |
.then(function() { |
| 166 |
assertLoaded('modA'); |
| 167 |
assertNotLoaded('modB'); |
| 168 |
assertTrue(modA1Loaded); |
| 169 |
}); |
| 170 |
} |
| 171 |
|
| 172 |
function testLoadDebugModuleB() { |
| 173 |
moduleLoader.setDebugMode(true); |
| 174 |
return new goog |
| 175 |
.Promise(function(resolve, reject) { |
| 176 |
moduleManager.execOnLoad('modB', resolve); |
| 177 |
}) |
| 178 |
.then(function() { |
| 179 |
assertLoaded('modA'); |
| 180 |
assertLoaded('modB'); |
| 181 |
assertTrue(modA1Loaded); |
| 182 |
}); |
| 183 |
} |
| 184 |
|
| 185 |
function testLoadDebugModuleAThenB() { |
| 186 |
// Swap the script tags of module A, to introduce a race condition. |
| 187 |
// See the comments on this in ModuleLoader's debug loader. |
| 188 |
moduleManager.setModuleTrustedUris({'modA': [modA2, modA1], 'modB': [modB1]}); |
| 189 |
moduleLoader.setDebugMode(true); |
| 190 |
return new goog |
| 191 |
.Promise(function(resolve, reject) { |
| 192 |
moduleManager.execOnLoad('modB', resolve); |
| 193 |
}) |
| 194 |
.then(function() { |
| 195 |
assertLoaded('modA'); |
| 196 |
assertLoaded('modB'); |
| 197 |
|
| 198 |
var scripts = goog.array.clone( |
| 199 |
goog.dom.getElementsByTagName(goog.dom.TagName.SCRIPT)); |
| 200 |
var seenLastScriptOfModuleA = false; |
| 201 |
for (var i = 0; i < scripts.length; i++) { |
| 202 |
var uri = scripts[i].src; |
| 203 |
if (uri.indexOf('modA_1.js') >= 0) { |
| 204 |
seenLastScriptOfModuleA = true; |
| 205 |
} else if (uri.indexOf('modB') >= 0) { |
| 206 |
assertTrue(seenLastScriptOfModuleA); |
| 207 |
} |
| 208 |
} |
| 209 |
}); |
| 210 |
} |
| 211 |
|
| 212 |
function testSourceInjection() { |
| 213 |
moduleLoader.setSourceUrlInjection(true); |
| 214 |
return assertSourceInjection(); |
| 215 |
} |
| 216 |
|
| 217 |
function testSourceInjectionViaDebugMode() { |
| 218 |
moduleLoader.setDebugMode(true); |
| 219 |
return assertSourceInjection(); |
| 220 |
} |
| 221 |
|
| 222 |
function assertSourceInjection() { |
| 223 |
return new goog |
| 224 |
.Promise(function(resolve, reject) { |
| 225 |
moduleManager.execOnLoad('modB', resolve); |
| 226 |
}) |
| 227 |
.then(function() { |
| 228 |
assertTrue(!!throwErrorInModuleB); |
| 229 |
|
| 230 |
var ex = assertThrows(function() { throwErrorInModuleB(); }); |
| 231 |
|
| 232 |
if (!ex.stack) { |
| 233 |
return; |
| 234 |
} |
| 235 |
|
| 236 |
var stackTrace = ex.stack.toString(); |
| 237 |
var expectedString = 'testdata/modB_1.js'; |
| 238 |
|
| 239 |
if (goog.module.ModuleLoader.supportsSourceUrlStackTraces()) { |
| 240 |
// Source URL should be added in eval or in jsloader. |
| 241 |
assertContains(expectedString, stackTrace); |
| 242 |
} else if (moduleLoader.getDebugMode()) { |
| 243 |
// Browsers used jsloader, thus URLs are present. |
| 244 |
assertContains(expectedString, stackTrace); |
| 245 |
} else { |
| 246 |
// Browser used eval, does not support source URL. |
| 247 |
assertNotContains(expectedString, stackTrace); |
| 248 |
} |
| 249 |
}); |
| 250 |
} |
| 251 |
|
| 252 |
function testModuleLoaderRecursesTooDeep(opt_numModules) { |
| 253 |
// There was a bug in the module loader where it would retry recursively |
| 254 |
// whenever there was a synchronous failure in the module load. When you |
| 255 |
// asked for modB, it would try to load its dependency modA. When modA |
| 256 |
// failed, it would move onto modB, and then start over, repeating until it |
| 257 |
// ran out of stack. |
| 258 |
var numModules = opt_numModules || 1; |
| 259 |
var uris = {}; |
| 260 |
var deps = {}; |
| 261 |
var mods = []; |
| 262 |
for (var num = 0; num < numModules; num++) { |
| 263 |
var modName = 'mod' + num; |
| 264 |
mods.unshift(modName); |
| 265 |
uris[modName] = []; |
| 266 |
deps[modName] = num ? ['mod' + (num - 1)] : []; |
| 267 |
for (var i = 0; i < 5; i++) { |
| 268 |
uris[modName].push(goog.html.TrustedResourceUrl.format( |
| 269 |
goog.string.Const.from( |
| 270 |
'https://www.google.com/crossdomain%{num}x%{i}.js'), |
| 271 |
{'num': num, 'i': i})); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
moduleManager.setAllModuleInfo(deps); |
| 276 |
moduleManager.setModuleTrustedUris(uris); |
| 277 |
|
| 278 |
// Make all XHRs throw an error, so that we test the error-handling |
| 279 |
// functionality. |
| 280 |
var oldXmlHttp = goog.net.XmlHttp; |
| 281 |
stubs.set(goog.net, 'XmlHttp', function() { |
| 282 |
return {open: goog.functions.error('mock error'), abort: goog.nullFunction}; |
| 283 |
}); |
| 284 |
goog.object.extend(goog.net.XmlHttp, oldXmlHttp); |
| 285 |
|
| 286 |
var errorCount = 0; |
| 287 |
var errorIds = []; |
| 288 |
var errorHandler = function(ignored, modId) { |
| 289 |
errorCount++; |
| 290 |
errorIds.push(modId); |
| 291 |
}; |
| 292 |
moduleManager.registerCallback( |
| 293 |
goog.module.ModuleManager.CallbackType.ERROR, errorHandler); |
| 294 |
|
| 295 |
moduleManager.execOnLoad( |
| 296 |
mods[0], function() { fail('modB should not load successfully'); }); |
| 297 |
|
| 298 |
assertEquals(mods.length, errorCount); |
| 299 |
|
| 300 |
goog.array.sort(mods); |
| 301 |
goog.array.sort(errorIds); |
| 302 |
assertArrayEquals(mods, errorIds); |
| 303 |
|
| 304 |
assertArrayEquals([], moduleManager.requestedModuleIdsQueue_); |
| 305 |
assertArrayEquals([], moduleManager.userInitiatedLoadingModuleIds_); |
| 306 |
} |
| 307 |
|
| 308 |
function testModuleLoaderRecursesTooDeep2modules() { |
| 309 |
testModuleLoaderRecursesTooDeep(2); |
| 310 |
} |
| 311 |
|
| 312 |
function testModuleLoaderRecursesTooDeep3modules() { |
| 313 |
testModuleLoaderRecursesTooDeep(3); |
| 314 |
} |
| 315 |
|
| 316 |
function testModuleLoaderRecursesTooDeep4modules() { |
| 317 |
testModuleLoaderRecursesTooDeep(3); |
| 318 |
} |
| 319 |
|
| 320 |
function testErrback() { |
| 321 |
// Don't run this test on IE, because the way the test runner catches |
| 322 |
// errors on IE plays badly with the simulated errors in the test. |
| 323 |
if (goog.userAgent.IE) return; |
| 324 |
|
| 325 |
// Modules will throw an exception if this boolean is set to true. |
| 326 |
modA1Loaded = true; |
| 327 |
|
| 328 |
return new goog.Promise(function(resolve, reject) { |
| 329 |
var errorHandler = function() { |
| 330 |
assertNotLoaded('modA'); |
| 331 |
resolve(); |
| 332 |
}; |
| 333 |
moduleManager.registerCallback( |
| 334 |
goog.module.ModuleManager.CallbackType.ERROR, errorHandler); |
| 335 |
|
| 336 |
moduleManager.execOnLoad( |
| 337 |
'modA', function() { fail('modA should not load successfully'); }); |
| 338 |
}); |
| 339 |
} |
| 340 |
|
| 341 |
function testEventError() { |
| 342 |
// Don't run this test on older IE, because the way the test runner catches |
| 343 |
// errors on IE plays badly with the simulated errors in the test. |
| 344 |
if (goog.userAgent.IE && !goog.userAgent.isVersionOrHigher(11)) { |
| 345 |
return; |
| 346 |
} |
| 347 |
|
| 348 |
// Modules will throw an exception if this boolean is set to true. |
| 349 |
modA1Loaded = true; |
| 350 |
|
| 351 |
return new goog |
| 352 |
.Promise(function(resolve, reject) { |
| 353 |
var errorHandler = function() { |
| 354 |
assertNotLoaded('modA'); |
| 355 |
resolve(); |
| 356 |
}; |
| 357 |
moduleManager.registerCallback( |
| 358 |
goog.module.ModuleManager.CallbackType.ERROR, errorHandler); |
| 359 |
|
| 360 |
moduleManager.execOnLoad( |
| 361 |
'modA', function() { fail('modA should not load successfully'); }); |
| 362 |
}) |
| 363 |
.then(function() { |
| 364 |
assertEquals( |
| 365 |
'EVALUATE_CODE', 3, |
| 366 |
observer.getEvents(EventType.EVALUATE_CODE).length); |
| 367 |
assertUndefined(observer.getEvents(EventType.EVALUATE_CODE)[0].error); |
| 368 |
|
| 369 |
assertEquals( |
| 370 |
'REQUEST_SUCCESS', 3, |
| 371 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 372 |
assertUndefined(observer.getEvents(EventType.REQUEST_SUCCESS)[0].error); |
| 373 |
|
| 374 |
var requestErrors = observer.getEvents(EventType.REQUEST_ERROR); |
| 375 |
assertEquals('REQUEST_ERROR', 3, requestErrors.length); |
| 376 |
assertNotNull(requestErrors[0].error); |
| 377 |
var expectedString = 'loaded twice'; |
| 378 |
var messageAndStack = |
| 379 |
requestErrors[0].error.message + requestErrors[0].error.stack; |
| 380 |
assertContains(expectedString, messageAndStack); |
| 381 |
}); |
| 382 |
} |
| 383 |
|
| 384 |
function testPrefetchThenLoadModuleA() { |
| 385 |
moduleManager.prefetchModule('modA'); |
| 386 |
stubs.set(goog.net.BulkLoader.prototype, 'load', function() { |
| 387 |
fail('modA should not be reloaded'); |
| 388 |
}); |
| 389 |
|
| 390 |
return new goog |
| 391 |
.Promise(function(resolve, reject) { |
| 392 |
moduleManager.execOnLoad('modA', resolve); |
| 393 |
}) |
| 394 |
.then(function() { |
| 395 |
assertLoaded('modA'); |
| 396 |
assertEquals( |
| 397 |
'REQUEST_SUCCESS', 1, |
| 398 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 399 |
assertArrayEquals( |
| 400 |
['modA'], |
| 401 |
observer.getEvents(EventType.REQUEST_SUCCESS)[0].moduleIds); |
| 402 |
assertEquals( |
| 403 |
'REQUEST_ERROR', 0, |
| 404 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 405 |
}); |
| 406 |
} |
| 407 |
|
| 408 |
function testPrefetchThenLoadModuleB() { |
| 409 |
moduleManager.prefetchModule('modB'); |
| 410 |
stubs.set(goog.net.BulkLoader.prototype, 'load', function() { |
| 411 |
fail('modA and modB should not be reloaded'); |
| 412 |
}); |
| 413 |
|
| 414 |
return new goog |
| 415 |
.Promise(function(resolve, reject) { |
| 416 |
moduleManager.execOnLoad('modB', resolve); |
| 417 |
}) |
| 418 |
.then(function() { |
| 419 |
assertLoaded('modA'); |
| 420 |
assertLoaded('modB'); |
| 421 |
assertEquals( |
| 422 |
'REQUEST_SUCCESS', 2, |
| 423 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 424 |
assertArrayEquals( |
| 425 |
['modA'], |
| 426 |
observer.getEvents(EventType.REQUEST_SUCCESS)[0].moduleIds); |
| 427 |
assertArrayEquals( |
| 428 |
['modB'], |
| 429 |
observer.getEvents(EventType.REQUEST_SUCCESS)[1].moduleIds); |
| 430 |
assertEquals( |
| 431 |
'REQUEST_ERROR', 0, |
| 432 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 433 |
}); |
| 434 |
} |
| 435 |
|
| 436 |
function testPrefetchModuleAThenLoadModuleB() { |
| 437 |
moduleManager.prefetchModule('modA'); |
| 438 |
|
| 439 |
return new goog |
| 440 |
.Promise(function(resolve, reject) { |
| 441 |
moduleManager.execOnLoad('modB', resolve); |
| 442 |
}) |
| 443 |
.then(function() { |
| 444 |
assertLoaded('modA'); |
| 445 |
assertLoaded('modB'); |
| 446 |
assertEquals( |
| 447 |
'REQUEST_SUCCESS', 2, |
| 448 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 449 |
assertArrayEquals( |
| 450 |
['modA'], |
| 451 |
observer.getEvents(EventType.REQUEST_SUCCESS)[0].moduleIds); |
| 452 |
assertArrayEquals( |
| 453 |
['modB'], |
| 454 |
observer.getEvents(EventType.REQUEST_SUCCESS)[1].moduleIds); |
| 455 |
assertEquals( |
| 456 |
'REQUEST_ERROR', 0, |
| 457 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 458 |
}); |
| 459 |
} |
| 460 |
|
| 461 |
function testLoadModuleBThenPrefetchModuleA() { |
| 462 |
return new goog |
| 463 |
.Promise(function(resolve, reject) { |
| 464 |
moduleManager.execOnLoad('modB', resolve); |
| 465 |
}) |
| 466 |
.then(function() { |
| 467 |
assertLoaded('modA'); |
| 468 |
assertLoaded('modB'); |
| 469 |
assertEquals( |
| 470 |
'REQUEST_SUCCESS', 2, |
| 471 |
observer.getEvents(EventType.REQUEST_SUCCESS).length); |
| 472 |
assertArrayEquals( |
| 473 |
['modA'], |
| 474 |
observer.getEvents(EventType.REQUEST_SUCCESS)[0].moduleIds); |
| 475 |
assertArrayEquals( |
| 476 |
['modB'], |
| 477 |
observer.getEvents(EventType.REQUEST_SUCCESS)[1].moduleIds); |
| 478 |
assertEquals( |
| 479 |
'REQUEST_ERROR', 0, |
| 480 |
observer.getEvents(EventType.REQUEST_ERROR).length); |
| 481 |
assertThrows('Module load already requested: modB', function() { |
| 482 |
moduleManager.prefetchModule('modA'); |
| 483 |
}); |
| 484 |
}); |
| 485 |
} |
| 486 |
|
| 487 |
function testPrefetchModuleWithBatchModeEnabled() { |
| 488 |
moduleManager.setBatchModeEnabled(true); |
| 489 |
assertThrows( |
| 490 |
'Modules prefetching is not supported in batch mode', |
| 491 |
function() { moduleManager.prefetchModule('modA'); }); |
| 492 |
} |
| 493 |
|
| 494 |
function testLoadErrorCallbackExecutedWhenPrefetchFails() { |
| 495 |
// Make all XHRs throw an error, so that we test the error-handling |
| 496 |
// functionality. |
| 497 |
var oldXmlHttp = goog.net.XmlHttp; |
| 498 |
stubs.set(goog.net, 'XmlHttp', function() { |
| 499 |
return {open: goog.functions.error('mock error'), abort: goog.nullFunction}; |
| 500 |
}); |
| 501 |
goog.object.extend(goog.net.XmlHttp, oldXmlHttp); |
| 502 |
|
| 503 |
var errorCount = 0; |
| 504 |
var errorHandler = function() { errorCount++; }; |
| 505 |
moduleManager.registerCallback( |
| 506 |
goog.module.ModuleManager.CallbackType.ERROR, errorHandler); |
| 507 |
|
| 508 |
moduleLoader.prefetchModule('modA', moduleManager.moduleInfoMap_['modA']); |
| 509 |
moduleLoader.loadModules(['modA'], moduleManager.moduleInfoMap_, function() { |
| 510 |
fail('modA should not load successfully'); |
| 511 |
}, errorHandler); |
| 512 |
|
| 513 |
assertEquals(1, errorCount); |
| 514 |
} |
| 515 |
|
| 516 |
function assertLoaded(id) { |
| 517 |
assertTrue(moduleManager.getModuleInfo(id).isLoaded()); |
| 518 |
} |
| 519 |
|
| 520 |
function assertNotLoaded(id) { |
| 521 |
assertFalse(moduleManager.getModuleInfo(id).isLoaded()); |
| 522 |
} |