chromium/third_party/blink/web_tests/http/tests/websocket/send-object-tostring-check.html

<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description("WebSocket: Object's toString method should be called only once.");

window.jsTestIsAsync = true;

var testObj = new function() {
    this.callCounter = 0;
    this.toString = function() {
        this.callCounter++;
        return "Goodbye";
    };
}

var ws = new WebSocket("ws://127.0.0.1:8880/echo");

ws.onopen = function()
{
    ws.send(testObj);
};

ws.onmessage = function(event)
{
    shouldBeEqualToString("event.data", "Goodbye");
};

ws.onclose = function(event)
{
    shouldEvaluateTo("testObj.callCounter", 1);

    window.closeEvent = event;
    shouldBeTrue("closeEvent.wasClean");

    finishJSTest();
};
</script>
</body>
</html>