Home | History | Annotate | Download | only in analysis
      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.trace_model.object_instance');
      8 base.require('tracing.analysis.generic_object_view');
      9 
     10 base.unittest.testSuite('tracing.analysis.generic_object_view', function() {
     11   var GenericObjectView = tracing.analysis.GenericObjectView;
     12 
     13   test('undefinedValue', function() {
     14     var view = new GenericObjectView();
     15     view.object = undefined;
     16     assertEquals('undefined', view.children[0].dataElement.textContent);
     17   });
     18 
     19   test('nullValue', function() {
     20     var view = new GenericObjectView();
     21     view.object = null;
     22     assertEquals('null', view.children[0].dataElement.textContent);
     23   });
     24 
     25   test('stringValue', function() {
     26     var view = new GenericObjectView();
     27     view.object = 'string value';
     28     assertEquals('"string value"', view.children[0].textContent);
     29   });
     30 
     31   test('booleanValue', function() {
     32     var view = new GenericObjectView();
     33     view.object = false;
     34     assertEquals('false', view.children[0].dataElement.textContent);
     35   });
     36 
     37   test('numberValue', function() {
     38     var view = new GenericObjectView();
     39     view.object = 3.14159;
     40     assertEquals('3.14159', view.children[0].textContent);
     41   });
     42 
     43   test('objectSnapshotValue', function() {
     44     var view = new GenericObjectView();
     45 
     46     var i10 = new tracing.trace_model.ObjectInstance(
     47         {}, '0x1000', 'cat', 'name', 10);
     48     var s10 = i10.addSnapshot(10, {foo: 1});
     49 
     50     view.object = s10;
     51     assertTrue(view.children[0].dataElement instanceof
     52                tracing.analysis.ObjectSnapshotLink);
     53   });
     54 
     55   test('objectInstanceValue', function() {
     56     var view = new GenericObjectView();
     57 
     58     var i10 = new tracing.trace_model.ObjectInstance(
     59         {}, '0x1000', 'cat', 'name', 10);
     60     var s10 = i10.addSnapshot(10, {foo: 1});
     61 
     62     view.object = i10;
     63     assertTrue(view.children[0].dataElement instanceof
     64                tracing.analysis.ObjectInstanceLink);
     65   });
     66 
     67   test('instantiate_emptyArrayValue', function() {
     68     var view = new GenericObjectView();
     69     view.object = [];
     70     this.addHTMLOutput(view);
     71   });
     72 
     73   test('instantiate_twoValueArrayValue', function() {
     74     var view = new GenericObjectView();
     75     view.object = [1, 2];
     76     this.addHTMLOutput(view);
     77   });
     78 
     79   test('instantiate_twoValueBArrayValue', function() {
     80     var view = new GenericObjectView();
     81     view.object = [1, {x: 1}];
     82     this.addHTMLOutput(view);
     83   });
     84 
     85   test('instantiate_arrayValue', function() {
     86     var view = new GenericObjectView();
     87     view.object = [1, 2, 'three'];
     88     this.addHTMLOutput(view);
     89   });
     90 
     91   test('instantiate_arrayWithSimpleObjectValue', function() {
     92     var view = new GenericObjectView();
     93     view.object = [{simple: 'object'}];
     94     this.addHTMLOutput(view);
     95   });
     96 
     97   test('instantiate_arrayWithComplexObjectValue', function() {
     98     var view = new GenericObjectView();
     99     view.object = [{complex: 'object', field: 'two'}];
    100     this.addHTMLOutput(view);
    101   });
    102 
    103   test('instantiate_objectValue', function() {
    104     var view = new GenericObjectView();
    105     view.object = {
    106       'entry_one': 'entry_one_value',
    107       'entry_two': 2,
    108       'entry_three': [3, 4, 5]
    109     };
    110     this.addHTMLOutput(view);
    111   });
    112 });
    113