Commit Graph

66 Commits

Author SHA1 Message Date
Joey Parrish 7e6a0f38ff fix: Correct license headers in misc. files
This corrects/normalizes license headers in misc. files, such as
config files, docs, build tools, tests, and externs.  This does not
affect the compiled output, and is only done for consistency.

Issue #2638

Change-Id: I9d8da2de55243b08d7df2b743aac73c6f15e858a
2020-06-09 16:13:56 -07:00
Joey Parrish 4dc2c65578 Add type assertions for Errors
In many places, we check error codes on shaka.util.Error.  But the
compiler doesn't know that what is caught in "catch" is that type, so
we add type assertions.

In some cases, we know that other types may also be thrown, so there
are also some runtime checks.  Some of these had to be refactored to
allow the compiler to correctly infer types.

Change-Id: I053bd7e96213c689aae3889315052dd402124690
2020-04-29 10:11:21 -07:00
Joey Parrish 64896d70b0 Use shorter license header
This reflects changes in Google's policy on JavaScript license
headers, which should be smaller to avoid increasing the size of the
binary unnecessarily.

This also updates the company name from "Google, Inc" to "Google LLC".

Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
2019-11-22 18:18:36 +00:00
Joey Parrish 9e92167910 Treat URL schemes as case-insensitive
According to RFC 3986, URL schemes should be case-insensitive.  Our
scheme plugin map is registered with exclusively-lowercase scheme
names, so we should convert the input scheme to lowercase before
looking up the plugin.

Closes #2173

Change-Id: I78218c18d3df154aabd101a9ef5fd3156d0c57a8
2019-10-04 10:32:58 -07:00
Jacob Trimble bf5547b78c Refactor ArrayBuffer usage in tests.
Change-Id: I27e898a7d3c2d706e265abfc4b9bde88b67f3256
2019-08-21 20:44:36 +00:00
Jacob Trimble 81568ca310 Avoid PromiseMock in HLS and HTTP plugin tests.
Issue #1379
Issue #1953

Change-Id: I4df945e517186409e21e58fea7cfb21f0e66c06f
2019-07-09 10:24:29 -07:00
Jacob Trimble 83de1ad634 Use toBe instead of toEqual for primitives.
This ensures that we get the expected types and that type coercion
doesn't convert between types.  This also ensures we are consistent
in how we check for equality of primitives in tests.

Change-Id: I9f3aacdf25ab1afe5e8d6e4b895b5299ee687d54
2019-06-26 18:57:18 +00:00
Jacob Trimble e2ba179201 Favor using toHaveBeenCalledTimes.
This gives better error messages than using toBe() or toEqual() with
the number of calls.

Change-Id: Ice353f1ebcc715da69416da2d983e919597f82d1
2019-06-26 18:52:36 +00:00
Jacob Trimble e2fa4626b5 Decrease time it takes to run tests.
- Reduce times for "short delays".
- Remove backoff delay from networking tests.
- Avoid hard-coding delays in the library.
- Move Storage tests to integration tests since they use indexedDB (and
  take over 200ms each to run).

This reduces the time it takes to run unit tests (with --quick) from
50 seconds to about 6 seconds.  Now all but one unit test finish <100ms.

Change-Id: I88461472a87c4cf750a36d07d07422818e069a4d
2019-06-12 20:53:08 +00:00
Jacob Trimble 3da809019b Enable additional ES6 linter rules.
Change-Id: I6861541b27153ba034364a5972a9b086de581cef
2019-06-11 18:35:09 +00:00
Jacob Trimble 7ecce742d2 Misc test ES6 changes.
Issue #1157

Change-Id: I47f537bca5106b4ffca5db3182c8a268d2f3d24a
2019-06-03 22:00:21 +00:00
Joey Parrish 615ce93178 Fix formatting of test failures/errors
Code in karma-jasmine's adapter will malform test failures when the
expectation message contains a stack trace, losing the failure message
and mixing up the stack trace of the failure.  To avoid this, we
modify shaka.util.Error not to create a stack trace.  This trace is
not available in production, and there is never any need for it in the
tests.

One test expectation had to be updated.  The previous version of
jasmineError would use the original error by reference.  Now that it's
capturing a few fields explicitly, the severity value doesn't update
when NetworkingEngine modifies the original.

Change-Id: If7af93a1a0357df9763dbf6a4afc45db2c8317df
2019-05-31 21:29:27 +00:00
Jacob Trimble 78d9fc840a Convert network tests to ES6.
Issue #1157

Change-Id: I30e39927c70d61f29d45698507b6ba809b33e2f3
2019-05-30 19:57:36 +00:00
Joey Parrish 393b0ecea7 Fix HTTP test failures
This makes progress callbacks into a required parameter on all network
scheme plugins.  This does not mean that every plugin must make use of
the callback, but every caller must supply the callback.

In production, NetworkingEngine already supplies this callback
universally, so our HTTP plugins make use of it whenever progress data
is available.

Our tests, however, did not always supply this callback, leading to
test failures.  These failures were more likely to show up in Jasmine
3 than Jasmine 2 for some reason, which caused us to downgrade back to
Jasmine 2 recently.

By making the callback required, we can clean up this inconsistency
between test and production and give the HTTP plugins what they expect
in all cases.

Issue #1949

Change-Id: I8a6e1904e73cf7ca6ae8f3964261c339f404854d
2019-05-22 15:42:06 +00:00
Jacob Trimble 74918b90ec Convert networking files to ES6.
Issue #1157

Change-Id: Iae83b88881b351c97e8ec020625167f5f700f97e
2019-05-20 17:10:06 +00:00
Jacob Trimble a6160c43ef Add additional message for net plugin error.
This adds more to the logs for the error in HTTP plugin tests.  This
test has been failing randomly recently and this will help us see why.

Change-Id: I6e4bfafd559d52527f7af3f21d6c9f836568c932
2019-05-20 16:05:11 +00:00
Jacob Trimble f130dffcef Enable eslint indentation rule.
This is a fully automated change.  The linter will fail because the
extra indentation caused line-length errors.  These won't be fixed
automatically.  They are fixed in a follow-up to make this one fully
automated.

Change-Id: I4d8cf9c998985add2bcd24a81c8d65495668c4f3
2019-05-13 22:31:09 +00:00
Jacob Trimble 0dd64074b9 Only allow one statement per line.
With the new style rule, we cannot have two statements on the same line.
So we can no longer have an "if" on a single line and we cannot have
an arrow function with a body on the same line as when it is used.
This is mostly a manual change.

Change-Id: I2285202dd5ecbad764308bc725e6d317ff2ee7f0
2019-05-13 22:11:50 +00:00
Jacob Trimble 47daf49f31 Use arrow functions for callbacks.
This is an automated change to convert use of "function" functions
to arrow functions.  This doesn't change all uses of bind() that
could be converted.  This also doesn't remove all "function" functions.

Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3
2019-05-09 16:40:46 +00:00
Jacob Trimble c81389741f Prefer const over let.
A coming update to the Google eslint config will require using "const"
over "let".  This makes that one change to isolate the big changes.

Change-Id: I7d0974c3ae15c53cc45a6b07bf9f6586e2d34aca
2019-05-08 09:22:10 -07:00
Jacob Trimble 8ec9e19c4a Add tests for progress events and aborts.
Closes #1051

Change-Id: I6d194751c9c248927688783805efe0335fffe312
2019-05-07 18:29:20 +00:00
Joey Parrish b513a48418 Fix range header regression
Range headers should not be sent when requesting the entire resource.
This fixes compatibility with Microsoft IIS web server.

Introduced in work on issue #1788

Change-Id: I151a2f15d4f5e95531e16d5372ee9a051135f12f
2019-05-01 17:02:53 +00:00
Aaron Vaage 71fb7a03ec Use Timer/DelayedTick instead of setTimeout
This CL limits the use of |setTimeout| by wrapping it in our own timer
class. The timer class makes it easier to track and cancel time-based
events.

To ensure that|setTimeout| is not used outside of our timer classes, the
conformance rules have been updated to only allow |setTimeout| to be
used by our timer classes.

