Home | History | Annotate | Download | only in analysis
      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.analysis.analysis_view');
      8 base.require('tracing.test_utils');
      9 base.require('tracing.trace_model');
     10 base.require('tracing.selection');
     11 
     12 base.unittest.testSuite('tracing.analysis.analysis_view', function() {
     13   var TraceModel = tracing.TraceModel;
     14   var Selection = tracing.Selection;
     15   var AnalysisView = tracing.analysis.AnalysisView;
     16   var ObjectInstance = tracing.trace_model.ObjectInstance;
     17   var DefaultObjectSnapshotView = tracing.analysis.DefaultObjectSnapshotView;
     18   var DefaultObjectInstanceView = tracing.analysis.DefaultObjectInstanceView;
     19 
     20   function withRegisteredType(registrar, typeName,
     21                               typeConstructor, opt_options, fn) {
     22     registrar.register(typeName, typeConstructor, opt_options);
     23     try {
     24       fn();
     25     } finally {
     26       registrar.unregister(typeName);
     27     }
     28   }
     29 
     30   test('instantiate_analysisWithObjects', function() {
     31     var model = new TraceModel();
     32     var p1 = model.getOrCreateProcess(1);
     33     var objects = p1.objects;
     34     var i10 = objects.idWasCreated('0x1000', 'cc', 'LayerTreeHostImpl', 10);
     35     var s10 = objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 10,
     36                                   'snapshot-1');
     37     var s25 = objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 25,
     38                                   'snapshot-2');
     39     var s40 = objects.addSnapshot('0x1000', 'cc', 'LayerTreeHostImpl', 40,
     40                                   'snapshot-3');
     41     objects.idWasDeleted('0x1000', 'cc', 'LayerTreeHostImpl', 45);
     42 
     43     var track = {};
     44     var selection = new Selection();
     45     selection.addObjectInstance(track, i10);
     46     selection.addObjectSnapshot(track, s10);
     47     selection.addObjectSnapshot(track, s25);
     48     selection.addObjectSnapshot(track, s40);
     49 
     50     var analysisEl = new AnalysisView();
     51     analysisEl.selection = selection;
     52     this.addHTMLOutput(analysisEl);
     53   });
     54 
     55   test('analyzeSelectionWithObjectSnapshotUnknownType', function() {
     56     var i10 = new ObjectInstance({}, '0x1000', 'cat', 'someUnhandledName', 10);
     57     var s10 = i10.addSnapshot(10, {foo: 1});
     58 
     59     var selection = new Selection();
     60     selection.addObjectSnapshot({}, s10);
     61 
     62     var view = new AnalysisView();
     63     view.selection = selection;
     64     assertTrue(view.currentView instanceof DefaultObjectSnapshotView);
     65     assertEquals(s10, view.currentView.objectSnapshot);
     66   });
     67 
     68   test('analyzeSelectionWithObjectSnapshotKnownType', function() {
     69     var i10 = new ObjectInstance({}, '0x1000', 'cat', 'MyView', 10);
     70     var s10 = i10.addSnapshot(10, {foo: 1});
     71 
     72     var selection = new Selection();
     73     selection.addObjectSnapshot({}, s10);
     74 
     75     var MyView = ui.define(
     76         'my-view', tracing.analysis.ObjectSnapshotView);
     77     MyView.prototype = {
     78       __proto__: tracing.analysis.ObjectSnapshotView.prototype,
     79 
     80       decorate: function() {
     81       },
     82 
     83       updateContents: function() {
     84         this.textContent = 'hello';
     85       }
     86     };
     87 
     88     var view = new AnalysisView();
     89     withRegisteredType(
     90         tracing.analysis.ObjectSnapshotView, 'MyView', MyView, undefined,
     91         function() {
     92           view.selection = selection;
     93           assertTrue(view.currentView instanceof MyView);
     94           assertEquals(s10, view.currentView.objectSnapshot);
     95           assertEquals('hello', view.currentView.textContent);
     96         });
     97   });
     98 
     99   test('analyzeSelectionWithObjectInstanceUnknownType', function() {
    100     var i10 = new ObjectInstance({}, '0x1000', 'cat', 'someUnhandledName', 10);
    101 
    102     var selection = new Selection();
    103     selection.addObjectInstance({}, i10);
    104 
    105     var view = new AnalysisView();
    106     view.selection = selection;
    107     assertTrue(view.currentView instanceof DefaultObjectInstanceView);
    108     assertEquals(i10, view.currentView.objectInstance);
    109   });
    110 
    111   test('analyzeSelectionWithObjectInstanceKnownType', function() {
    112     var i10 = new ObjectInstance({}, '0x1000', 'cat', 'MyView', 10);
    113 
    114     var selection = new Selection();
    115     selection.addObjectInstance({}, i10);
    116 
    117     var MyView = ui.define(
    118         'my-view', tracing.analysis.ObjectInstanceView);
    119     MyView.prototype = {
    120       __proto__: tracing.analysis.ObjectInstanceView.prototype,
    121 
    122       decorate: function() {
    123       },
    124 
    125       updateContents: function() {
    126         this.textContent = 'hello';
    127       }
    128     };
    129 
    130     var view = new AnalysisView();
    131     withRegisteredType(
    132         tracing.analysis.ObjectInstanceView,
    133         'MyView', MyView, undefined, function() {
    134           view.selection = selection;
    135           assertTrue(view.currentView instanceof MyView);
    136           assertEquals(i10, view.currentView.objectInstance);
    137           assertEquals('hello', view.currentView.textContent);
    138         });
    139   });
    140 
    141   test('analyzeSelectionWithSliceKnownType', function() {
    142     var s10 = new tracing.trace_model.Slice('cat', 'MySlice', 0, 10, {}, 4);
    143 
    144     var selection = new tracing.Selection();
    145     selection.addSlice({}, s10);
    146 
    147     var MySlice = ui.define(
    148         'my-slice', tracing.analysis.SliceView);
    149     MySlice.prototype = {
    150       __proto__: tracing.analysis.SliceView.prototype,
    151 
    152       decorate: function() {
    153       },
    154 
    155       updateContents: function() {
    156         this.textContent = 'hello';
    157       }
    158     };
    159 
    160     var view = new AnalysisView();
    161     withRegisteredType(
    162         tracing.analysis.SliceView,
    163         'MySlice', MySlice, undefined, function() {
    164           view.selection = selection;
    165           assertTrue(view.currentView instanceof MySlice);
    166           assertEquals(s10, view.currentView.slice);
    167           assertEquals('hello', view.currentView.textContent);
    168         });
    169   });
    170 });
    171