| OLD | NEW |
| (Empty) |
| 1 // Copyright 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 /** | |
| 6 * Test whether given model is valid. | |
| 7 * @param {Object} model | |
| 8 * @return {boolean} Model is valid or not. | |
| 9 */ | |
| 10 var modelIsValid = function(model) { | |
| 11 // Model object must contain 'name' and 'id'. | |
| 12 if (!('name' in model) || !('id' in model)) | |
| 13 return false; | |
| 14 | |
| 15 // Model object cant contain 'children' and 'size' together. | |
| 16 if ('children' in model && 'size' in model || | |
| 17 !('children' in model) && !('size' in model)) | |
| 18 return false; | |
| 19 | |
| 20 // Model object must contain 'subs' and 'template' both or neither. | |
| 21 if ('subs' in model && !('template' in model) || | |
| 22 !('subs' in model) && 'template' in model) | |
| 23 return false; | |
| 24 | |
| 25 // If model contains children, every child also must be valid. | |
| 26 if ('children' in model) { | |
| 27 return model.children.reduce(function(previous, current) { | |
| 28 return previous && modelIsValid(current); | |
| 29 }, true); | |
| 30 } | |
| 31 | |
| 32 return true; | |
| 33 }; | |
| 34 | |
| 35 // Test title format is file-name:function-name. | |
| 36 test('profiler:parseTemplate_', function() { | |
| 37 stop(); | |
| 38 $.getJSON('data/sample.json', function(data) { | |
| 39 start(); | |
| 40 var profiler = new Profiler(data); | |
| 41 var models = profiler.parseTemplate_(); | |
| 42 equal(models.length, data.snapshots.length); | |
| 43 models.forEach(function(model) { | |
| 44 ok(modelIsValid(model)); | |
| 45 }); | |
| 46 inspect(models, 'models generated by profile:\n'); | |
| 47 }); | |
| 48 }); | |
| OLD | NEW |