export function createInjector(zone: NgZone, bus: MessageBus): Injector {
  BrowserDomAdapter.makeCurrent();
  _rootBindings.push(bind(NgZone).toValue(zone));
  _rootBindings.push(bind(MessageBus).toValue(bus));
  var injector: Injector = Injector.resolveAndCreate(_rootBindings);
  return injector.resolveAndCreateChild(_injectorBindings());
}
Beispiel #2
0
 static createBindings(childTokens: any[]): Provider[] {
   return [
     bind(_CHILDREN).toFactory(
         (injector: Injector) => childTokens.map(token => injector.get(token)), [Injector]),
     bind(MultiReporter).toFactory(children => new MultiReporter(children), [_CHILDREN])
   ];
 }
Beispiel #3
0
        .then((args) => {
          var capabilities = args[0];
          var userAgent = args[1];

          // This might still create instances twice. We are creating a new injector with all the
          // providers.
          // Only WebDriverAdapter is reused.
          // TODO vsavkin consider changing it when toAsyncFactory is added back or when child
          // injectors are handled better.
          var injector = Injector.resolveAndCreate([
            sampleBindings, bind(Options.CAPABILITIES).toValue(capabilities),
            bind(Options.USER_AGENT).toValue(userAgent),
            provide(WebDriverAdapter, {useValue: adapter})
          ]);

          var sampler = injector.get(Sampler);
          return sampler.sample();
        });
Beispiel #4
0
  sample({id, execute, prepare, microMetrics, bindings}:
             {id: string, execute?: any, prepare?: any, microMetrics?: any, bindings?: any}):
      Promise<SampleState> {
    var sampleBindings = [
      _DEFAULT_PROVIDERS,
      this._defaultBindings,
      bind(Options.SAMPLE_ID).toValue(id),
      bind(Options.EXECUTE).toValue(execute)
    ];
    if (isPresent(prepare)) {
      sampleBindings.push(bind(Options.PREPARE).toValue(prepare));
    }
    if (isPresent(microMetrics)) {
      sampleBindings.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
    }
    if (isPresent(bindings)) {
      sampleBindings.push(bindings);
    }

    var inj = Injector.resolveAndCreate(sampleBindings);
    var adapter = inj.get(WebDriverAdapter);

    return PromiseWrapper
        .all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
        .then((args) => {
          var capabilities = args[0];
          var userAgent = args[1];

          // This might still create instances twice. We are creating a new injector with all the
          // providers.
          // Only WebDriverAdapter is reused.
          // TODO vsavkin consider changing it when toAsyncFactory is added back or when child
          // injectors are handled better.
          var injector = Injector.resolveAndCreate([
            sampleBindings,
            bind(Options.CAPABILITIES).toValue(capabilities),
            bind(Options.USER_AGENT).toValue(userAgent),
            provide(WebDriverAdapter, {useValue: adapter})
          ]);

          var sampler = injector.get(Sampler);
          return sampler.sample();
        });
  }
