mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-25 17:45:03 +03:00
82e5654636
The optional arguments in this convenience function really only help in the tests. To avoid some component in the library accidentally making a request with default retry parameters instead of those configured by the user, I'm making the retry parameters required. The optional argument for method is only used once. To avoid the temptation to add more positional arguments for other seldom-used fields, I'm dropping the method argument completely. Change-Id: Ib0afb5766f68c5505f11372e3b004fc8eaca1223
99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2015 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('DataUriPlugin', function() {
|
|
var retryParameters;
|
|
|
|
beforeAll(function() {
|
|
retryParameters = shaka.net.NetworkingEngine.defaultRetryParameters();
|
|
});
|
|
|
|
it('supports MIME types', function(done) {
|
|
testSucceeds('data:text/plain,Hello', 'Hello', done);
|
|
});
|
|
|
|
it('supports URI encoded text', function(done) {
|
|
testSucceeds(
|
|
'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E',
|
|
'<h1>Hello, World!</h1>',
|
|
done);
|
|
});
|
|
|
|
it('supports base64 encoded text', function(done) {
|
|
testSucceeds(
|
|
'data:;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', 'Hello, World!', done);
|
|
});
|
|
|
|
it('supports extra colin', function(done) {
|
|
testSucceeds('data:,Hello:', 'Hello:', done);
|
|
});
|
|
|
|
it('supports extra semi-colin', function(done) {
|
|
testSucceeds('data:,Hello;', 'Hello;', done);
|
|
});
|
|
|
|
it('supports extra comma', function(done) {
|
|
testSucceeds('data:,Hello,', 'Hello,', done);
|
|
});
|
|
|
|
it('fails for empty URI', function(done) {
|
|
testFails('', done);
|
|
});
|
|
|
|
it('fails for non-data URIs', function(done) {
|
|
testFails('http://google.com/', done);
|
|
});
|
|
|
|
it('fails for decoding errors', function(done) {
|
|
testFails('data:Bad%', done);
|
|
});
|
|
|
|
it('fails if missing comma', function(done) {
|
|
testFails('data:Bad', done);
|
|
});
|
|
|
|
function testSucceeds(uri, text, done) {
|
|
var request =
|
|
shaka.net.NetworkingEngine.makeRequest([uri], retryParameters);
|
|
shaka.net.DataUriPlugin(uri, request)
|
|
.then(function(response) {
|
|
expect(response).toBeTruthy();
|
|
expect(response.uri).toBe(uri);
|
|
expect(response.data).toBeTruthy();
|
|
var array = new Uint8Array(response.data);
|
|
var data = shaka.util.Uint8ArrayUtils.toString(array);
|
|
expect(data).toBe(text);
|
|
})
|
|
.catch(fail)
|
|
.then(done);
|
|
}
|
|
|
|
function testFails(uri, done) {
|
|
var request =
|
|
shaka.net.NetworkingEngine.makeRequest([uri], retryParameters);
|
|
shaka.log.setLevel(shaka.log.Level.NONE);
|
|
shaka.net.DataUriPlugin(uri, request)
|
|
.then(fail)
|
|
.catch(function() { expect(true).toBe(true); })
|
|
.then(function() {
|
|
shaka.log.setLevel(shaka.log.MAX_LOG_LEVEL);
|
|
done();
|
|
});
|
|
}
|
|
});
|
|
|