Since |setTimeout| is very similar to |setInterval|, the conformance
rules for |setInternal| rules were updates to reflect more of the logic
behind why we don't want to use |setTimeout| and |setInterval| directly.

Change-Id: Iff5da32a61b515dd2016837fa74a34c04b6c5fd2
2019-03-12 18:52:32 +00:00
Theodore Abshire 809d86d2ee Make Http Fetch plugin require ReadableStream
In a recent CL, the Http Fetch plugin was modified to make use of
ReadableStream. However, ReadableStream isn't available on every
platform. This change modifies the Fetch plugin to not be used if
ReadableStream isn't defined.
This also adds a basic mock ReadableStream for tests.

Change-Id: I7554298779040ce0cef1b8ad55c3ee113f932954
2018-09-26 10:40:59 -07:00
Michelle Zhuo d6720cc7a6 Add Progress Event Handler for XHR plugin
This is part 1 of conditionally aborting requests when network
downgrading.
1. Add progress event handler for Http XHR Plugin, to get more frequent
updates for network bandwidth estimate and suggest streams based on
that.
2. When the plugin doesn't support progress event, call
onProgressUpdated function after every segment is downloaded.
3. Replace onSegmentDownloaded with onProgressUpdated function in
player.js and network_engine.js.
4. Since XHR Plugin supports progress event while Fetch doesn't, change
the config to prefer XHR over Fetch API.

Issue #1051.

Change-Id: Icf6775dd3520fb2e359b13d29e3b39d3792fe865
2018-09-07 16:10:41 -07:00
Theodore Abshire d32d951dde Added 'retry' event to networking engine
This makes NetworkingEngine a FakeEventTarget, and gives it a 'retry'
event which is fired when there is a recoverable error that results in
a retry.

Closes #1529

