Skip to content

Update webview-helpers to handle crosswalk webviews #238

Merged
imurchie merged 2 commits intoappium:masterfrom
blutter:fix-crosswalk-webviews
May 18, 2017
Merged

Update webview-helpers to handle crosswalk webviews #238
imurchie merged 2 commits intoappium:masterfrom
blutter:fix-crosswalk-webviews

Conversation

@blutter
Copy link
Copy Markdown
Contributor

@blutter blutter commented May 17, 2017

There has been a long running issue with finding crosswalk webviews on Android as logged in appium/appium#4597

There is a two part fix:

  1. Fix chromedriver (there is a patch in codereview at https://codereview.chromium.org/2375613002/)
  2. Update appium-android-driver to find the corresponding crosswalk webviews (this PR)

I have updated the tests to cover this scenario and implemented the changes to the webview-helper code.

Copy link
Copy Markdown
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

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

@blutter thanks for taking this on! it's a huge win. I made a small comment. Otherwise if I'm reading this right, it shouldn't hurt to merge this in even before chromedriver is updated, right? It just won't find anything yet? Or do we need to hold off on this until the Chromedriver update?

Comment thread lib/webview-helpers.js Outdated
let webviewPid;
let crosswalkWebviewSocket;

if ((webviewPid = line.match(new RegExp(WEBVIEW_REGEXP)))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this block looks duplicated; should we pull it out of the conditional so it's not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure - I originally pulled it up out of the conditional but didn't think it was as readable.

I'll have another go at refactoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok - updated with an alternative to avoid DRY

@blutter
Copy link
Copy Markdown
Contributor Author

blutter commented May 17, 2017

Thanks. It shouldn't hurt to merge this before chromedriver is updated as it is already broken for crosswalk webviews. The only risk is that the chromedriver patch gets some further changes down the track that break my changes. But given that it is already broken I would prefer that this change goes in now as it means one less thing for my team to maintain/patch.

Copy link
Copy Markdown
Contributor

@imurchie imurchie left a comment

Choose a reason for hiding this comment

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

Awesome!

My only comment would be that the regular expressions ought to be actual regular expressions. They are all constant (not dependent on any input from any runtime systems) so they can be real constants at the top, and not need to be made into RegExp objects right before using.

Also, can you run gulp eslint? There is an error that is causing CI to fail (https://travis-ci.org/appium/appium-android-driver/jobs/233108399#L3317).

Comment thread lib/webview-helpers.js Outdated
// same as chrome-backed webviews)
// TODO: some of this function belongs in appium-adb
async function webviewsFromProcs (adb, deviceSocket) {
const WEBVIEW_REGEXP = `@?webview_devtools_remote_(\\d+)`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just make this a RegExp object and skip the step in line 38. It could also go above wth the rest of the constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Though IMHO I consider this less readable as the scope of the constant is only the function.

Comment thread lib/webview-helpers.js Outdated
// not some other running app
// TODO: this should be called procFromPid and exist in appium-adb
async function procFromWebview (adb, webview) {
if (webview.match(new RegExp(WEBVIEW_BASE + "(\\d+)")) === null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use string interpolation instead of concatenating strings

`${WEBVIEW_BASE}(\\d+)`

This is also constant, so could be a constant like the other regular expressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done as well

Comment thread lib/webview-helpers.js Outdated
if (deviceSocket)
{
if (crosswalkWebviewSocket[0].slice(1) === deviceSocket) {
webviews.push(WEBVIEW_BASE + crosswalkWebviewSocket[1]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

String interpolation here and line 49.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks - Done

Copy link
Copy Markdown
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

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

agree with isaac's subsequent feedback, then we should be good to go

@blutter blutter force-pushed the fix-crosswalk-webviews branch from e8fc425 to 6881325 Compare May 18, 2017 07:09
@blutter
Copy link
Copy Markdown
Contributor Author

blutter commented May 18, 2017

I've also fixed the eslint issue.

@imurchie imurchie merged commit 11072c9 into appium:master May 18, 2017
@blutter blutter deleted the fix-crosswalk-webviews branch May 18, 2017 23:09
vrunoa pushed a commit to vrunoa/appium-android-driver that referenced this pull request Jul 16, 2017
* Update webview-helpers to handle crosswalk webviews

* Refactor with code review feedback
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.

3 participants