testDisposeInTheMiddleOfLoadingWorks() {
    const resolver = GoogPromise.withResolver();

    events.listen(loader, TEST_EVENT_TYPES, (e) => {
      assertFalse(
          'Handler is still invoked after loader is disposed.',
          loader.isDisposed());

      switch (e.type) {
        case NetEventType.COMPLETE:
          resolver.reject('This test should never get COMPLETE event.');
          return;

        case EventType.LOAD:
        case NetEventType.ERROR:
          loader.dispose();
          break;
      }

      // Make sure that handler is never called again after disposal before
      // marking test as successful.
      Timer.callOnce(() => {
        resolver.resolve();
      }, 500);
    });

    loader.start();
    return resolver.promise;
  }
Tests loading image and disposing before loading completes.