Change-Id: I0c15ed20f4d6abf971d280263c6d62841daf440e
2018-08-15 20:31:02 +00:00
Chris Fillmore 05731446ae Correct Casing On Constructor Function Name (#1507)
In "test/net/http_plugin_unit.js" we had a constructor that did not conform to proper standards causing some ESLint issues with some configurations (but not the project's current config).

Since the project style guide says that constructors/classes should start with a capital letter, this will be accepted regardless of the config not failing.

Closes #1506
2018-07-25 10:52:18 -07:00
Joey Parrish fd0449d8f7 Re-enable some disabled style rules
This re-enables the following style rules:
  - "block-spacing"
  - "brace-style"
  - "comma-dangle"
  - "comma-spacing"
  - "new-cap"
  - "no-multi-spaces"
  - "no-multiple-empty-lines"
  - "one-var"
  - "padded-blocks"
  - "prefer-rest-params"

Change-Id: I15d616e8d5b88b273ded6128b4f9ad86bdb26bd1
2018-07-09 19:44:56 +00:00
Michelle Zhuo 535de4db84 Refactor: Remove underscore from parameter names
Change-Id: Ie9e6fb59763f454f245175f23c6444f919ba8135
2018-05-08 19:21:51 +00:00
Sandra Lokshina 8065bd54a8 Change namespace from shakaExterns to shaka.externs
Change-Id: I16432351e2a266aa8fd175669aa27c44bfdffeae
2018-04-11 17:26:26 +00:00
Chris Fillmore 40e7524ed9 Catch BAD_HTTP_STATUS error thrown by makeResponse in xhr.onload (#1303)
Catch BAD_HTTP_STATUS error thrown by makeResponse in xhr.onload

Also wrap mock XHR event handlers in try-catch blocks in
http_plugin_unit to avoid regression.

Resolves #1302
2018-02-27 13:14:44 -08:00
Jacob Trimble 064089152b Remove spacing around object definitions.
This is an automated fix to be inline with Google style guides, this
was created with eslint's --fix option.

Change-Id: I860eecbc8152603e730aa17a1393f16d26b3b6fc
2018-02-21 13:35:00 -08:00
Jacob Trimble 624acc66b8 Add curly braces to all blocks.
Google style guide requires adding curly braces to all block statements
even if it is only has one line.  This fixes it by using eslint's
--fix flag followed by running clang-format to reformat the change.

Change-Id: Idc086c2aa8c02df5ef8b2140a11bfb9128eeb4bd
2018-02-21 11:23:34 -08:00
Jacob Trimble d47ab5c98c Disallow use of 'var'.
This also fixes some usages of 'var' that didn't get caught by the
previous CLs.

Change-Id: I4ce53d62d24e53e121d7eced70590836c1d26523
2018-02-20 22:43:30 +00:00
Jacob Trimble 0154dbc4d4 Convert 'var' to 'let'/'const' (6 of 9).
This is part of a change to convert all usages of 'var' with either
'let' or 'const'.  This takes a conservative approach for 'const' where
it will only be used for aliases and storing the "original" values in
tests.

Change-Id: I475eba0a477d13cd9201c88ad44899d521ad8991
2018-02-20 11:28:02 -08:00
Chris Fillmore 4ac1a40578 Provide RequestType in error data from HttpPlugin. (#1254)
Closes #1253
2018-02-12 10:01:58 -08:00
Theodore Abshire 35d8838ed3 Change null body to undefined in Fetch
Fetch requests with a method of GET or HEADER cannot have a body, or
else the request will fail. Normally we had no problems with this, but
it turns out that Edge counts a body of 'null' as being defined.
This changes the Fetch scheme plugin so that it will replace null with
undefined for the body in the init data.

This also makes it so that HTTP_ERROR errors emitted by the http
plugin will include the original error, to aid in debugging future
issues.

Change-Id: I0531656dada25f97ef610d4285c225d57d7ef262
2018-02-09 22:21:27 +00:00
theodab b4ca4bf51c Adds an HTTP/s scheme plugin using Fetch
This plugin is preferred over the XHR plugin, if available.
This plugin requires AbortController, which is only present on
Firefox 57 and Edge 16, so this will not be active on every platform.

This also adds a simple mock for the Fetch API for use with Jasmine.

Closes #829

Change-Id: Ifb79d29334fbfcfd175afe0706da5a3d5e452e2f
2018-02-08 23:11:53 +00:00
theodab abeb0ead7f Make net engine returns error when out of retries
When changing networking engine to use AbortableOperation, we had an
accidental regression. Now, when it runs out of retries, it rejects
with an error of "undefined" instead of with the actual error that was
causing it to retry.
This changes networking engine to save the last error and return with
that. It also modifies the unit tests to catch this problem.

Closes #1278

Change-Id: I8af9a81d7a8ad58d195a8e9f1af622ddbc3592f2
2018-02-07 17:52:05 +00:00
Joey Parrish 2f55d2a3bd Use AbortableOperation in networking
This uses AbortableOperation in all networking, from the scheme
plugins all the way to the request interface.

This also updates all default scheme plugins, docs, and sample code.

Backward compatibility is provided for scheme plugins and the
request API in NetworkingEngine.  This compatibility will be
removed in v2.5.

Two cancelation-related tests have been disabled in
player_integration until the new abort interface has been adopted
in the manifest parsers.

Issue #829

Change-Id: I91c8e6efe97798d111e8ddca5655cddc1f6bcbf3
2018-01-29 19:23:47 +00:00
Joey Parrish 374653abba [ES6] Use babel to preprocess tests
Once we start moving to ES6, uncompiled mode stops working on non-ES6
browsers (IE11 is the only one we test on).  We can disable uncompiled
mode in the demo, but we still want our tests to be uncompiled.  With
uncompiled library & tests, we can test units that are not exported
and even access private members that would otherwise be renamed.

For production/demo, Babel plays no role.  The Closure Compiler will
take in ES6 and spit out ES3 syntax (even older than ES5, so we can
at least run & fail a support check).

Babel will be used by Karma to preprocess all test and library code
before serving it from Karma.  This will allow us to use ES6 in both
the library and the tests, and still run uncompiled tests and test the
uncompiled library on ES5 browsers such as IE 11.

Issue #1157

Change-Id: Idd185d0e231d16b6df52babda777111e85890012
2018-01-05 20:10:42 +00:00
Michelle Zhuo d221339326 Remove empty lines in response header
Since IE/Edge returns the header with a leading new line('\n'), we need
to remove it from the response.

Closes #1172.

Change-Id: I133f9cfbada6486edc438f3dcbc37c7c78dbf36c
2017-12-12 18:03:01 +00:00
Theodore Abshire 7d23729c78 Add ability to cancel backoff early.
This adds the ability to supply an isCanceled() callback when making a
backoff object. If the callback is provided, the backoff will break the
timeout into a series of 200 MS timeouts, and check isCanceled() between
every segment.

This changes makes it so that, when canceling a load, you can quickly end
the current backoff. This will making canceling a load significantly faster,
especially if the player is on a late retry.

This still does not quite fix issue #1084 to my satisfaction; if the
manifest is currently downloading, the cancel will need to wait on that.
Canceling an in-progress manifest download will be yet another followup CL.

Issue #1084

Change-Id: I0a53310a9b521de375f2e128f63eaa133547c340
2017-11-06 13:57:58 -08:00
Theodore Abshire cbdf76d6aa Skip manifest load retries when destroying player
If the parser is failing to load a manifest, perhaps due to being offline,
and the player is destroyed mid-load, it will wait for all of the retries to
run out before canceling. This causes a significant wait time on destroy.
This change adds an optional isCanceled callback to the request method in
NetworkingEngine, allowing requests to be made that can be canceled via a
provided callback. This is then used to quickly skip past all of the
retries, when destroying the parser.

This doesn't stop any backoff in progress, so there still might be a delay of
a second or two (depending on networking settings, of course) if you destroy
during a backoff period. That will be changed in a followup CL.

Issue #1084

Change-Id: I0b99616ed4d5be078161122532ea271e84613170
2017-11-06 18:42:33 +00:00
theodab fefe93480d Allowed multiple plugins for one scheme
This modified the networking engine to store every plugin it is given
for a scheme, and adds a priority system to pick which of the plugins
to use.

Issue #829

Change-Id: I21a8a534383f2be898160d609d77efecfc2b684b
2017-11-03 22:38:55 +00:00
Joey Parrish 9f43c15d80 Factor out backoff code in NetworkingEngine
This extracts the delay, backoff, and fuzzing code from
NetworkingEngine in a way that can be used by other classes that need
this same backoff/retry behavior.

Issue #976

Change-Id: I2a370fc996e6f8f507768559c44cf7855e16abe1
2017-08-22 21:19:00 +00:00
Jacob Trimble 78fc6d9b36 Disallow unknown properties (2/5).
This is part of adding a new conformance rule to add additional type
safety.  This will disallow using properties of unknown types or using
unknown properties.

The first parts will be fixing errors caused by the new rule.  These
are backwards compatible, so can be applied before the rule is enabled.
Once all the errors and bugs are fixed, the rule will be enabled.

Change-Id: I48335fc6659d3c33a6d55b00d087b59410c79cf7
2017-06-27 19:47:42 +00:00
Jacob Trimble d8a3d8d2f7 Change jasmine.Spy type definition.
The old definition using a union with a Function causes problems.  The
compiler tends to treat this as an unknown type, so we loose type
safety.  The new types ensure full type safety, at the cost of needing
to "convert" the spy when it is used as a function.

Change-Id: I98ebd9dffd9cb865d0cf5d03db0fb5d6ea001ed3
2017-06-27 12:18:48 -07:00
Joey Parrish 22b736acc5 Fix NetworkingEngine unit test typo
The callback parameter should have a different name from the input
parameter for the comparison between requests to make sense.

Change-Id: I7157bc083d7b4a94fe59db0e5d3547db718af9f6
2017-05-03 09:13:30 -07:00
Jacob Trimble b5cbc01088 Don't retry for 401/403 HTTP codes.
Closes #620

Change-Id: I1df99cca6bb6a704b6ff055399298914d6e91e8f
2017-04-05 21:35:24 +00:00