Home | History | Annotate | Download | only in src
      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
      5 Use of this source code is governed by a BSD-style license that can be
      6 found in the LICENSE file.
      7 -->
      8 <head>
      9 <title>TimelineView tests</title>
     10 <script src="base.js"></script>
     11 <style>
     12   .timeline-view {
     13     border: 1px solid black;
     14     margin: 10px;
     15     height: 350px;
     16   }
     17   .timeline-find-dialog {
     18     border: 1px solid black;
     19     margin: 10px;
     20   }
     21 </style>
     22 </head>
     23 <body>
     24   <script>
     25     base.require('unittest');
     26     base.require('test_utils');
     27     base.require('timeline_view');
     28   </script>
     29   <script>
     30     'use strict';
     31 
     32     var newSliceNamed = test_utils.newSliceNamed;
     33 
     34     function createFullyPopulatedModel(opt_withError, opt_withMetadata) {
     35       var withError = opt_withError !== undefined ? opt_withError : true;
     36       var withMetadata = opt_withMetadata !== undefined ?
     37           opt_withMetadata : true;
     38 
     39       var num_tests = 50;
     40       var testIndex = 0;
     41       var startTime = 0;
     42 
     43       var model = new tracing.TimelineModel();
     44       for (testIndex = 0; testIndex < num_tests; ++testIndex) {
     45         var process = model.getOrCreateProcess(10000 + testIndex);
     46         if (testIndex % 2 == 0) {
     47           var thread = process.getOrCreateThread('Thread Name Here');
     48           thread.slices.push(
     49               new tracing.TimelineSlice('foo', 'a', 0, startTime, {}, 1));
     50           thread.slices.push(
     51               new tracing.TimelineSlice('bar', 'b', 0,
     52                                         startTime + 1.15, {}, .5));
     53         } else {
     54           var thread = process.getOrCreateThread('Name');
     55           thread.slices.push(
     56               new tracing.TimelineSlice('foo', 'a', 0,
     57                                         startTime + .17, {}, .55));
     58           thread.slices.push(
     59               new tracing.TimelineSlice('bar', 'b', 0,
     60                                         startTime + 1.1, {}, .7));
     61         }
     62       }
     63       model.updateCategories_();
     64 
     65       // Add a known problematic piece of data to test the import errors UI.
     66       model.importErrors.push('Synthetic Import Error');
     67       model.updateBounds();
     68 
     69       // Add data with metadata information stored
     70       model.metadata.push({name: 'a', value: 'testA'});
     71       model.metadata.push({name: 'b', value: 'testB'});
     72       model.metadata.push({name: 'c', value: 'testC'});
     73 
     74       return model;
     75     }
     76 
     77     /*
     78      * This test just instantiates a TimelineView and adds it to the DOM
     79      * to help with non-unittest UI work.
     80      */
     81     function testInstantiateTimelineView() {
     82       var model = createFullyPopulatedModel(true, true);
     83 
     84       var view = new tracing.TimelineView();
     85       view.style.height = '400px';
     86       view.model = model;
     87       view.tabIndex = 0;
     88       view.focusElement = view;
     89 
     90       var selection = new tracing.TimelineSelection();
     91       view.timeline.addAllObjectsMatchingFilterToSelection({
     92           matchSlice: function() { return true;}
     93       }, selection);
     94       view.timeline.selection = selection;
     95 
     96       this.addHTMLOutput(undefined, view);
     97     }
     98 
     99     function testChangeModelToSomethingDifferent() {
    100       var model00 = createFullyPopulatedModel(false, false);
    101       var model11 = createFullyPopulatedModel(true, true);
    102 
    103       var view = new tracing.TimelineView();
    104       view.style.height = '400px';
    105       view.model = model00;
    106       view.model = undefined;
    107       view.model = model11;
    108       view.model = model00;
    109     }
    110 
    111 
    112     function testSetModelToSameThingAgain() {
    113       var model = createFullyPopulatedModel(false, false);
    114 
    115       // Create a view with am model.
    116       var view = new tracing.TimelineView();
    117       view.style.height = '400px';
    118       view.model = model;
    119 
    120       // Mutate the model and update the view.
    121       var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
    122       t123.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
    123       view.model = model;
    124 
    125       // Verify that the new bits of the model show up in the view.
    126       var selection = new tracing.TimelineSelection();
    127       var filter = new tracing.TimelineTitleFilter('somethingUnusual');
    128       view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection);
    129       assertEquals(selection.length, 1);
    130     }
    131 
    132     function testChangeModelToSomethingDifferent() {
    133       var model00 = createFullyPopulatedModel(false, false);
    134       var model11 = createFullyPopulatedModel(true, true);
    135 
    136       var view = new tracing.TimelineView();
    137       view.style.height = '400px';
    138       view.model = model00;
    139       view.model = undefined;
    140       view.model = model11;
    141       view.model = model00;
    142     }
    143 
    144 
    145     function testSetModelToSameThingAgain() {
    146       var model = createFullyPopulatedModel(false, false);
    147 
    148       // Create a view with am model.
    149       var view = new tracing.TimelineView();
    150       view.style.height = '400px';
    151       view.model = model;
    152 
    153       // Mutate the model and update the view.
    154       var t123 = model.getOrCreateProcess(123).getOrCreateThread(123);
    155       t123.pushSlice(newSliceNamed('somethingUnusual', 0, 5));
    156       view.model = model;
    157 
    158       // Verify that the new bits of the model show up in the view.
    159       var selection = new tracing.TimelineSelection();
    160       var filter = new tracing.TimelineTitleFilter('somethingUnusual');
    161       view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection);
    162       assertEquals(selection.length, 1);
    163     }
    164 
    165     function testSetModelUpdatesCategories() {
    166       var model = new tracing.TimelineModel();
    167       var p1 = model.getOrCreateProcess(1);
    168       var t1 = p1.getOrCreateThread(1);
    169 
    170       t1.pushSlice(new tracing.TimelineThreadSlice('foo', 'a',
    171                                                    0, 1, {}, 3));
    172       t1.pushSlice(new tracing.TimelineThreadSlice('bar', 'b',
    173                                                    0, 1.1, {}, 2.8));
    174       t1.pushSlice(new tracing.TimelineThreadSlice('baz', 'b',
    175                                                    0, 1.2, {}, 2.4));
    176       model.updateCategories_();
    177       model.updateBounds();
    178 
    179       var view = new tracing.TimelineView();
    180       view.settings.set('foo', true, 'categories');
    181       view.settings.set('bar', false, 'categories');
    182       view.model = model;
    183 
    184       assertUndefined(view.timeline.categoryFilter_.categories_['foo']);
    185       assertTrue(view.timeline.categoryFilter_.categories_['bar']);
    186       assertUndefined(view.timeline.categoryFilter_.categories_['baz']);
    187     }
    188 
    189     function testUpdateCategoryFilterFromSettings() {
    190       var view = new tracing.TimelineView();
    191       view.timeline_ = {};
    192       view.settings.set('foo', true, 'categories');
    193       view.settings.set('bar', false, 'categories');
    194       view.settings.set('baz', false, 'categories');
    195       view.updateCategoryFilterFromSettings_();
    196       assertUndefined(view.timeline_.categoryFilter.categories_['foo']);
    197       assertTrue(view.timeline_.categoryFilter.categories_['bar']);
    198       assertTrue(view.timeline_.categoryFilter.categories_['baz']);
    199     }
    200 
    201 </script>
    202 </body>
    203 </html>
    204