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