Closed Bug 818287 Opened 12 years ago Closed 11 years ago

Screenshots include data URL prefix

Categories

(Remote Protocol :: Marionette, defect)

defect
Not set
normal

Tracking

(firefox28 fixed, b2g-v1.2 fixed)

RESOLVED FIXED
mozilla28
Tracking Status
firefox28 --- fixed
b2g-v1.2 --- fixed

People

(Reporter: davehunt, Assigned: sebastiaan)

Details

(Whiteboard: [mentor=davehunt][lang=py][good first bug])

Attachments

(2 files, 2 obsolete files)

The screenshots method states that it returns a base64 encoding string representation of the element/canvas, however it actually returns a data URL. This differs from WebDriver, and means we have to strip the leading characters when decoding the image.

By skipping the first 22 characters I'm able to use base64.decodestring in Python:

The data URL prefix:
data:image/png;base64,

We should either correct this to return a base64 encoded string, which can be prefixed for using as a data URL, or adjust the comment to indicate that a data URL will be returned.
Same we had with Mozmill. Please see bug 783223 how to do it.
(In reply to Henrik Skupin (:whimboo) from comment #1)
> Same we had with Mozmill. Please see bug 783223 how to do it.

How to do what? I already have working code as mentioned in comment 0. The fix here is either to return a base64 string as the documentation suggests, or adjust the documentation.
See the referenced bug and the NetUtil.asyncFetch() call which correctly transforms the dataURL to a stream you need.
This bug is concerning the Python client. Sorry for not being clear.
We should do whatever standard webdriver implementations do, which I'd guess is omit the data url prefix.  AutomatedTester?
Flags: needinfo?(dburns)
(In reply to Jonathan Griffin (:jgriffin) from comment #5)
> We should do whatever standard webdriver implementations do, which I'd guess
> is omit the data url prefix.  AutomatedTester?

Yea, I had originally left it in there so its useful for tbpl but we should follow spec and easily add in the prefix in the client code if need be
Flags: needinfo?(dburns)
Whiteboard: [mentor=davehunt][lang=py][good first bug]
Hi, I am new to the mozilla codebase and would like to work on this bug. I have worked in python previously but have no idea how to go about this. Can someone please help? 
Thank you.
Hey sud! Sorry for the delay, I just noticed your comment. What needs to happen here is the data URL prefix needs to be removed from the screenshots returned by Marionette.

The relevant code for Marionette is here: http://hg.mozilla.org/mozilla-central/file/065727546e13/testing/marionette/marionette-listener.js#l1851

Along with this change, we'll need to update gaiatest, which currently strips the data URL prefix. The code for this is here: https://github.com/mozilla/gaia-ui-tests/blob/master/gaiatest/runtests.py#L60

We'll need to submit the change to gaia-ui-tests at the same time as the server-side change to avoid test failures.

Let me know if you have any questions. You can also find me on IRC in #automation or #ateam.
Assignee: nobody → s.shekhar211
I just noticed your mention of Python, however you'll find the server side is actually JavaScript. Let me know if this is an issue, otherwise I'm happy to mentor you through it! :)
Hey Dave,

I thought the bug was in python. But I have worked in JavaScript before and would be happy to help. Will catch you on the irc then. :)
Hi,
I went through the code and realized that simply doing :

var base64str = canvas.toDataURL("image/png","")[22:]
sendResponse({value: base64str}, msg.json.command_id);

would be enough as the gaia tests add the prefix when they check the Data/Url.

Please confirm whether this is all that's required or have I misunderstood something?
Rather than hard-code the number of characters, could we split on the first occurrence of comma? Otherwise, your approach looks fine to me.
Hey Dave,
Sorry for the delay, I was out of town for a while.

I believe the following lines:

var str = canvas.toDataURL("image/png","");
var URLlength =str.indexOf(",");
var base64str = str.substring(n+1);
sendResponse({value: base64str}, msg.json.command_id);


Finish your problem. Please confirm this once. Also, please guide me on how to proceed from here. I tried to catch you on the irc but you weren't active at that time.
Sorry that was 

