| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 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. |
| --> |
| |
| <link rel="import" href="/base/task.html"> |
| <link rel="import" href="/core/test_utils.html"> |
| <link rel="import" href="/extras/importer/trace_event_importer.html"> |
| <link rel="import" href="/core/timeline_view.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tv.b.unittest.testSuite(function() { |
| var newSliceEx = tv.c.test_utils.newSliceEx; |
| |
| var Selection = tv.c.Selection; |
| var SelectionState = tv.c.trace_model.SelectionState; |
| |
| function newSimpleModel() { |
| return tv.c.test_utils.newModel(function(m) { |
| m.p1 = m.getOrCreateProcess(1); |
| m.t2 = m.p1.getOrCreateThread(2); |
| |
| m.sA = m.t2.sliceGroup.pushSlice( |
| newSliceEx({title: 'a', start: 0, end: 5})); |
| m.sB = m.t2.sliceGroup.pushSlice( |
| newSliceEx({title: 'b', start: 10, end: 15})); |
| m.sC = m.t2.sliceGroup.pushSlice( |
| newSliceEx({title: 'c', start: 20, end: 20})); |
| }); |
| } |
| |
| test('brushingStateSimple', function() { |
| var m = newSimpleModel(); |
| |
| var bs = new tv.c.BrushingState(); |
| bs.selection = new Selection([m.sA]); |
| |
| bs.applyToModelSelectionState(m); |
| assert.equal(m.sA.selectionState, SelectionState.SELECTED); |
| bs.unapplyFromModelSelectionState(); |
| assert.equal(m.sA.selectionState, SelectionState.NONE); |
| }); |
| |
| test('brushingStateWithSimpleHighlight', function() { |
| var m = newSimpleModel(); |
| |
| var bs = new tv.c.BrushingState(); |
| bs.selection = new Selection([m.sA]); |
| bs.findMatches = new Selection([m.sA, m.sB]); |
| |
| bs.applyToModelSelectionState(m); |
| assert.equal(m.sA.selectionState, SelectionState.SELECTED); |
| assert.equal(m.sB.selectionState, SelectionState.HIGHLIGHTED); |
| assert.equal(m.sC.selectionState, SelectionState.DIMMED); |
| bs.unapplyFromModelSelectionState(); |
| assert.equal(m.sA.selectionState, SelectionState.NONE); |
| assert.equal(m.sB.selectionState, SelectionState.NONE); |
| assert.equal(m.sC.selectionState, SelectionState.NONE); |
| }); |
| |
| test('brushingTransfer', function() { |
| var m = newSimpleModel(); |
| |
| var bs = new tv.c.BrushingState(); |
| bs.selection = new Selection([m.sA]); |
| |
| var bs2 = bs.clone(); |
| |
| bs.applyToModelSelectionState(m); |
| assert.equal(m.sA.selectionState, SelectionState.SELECTED); |
| bs.transferModelOwnershipToClone(bs2); |
| assert.isFalse(bs.isAppliedToModel); |
| assert.isTrue(bs2.isAppliedToModel); |
| |
| bs2.unapplyFromModelSelectionState(); |
| assert.equal(m.sA.selectionState, SelectionState.NONE); |
| assert.equal(m.sB.selectionState, SelectionState.NONE); |
| assert.equal(m.sC.selectionState, SelectionState.NONE); |
| }); |
| |
| test('equality', function() { |
| var m = newSimpleModel(); |
| |
| var bs = new tv.c.BrushingState(); |
| bs.selection = new Selection([m.sA]); |
| bs.findMatches = new Selection([m.sB]); |
| bs.applyToModelSelectionState = new Selection([m.sC]); |
| |
| // Clone equality, but with shared refs. |
| var bs2 = bs.clone(); |
| assert.isTrue(bs.equals(bs2)); |
| |
| // Same value, different refs. |
| bs2.selection = new Selection([m.sA]); |
| assert.isTrue(bs.equals(bs2)); |
| |
| // Different actual values. |
| bs2.selection = new Selection([m.sB]); |
| assert.isFalse(bs.equals(bs2)); |
| }); |
| |
| }); |
| </script> |