Home | History | Annotate | Download | only in importer
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/tracing/extras/chrome/chrome_test_utils.html">
      9 <link rel="import" href="/tracing/importer/user_model_builder.html">
     10 
     11 <script>
     12 'use strict';
     13 tr.exportTo('tr.importer', function() {
     14   function compareEvents(x, y) {
     15     if (x.start !== y.start)
     16       return x.start - y.start;
     17     return x.guid - y.guid;
     18   }
     19 
     20   function UserExpectationVerifier() {
     21     this.customizeModelCallback_ = undefined;
     22     this.expectedIRs_ = undefined;
     23   }
     24 
     25   UserExpectationVerifier.prototype = {
     26     set customizeModelCallback(cmc) {
     27       this.customizeModelCallback_ = cmc;
     28     },
     29 
     30     // |irs| must be sorted by start time.
     31     set expectedIRs(irs) {
     32       this.expectedIRs_ = irs;
     33     },
     34 
     35     verify: function() {
     36       var model = tr.e.chrome.ChromeTestUtils.newChromeModel(
     37           this.customizeModelCallback_);
     38       var actualUEs = model.userModel.expectations;
     39 
     40       var failure = undefined;
     41       try {
     42         assert.equal(this.expectedIRs_.length, actualUEs.length);
     43         for (var i = 0; i < this.expectedIRs_.length; ++i) {
     44           var at = 'IRs[' + i + '].';
     45           assert.equal(this.expectedIRs_[i].title, actualUEs[i].title,
     46                       at + 'title');
     47           if (this.expectedIRs_[i].name !== undefined) {
     48             assert.equal(this.expectedIRs_[i].name, actualUEs[i].name,
     49                         at + 'name');
     50           }
     51           assert.equal(this.expectedIRs_[i].start, actualUEs[i].start,
     52                       at + 'start');
     53           assert.equal(this.expectedIRs_[i].end, actualUEs[i].end, at + 'end');
     54           assert.equal(this.expectedIRs_[i].eventCount,
     55                       actualUEs[i].associatedEvents.length, at + 'eventCount');
     56           if (actualUEs[i] instanceof tr.model.um.ResponseExpectation)
     57             assert.equal(this.expectedIRs_[i].isAnimationBegin || false,
     58                          actualUEs[i].isAnimationBegin,
     59                          at + 'isAnimationBegin');
     60         }
     61       } catch (caught) {
     62         failure = caught;
     63       }
     64 
     65       var debug = !tr.isHeadless && (
     66           location.search.split('&').indexOf('debug') >= 0);
     67       if (!failure && !debug)
     68         return;
     69 
     70       if (failure)
     71         throw failure;
     72     }
     73   };
     74 
     75   return {UserExpectationVerifier: UserExpectationVerifier};
     76 });
     77 </script>
     78