base64str = str.substring(URLlength+1); 

in the code above.
This approach looks good to me. I would use a more descriptive name than just 'str' though, perhaps 'data_url'. Also, you don't need to store URLlength or base64str as they're only used once, so you can just use:

var data_url = canvas.toDataURL("image/png","");
sendResponse({value: data_url.substring(data_url.indexOf(",") + 1)}, msg.json.command_id);

If you're ready to work on a patch, you will need to clone the mozilla-central repository, make your changes, and attach a diff to this bug. Follow the guide here, and ping me if you get stuck: https://developer.mozilla.org/en-US/docs/Mercurial_FAQ

Note that you will also need to update the tests so they're no longer expecting the data url prefix. You can find these here: http://hg.mozilla.org/mozilla-central/file/default/testing/marionette/client/marionette/tests/unit/test_screenshot.py
Hey sud, are you still interesting on fixing this? If not, we can free it up for someone else to look at.
Flags: needinfo?(s.shekhar211)
Assigning this to :kyr0 as he's expressed interest in it, and there's been no response from sud. If you're still interested, sud, I'm sure we can find something else for you to work on.
Assignee: s.shekhar211 → sebastiaan
Flags: needinfo?(s.shekhar211)
Stage 2 will be the marionette update.
Stage 3 will be the removal of this condition
Attachment #825896 - Flags: review?(dave.hunt)
https://hg.mozilla.org/mozilla-central/rev/3ea1f8e46b87
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
There are still a couple more patches to land before this can be considered resolved.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attached patch 818287.patch (obsolete) — Splinter Review
Stage 2: The change to the return of the screenshot function in marionette.
Attachment #826755 - Flags: review?(dave.hunt)
Comment on attachment 826755 [details] [diff] [review]
818287.patch

Review of attachment 826755 [details] [diff] [review]:
-----------------------------------------------------------------

The change looks good but we need to update the tests too. See comment 15 for the location of these.

::: testing/marionette/marionette-listener.js
@@ +1934,5 @@
>        ctx.strokeRect(rect.left + offsetX, rect.top + offsetY, rect.width, rect.height);
>      }
>    }
>  
> +  // Return the data URL String back to the client bindings and they can manage

We're actually only now passing back the Base64 string. Previously we were passing back the whole data URL.
Attachment #826755 - Flags: review?(dave.hunt) → review-
Attachment #826755 - Attachment is obsolete: true
Attachment #828626 - Flags: review?(dave.hunt)
Comment on attachment 828626 [details] [diff] [review]
Corrected the patch with regards to comment 15.

Review of attachment 828626 [details] [diff] [review]:
-----------------------------------------------------------------

Just a minor nit with the comment.

::: testing/marionette/marionette-listener.js
@@ +1934,5 @@
>        ctx.strokeRect(rect.left + offsetX, rect.top + offsetY, rect.width, rect.height);
>      }
>    }
>  
> +  // Return the data URL String back to the client bindings and they can manage

As mentioned in previous review, please revert the change to the comment.
Attachment #828626 - Flags: review?(dave.hunt) → review-
Attached patch nit addressed.Splinter Review
Attachment #828626 - Attachment is obsolete: true
Attachment #829311 - Flags: review?(dave.hunt)
Comment on attachment 829311 [details] [diff] [review]
nit addressed.

Review of attachment 829311 [details] [diff] [review]:
-----------------------------------------------------------------

Looks great. Triggered a try run:
https://tbpl.mozilla.org/?tree=Try&rev=244d344c2aa8
Attachment #829311 - Flags: review?(dave.hunt) → review+
Landed as:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4fbb4e40ee25
Status: REOPENED → RESOLVED
Closed: 11 years ago11 years ago
Resolution: --- → FIXED
Not landed on mozilla-central yet. Reopening until that is the case.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
https://hg.mozilla.org/mozilla-central/rev/4fbb4e40ee25
Status: REOPENED → RESOLVED
Closed: 11 years ago11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: