Closed Bug 1126362 Opened 10 years ago Closed 7 years ago

Add unit tests for navigating to a data: url containing an image

Categories

(Remote Protocol :: Marionette, defect, P2)

defect

Tracking

(firefox61 fixed)

RESOLVED FIXED
mozilla61
Tracking Status
firefox61 --- fixed

People

(Reporter: jgraham, Assigned: iceman, Mentored)

References

(Blocks 2 open bugs)

Details

(Keywords: pi-marionette-server, Whiteboard: [lang=py])

User Story

Please check the following URL in how to get started in contributing to Marionette:

https://dxr.mozilla.org/mozilla-central/source/testing/marionette/doc/NewContributors.md

For questions please let me know here or in #ateam on irc.mozilla.org.

Attachments

(1 file, 1 obsolete file)

If I (using the python client) navigate to a data: url containing a base64 encoded png image the navigate call never returns.
I believe this was solved by :whimboo’s excellent navigation work. Letting him confirm that.
Blocks: webdriver
Flags: needinfo?(hskupin)
OS: Linux → All
Priority: -- → P2
Hardware: x86_64 → All
Version: unspecified → Trunk
It works but we don't have a test for that. Given that all of our navigation tests are under Marionette harness unit tests we should add one there for now: https://dxr.mozilla.org/mozilla-central/source/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py The following test loads a 1px x 1px PNG file: > def test(self): > self.marionette.navigate("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==") We would need as best a test for the bfcache class, so we can verify `back()` and `forward()` at the same time.
Mentor: hskupin
User Story: (updated)
Flags: needinfo?(hskupin)
Priority: P2 → P5
Whiteboard: [lang=py]
Summary: Navigating to a data: url containing an image never finishes → Add unit tests for navigating to a data: url containing an image
Bumping to P2 then as that is conformance work.
Priority: P5 → P2
Mike, would you be interested on this bug?
Flags: needinfo?(mykhaylo.yusko)
(In reply to Henrik Skupin (:whimboo) from comment #4) > Mike, would you be interested on this bug? Hey Henrik, yes I'll work on the bug, could you provide a little bit more details? Thank you.
Flags: needinfo?(mykhaylo.yusko)
Mike, please see my comment 2. I think that all the necessary information is there already.
Comment on attachment 8953989 [details] Bug 1126362 - Add unit tests for navigating to a data: url containing an image https://reviewboard.mozilla.org/r/223144/#review229472 Thank you Mike for that first patch. It's good to see that you were able to figure out all the necessary changes yourself. Nevertheless I have a couple of comments which would need to be addressed. Once that has been done I will trigger a try build. Thank you! ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:29 (Diff revision 1) > > def inline(doc): > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > +def inline_image(base64_img): > + formatted_url = base64_img.replace('\n', '').replace(' ', '') Lets kill this line by having the image data in a single line, as mentioned below. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:30 (Diff revision 1) > def inline(doc): > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > +def inline_image(base64_img): > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > + base64_url = 'data:image/png;base64,' + formatted_url Strings shouldn't be concatenated by using `+`, but via a formatting like `%s` or `.format()`. See the `inline()` method above. Also the function argument can just be named `data`. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:31 (Diff revision 1) > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > +def inline_image(base64_img): > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > + base64_url = 'data:image/png;base64,' + formatted_url > + return base64_url There is no need to have this extra variable. You can directly return the computated value. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:33 (Diff revision 1) > +def inline_image(base64_img): > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > + base64_url = 'data:image/png;base64,' + formatted_url > + return base64_url > + > +FIRST_BASE64_IMAGE = """ What kind of image is that? Size, color, etc? Please put all base64 encoded data into a single line. If the linter complains we should add maybe #noqa to that line. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:39 (Diff revision 1) > + iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAY > + AAAAfFcSJAAAADUlEQVR42mNkYPhfDwACh > + wGA60e6kgAAAABJRU5ErkJggg== > +""" > + > +SECOND_BASE64_IMAGE = """ Same question as above for the other image. Lets make the name a bit more clear. Also please try to reduce this base64 encoded data so that it has a similar lenght like the first image. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:529 (Diff revision 1) > test_pages = [ > {"url": self.marionette.absolute_url("black.png")}, > {"url": self.marionette.absolute_url("white.png")}, > ] > self.run_bfcache_test(test_pages) > + Please note these red blocks as shown in mozreview. The linter should have complained about those. Did you ran `mach lint testing/marionette`? ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:531 (Diff revision 1) > {"url": self.marionette.absolute_url("white.png")}, > ] > self.run_bfcache_test(test_pages) > + > > + def test_image_urls(self): To be inline with the naming of other tests lets use `test_data_images`, and put the test close to `test_data_urls`. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:532 (Diff revision 1) > + image_urls = [ > + {"url": inline_image(FIRST_BASE64_IMAGE)}, A test like that tests that the navigation works fine between data images, which is one part. What I would like to see too is a navigation to a normal image. Something which "test_data_url" does for a HTML page. Please add that in the middle of this list.
Attachment #8953989 - Flags: review?(hskupin) → review-
(In reply to Henrik Skupin (:whimboo) from comment #8) > Comment on attachment 8953989 [details] > Bug 1126362 - Add unit tests for navigating to a data: url containing an > image > > https://reviewboard.mozilla.org/r/223144/#review229472 > > Thank you Mike for that first patch. It's good to see that you were able to > figure out all the necessary changes yourself. Nevertheless I have a couple > of comments which would need to be addressed. Once that has been done I will > trigger a try build. Thank you! > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 29 > (Diff revision 1) > > > > def inline(doc): > > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > > > +def inline_image(base64_img): > > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > > Lets kill this line by having the image data in a single line, as mentioned > below. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 30 > (Diff revision 1) > > def inline(doc): > > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > > > +def inline_image(base64_img): > > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > > + base64_url = 'data:image/png;base64,' + formatted_url > > Strings shouldn't be concatenated by using `+`, but via a formatting like > `%s` or `.format()`. See the `inline()` method above. > > Also the function argument can just be named `data`. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 31 > (Diff revision 1) > > return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) > > > > +def inline_image(base64_img): > > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > > + base64_url = 'data:image/png;base64,' + formatted_url > > + return base64_url > > There is no need to have this extra variable. You can directly return the > computated value. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 33 > (Diff revision 1) > > +def inline_image(base64_img): > > + formatted_url = base64_img.replace('\n', '').replace(' ', '') > > + base64_url = 'data:image/png;base64,' + formatted_url > > + return base64_url > > + > > +FIRST_BASE64_IMAGE = """ > > What kind of image is that? Size, color, etc? > > Please put all base64 encoded data into a single line. If the linter > complains we should add maybe #noqa to that line. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 39 > (Diff revision 1) > > + iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAY > > + AAAAfFcSJAAAADUlEQVR42mNkYPhfDwACh > > + wGA60e6kgAAAABJRU5ErkJggg== > > +""" > > + > > +SECOND_BASE64_IMAGE = """ > > Same question as above for the other image. Lets make the name a bit more > clear. > > Also please try to reduce this base64 encoded data so that it has a similar > lenght like the first image. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 529 > (Diff revision 1) > > test_pages = [ > > {"url": self.marionette.absolute_url("black.png")}, > > {"url": self.marionette.absolute_url("white.png")}, > > ] > > self.run_bfcache_test(test_pages) > > + > > Please note these red blocks as shown in mozreview. The linter should have > complained about those. Did you ran `mach lint testing/marionette`? > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 531 > (Diff revision 1) > > {"url": self.marionette.absolute_url("white.png")}, > > ] > > self.run_bfcache_test(test_pages) > > + > > > > + def test_image_urls(self): > > To be inline with the naming of other tests lets use `test_data_images`, and > put the test close to `test_data_urls`. > > ::: > testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py: > 532 > (Diff revision 1) > > + image_urls = [ > > + {"url": inline_image(FIRST_BASE64_IMAGE)}, > > A test like that tests that the navigation works fine between data images, > which is one part. What I would like to see too is a navigation to a normal > image. Something which "test_data_url" does for a HTML page. Please add that > in the middle of this list. Thank you for the review, I'll fix all your comments today, or tomorrow. Thanks!
Assignee: nobody → mykhaylo.yusko
Status: NEW → ASSIGNED
Comment on attachment 8953989 [details] Bug 1126362 - Add unit tests for navigating to a data: url containing an image https://reviewboard.mozilla.org/r/223144/#review231218 ::: commit-message-66e87:6 (Diff revision 3) > +Bug 1126362 - Add unit tests for navigating to a data: url containing an image r?whimboo > + > +MozReview-Commit-ID: GZg1BOY7tOj > + > +Bug 1126362 - Add unit tests for navigating to a data: url containing an image r?whimboo > +Bug 1126362 - Add unit tests for navigating to a data: url containing an image, also remove tralling spaces r?whimboo When you commit or run a histedit make sure to remove those extra commit messages at the bottom. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:25 (Diff revision 3) > ) > > here = os.path.abspath(os.path.dirname(__file__)) > > > +BLACK_IMAGE_PX1 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==' # noqa I would suggest to name the variables like `BLACK_PIXEL` and `RED_PIXEL`. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:414 (Diff revision 3) > {"url": inline("<p>foobar</p>")}, > ] > self.run_bfcache_test(test_pages) > > + def test_data_url(self): > + self.marionette.navigate(inline_image(BLACK_IMAGE_PX1)) This is not a valid bfcache test because it doesn't setup test_pages. Please remove this test also because it is testing what you already added in test_image_urls. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:419 (Diff revision 3) > + self.marionette.navigate(inline_image(BLACK_IMAGE_PX1)) > + > + def test_image_urls(self): > + image_urls = [ > + {"url": inline_image(BLACK_IMAGE_PX1)}, > + {"url": inline_image(RED_IMAGE_PX1)} Please make sure that we test the following states: - normal image - data image - data image - normal image And as mentioned the last time please move the test close to test_navigate_to_same_image_document_twice, or better extend the test with the above additional states.
Attachment #8953989 - Flags: review?(hskupin) → review-
Hello Henrik, I added the additional commit, and sorry that I did't `--amend`, I'm a little bit was confused with mercurial.
Flags: needinfo?(hskupin)
(In reply to Mike Yusko(:iceman) from comment #15) > Hello Henrik, I added the additional commit, and sorry that I did't > `--amend`, I'm a little bit was confused with mercurial. Please always amend fixes for review comments. Otherwise you won't get a r+. Also it's not necessary to set an additional needinfo flag when the review flag is set. I will see it in my inbox. Thanks.
Flags: needinfo?(hskupin)
(In reply to Henrik Skupin (:whimboo) from comment #16) > (In reply to Mike Yusko(:iceman) from comment #15) > > Hello Henrik, I added the additional commit, and sorry that I did't > > `--amend`, I'm a little bit was confused with mercurial. > > Please always amend fixes for review comments. Otherwise you won't get a r+. > Also it's not necessary to set an additional needinfo flag when the review > flag is set. I will see it in my inbox. Thanks. Yes Henrik, I know it, you mentioned concerning this case, a few weeks ago. I was amended a commits, but I didn't see their in my first commit. So, it's was forced step, sorry;(
Comment on attachment 8953989 [details] Bug 1126362 - Add unit tests for navigating to a data: url containing an image https://reviewboard.mozilla.org/r/223144/#review231616 ::: commit-message-66e87 (Diff revisions 3 - 4) > Bug 1126362 - Add unit tests for navigating to a data: url containing an image r?whimboo > > MozReview-Commit-ID: GZg1BOY7tOj > > Bug 1126362 - Add unit tests for navigating to a data: url containing an image r?whimboo > -Bug 1126362 - Add unit tests for navigating to a data: url containing an image, also remove tralling spaces r?whimboo Please remove that line. I would suggest that you check your uploaded patch before publishing it. It should only contain the appropriate changes. By having a look at the mozreview patch preview (click the last link when submitting a patch), you would have seen all this. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:499 (Diff revisions 3 - 4) > test_pages = [ > {"url": self.marionette.absolute_url("black.png")}, > {"url": self.marionette.absolute_url("white.png")}, > ] > self.run_bfcache_test(test_pages) > + There are white-spaces again, which should have caused linter failures. Please remember to always run the test after a modification, and to use the linter before submission.
Attachment #8953989 - Flags: review?(hskupin) → review-
Attachment #8956750 - Flags: review?(hskupin)
Attachment #8956750 - Attachment is obsolete: true
Comment on attachment 8953989 [details] Bug 1126362 - Add unit tests for navigating to a data: url containing an image https://reviewboard.mozilla.org/r/223144/#review232270 Mike, this looks way better now. Thank you for the update! There are three issues remaining to fix. Once that is done I can push the patch to try, and we can see how it works across platforms. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:25 (Diff revision 5) > ) > > here = os.path.abspath(os.path.dirname(__file__)) > > > +BLACK_PIXEL= 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==' # noqa nit: please add spaces around `=`. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:413 (Diff revision 5) > {"url": self.test_page_remote}, > {"url": inline("<p>foobar</p>")}, > ] > self.run_bfcache_test(test_pages) > > + This added extra line should cause again a linter failure. ::: testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py:500 (Diff revision 5) > {"url": self.marionette.absolute_url("black.png")}, > {"url": self.marionette.absolute_url("white.png")}, > ] > self.run_bfcache_test(test_pages) > > + def test_image_urls(self): You want to add the content of this test to `test_image_to_image`. Otherwise we would have duplication now.
Attachment #8953989 - Flags: review?(hskupin) → review-
The test looks fine to me now. I pushed a try build and will finally review once the tests in CI are done.
(In reply to Henrik Skupin (:whimboo) from comment #23) > The test looks fine to me now. I pushed a try build and will finally review > once the tests in CI are done. Nice!
Comment on attachment 8953989 [details] Bug 1126362 - Add unit tests for navigating to a data: url containing an image https://reviewboard.mozilla.org/r/223144/#review233256 Try job is green. So we can get this landed. Thank you Mike!
Attachment #8953989 - Flags: review?(hskupin) → review+
Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5a8f38951454 Add unit tests for navigating to a data: url containing an image r=whimboo
(In reply to Henrik Skupin (:whimboo) from comment #25) > Comment on attachment 8953989 [details] > Bug 1126362 - Add unit tests for navigating to a data: url containing an > image > > https://reviewboard.mozilla.org/r/223144/#review233256 > > Try job is green. So we can get this landed. Thank you Mike! Np;) I'll see you via IRC, and maybe we will find a new bugs for me. Thank you Henrik for the reviews!
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
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: