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 7base.require('tracing.test_utils'); 8base.require('tracing.trace_model'); 9 10base.unittest.testSuite('tracing.trace_model.async_slice_group', function() { 11 var Process = tracing.trace_model.Process; 12 var Thread = tracing.trace_model.Thread; 13 var AsyncSlice = tracing.trace_model.AsyncSlice; 14 var AsyncSliceGroup = tracing.trace_model.AsyncSliceGroup; 15 var newAsyncSlice = tracing.test_utils.newAsyncSlice; 16 17 test('asyncSliceGroupBounds_Empty', function() { 18 var g = new AsyncSliceGroup(); 19 g.updateBounds(); 20 assertTrue(g.bounds.isEmpty); 21 }); 22 23 test('asyncSliceGroupBounds_Basic', function() { 24 var model = new tracing.TraceModel(); 25 var p1 = new Process(model, 1); 26 var t1 = new Thread(p1, 1); 27 var g = new AsyncSliceGroup(); 28 g.push(newAsyncSlice(0, 1, t1, t1)); 29 g.push(newAsyncSlice(1, 1.5, t1, t1)); 30 assertEquals(2, g.length); 31 g.updateBounds(); 32 assertEquals(0, g.bounds.min); 33 assertEquals(2.5, g.bounds.max); 34 }); 35 36 test('asyncSlice_toJSON', function() { 37 var js = [ 38 '{', 39 ' "category" : "",', 40 ' "title" : "a",', 41 ' "colorId" : 0,', 42 ' "start" : 0,', 43 ' "didNotFinish" : false,', 44 ' "duration" : 1,', 45 ' "startThread" : __T1_GUID__,', 46 ' "endThread" : __T1_GUID__,', 47 ' "subSlices" : [ {', 48 ' "category" : "",', 49 ' "title" : "a",', 50 ' "colorId" : 0,', 51 ' "start" : 0,', 52 ' "didNotFinish" : false,', 53 ' "duration" : 1,', 54 ' "startThread" : __T1_GUID__,', 55 ' "endThread" : __T1_GUID__', 56 ' } ]', 57 '}'].join('\n'); 58 59 var model = new tracing.TraceModel(); 60 var p1 = new Process(model, 1); 61 var t1 = new Thread(p1, 1); 62 var s = newAsyncSlice(0, 1, t1, t1); 63 64 // Replace __T1_GUID__ with t1's actual GUID 65 js = js.replace(/__T1_GUID__/g, t1.guid); 66 67 // Modify whitespace of "js" so that string compare with another 68 // JSON.stringified version can succeed. 69 js = JSON.stringify(JSON.parse(js)); 70 71 assertEquals(js, JSON.stringify(s)); 72 }); 73}); 74