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'); 8 base.require('tracing.trace_model_settings'); 9 10 base.unittest.testSuite('tracing.trace_model_settings', function() { 11 12 test('process_name_uniqueness_0', function() { 13 var model = new tracing.TraceModel(); 14 var p1 = model.getOrCreateProcess(1); 15 var settings = new tracing.TraceModelSettings(model); 16 assertFalse(settings.hasUniqueSettingKey(p1)); 17 }); 18 19 test('process_name_uniqueness_1', function() { 20 var model = new tracing.TraceModel(); 21 var p1 = model.getOrCreateProcess(1); 22 p1.name = 'Browser'; 23 var settings = new tracing.TraceModelSettings(model); 24 assertTrue(settings.hasUniqueSettingKey(p1)); 25 }); 26 27 test('process_name_uniqueness_2', function() { 28 var model = new tracing.TraceModel(); 29 var p1 = model.getOrCreateProcess(1); 30 var p2 = model.getOrCreateProcess(2); 31 p1.name = 'Renderer'; 32 p2.name = 'Renderer'; 33 var settings = new tracing.TraceModelSettings(model); 34 assertFalse(settings.hasUniqueSettingKey(p1)); 35 assertFalse(settings.hasUniqueSettingKey(p2)); 36 }); 37 38 test('process_name_uniqueness_3', function() { 39 var model = new tracing.TraceModel(); 40 var p1 = model.getOrCreateProcess(1); 41 var p2 = model.getOrCreateProcess(2); 42 p1.name = 'Renderer'; 43 p1.labels.push('Google Search'); 44 p2.name = 'Renderer'; 45 var settings = new tracing.TraceModelSettings(model); 46 assertTrue(settings.hasUniqueSettingKey(p1)); 47 assertTrue(settings.hasUniqueSettingKey(p2)); 48 }); 49 50 test('thread_name_uniqueness_0', function() { 51 var model = new tracing.TraceModel(); 52 var p1 = model.getOrCreateProcess(1); 53 var p2 = model.getOrCreateProcess(2); 54 var t1 = p1.getOrCreateThread(1); 55 var t2 = p2.getOrCreateThread(2); 56 p1.name = 'Browser'; 57 p2.name = 'Renderer'; 58 t1.name = 'Main'; 59 t2.name = 'Main'; 60 var settings = new tracing.TraceModelSettings(model); 61 assertTrue(settings.hasUniqueSettingKey(t1)); 62 assertTrue(settings.hasUniqueSettingKey(t2)); 63 }); 64 65 test('thread_name_uniqueness_1', function() { 66 var model = new tracing.TraceModel(); 67 var p1 = model.getOrCreateProcess(1); 68 var p2 = model.getOrCreateProcess(2); 69 var t1 = p1.getOrCreateThread(1); 70 var t2 = p2.getOrCreateThread(2); 71 p1.name = 'Renderer'; 72 p2.name = 'Renderer'; 73 t1.name = 'Main'; 74 t2.name = 'Main'; 75 var settings = new tracing.TraceModelSettings(model); 76 assertFalse(settings.hasUniqueSettingKey(t1)); 77 assertFalse(settings.hasUniqueSettingKey(t2)); 78 }); 79 80 test('process_persistence_when_not_unique', function() { 81 var model = new tracing.TraceModel(); 82 var p1 = model.getOrCreateProcess(1); 83 var settings = new tracing.TraceModelSettings(model); 84 assertTrue(settings.getSettingFor(p1, 'true_by_default', true)); 85 86 settings.setSettingFor(p1, 'true_by_default', false); 87 assertFalse(settings.getSettingFor(p1, 'true_by_default', true)); 88 89 // Now, clobber the model, and verify that it didn't persist. 90 model = new tracing.TraceModel(); 91 p1 = model.getOrCreateProcess(1); 92 settings = new tracing.TraceModelSettings(model); 93 assertTrue(settings.getSettingFor(p1, 'true_by_default', true)); 94 }); 95 96 test('process_persistence_when_not_unique_with_name', function() { 97 var model = new tracing.TraceModel(); 98 var p1 = model.getOrCreateProcess(1); 99 p1.name = 'Browser'; 100 var settings = new tracing.TraceModelSettings(model); 101 assertTrue(settings.getSettingFor(p1, 'true_by_default', true)); 102 103 settings.setSettingFor(p1, 'true_by_default', false); 104 assertFalse(settings.getSettingFor(p1, 'true_by_default', true)); 105 106 // Now, clobber the model, and verify that it persisted. 107 model = new tracing.TraceModel(); 108 p1 = model.getOrCreateProcess(1); 109 p1.name = 'Browser'; 110 settings = new tracing.TraceModelSettings(model); 111 assertFalse(settings.getSettingFor(p1, 'true_by_default', true)); 112 }); 113 114 test('thread_persistence_when_not_unique', function() { 115 var model = new tracing.TraceModel(); 116 var p1 = model.getOrCreateProcess(1); 117 var p2 = model.getOrCreateProcess(2); 118 var t1 = p1.getOrCreateThread(1); 119 var t2 = p2.getOrCreateThread(2); 120 p1.name = 'Renderer'; 121 p2.name = 'Renderer'; 122 t1.name = 'Main'; 123 t2.name = 'Main'; 124 var settings = new tracing.TraceModelSettings(model); 125 assertTrue(settings.getSettingFor(t1, 'true_by_default', true)); 126 127 settings.setSettingFor(t1, 'true_by_default', false); 128 assertFalse(settings.getSettingFor(t1, 'true_by_default', true)); 129 130 // Now, clobber the model, and verify that it persisted. 131 model = new tracing.TraceModel(); 132 p1 = model.getOrCreateProcess(1); 133 p2 = model.getOrCreateProcess(2); 134 t1 = p1.getOrCreateThread(1); 135 t2 = p2.getOrCreateThread(2); 136 p1.name = 'Renderer'; 137 p2.name = 'Renderer'; 138 t1.name = 'Main'; 139 t2.name = 'Main'; 140 settings = new tracing.TraceModelSettings(model); 141 assertTrue(settings.getSettingFor(t1, 'true_by_default', true)); 142 }); 143 144 test('thread_persistence_when_unique', function() { 145 var model = new tracing.TraceModel(); 146 var p1 = model.getOrCreateProcess(1); 147 var p2 = model.getOrCreateProcess(2); 148 var t1 = p1.getOrCreateThread(1); 149 var t2 = p2.getOrCreateThread(2); 150 p1.name = 'Browser'; 151 p2.name = 'Renderer'; 152 t1.name = 'Main'; 153 t2.name = 'Main'; 154 var settings = new tracing.TraceModelSettings(model); 155 assertTrue(settings.getSettingFor(t1, 'true_by_default', true)); 156 157 settings.setSettingFor(t1, 'true_by_default', false); 158 assertFalse(settings.getSettingFor(t1, 'true_by_default', true)); 159 160 // Now, clobber the model, and verify that it persisted. 161 model = new tracing.TraceModel(); 162 p1 = model.getOrCreateProcess(1); 163 p2 = model.getOrCreateProcess(2); 164 t1 = p1.getOrCreateThread(1); 165 t2 = p2.getOrCreateThread(2); 166 p1.name = 'Browser'; 167 p2.name = 'Renderer'; 168 t1.name = 'Main'; 169 t2.name = 'Main'; 170 settings = new tracing.TraceModelSettings(model); 171 assertFalse(settings.getSettingFor(t1, 'true_by_default', true)); 172 }); 173 174 }); 175