-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proxyless: fix 'window.postMessage' function (#7414)
- Loading branch information
1 parent
aed7683
commit 5534e34
Showing
10 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/functional/fixtures/api/es-next/iframe-switching/pages/message-event/cross-domain.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Cross-domain page</title> | ||
</head> | ||
<body> | ||
<h1>Cross-domain page</h1> | ||
<div> | ||
<strong>Received log</strong> | ||
<div id="received-log"></div> | ||
</div> | ||
<div> | ||
<strong>Interactions</strong> | ||
<input id="input"> | ||
</div> | ||
<script> | ||
function processMessageEventData (e) { | ||
let data = e.data; | ||
|
||
if (typeof data === 'string') | ||
data += ' processed'; | ||
else if (typeof data === 'object') | ||
data.processed = true; | ||
|
||
return data; | ||
} | ||
const receivedLog = document.getElementById('received-log'); | ||
|
||
window.addEventListener('message', e => { | ||
const text = JSON.stringify(e.data); | ||
const logEntry = document.createTextNode(text); | ||
|
||
receivedLog.appendChild(logEntry); | ||
|
||
e.source.postMessage(processMessageEventData(e), e.origin); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
45 changes: 45 additions & 0 deletions
45
test/functional/fixtures/api/es-next/iframe-switching/pages/message-event/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Index Page</title> | ||
</head> | ||
<body> | ||
<h1>Index Page</h1> | ||
<div> | ||
<button id="post-string-message">Post string message</button> | ||
<button id="post-object-message">Post object message</button> | ||
</div> | ||
<div> | ||
<strong>Received log</strong> | ||
<div id="received-log"></div> | ||
</div> | ||
<iframe id="cross-domain-iframe" src="http://localhost:3001/fixtures/api/es-next/iframe-switching/pages/message-event/cross-domain.html" style="width: auto; height: 300px"></iframe> | ||
<script> | ||
function postMessage (msg) { | ||
const crossDomainIframe = document.getElementById('cross-domain-iframe'); | ||
|
||
crossDomainIframe.contentWindow.postMessage(msg, 'http://localhost:3001'); | ||
} | ||
|
||
const receivedLog = document.getElementById('received-log'); | ||
const postStringMessageButton = document.getElementById('post-string-message'); | ||
const postObjectMessageButton = document.getElementById('post-object-message'); | ||
|
||
postStringMessageButton.addEventListener('click', () => { | ||
postMessage('string message'); | ||
}); | ||
|
||
postObjectMessageButton.addEventListener('click', () => { | ||
postMessage({ object: 'message' }); | ||
}); | ||
|
||
window.addEventListener('message', e => { | ||
const text = JSON.stringify(e.data); | ||
const logEntry = document.createTextNode(text); | ||
|
||
receivedLog.appendChild(logEntry); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/functional/fixtures/api/es-next/iframe-switching/testcafe-fixtures/message-event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Selector } from 'testcafe'; | ||
|
||
fixture `Message Event` | ||
.page('http://localhost:3000/fixtures/api/es-next/iframe-switching/pages/message-event/index.html'); | ||
|
||
test('test', async t => { | ||
const receivedLog = Selector('#received-log').addCustomDOMProperties({ | ||
trimmedInnerText: el => el.innerText.replace('\n', ''), | ||
}); | ||
|
||
await t | ||
.click('#post-string-message') | ||
.click('#post-object-message') | ||
.expect(receivedLog.trimmedInnerText).eql('"string message processed"{"object":"message","processed":true}') | ||
.switchToIframe('#cross-domain-iframe') | ||
.expect(receivedLog.trimmedInnerText).eql('"string message"{"object":"message"}') | ||
.typeText('#input', 'Text') | ||
.expect(Selector('#input').value).eql('Text') | ||
.switchToMainWindow(); | ||
}); |
34 changes: 34 additions & 0 deletions
34
test/functional/fixtures/hammerhead/worker/pages/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Worker</title> | ||
</head> | ||
<body> | ||
<h1>Worker</h1> | ||
<div> | ||
<input id="first"> * <input id="second"> = <input id="result"> | ||
</div> | ||
<script> | ||
const first = document.getElementById('first'); | ||
const second = document.getElementById('second'); | ||
const result = document.getElementById('result'); | ||
|
||
const worker = new Worker('worker.js'); | ||
|
||
function sendDataToWorker () { | ||
worker.postMessage({ | ||
first: first.value, | ||
second: second.value | ||
}); | ||
} | ||
|
||
first.oninput = sendDataToWorker; | ||
second.oninput = sendDataToWorker; | ||
|
||
worker.onmessage = function (e) { | ||
result.value = e.data; | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
onmessage = function (e) { | ||
const result = parseInt(e.data.first, 10) * parseInt(e.data.second, 10); | ||
|
||
postMessage(isNaN(result) ? '' : result); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('Worker', function () { | ||
it('Basic Worker', function () { | ||
return runTests('testcafe-fixtures/index.js', null, { skip: 'ie' }); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
test/functional/fixtures/hammerhead/worker/testcafe-fixtures/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Selector } from 'testcafe'; | ||
|
||
fixture `Worker` | ||
.page `http://localhost:3000/fixtures/hammerhead/worker/pages/index.html`; | ||
|
||
test('test', async t => { | ||
await t | ||
.typeText('#first', '2') | ||
.typeText('#second', '3') | ||
.expect(Selector('#result').value).eql('6'); | ||
}); |