Home | History | Annotate | Download | only in tracing
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('tracing.test_utils');
      8 base.require('tracing.timeline_view');
      9 base.require('tracing.trace_model');
     10 
     11 base.unittest.testSuite('tracing.timeline_view', function() {
     12   var newSliceNamed = tracing.test_utils.newSliceNamed;
     13 
     14   var createFullyPopulatedModel = function(opt_withError, opt_withMetadata) {
     15     var withError = opt_withError !== undefined ? opt_withError : true;
     16     var withMetadata = opt_withMetadata !== undefined ?
     17         opt_withMetadata : true;
     18 
     19     var num_tests = 50;
     20     var testIndex = 0;
     21     var startTime = 0;
     22 
     23     var model = new tracing.TraceModel();
     24     for (testIndex = 0; testIndex < num_tests; ++testIndex) {
     25       var process = model.getOrCreateProcess(10000 + testIndex);
     26       if (testIndex % 2 == 0) {
     27         var thread = process.getOrCreateThread('Thread Name Here');
     28         thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
     29             'foo', 'a', 0, startTime, {}, 1));
     30         thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
     31             'bar', 'b', 0, startTime + 23, {}, 10));
     32       } else {
     33         var thread = process.getOrCreateThread('Name');
     34         thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
     35             'foo', 'a', 0, startTime + 4, {}, 11));
     36         thread.sliceGroup.pushSlice(new tracing.trace_model.Slice(
     37             'bar', 'b', 0, startTime + 22, {}, 14));
     38       }
     39     }
     40     var p1000 = model.getOrCreateProcess(1000);
     41     var objects = p1000.objects;
     42     objects.idWasCreated('0x1000', 'cc', 'LayerTreeHostImpl', 10);
     43     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 10,
     44                         'snapshot-1');
     45     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
     46                         'snapshot-2');
     47     objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
     48                         'snapshot-3');
     49     objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
     50     model.updateCategories_();
     51 
     52     // Add a known problematic piece of data to test the import errors UI.
     53     model.importErrors.push('Synthetic Import Error');
     54     model.updateBounds();
     55 
     56     // Add data with metadata information stored
     57     model.metadata.push({name: 'a', value: 'testA'});
     58     model.metadata.push({name: 'b', value: 'testB'});
     59     model.metadata.push({name: 'c', value: 'testC'});
     60 
     61     return model;
     62   };
     63 
     64   var visibleTracks = function(trackButtons) {
     65     return trackButtons.reduce(function(numVisible, button) {
     66       var style = button.parentElement.style;
     67       var visible = (style.display.indexOf('none') === -1);
     68       return visible ? numVisible + 1 : numVisible;
     69     }, 0);
     70   };
     71 
     72   var modelsEquivalent = function(lhs, rhs) {
     73     if (lhs.length !== rhs.length)
     74       return false;
     75     return lhs.every(function(lhsItem, index) {
     76       var rhsItem = rhs[index];
     77       return rhsItem.regexpText === lhsItem.regexpText &&
     78           rhsItem.isOn === lhsItem.isOn;
     79     });
     80   };
     81 
     82   var buildView = function() {
     83     var view = new tracing.TimelineView();
     84     view.model = createFullyPopulatedModel();
     85 
     86     var selection = new tracing.Selection();
     87     view.timeline.addAllObjectsMatchingFilterToSelection({
     88       matchSlice: function() { return true; }
     89     }, selection);
     90     view.timeline.selection = selection;
     91 
     92     return view;
     93   };
     94 
     95   test('changeModelToSomethingDifferent', function() {
     96     var model00 = createFullyPopulatedModel(false, false);
     97     var model11 = createFullyPopulatedModel(true, true);
     98 
     99     var view = new tracing.TimelineView();
    100     view.style.height = '400px';
    101     view.model = model00;
    102     view.model = undefined;
    103     view.model = model11;
    104     view.model = model00;
    105   });
    106 
    107   test('setModelToSameThingAgain', function() {
    108     var model = createFullyPopulatedModel(false, false);
    109 
    110     // Create a view with am model.
    111     var view = new tracing.TimelineView();
    112     view.style.height = '400px';
    113     view.model = model;
    114 
    115     // Mutate the model and update the view.
    116     var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
    117     t123.sliceGroup.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
    118     view.model = model;
    119 
    120     // Verify that the new bits of the model show up in the view.
    121     var selection = new tracing.Selection();
    122     var filter = new tracing.TitleFilter('somethingUnusual');
    123     view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection);
    124     assertEquals(selection.length, 1);
    125   });
    126 
    127 });
    128