apache / cordova-plugin-screen-orientation

Apache Cordova Screen Orientation Plugin
https://cordova.apache.org/
Apache License 2.0
219 stars 229 forks source link

fix(chrome): lock test #105

Closed breautek closed 2 years ago

breautek commented 2 years ago

Platforms affected

Browser

Motivation and Context

Fixes a failing test:

1) cordova-plugin-screen-orientation-tests.tests >> window.screen.orientation should successfully lock and unlock screen orientation
  - Expected 'landscape-primary' to match /^portrait-/.

Description

The fix isn't truly a fix, but I don't think this issue is fixable. Previously this worked when the browser had no screen orientation API I believe, but modern versions of browser does. Just because the API exists however doesn't mean it's usable. Chrome on desktop will have the API exists but attempting to use it will result with a DOMException stating that the device isn't supported for locking.

Additionally, testing this specific case is also problematic because the lock promise still gets resolved without rejection. You cannot catch or otherwise capture the DOMException. The DOMException is only ever printed to the JS console if you attempt to run the code without anything catching the promise (and the promise is then resolved later).

It's not something I really like, but I don't think we have a better option, and I think this is better than having a false negative test.

The old unit test still exists, but is hidden behind a isLockable flag. It's generally expected that mobile devices will have a working lock API, should the browser cordova app ever be loaded on a mobile browser, therefore isLockable is set to true if it is believed the test is running on a mobile device (based on some userAgent keywords). This is however untested because I don't think we have a way to test browser platform on a mobile device.

Testing

Ran cordova-paramedic manually.

Checklist