forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change makes state history track any state by moving the idea of buffering, playing, etc to the player. This allowed the stats and state history to drop they connection to the media element. Change-Id: Ieed198a09b3ade33e4ee850445b809f251cf2558
- Loading branch information
Showing
5 changed files
with
113 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @license | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
describe('StateHistory', () => { | ||
/** @type {!shaka.util.StateHistory} */ | ||
let history; | ||
|
||
beforeAll(() => { | ||
// Mock the clock so that the timing logic inside the state history will be | ||
// controlled by the test and not the system. | ||
jasmine.clock().install(); | ||
jasmine.clock().mockDate(); | ||
}); | ||
|
||
afterAll(() => { | ||
jasmine.clock().uninstall(); | ||
}); | ||
|
||
beforeEach(() => { | ||
history = new shaka.util.StateHistory(); | ||
}); | ||
|
||
// After a state change, the new state should have no duration. It must have | ||
// an update after (regardless of state) to update the duration. | ||
it('open entry have no duration', () => { | ||
history.update('a'); | ||
jasmine.clock().tick(5000); | ||
|
||
const entries = history.getCopy(); | ||
expect(entries.length).toBe(1); | ||
expect(entries[0].state).toBe('a'); | ||
expect(entries[0].duration).toBe(0); | ||
}); | ||
|
||
// Updating while in the same state should only add duration to the previous | ||
// entry. | ||
it('accumulates time', () => { | ||
history.update('a'); | ||
jasmine.clock().tick(5000); | ||
history.update('a'); | ||
|
||
const entries = history.getCopy(); | ||
expect(entries.length).toBe(1); | ||
expect(entries[0].state).toBe('a'); | ||
expect(entries[0].duration).toBe(5); | ||
}); | ||
|
||
it('state changes update duration of last entry', () => { | ||
history.update('a'); | ||
jasmine.clock().tick(5000); | ||
history.update('b'); | ||
|
||
const entries = history.getCopy(); | ||
expect(entries.length).toBe(2); | ||
expect(entries[0].state).toBe('a'); | ||
expect(entries[0].duration).toBe(5); | ||
expect(entries[1].state).toBe('b'); | ||
expect(entries[1].duration).toBe(0); | ||
}); | ||
}); |