Skip to content

Commit

Permalink
Fixed an issue in verifyTimestamps that returned invalid result objec…
Browse files Browse the repository at this point in the history
…t when dynamic manifest was ok
  • Loading branch information
birme committed Jan 28, 2017
1 parent df72035 commit c25844a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ DashValidator.prototype.verifyTimestamps = function verifyTimestamps(allowedDiff
if (Math.abs(timeAtHead - d) > diffCriteria) {
result.clock = "BAD";
result.clockOffset = Math.abs(timeAtHead - d);
} else {
result.clock = "OK";
result.clockOffset = Math.abs(timeAtHead - d);
}
}
resolve(result);
Expand Down
47 changes: 47 additions & 0 deletions test/dash_validator_unit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const MockDate = require("mockdate");
const DashValidator = require("../index.js");
const util = require("../lib/util.js");
const TestAssetsModule = require("./support/testassets.js");
Expand Down Expand Up @@ -86,6 +87,11 @@ describe("Dash Validator", () => {
done();
});

afterEach((done) => {
MockDate.reset();
done();
});

it("can load and parse an MPD", (done) => {
const validator = new DashValidator("http://mock.example.com/usp-vod.mpd");
validator.load().then(() => {
Expand Down Expand Up @@ -173,4 +179,45 @@ describe("Dash Validator", () => {
}).then(done);
}).catch(fail).then(done);
});

it("should fail a manifest if playhead is out of bounds", (done) => {
MockDate.set(new Date("2016-12-23T19:20:58.692000Z"));
const validator = new DashValidator("http://mock.example.com/usp-live.mpd");
validator.load().then(() => {
validator.verifyTimestamps(10000).then((result) => {
expect(result.clock).toBe("BAD");
expect(result.clockOffset).toBe(122000);
done();
}).catch((error) => {
console.error(error);
}).then(done);
}).catch(fail).then(done);
});

it("should approve a manifest if playhead is within bounds", (done) => {
MockDate.set(new Date("2016-12-23T19:18:59.692000Z"));
const validator = new DashValidator("http://mock.example.com/usp-live.mpd");
validator.load().then(() => {
validator.verifyTimestamps(10000).then((result) => {
expect(result.clock).toBe("OK");
expect(result.clockOffset).toBe(3000);
done();
}).catch((error) => {
console.error(error);
}).then(done);
}).catch(fail).then(done);
});

it("should approve a manifest that is static no matter what playhead it has", (done) => {
MockDate.set(new Date("2016-12-21T19:18:59.692000Z"));
const validator = new DashValidator("http://mock.example.com/usp-vod.mpd");
validator.load().then(() => {
validator.verifyTimestamps(10000).then((result) => {
expect(result.clock).toBe("OK");
done();
}).catch((error) => {
console.error(error);
}).then(done);
}).catch(fail).then(done);
});
});

0 comments on commit c25844a

Please sign in to comment.