Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

any postMessage to TestSwarm kills the test iframe #272

Open
jsgoupil opened this issue Jun 11, 2013 · 4 comments
Open

any postMessage to TestSwarm kills the test iframe #272

jsgoupil opened this issue Jun 11, 2013 · 4 comments

Comments

@jsgoupil
Copy link

Our tests use some parent.postMessage which usually points to ourselves (since we are the topmost)
However, in an iFrame scenario, that postMessage will post to TestSwarm. In this case, TestSwarm is configured to send anything to the server; on success, it kills the iFrame.
This causes the test to never resolve as it never posts its result back.

I agree my test should not post to a parent that it is not aware of, but at least, my test could fail instead of silently be stopped.

A mechanism should be in place to listen to a specific set of message such as
__TESTSWARM__restOfMessage
When run.js reads the message, if the first bytes don't start with that string constant, you could ignore the message.

@buley
Copy link

buley commented Dec 4, 2013

Thanks for posting this issue @jsgoupil. I can confirm this as responsible for my own Testswarm failures to save results: any non-Testswarm postMessage requests will kill off the iFrame, which cancels the load of additional resources and stops testing. I resolved this for my own needs using a namespacing approach.

I would recommend two updates:

I'd be happy to create a pull request with these changes if the project leaders are interested.

Background:
https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
http://msdn.microsoft.com/en-us/library/ie/cc197015(v=vs.85).aspx

@Krinkle
Copy link
Member

Krinkle commented Dec 4, 2013

Thanks @jsgoupil and @editor. Those are excellent suggestions.

How would the following changes sound?

  • Namespace the message (or leave some other kind of signature of property to identify itself) to avoid acting on unknown data.
  • When encountering any foreign data, treat it as a bad thing by aborting the test marking the test as failed (similarly to other meta-level errors such as "Uncaught Exception" and "Timed-out").

@buley
Copy link

buley commented Dec 4, 2013

Those changes, together, seem great @Krinkle. What we have today, more or less, is piece two without piece one.

These two changes wouldn't account for the sending of postMessage requests to anything else that iFrames a page with inject.js on it (https://github.com/jquery/testswarm/blob/master/js/inject.js#L130), but the "fix" of restricting messages to the Testswarm domain isn't strictly necessary to resolve this issue anyways (just seems to me like a courteous thing to do).

I'd be beyond happy to contribute any or all these two changes via pull request. Just let me know how I can help.

@Krinkle
Copy link
Member

Krinkle commented Dec 5, 2013

Restricting the target origin by using the swarmURL parameter sounds good as well, I have no opposition to that. It isn't strictly necessary, but it's a good habit.

I'd love to get a pull request for this. Let me know if you need any pointers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants