appendBufferImpl(type, data, reference) {
    if (!this.segments[type]) {
      throw new Error('unexpected type');
    }

    // Remains 'video' even when we detect a 'trickvideo' segment.
    const originalType = type;
    const ContentType = shaka.util.ManifestParserUtils.ContentType;

    // Set init segment.
    let i = this.segmentData[type].initSegments.indexOf(data);
    if (i < 0 && type == ContentType.VIDEO &&
        this.segmentData['trickvideo']) {
      // appendBuffer('video', ...) might be for 'trickvideo' data.
      i = this.segmentData['trickvideo'].initSegments.indexOf(data);
      if (i >= 0) {
        // 'trickvideo' value is only used for testing.
        // Cast to the ContentType enum for compatibility.
        type = /** @type {shaka.util.ManifestParserUtils.ContentType} */(
          'trickvideo');
      }
    }
    if (i >= 0) {
      // Update the list of which init segment was appended last.
      expect(reference).toBe(null);
      this.initSegments[type] =
          this.segmentData[type].initSegments.map((c) => false);
      this.initSegments[type][i] = true;
      return Promise.resolve();
    }

    // Set media segment.
    i = this.segmentData[type].segments.indexOf(data);
    if (i < 0 && type == ContentType.VIDEO &&
        this.segmentData['trickvideo']) {
      // appendBuffer('video', ...) might be for 'trickvideo' data.
      i = this.segmentData['trickvideo'].segments.indexOf(data);
      if (i >= 0) {
        // 'trickvideo' value is only used for testing.
        // Cast to the ContentType enum for compatibility.
        type = /** @type {shaka.util.ManifestParserUtils.ContentType} */(
          'trickvideo');
      }
    }
    if (i < 0) {
      throw new Error('unexpected data');
    }

    // Verify that the segment is aligned.
    const segmentData = this.segmentData[type];
    const appendedTime = segmentData.segmentStartTimes[i] +
                         this.timestampOffsets_[originalType];
    const expectedStartTime = i * segmentData.segmentDuration;
    const expectedEndTime = expectedStartTime + segmentData.segmentDuration;
    expect(appendedTime).toBe(expectedStartTime);
    expect(reference).not.toBe(null);
    if (reference) {
      expect(reference.startTime).toBe(expectedStartTime);
      expect(reference.endTime).toBe(expectedEndTime);
    }

    this.segments[type][i] = true;
    return Promise.resolve();
  }
@param {string} type
@param {!ArrayBuffer} data
@param {?shaka.media.SegmentReference} reference
@return {!Promise}