Closed Bug 1590451 Opened 5 years ago Closed 2 years ago

Use "SpecialPowers.spawn" instead of "Runtime.evaluate" in non-Runtime tests

Categories

(Remote Protocol :: CDP, task, P3)

task

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: impossibus, Unassigned, Mentored)

Details

(Whiteboard: [lang=js])

Attachments

(1 file)

When testing the remote agent, we should aim to use only the domain under test whenever possible.

For example, here we're testing Input, and we're using another protocol method, Runtime.evaluate to do so. However, content.eval in ContentTask.spawn could probably be used instead.

https://searchfox.org/mozilla-central/rev/55aa17110091deef24b913d033ccaf58f9c6d337/remote/test/browser/browser_input_dispatchKeyEvent_race.js#92-99

(This is a follow-up from https://phabricator.services.mozilla.com/D47032?id=170493#inline-296911)

Priority: -- → P3
Whiteboard: [puppeteer-alpha]
Priority: P3 → P5

I don't see how a P5 should be a puppteer-alpha blocker. Removing it from that blocking list.

Otherwise this is great for a mentored bug. Example for ContentTask.span() we already have a lot under /remote/test/browser:

https://searchfox.org/mozilla-central/search?q=ContentTask.spawn&path=remote%2Ftest%2Fbrowser

Once the change has been made, make sure to run the specific test and that it passes:

./mach test remote/test/browser/input/browser_dispatchKeyEvent_race.js

Note that since the bug has been filed, the location of the originally targeted file has been changed.

Mentor: hskupin
Whiteboard: [puppeteer-alpha] → [lang=js]

Hi, I've been working with these files from another bug and I'd like to take on this bug too. Is it still available?

Yes, you can if you want to work on multiple bugs in parallel. But please do not over-commit, and just pick bugs whenever you are actually free to work on them. Thanks!

Hi, I'm looking to clarify what needs to be done.
I can see the use of "Runtime.evaluate()" in "checkWindowTestValue" in "browser_dispatchKeyEvent_race.js".
And I've looked at the examples of "ContentTask.spawn()" being used.
Do I need to simply replace "Runtime.evaluate()" with "ContentTask.spawn()" as spawn() seems to take in different arguments than whats given to evaluate()?

It's not a simple replacement, but close. The essential is to take whatever expression is passed to Runtime.evaluate and get it executed in the scope of the html document loaded by the test. We want to do that with ContentTask.spawn instead and remove all references to Runtime.

The other tests in https://searchfox.org/mozilla-central/rev/4df8821c1b824db5f40f381f48432f219d99ae36/remote/test/browser/input/ have lots of examples.

The third arg to ContentTask.spawn is a function that will get executed in a special "frame script" in the document that is currently loaded in the browser. In the scope of that function, the content variable gives you access to the page, I believe. content.eval let's you evaluate expressions on the page's global.

Assignee: nobody → walshd9

I've submitted my first attempt. The tests seem to run the same as they did before.

Please note that with bug 1596918 we are now going to get rid of ContentTask.spawn in favor of SpecialPowers.spawn. Beside changing the method name, also the 2nd argument will have to obeyed which seems to have to be changed from null to [].

Summary: Use ContentTask.spawn instead of Runtime.evaluate in non-Runtime tests → Use "SpecialPowers.spawn" instead of "Runtime.evaluate" in non-Runtime tests

Dan, will you have time to update the patch based on whimboo’s latest feedback?

Flags: needinfo?(walshd9)
Priority: P5 → P3

We haven't heard back from Dan on several other bugs so I assume that he is not continuing on this bug.

Assignee: walshd9 → nobody
Flags: needinfo?(walshd9)

I want to work on this bug

Please, go ahead. If you have any questions, you can post comments on this bug.

Hello all, is anyone actively working on this bug? If not, may I have a crack at it?

Hi Lupita. Great to see that you have interest to work on this bug. Feel free to get started, and have a look at the already attached patch and my comment 8. Let me know when you have more questions.

Thank you, Henrik! I've looked at the attached patch, and it doesn't pass the tests. I've modified the browser_dispatchKeyEvent_race.js as so:
const result = await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
return context.eval("window.testValue");
However, I get a referenceError claiming "context" is not defined, and I'm not sure why. Any help is appreciated. Thanks :)

You don't need the context in the content function. Just return window.testValue. The right tab is selected by gBrowser.selectedBrowser and that's enough.

Hi Lupita. I just want to check back with you, do you have any further questions?

Flags: needinfo?(stormie.arroyo)

Given that Lupita didn't respond on this bug it's open to get picked-up by someone else.

Flags: needinfo?(stormie.arroyo)
Component: CDP: Input → CDP

Henrik, is it alright if I commandeer the patch? I found this bug while searching for more information regarding SpecialPowers.spawn.

Based on reading Maja's comment it seems that the only file that needs to be changed in the test directory is browser_dispatchKeyEvent_race.js, although that comment was from a few years ago. Does the statement remain true? There are a couple instances of Runtime.evaluate inside the test directory but outside of runtime/.

Flags: needinfo?(hskupin)

Hi James. Thanks for the question. It's a bug that bitrotted a bit.

Thinking more about the requested change here I feel that we probably should keep what we have right now and not convert any usage of Runtime.evaluate. The benefit from the current code is that we have a way better test coverage for this API, which we would loose when using the standard SpecialPowers.spawn method. Also work on CDP is on hold.

As such I think lets close this bug as wontfix. If needed we could re-evaluate at a later time.

Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(hskupin)
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: