diff --git a/src/os/time/timelinecontroller.js b/src/os/time/timelinecontroller.js index 9466aca97..294a7ee91 100644 --- a/src/os/time/timelinecontroller.js +++ b/src/os/time/timelinecontroller.js @@ -957,7 +957,6 @@ os.time.TimelineController.prototype.restore = function(config) { this.setLoadRanges(config['loadRanges']); this.setAnimateRanges(config['animateRanges']); this.setHoldRanges(config['holdRanges']); - this.updateOffetsAndCurrent_(); if (config['playing']) { this.play(); @@ -968,8 +967,8 @@ os.time.TimelineController.prototype.restore = function(config) { /** - * Updates the current position to the beginning of the anmation sequence, and - * re-computes the step size and offests based on the current animation range. + * Updates the current position to the beginning of the animation sequence, and + * re-computes the step size and offsets based on the current animation range. * @private */ os.time.TimelineController.prototype.updateOffetsAndCurrent_ = function() { @@ -977,6 +976,16 @@ os.time.TimelineController.prototype.updateOffetsAndCurrent_ = function() { }; +/** + * Reset the timeline to config state + * @param {Object} config The state + */ +os.time.TimelineController.prototype.reset = function(config) { + this.restore(config); + this.updateOffetsAndCurrent_(); +}; + + /** * Repositions the current playback position to the start of the * timeline animation. @@ -1119,7 +1128,7 @@ os.time.TimelineController.prototype.removeSliceRange = function(timerange) { * @param {?goog.math.RangeSet} ranges */ os.time.TimelineController.prototype.setSliceRanges = function(ranges) { - if (ranges) { + if (ranges && ranges instanceof goog.math.RangeSet) { var tr = this.sliceRanges_.clone(); this.sliceRanges_ = ranges.clone(); this.calcRangeCache_.clear(); @@ -1336,7 +1345,7 @@ os.time.TimelineController.prototype.removeLoadRange = function(timerange) { * @param {?goog.math.RangeSet} ranges */ os.time.TimelineController.prototype.setLoadRanges = function(ranges) { - if (ranges) { + if (ranges && ranges instanceof goog.math.RangeSet) { var numPrev = this.getLoadRanges().length; var numNow = goog.iter.toArray(ranges).length; if ((numPrev === 1 && numNow != 1) || (numPrev > 1 && numNow === 1)) { @@ -1435,7 +1444,7 @@ os.time.TimelineController.prototype.removeAnimateRange = function(timerange) { * @param {?goog.math.RangeSet} ranges */ os.time.TimelineController.prototype.setAnimateRanges = function(ranges) { - if (ranges) { + if (ranges && ranges instanceof goog.math.RangeSet) { this.animateRanges_ = ranges.clone(); this.dispatchEvent(os.time.TimelineEventType.ANIMATE_RANGE_CHANGED); this.dispatchShowEvent_(); @@ -1482,7 +1491,7 @@ os.time.TimelineController.prototype.getHoldRanges = function() { * @param {?goog.math.RangeSet} ranges */ os.time.TimelineController.prototype.setHoldRanges = function(ranges) { - if (ranges) { + if (ranges && ranges instanceof goog.math.RangeSet) { this.holdRanges_ = ranges.clone(); this.dispatchEvent(os.time.TimelineEventType.HOLD_RANGE_CHANGED); this.dispatchShowEvent_(); diff --git a/src/os/ui/timeline/abstracttimelinectrl.js b/src/os/ui/timeline/abstracttimelinectrl.js index 67aaa6189..d2105c840 100644 --- a/src/os/ui/timeline/abstracttimelinectrl.js +++ b/src/os/ui/timeline/abstracttimelinectrl.js @@ -786,7 +786,7 @@ os.ui.timeline.AbstractTimelineCtrl.prototype.previousFrame = function() { */ os.ui.timeline.AbstractTimelineCtrl.prototype.reset = function() { if (this.tlcState_) { - this.tlc.restore(this.tlcState_); + this.tlc.reset(this.tlcState_); this.updateTimeline(true); os.metrics.Metrics.getInstance().updateMetric(os.metrics.keys.Timeline.RESET, 1); var refreshTimer = new goog.async.Delay(this.refreshLoadBrushes_, 10, this); diff --git a/test/os/time/timelinecontroller.test.js b/test/os/time/timelinecontroller.test.js index 0be3708e3..d14cdf557 100644 --- a/test/os/time/timelinecontroller.test.js +++ b/test/os/time/timelinecontroller.test.js @@ -137,6 +137,34 @@ describe('os.time.TimelineController', function() { expect(getDispatchEventCallCount(os.time.TimelineEventType.SHOW)).toBeGreaterThan((fps * runtime / 1000) - 2); }); + it('setting ranges must be a range set', function() { + controller.clearLoadRanges(); + controller.setHoldRanges({'g': []}); + + // we should have zero range + target = controller.getLoadRanges(); + expect(target.length).toBe(0); + + controller.clearSliceRanges(); + controller.setSliceRanges({'g': []}); + + // we should have zero range + target = controller.getSliceRanges(); + expect(target.length).toBe(0); + + controller.clearHoldRanges(); + controller.setHoldRanges({'g': []}); + + target = controller.getHoldRanges(); + expect(target.length).toBe(0); + + controller.clearAnimateRanges(); + controller.setAnimateRanges({'g': []}); + + target = controller.getAnimationRanges(); + expect(target.length).toBe(0); + }); + it('adding range should fire range changed event', function() { var fullRange = controller.getRange(); controller.addAnimateRange(fullRange);