| <!DOCTYPE HTML> |
| <html> |
| <!-- |
| Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <head> |
| <title>TimelineView tests</title> |
| <script src="base.js"></script> |
| <style> |
| .timeline-view { |
| border: 1px solid black; |
| margin: 10px; |
| height: 350px; |
| } |
| .timeline-find-dialog { |
| border: 1px solid black; |
| margin: 10px; |
| } |
| </style> |
| </head> |
| <body> |
| <script> |
| base.require('unittest'); |
| base.require('test_utils'); |
| base.require('timeline_view'); |
| </script> |
| <script> |
| 'use strict'; |
| |
| var newSliceNamed = test_utils.newSliceNamed; |
| |
| function createFullyPopulatedModel(opt_withError, opt_withMetadata) { |
| var withError = opt_withError !== undefined ? opt_withError : true; |
| var withMetadata = opt_withMetadata !== undefined ? |
| opt_withMetadata : true; |
| |
| var num_tests = 50; |
| var testIndex = 0; |
| var startTime = 0; |
| |
| var model = new tracing.TimelineModel(); |
| for (testIndex = 0; testIndex < num_tests; ++testIndex) { |
| var process = model.getOrCreateProcess(10000 + testIndex); |
| if (testIndex % 2 == 0) { |
| var thread = process.getOrCreateThread('Thread Name Here'); |
| thread.slices.push( |
| new tracing.TimelineSlice('foo', 'a', 0, startTime, {}, 1)); |
| thread.slices.push( |
| new tracing.TimelineSlice('bar', 'b', 0, |
| startTime + 1.15, {}, .5)); |
| } else { |
| var thread = process.getOrCreateThread('Name'); |
| thread.slices.push( |
| new tracing.TimelineSlice('foo', 'a', 0, |
| startTime + .17, {}, .55)); |
| thread.slices.push( |
| new tracing.TimelineSlice('bar', 'b', 0, |
| startTime + 1.1, {}, .7)); |
| } |
| } |
| model.updateCategories_(); |
| |
| // Add a known problematic piece of data to test the import errors UI. |
| model.importErrors.push('Synthetic Import Error'); |
| model.updateBounds(); |
| |
| // Add data with metadata information stored |
| model.metadata.push({name: 'a', value: 'testA'}); |
| model.metadata.push({name: 'b', value: 'testB'}); |
| model.metadata.push({name: 'c', value: 'testC'}); |
| |
| return model; |
| } |
| |
| /* |
| * This test just instantiates a TimelineView and adds it to the DOM |
| * to help with non-unittest UI work. |
| */ |
| function testInstantiateTimelineView() { |
| var model = createFullyPopulatedModel(true, true); |
| |
| var view = new tracing.TimelineView(); |
| view.style.height = '400px'; |
| view.model = model; |
| view.tabIndex = 0; |
| view.focusElement = view; |
| |
| var selection = new tracing.TimelineSelection(); |
| view.timeline.addAllObjectsMatchingFilterToSelection({ |
| matchSlice: function() { return true;} |
| }, selection); |
| view.timeline.selection = selection; |
| |
| this.addHTMLOutput(undefined, view); |
| } |
| |
| function testChangeModelToSomethingDifferent() { |
| var model00 = createFullyPopulatedModel(false, false); |
| var model11 = createFullyPopulatedModel(true, true); |
| |
| var view = new tracing.TimelineView(); |
| view.style.height = '400px'; |
| view.model = model00; |
| view.model = undefined; |
| view.model = model11; |
| view.model = model00; |
| } |
| |
| |
| function testSetModelToSameThingAgain() { |
| var model = createFullyPopulatedModel(false, false); |
| |
| // Create a view with am model. |
| var view = new tracing.TimelineView(); |
| view.style.height = '400px'; |
| view.model = model; |
| |
| // Mutate the model and update the view. |
| var t123 = model.getOrCreateProcess(123).getOrCreateThread(123); |
| t123.pushSlice(newSliceNamed('somethingUnusual', 0, 5)); |
| view.model = model; |
| |
| // Verify that the new bits of the model show up in the view. |
| var selection = new tracing.TimelineSelection(); |
| var filter = new tracing.TimelineTitleFilter('somethingUnusual'); |
| view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection); |
| assertEquals(selection.length, 1); |
| } |
| |
| function testChangeModelToSomethingDifferent() { |
| var model00 = createFullyPopulatedModel(false, false); |
| var model11 = createFullyPopulatedModel(true, true); |
| |
| var view = new tracing.TimelineView(); |
| view.style.height = '400px'; |
| view.model = model00; |
| view.model = undefined; |
| view.model = model11; |
| view.model = model00; |
| } |
| |
| |
| function testSetModelToSameThingAgain() { |
| var model = createFullyPopulatedModel(false, false); |
| |
| // Create a view with am model. |
| var view = new tracing.TimelineView(); |
| view.style.height = '400px'; |
| view.model = model; |
| |
| // Mutate the model and update the view. |
| var t123 = model.getOrCreateProcess(123).getOrCreateThread(123); |
| t123.pushSlice(newSliceNamed('somethingUnusual', 0, 5)); |
| view.model = model; |
| |
| // Verify that the new bits of the model show up in the view. |
| var selection = new tracing.TimelineSelection(); |
| var filter = new tracing.TimelineTitleFilter('somethingUnusual'); |
| view.timeline.addAllObjectsMatchingFilterToSelection(filter, selection); |
| assertEquals(selection.length, 1); |
| } |
| |
| function testSetModelUpdatesCategories() { |
| var model = new tracing.TimelineModel(); |
| var p1 = model.getOrCreateProcess(1); |
| var t1 = p1.getOrCreateThread(1); |
| |
| t1.pushSlice(new tracing.TimelineThreadSlice('foo', 'a', |
| 0, 1, {}, 3)); |
| t1.pushSlice(new tracing.TimelineThreadSlice('bar', 'b', |
| 0, 1.1, {}, 2.8)); |
| t1.pushSlice(new tracing.TimelineThreadSlice('baz', 'b', |
| 0, 1.2, {}, 2.4)); |
| model.updateCategories_(); |
| model.updateBounds(); |
| |
| var view = new tracing.TimelineView(); |
| view.settings.set('foo', true, 'categories'); |
| view.settings.set('bar', false, 'categories'); |
| view.model = model; |
| |
| assertUndefined(view.timeline.categoryFilter_.categories_['foo']); |
| assertTrue(view.timeline.categoryFilter_.categories_['bar']); |
| assertUndefined(view.timeline.categoryFilter_.categories_['baz']); |
| } |
| |
| function testUpdateCategoryFilterFromSettings() { |
| var view = new tracing.TimelineView(); |
| view.timeline_ = {}; |
| view.settings.set('foo', true, 'categories'); |
| view.settings.set('bar', false, 'categories'); |
| view.settings.set('baz', false, 'categories'); |
| view.updateCategoryFilterFromSettings_(); |
| assertUndefined(view.timeline_.categoryFilter.categories_['foo']); |
| assertTrue(view.timeline_.categoryFilter.categories_['bar']); |
| assertTrue(view.timeline_.categoryFilter.categories_['baz']); |
| } |
| |
| </script> |
| </body> |
| </html> |