Home | History | Annotate | Download | only in trace_model
      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.test_utils');
      8 base.require('tracing.trace_model.object_instance');
      9 
     10 base.unittest.testSuite('tracing.trace_model.object_instance', function() {
     11   test('getSnapshotAtWithImplicitCreation', function() {
     12     var instance = new tracing.trace_model.ObjectInstance(
     13         {}, '0x1000', 'cat', 'n', 10);
     14     var s10 = instance.addSnapshot(10, 'a');
     15     instance.addSnapshot(40, 'b');
     16     instance.wasDeleted(60);
     17 
     18     var s1 = instance.getSnapshotAt(1);
     19     assertEquals(s10, s1);
     20 
     21     var s10 = instance.getSnapshotAt(10);
     22     assertEquals('a', s10.args);
     23     assertEquals(s10, instance.getSnapshotAt(15));
     24 
     25     var s40 = instance.getSnapshotAt(40);
     26     assertEquals('b', s40.args);
     27     assertEquals(s40, instance.getSnapshotAt(50));
     28     assertEquals(s40, instance.getSnapshotAt(59.9));
     29   });
     30 
     31   test('getSnapshotAtWithExplicitCreation', function() {
     32     var instance = new tracing.trace_model.ObjectInstance(
     33         {}, '0x1000', 'cat', 'n', 10);
     34     instance.creationTsWasExplicit = true;
     35     instance.addSnapshot(10, 'a');
     36     instance.wasDeleted(60);
     37 
     38     assertThrows(function() {
     39       instance.getSnapshotAt(1);
     40     });
     41 
     42     var s10 = instance.getSnapshotAt(10);
     43     assertEquals('a', s10.args);
     44     assertEquals(s10, instance.getSnapshotAt(15));
     45   });
     46 
     47   test('getSnapshotBeforeFirstSnapshot', function() {
     48     var instance = new tracing.trace_model.ObjectInstance(
     49         {}, '0x1000', 'cat', 'n', 10);
     50     var s15 = instance.addSnapshot(15, 'a');
     51     instance.wasDeleted(40);
     52 
     53     assertEquals(s15, instance.getSnapshotAt(10));
     54   });
     55 
     56   test('getSnapshotAfterLastSnapshot', function() {
     57     var instance = new tracing.trace_model.ObjectInstance(
     58         {}, '0x1000', 'cat', 'n', 10);
     59     var s15 = instance.addSnapshot(15, 'a');
     60     instance.wasDeleted(40);
     61 
     62     assertEquals(s15, instance.getSnapshotAt(20));
     63   });
     64 });
     65