// TODO: This code is nearly identical to core/application. There should be a way to only write it
// once
function _injectorBindings(): any[] {
  return [
    bind(DOCUMENT)
        .toValue(DOM.defaultDoc()),
    EventManager,
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
    DomRenderer,
    bind(Renderer).toAlias(DomRenderer),
    APP_ID_RANDOM_BINDING,
    DomSharedStylesHost,
    bind(SharedStylesHost).toAlias(DomSharedStylesHost),
    Serializer,
    bind(ON_WEB_WORKER).toValue(false),
    bind(ElementSchemaRegistry).toValue(new DomElementSchemaRegistry()),
    RenderViewWithFragmentsStore,
    RenderProtoViewRefStore,
    AppViewPool,
    bind(APP_VIEW_POOL_CAPACITY).toValue(10000),
    AppViewManager,
    AppViewManagerUtils,
    AppViewListener,
    ProtoViewFactory,
    ViewResolver,
    DEFAULT_PIPES,
    DirectiveResolver,
    Parser,
    Lexer,
    bind(ExceptionHandler).toFactory(() => new ExceptionHandler(DOM), []),
    bind(XHR).toValue(new XHRImpl()),
    UrlResolver,
    DynamicComponentLoader,
    Testability,
    AnchorBasedAppRootUrl,
    bind(AppRootUrl).toAlias(AnchorBasedAppRootUrl),
    WebWorkerApplication,
    WebWorkerSetup,
    MessageBasedXHRImpl,
    MessageBasedRenderer,
    ServiceMessageBrokerFactory,
    ClientMessageBrokerFactory,
    BrowserDetails,
    AnimationBuilder,
  ];
}
 static bindTo(childTokens: any[]): Provider[] {
   var res = [
     bind(_CHILDREN).toFactory(
         (injector: Injector) => childTokens.map(token => injector.get(token)), [Injector]),
     bind(WebDriverExtension)
         .toFactory(
             (children: WebDriverExtension[], capabilities) => {
               var delegate;
               children.forEach(extension => {
                 if (extension.supports(capabilities)) {
                   delegate = extension;
                 }
               });
               if (isBlank(delegate)) {
                 throw new BaseException('Could not find a delegate for given capabilities!');
               }
               return delegate;
             },
             [_CHILDREN, Options.CAPABILITIES])
   ];
   return res;
 }
export function applicationDomBindings(): Array<Type | Binding | any[]> {
  if (isBlank(DOM)) {
    throw "Must set a root DOM adapter first.";
  }
  return [
    bind(DOCUMENT)
        .toValue(DOM.defaultDoc()),
    EventManager,
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
    new Binding(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
    DomRenderer,
    bind(Renderer).toAlias(DomRenderer),
    DomSharedStylesHost,
    bind(SharedStylesHost).toAlias(DomSharedStylesHost),
    EXCEPTION_BINDING,
    bind(XHR).toValue(new XHRImpl()),
    Testability,
    BrowserDetails,
    AnimationBuilder,
    FORM_BINDINGS
  ];
}
export function compilerBindings(): Array<Type | Binding | any[]> {
  return [
    Lexer,
    Parser,
    HtmlParser,
    TemplateParser,
    TemplateNormalizer,
    RuntimeMetadataResolver,
    StyleCompiler,
    CommandCompiler,
    ChangeDetectionCompiler,
    bind(ChangeDetectorGenConfig)
        .toValue(
            new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), false, true)),
    TemplateCompiler,
    RuntimeCompiler,
    bind(Compiler).toAlias(RuntimeCompiler),
    DomElementSchemaRegistry,
    bind(ElementSchemaRegistry).toAlias(DomElementSchemaRegistry),
    AnchorBasedAppRootUrl,
    bind(AppRootUrl).toAlias(AnchorBasedAppRootUrl),
    UrlResolver
  ];
}
Beispiel #9
0
 static bindTo(delegateToken): Provider[] {
   return [bind(Validator).toFactory((delegate) => delegate, [delegateToken])];
 }
Beispiel #10
0
    this._description = sampleDescription;
    this._path = path;
    this._writeFile = writeFile;
    this._now = now;
  }

  reportMeasureValues(measureValues: MeasureValues): Promise<any> {
    return PromiseWrapper.resolve(null);
  }

  reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise<any> {
    var content = Json.stringify({
      'description': this._description,
      'completeSample': completeSample,
      'validSample': validSample
    });
    var filePath =
        `${this._path}/${this._description.id}_${DateWrapper.toMillis(this._now())}.json`;
    return this._writeFile(filePath, content);
  }
}

var _PATH = new OpaqueToken('JsonFileReporter.path');
var _PROVIDERS = [
  bind(JsonFileReporter)
      .toFactory((sampleDescription, path, writeFile, now) =>
                     new JsonFileReporter(sampleDescription, path, writeFile, now),
                 [SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
  provide(_PATH, {useValue: '.'})
];