Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS HLS tests #2668

Merged
merged 8 commits into from
May 17, 2017
Merged

Add iOS HLS tests #2668

merged 8 commits into from
May 17, 2017

Conversation

machenmusik
Copy link
Contributor

Add tests and do minor refactoring per discussion on #2597

@machenmusik
Copy link
Contributor Author

Doing the tests was a bit ugly, but they are now fully functional; in particular, there is not a mechanism to mock things like AFRAME.utils.device.isIOS() without the ugly hack of temporarily modifying AFRAME.utils.device i.e. the scene.isIOS flag discussed in #2597 to make the tests easy does not exist.

@machenmusik machenmusik changed the title Add ios hls tests [WIP] Add ios hls tests May 13, 2017
@ngokevin
Copy link
Member

I meant In the system, if you change the utils.device.isIOS call to check the scene value, it should be easily mockable by setting the scene.isIOS.

@machenmusik
Copy link
Contributor Author

machenmusik commented May 13, 2017

aaargh, for some reason even though shader substitution test works on firefox and chrome on my machine, it fails on firefox in the cloud. :-/ gonna have to disable those tests for now as I don't have more time to spend on that

@machenmusik machenmusik changed the title [WIP] Add ios hls tests Add iOS HLS tests May 13, 2017
@@ -146,7 +146,7 @@ module.exports.System = registerSystem('material', {
setTextureProperties(texture, data);

// if we're on iOS, and the video is HLS, we currently need to do some hacks
if (utils.device.isIOS() && isHLS(videoEl)) {
if (utils.device.isIOS() && isHLS(videoEl.src || videoEl.getAttribute('src'), videoEl.type || videoEl.getAttribute('type'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, you tried changing utils.device.isIOS() here to this.el.sceneEl.isIOS, and in the test, try mocking sceneEl.isIOS = true before the assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i thought you were saying the substitution had already been done, so only changing the flag was necessary. if the function has to be monkey patched, not sure it is any clearer to do it as you suggest rather than directly manipulating to return desired value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the check for the property and if none the getAttribute value was unexpectedly required for both synthetic tests and actual real-world usage to work correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sceneEl.iIOS here so it doesn't have to run the user agent parse again, and you can stub it in the tests.

@@ -151,6 +151,13 @@ Checks if device is Gear VR. Returns a `boolean`.

Checks if device is a smartphone. Returns a `boolean`.

## `AFRAME.utils.material`

### `AFRAME.utils.material.isHLS (src, type)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has to be public API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it did to be accessible in tests...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public API meaning documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I understand you now.

@machenmusik
Copy link
Contributor Author

@ngokevin good now?

@@ -118,11 +120,16 @@ function handleTextureEvents (el, texture) {

// Video events.
if (!texture.image || texture.image.tagName !== 'VIDEO') { return; }

texture.image.addEventListener('loadeddata', function emitVideoTextureLoadedDataAll () {
// Check to see if we need to use iOS 10 HLS shader.
if (texture.needsCorrectionBGRA && texture.needsCorrectionFlipY) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do:

if (texture.needsCorrectionBGRA && texture.needsCorrectionFlipY &&
    ['standard', 'flat', 'testShader'].indexOf(el.components.material.data.shader) !== -1)

indexOf to be safe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I was considering is passing needsCorrectionBGRA and needsCorrectionFlipY into shaders in general when true, so someone with a custom shader would know when corrections are necessary. Thoughts?

@@ -152,6 +152,114 @@ suite('shader', function () {
instance.attributes['src']));
});

// Skip since this fails Travis CI Firefox run, even though it works on Chrome, and with local Firefox.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know where Firefox fails? Might be a timing issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but it is irrelevant since the actual substitution code won't be ever really be fired using Firefox, and I don't have the time to spare to investigate that

assert.notOk(initSpy.called);
assert.notOk(updateSpy.called);

// Mock iOS. NOTE: this doesn't work... el.sceneEl.isIOS = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas why this wouldn't work? We set the boolean and it checks the boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may work now (I didn't clean up the skipped tests per the last changes) but I don't have the time to spare to investigate that


// Mock iOS. NOTE: this doesn't work... el.sceneEl.isIOS = true;
var realIsIOS = AFRAME.utils.device.isIOS;
AFRAME.utils.device.isIOS = function () { return true; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.sinon.stub(AFRAME.utils.device.isIOS, () => true) might work, if we use sinon, the teardown will automatically restore it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps, but I don't have the time to spare to investigate that

done();
});
});
el.setAttribute('material', {shader: 'testShader', src: videoEl});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify testShader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, the original test on which this was based did so kept it, I don't have the time to spare to investigate that

el.setAttribute('material', {shader: 'testShader', src: videoEl});
var material = el.components.material;
var instance = material.shader;
assert.ok(instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to assert these, should keep focused on what we want to assert (e.g., the shader is switched)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original test on which this was based did so kept it

});

// Skip since this fails Travis CI Firefox run, even though it works on Chrome, and with local Firefox.
test.skip('iOS HLS video uses appropriate shader (setAttribute)', function (done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a large test, hard to spot what's different from the previous one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, maybe we should just remove the skipped tests for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one of the two tests should suffice, I can help try to simplify.

@machenmusik
Copy link
Contributor Author

@ngokevin if you have the time to tidy up whichever of the skipped tests you prefer and get rid of the other one, that should wrap this one up

@ngokevin
Copy link
Member

Will do right now, thanks!

@ngokevin ngokevin merged commit da71c5f into aframevr:master May 17, 2017
@ngokevin
Copy link
Member

ngokevin commented May 17, 2017

Cleaned up at a2d641a

  • The isIOS check worked for me
  • Rather than waiting for the video to load, I just mock the event
  • Remove extraneous assertions and other setup meant for other tests
  • FF works for me without waiting for the vid

@machenmusik
Copy link
Contributor Author

nice @ngokevin, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants