Skip to content

Conversation

mzboray
Copy link

@mzboray mzboray commented Aug 8, 2020

Summary: [summary of the change and which issue is fixed here]

  • Added tests to the JavascriptBinding integration tests.

Changes: [specify the structures changed]

  • Added IntegrationTestFacts.JavascriptsEventsReceived
  • Added JavascriptTestWebBrowser to simplify setup

How Has This Been Tested?
Yup just tests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Updated documentation
  • Tests

Checklist:

  • Tested the code(if applicable)
  • Commented my code
  • Changed the documentation(if applicable)
  • New files have a license disclaimer
  • The formatting is consistent with the project (project supports .editorconfig)

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@mzboray
Copy link
Author

mzboray commented Aug 8, 2020

The tests seemed to work. I'll see if I can reproduce on my machines, since I had to simply a little to bring over the code.

@amaitland
Copy link
Member

Thanks, I'll have a look when I have a moment.

@amaitland
Copy link
Member

It's possible that the Javascript you are injecting in OnContextCreated is called after the window.dispatchEvent calls.

Javascript is executed in the render process, in CEF terms your application is referred to as the browser process. IPC messages are sent in an async fashion. Whilst Chromium supports sync messages the CEF API limits us to sending only async messages.

Render Process -> Sends OnContextCreated message over IPC to Browser Process
Browser Process -> Sends ExecuteJavaScriptAsync message over IPC to Render Process

If this happens after the V8 Engine has executed the page script you'll have missed the events.

CefSharp doesn't currently run it's tests in parallel as to limit the resource usage on the free appveyor host we're using. I suspect if you run with higher load you are more likely to see issues.

In this scenario it would be better use to use Page.addScriptToEvaluateOnNewDocument command via the DevTools protocol (#3158)

@amaitland amaitland changed the title Add tests for receiving cefsharp.postmessage registered in OnContextCreated Test - Add Cefsharp.PostMessage test with script injection via IRenderProcessMessageHandler.OnContextCreated Aug 14, 2020
@amaitland
Copy link
Member

As part of #3229 I've added a PostMessage test that uses Page.addScriptToEvaluateOnNewDocument

See b2f0dab#diff-f0c38402ef111b766d0726ea3818f1f6R38

Closing as this test could potentially be unreliable as detailed above.

@amaitland amaitland closed this Sep 18, 2020
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