<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/base.html">
<link rel="import" href="/tracing/base/range_utils.html">
<link rel="import" href="/tracing/core/auditor.html">
<link rel="import" href="/tracing/model/event_info.html">
<link rel="import" href="/tracing/model/user_model/animation_expectation.html">
<link rel="import" href="/tracing/model/user_model/response_expectation.html">
<link rel="import" href="/tracing/model/user_model/user_expectation.html">

<script>
'use strict';

tr.exportTo('tr.importer', function() {
  // This is an intermediate data format between InputLatencyAsyncSlices and
  // Response and Animation IRs.
  function ProtoExpectation(irType, initiatorType) {
    this.irType = irType;
    this.initiatorType = initiatorType;
    this.start = Infinity;
    this.end = -Infinity;
    this.associatedEvents = new tr.model.EventSet();
    this.isAnimationBegin = false;
  }

  ProtoExpectation.RESPONSE_TYPE = 'r';
  ProtoExpectation.ANIMATION_TYPE = 'a';

  // Explicitly ignore some input events to allow
  // UserModelBuilder.checkAllInputEventsHandled() to determine which events
  // were unintentionally ignored due to a bug.
  ProtoExpectation.IGNORED_TYPE = 'ignored';

  /**
   * Combine initiator titles by selecting the initiator title first in a
   * hard-coded hierarchy. Higher up in the hierarchy are more "specific"
   * initiator titles (e.g. a scroll is higher than a touch, because a
   * touch could mean many different things, of which a scroll is one)
   */
  var INITIATOR_HIERARCHY = [
      tr.model.um.INITIATOR_TYPE.PINCH,
      tr.model.um.INITIATOR_TYPE.FLING,
      tr.model.um.INITIATOR_TYPE.MOUSE_WHEEL,
      tr.model.um.INITIATOR_TYPE.SCROLL,
      tr.model.um.INITIATOR_TYPE.VIDEO,
      tr.model.um.INITIATOR_TYPE.WEBGL,
      tr.model.um.INITIATOR_TYPE.CSS,
      tr.model.um.INITIATOR_TYPE.MOUSE,
      tr.model.um.INITIATOR_TYPE.KEYBOARD,
      tr.model.um.INITIATOR_TYPE.TAP,
      tr.model.um.INITIATOR_TYPE.TOUCH
    ];

  function combineInitiatorTypes(title1, title2) {
    for (var item of INITIATOR_HIERARCHY)
      if (title1 === item || title2 === item) return item;
    console.error('Invalid titles in combineInitiatorTypes')
    return undefined;
  }

  ProtoExpectation.prototype = {
    get isValid() {
      return this.end > this.start;
    },

    // Return true if any associatedEvent's typeName is in typeNames.
    containsTypeNames: function(typeNames) {
      return this.associatedEvents.some(
          x => typeNames.indexOf(x.typeName) >= 0);
    },

    containsSliceTitle: function(title) {
      return this.associatedEvents.some(x => title === x.title);
    },

    createInteractionRecord: function(model) {
      if (!this.isValid) {
        console.error('Invalid ProtoExpectation: ' + this.debug() +
                      ' File a bug with this trace!');
        return undefined;
      }

      var duration = this.end - this.start;

      var ir = undefined;
      switch (this.irType) {
        case ProtoExpectation.RESPONSE_TYPE:
          ir = new tr.model.um.ResponseExpectation(
              model, this.initiatorType, this.start, duration,
              this.isAnimationBegin);
          break;
        case ProtoExpectation.ANIMATION_TYPE:
          ir = new tr.model.um.AnimationExpectation(
              model, this.initiatorType, this.start, duration);
          break;
      }<commit_msg>Exempt ignored ProtoExpectations from validity check.<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/base.html">
<link rel="import" href="/tracing/base/range_utils.html">
<link rel="import" href="/tracing/core/auditor.html">
<link rel="import" href="/tracing/model/event_info.html">
<link rel="import" href="/tracing/model/user_model/animation_expectation.html">
<link rel="import" href="/tracing/model/user_model/response_expectation.html">
<link rel="import" href="/tracing/model/user_model/user_expectation.html">

<script>
'use strict';

tr.exportTo('tr.importer', function() {
  // This is an intermediate data format between InputLatencyAsyncSlices and
  // Response and Animation IRs.
  function ProtoExpectation(irType, initiatorType) {
    this.irType = irType;
    this.initiatorType = initiatorType;
    this.start = Infinity;
    this.end = -Infinity;
    this.associatedEvents = new tr.model.EventSet();
    this.isAnimationBegin = false;
  }

  ProtoExpectation.RESPONSE_TYPE = 'r';
  ProtoExpectation.ANIMATION_TYPE = 'a';

  // Explicitly ignore some input events to allow
  // UserModelBuilder.checkAllInputEventsHandled() to determine which events
  // were unintentionally ignored due to a bug.
  ProtoExpectation.IGNORED_TYPE = 'ignored';

  /**
   * Combine initiator titles by selecting the initiator title first in a
   * hard-coded hierarchy. Higher up in the hierarchy are more "specific"
   * initiator titles (e.g. a scroll is higher than a touch, because a
   * touch could mean many different things, of which a scroll is one)
   */
  var INITIATOR_HIERARCHY = [
      tr.model.um.INITIATOR_TYPE.PINCH,
      tr.model.um.INITIATOR_TYPE.FLING,
      tr.model.um.INITIATOR_TYPE.MOUSE_WHEEL,
      tr.model.um.INITIATOR_TYPE.SCROLL,
      tr.model.um.INITIATOR_TYPE.VIDEO,
      tr.model.um.INITIATOR_TYPE.WEBGL,
      tr.model.um.INITIATOR_TYPE.CSS,
      tr.model.um.INITIATOR_TYPE.MOUSE,
      tr.model.um.INITIATOR_TYPE.KEYBOARD,
      tr.model.um.INITIATOR_TYPE.TAP,
      tr.model.um.INITIATOR_TYPE.TOUCH
    ];

  function combineInitiatorTypes(title1, title2) {
    for (var item of INITIATOR_HIERARCHY)
      if (title1 === item || title2 === item) return item;
    console.error('Invalid titles in combineInitiatorTypes')
    return undefined;
  }

  ProtoExpectation.prototype = {
    get isValid() {
      return this.end > this.start;
    },

    // Return true if any associatedEvent's typeName is in typeNames.
    containsTypeNames: function(typeNames) {
      return this.associatedEvents.some(
          x => typeNames.indexOf(x.typeName) >= 0);
    },

    containsSliceTitle: function(title) {
      return this.associatedEvents.some(x => title === x.title);
    },

    createInteractionRecord: function(model) {
      if (this.irType !== ProtoExpectation.IGNORED_TYPE && !this.isValid) {
        console.error('Invalid ProtoExpectation: ' + this.debug() +
                      ' File a bug with this trace!');
        return undefined;
      }

      var duration = this.end - this.start;

      var ir = undefined;
      switch (this.irType) {
        case ProtoExpectation.RESPONSE_TYPE:
          ir = new tr.model.um.ResponseExpectation(
              model, this.initiatorType, this.start, duration,
              this.isAnimationBegin);
          break;
        case ProtoExpectation.ANIMATION_TYPE:
          ir = new tr.model.um.AnimationExpectation(
              model, this.initiatorType, this.start, duration);
          break;
      }
{'fraction_non_alphanumeric': 0.11118737131091283, 'fraction_numerical': 0.0024708304735758407, 'mean_word_length': 3.1374219193639976, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6979439', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2259, 'n_words': 531}