Skip to content

Commit

Permalink
Fixed DBEngine Test Failures
Browse files Browse the repository at this point in the history
It looks like some browsers don't do equality checks on ArrayBuffers
the same way as others. So to fix this, we checking that segments
are the same, convert each ArrayBuffer into an Uint8Array.

Change-Id: Iceb6e39e326ced4e86c52968e364bf927116c250
  • Loading branch information
vaage committed Dec 13, 2017
1 parent b08ea87 commit e7c5a3a
Showing 2 changed files with 70 additions and 5 deletions.
33 changes: 33 additions & 0 deletions test/assumptions/uint8_array_unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @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('Uint8Array', function() {
it('checks equality', function() {
var subject = new Uint8Array([0, 1, 2, 3]);
var same = new Uint8Array([0, 1, 2, 3]);
var different = new Uint8Array([4, 5, 6, 7]);

expect(subject).toBe(subject);
expect(subject).toEqual(subject);

expect(subject).not.toBe(same);
expect(subject).toEqual(same);

expect(subject).not.toBe(different);
expect(subject).not.toEqual(different);
});
});
42 changes: 37 additions & 5 deletions test/offline/db_engine_unit.js
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ describe('DBEngine', /** @suppress {accessControls} */ function() {
.then(done).catch(fail);
}));

it('stores and remove a manifest', checkAndRun(function(done) {
it('stores and removes a manifest', checkAndRun(function(done) {
/** @type {shakaExtern.ManifestDB} */
var original = createManifest('original manifest');

@@ -135,7 +135,7 @@ describe('DBEngine', /** @suppress {accessControls} */ function() {
return db.getSegment(id);
})
.then(function(copy) {
expect(copy).toEqual(original);
expectSegmentToEqual(copy, original);
})
.then(done).catch(fail);
}));
@@ -165,13 +165,13 @@ describe('DBEngine', /** @suppress {accessControls} */ function() {
})
.then(function() {
originals.forEach(function(original) {
expect(copies).toContain(original);
expectSegmentsToContain(copies, original);
});
})
.then(done).catch(fail);
}));

it('stores and remove a segment', checkAndRun(function(done) {
it('stores and removes a segment', checkAndRun(function(done) {
/** @type {shakaExtern.SegmentDataDB} */
var original = createSegment([0, 1, 2]);

@@ -187,7 +187,7 @@ describe('DBEngine', /** @suppress {accessControls} */ function() {
return db.getSegment(id);
})
.then(function(value) {
expect(value).toEqual(original);
expectSegmentToEqual(value, original);
return db.removeSegments([id], null);
})
.then(function() {
@@ -329,4 +329,36 @@ describe('DBEngine', /** @suppress {accessControls} */ function() {
data: array.buffer
};
}


/**
* @param {!Array.<shakaExtern.SegmentDataDB>} segments
* @param {shakaExtern.SegmentDataDB} expected
*/
function expectSegmentsToContain(segments, expected) {
var actualData = segments.map(function(segment) {
expect(segment.data).toBeTruthy();
return new Uint8Array(segment.data);
});

expect(expected.data).toBeTruthy();
var expectedData = new Uint8Array(expected.data);

expect(actualData).toContain(expectedData);
}


/**
* @param {shakaExtern.SegmentDataDB} actual
* @param {shakaExtern.SegmentDataDB} expected
*/
function expectSegmentToEqual(actual, expected) {
expect(actual.data).toBeTruthy();
expect(expected.data).toBeTruthy();

var actualData = new Uint8Array(actual.data);
var expectedData = new Uint8Array(expected.data);

expect(actualData).toEqual(expectedData);
}
});

0 comments on commit e7c5a3a

Please sign in to comment.