@DonnaWuDongxia I think we could simplify the test case without creating DOM element manually and using setTimeout. The following is for your reference.

The `broadcast.html` would be:
```
<html>
<head>
	<title></title>
</head>
<body>
<iframe id="subFrame"></iframe>
<script>
var iframe = document.getElementById("subFrame");

// Write the iframe content. Might be better to put it into a separate html file. 
iframe.contentDocument.write("
<html>
	<script>
		var messageReceivedInIframe = null;
		function messageHandler (msg) {
			messageReceivedInIframe = msg;
			if (top.window.messageReceivedInIframe != null)
				top.window.verifyResult();
		}
	</script>
</html>");

// Drive the native side to broadcast a message to all frames.
broadcast.trigger(msg);

// Verify the message received in both top window and iframe window. 
// Called only when both top window and iframe receive the message from native side.
var expected_msg = "XXX";
function verifyResult() {
	if (iframe.contentWindow.receivedMessageInIframe === expected_message &&
		window.receivedMessageInTop == expected_message)
		document.title = "PASS"
	else document.title = "FAIL";
}

var messageReceivedInTop = null;
function messageHandler(msg) {
	messageReceivedInTop = msg;
	if (iframe.contentWindow.messageReceivedInIframe != null)
		verifyResult();
}
</script>
</body>
<html>
```

and the JS code piece in extension code would be:
```
extension.setMessageListener(function(msg) { messageHandler(msg); })
...
```

Right now, we don't need to create a DOM element to save the received message, and also setTimeout usage is removed. Can you have a try? Thanks.