Home | History | Annotate | Download | only in model
      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>AsyncSliceGroup tests</title>
     10 <script src="/src/base.js"></script>
     11 </head>
     12 <body>
     13   <script>
     14     base.require('unittest');
     15     base.require('test_utils');
     16     base.require('model');
     17   </script>
     18   <script>
     19     'use strict';
     20 
     21   var Model = tracing.Model;
     22   var Process = tracing.model.Process;
     23   var Thread = tracing.model.Thread;
     24   var AsyncSlice = tracing.model.AsyncSlice;
     25   var AsyncSliceGroup = tracing.model.AsyncSliceGroup;
     26   var newAsyncSlice = test_utils.newAsyncSlice;
     27 
     28   function testAsyncSliceGroupBounds_Empty() {
     29     var g = new AsyncSliceGroup();
     30     g.updateBounds();
     31     assertTrue(g.bounds.isEmpty);
     32   }
     33 
     34   function testAsyncSliceGroupBounds_Basic() {
     35     var p1 = new Process(1);
     36     var t1 = new Thread(p1, 1);
     37     var g = new AsyncSliceGroup();
     38     g.push(newAsyncSlice(0, 1, t1, t1));
     39     g.push(newAsyncSlice(1, 1.5, t1, t1));
     40     assertEquals(2, g.length);
     41     g.updateBounds();
     42     assertEquals(0, g.bounds.min);
     43     assertEquals(2.5, g.bounds.max);
     44   }
     45 
     46   function testAsyncSlice_toJSON() {
     47     var js = [
     48       '{',
     49       '  "category" : "",',
     50       '  "title" : "a",',
     51       '  "start" : 0,',
     52       '  "colorId" : 0,',
     53       '  "didNotFinish" : false,',
     54       '  "duration" : 1,',
     55       '  "startThread" : __T1_GUID__,',
     56       '  "endThread" : __T1_GUID__,',
     57       '  "subSlices" : [ {',
     58       '        "category" : "",',
     59       '        "title" : "a",',
     60       '        "start" : 0,',
     61       '        "colorId" : 0,',
     62       '        "didNotFinish" : false,',
     63       '        "duration" : 1,',
     64       '        "startThread" : __T1_GUID__,',
     65       '        "endThread" : __T1_GUID__',
     66       '      } ]',
     67       '}'].join('\n');
     68 
     69     var p1 = new Process(1);
     70     var t1 = new Thread(p1, 1);
     71     var s = newAsyncSlice(0, 1, t1, t1);
     72 
     73     // Replace __T1_GUID__ with t1's actual GUID
     74     js = js.replace(/__T1_GUID__/g, t1.guid);
     75 
     76     // Modify whitespace of "js" so that string compare with another
     77     // JSON.stringified version can succeed.
     78     js = JSON.stringify(JSON.parse(js));
     79 
     80 
     81     assertEquals(js, JSON.stringify(s));
     82   }
     83 
     84 </script>
     85 </body>
     86 </html>
     87