WebSocket: Copy existing WebSocket tests
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 07:51:22 +0000 (07:51 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 07:51:22 +0000 (07:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=64242

Reviewed by Kent Tamura.

Copy the existing WebSocket tests under http/tests/websocket/tests/hybi/ and skip them.

These tests will be used to test the latest WebSocket protocol implementation. They are skipped
in all ports for now, and will be unskipped when the new protocol implementation is landed in WebCore.

The following modifications are applied to the new tests:
- Change paths and URLs appeared in the tests and the test results so they fit for the new location.
- Call layoutTestController.overridePreferences() to enable the new protocol implementation.

* http/tests/websocket/tests/hybi/alert-in-event-handler-expected.txt: Added.
* http/tests/websocket/tests/hybi/alert-in-event-handler.html: Added.
* http/tests/websocket/tests/hybi/bad-handshake-crash-expected.txt: Added.
* http/tests/websocket/tests/hybi/bad-handshake-crash.html: Added.
* http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars-expected.txt: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars.html: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-empty-expected.txt: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-empty.html: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii-expected.txt: Added.
* http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii.html: Added.
* http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt: Added.
* http/tests/websocket/tests/hybi/bufferedAmount-after-close.html: Added.
* http/tests/websocket/tests/hybi/client-close-expected.txt: Added.
* http/tests/websocket/tests/hybi/client-close.html: Added.
* http/tests/websocket/tests/hybi/client-close_wsh.py: Added.
* http/tests/websocket/tests/hybi/close-before-open-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-before-open.html: Added.
* http/tests/websocket/tests/hybi/close-event-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-event.html: Added.
* http/tests/websocket/tests/hybi/close-on-navigate-new-location-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-on-navigate-new-location.html: Added.
* http/tests/websocket/tests/hybi/close-on-unload-and-force-gc-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-on-unload-and-force-gc.html: Added.
* http/tests/websocket/tests/hybi/close-on-unload-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent.html: Added.
* http/tests/websocket/tests/hybi/close-on-unload.html: Added.
* http/tests/websocket/tests/hybi/close-on-unload_wsh.py: Added.
* http/tests/websocket/tests/hybi/close-unref-websocket-expected.txt: Added.
* http/tests/websocket/tests/hybi/close-unref-websocket.html: Added.
* http/tests/websocket/tests/hybi/cross-origin-expected.txt: Added.
* http/tests/websocket/tests/hybi/cross-origin.html: Added.
* http/tests/websocket/tests/hybi/echo-challenge_wsh.py: Added.
* http/tests/websocket/tests/hybi/echo-cookie_wsh.py: Added.
* http/tests/websocket/tests/hybi/echo-location_wsh.py: Added.
* http/tests/websocket/tests/hybi/echo_wsh.py: Added.
* http/tests/websocket/tests/hybi/error-detect-expected.txt: Added.
* http/tests/websocket/tests/hybi/error-detect.html: Added.
* http/tests/websocket/tests/hybi/fixed-origin_wsh.py: Added.
* http/tests/websocket/tests/hybi/frame-length-longer-than-buffer-expected.txt: Added.
* http/tests/websocket/tests/hybi/frame-length-longer-than-buffer.html: Added.
* http/tests/websocket/tests/hybi/frame-length-longer-than-buffer_wsh.py: Added.
* http/tests/websocket/tests/hybi/frame-length-overflow-expected.txt: Added.
* http/tests/websocket/tests/hybi/frame-length-overflow.html: Added.
* http/tests/websocket/tests/hybi/frame-length-overflow_wsh.py: Added.
* http/tests/websocket/tests/hybi/frame-length-skip-expected.txt: Added.
* http/tests/websocket/tests/hybi/frame-length-skip.html: Added.
* http/tests/websocket/tests/hybi/frame-length-skip_wsh.py: Added.
* http/tests/websocket/tests/hybi/frame-lengths-expected.txt: Added.
* http/tests/websocket/tests/hybi/frame-lengths.html: Added.
* http/tests/websocket/tests/hybi/handshake-challenge-randomness-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-challenge-randomness.html: Added.
* http/tests/websocket/tests/hybi/handshake-error-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-error.html: Added.
* http/tests/websocket/tests/hybi/handshake-error_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-maxlength-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-maxlength.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-cr-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-cr.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch.html: Added.
* http/tests/websocket/tests/hybi/hanging-handshake_wsh.py: Added.
* http/tests/websocket/tests/hybi/httponly-cookie-expected.txt: Added.
* http/tests/websocket/tests/hybi/httponly-cookie.pl: Added.
* http/tests/websocket/tests/hybi/long-invalid-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/long-invalid-header.html: Added.
* http/tests/websocket/tests/hybi/long-invalid-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/multiple-connections-expected.txt: Added.
* http/tests/websocket/tests/hybi/multiple-connections.html: Added.
* http/tests/websocket/tests/hybi/no-query_wsh.py: Added.
* http/tests/websocket/tests/hybi/null-character-expected.txt: Added.
* http/tests/websocket/tests/hybi/null-character.html: Added.
* http/tests/websocket/tests/hybi/origin-test_wsh.py: Added.
* http/tests/websocket/tests/hybi/protocol-test_wsh.py: Added.
* http/tests/websocket/tests/hybi/reload-crash-expected.txt: Added.
* http/tests/websocket/tests/hybi/reload-crash.html: Added.
* http/tests/websocket/tests/hybi/resources/close-on-unload-iframe-reference-in-parent.html: Added.
* http/tests/websocket/tests/hybi/resources/close-on-unload-iframe.html: Added.
* http/tests/websocket/tests/hybi/resources/reload-crash-iframe.html: Added.
* http/tests/websocket/tests/hybi/send-after-close-on-unload-expected.txt: Added.
* http/tests/websocket/tests/hybi/send-after-close-on-unload.html: Added.
* http/tests/websocket/tests/hybi/send-expected.txt: Added.
* http/tests/websocket/tests/hybi/send-throw-expected.txt: Added.
* http/tests/websocket/tests/hybi/send-throw.html: Added.
* http/tests/websocket/tests/hybi/send.html: Added.
* http/tests/websocket/tests/hybi/send2_wsh.py: Added.
* http/tests/websocket/tests/hybi/send_wsh.py: Added.
* http/tests/websocket/tests/hybi/server-close-expected.txt: Added.
* http/tests/websocket/tests/hybi/server-close.html: Added.
* http/tests/websocket/tests/hybi/server-close_wsh.py: Added.
* http/tests/websocket/tests/hybi/simple-expected.txt: Added.
* http/tests/websocket/tests/hybi/simple-stress-expected.txt: Added.
* http/tests/websocket/tests/hybi/simple-stress.html: Added.
* http/tests/websocket/tests/hybi/simple.html: Added.
* http/tests/websocket/tests/hybi/simple_wsh.py: Added.
* http/tests/websocket/tests/hybi/sub-protocol-expected.txt: Added.
* http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt: Added.
* http/tests/websocket/tests/hybi/sub-protocol-with-space.html: Added.
* http/tests/websocket/tests/hybi/sub-protocol.html: Added.
* http/tests/websocket/tests/hybi/unicode-expected.txt: Added.
* http/tests/websocket/tests/hybi/unicode.html: Added.
* http/tests/websocket/tests/hybi/unicode_wsh.py: Added.
* http/tests/websocket/tests/hybi/unknown-frame-type_wsh.py: Added.
* http/tests/websocket/tests/hybi/url-no-trailing-slash-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-no-trailing-slash.html: Added.
* http/tests/websocket/tests/hybi/url-parsing-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-parsing.html: Added.
* http/tests/websocket/tests/hybi/url-with-credential-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-with-credential.html: Added.
* http/tests/websocket/tests/hybi/url-with-empty-query-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-with-empty-query.html: Added.
* http/tests/websocket/tests/hybi/url-with-query-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-with-query-for-no-query-expected.txt: Added.
* http/tests/websocket/tests/hybi/url-with-query-for-no-query.html: Added.
* http/tests/websocket/tests/hybi/url-with-query.html: Added.
* http/tests/websocket/tests/hybi/websocket-event-target-expected.txt: Added.
* http/tests/websocket/tests/hybi/websocket-event-target.html: Added.
* http/tests/websocket/tests/hybi/websocket-pending-activity-expected.txt: Added.
* http/tests/websocket/tests/hybi/websocket-pending-activity.html: Added.
* http/tests/websocket/tests/hybi/websocket-protocol-ignored-expected.txt: Added.
* http/tests/websocket/tests/hybi/websocket-protocol-ignored.html: Added.
* http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash.html: Added.
* http/tests/websocket/tests/hybi/workers/close-in-shared-worker-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html: Added.
* http/tests/websocket/tests/hybi/workers/close-in-worker-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/close-in-worker.html: Added.
* http/tests/websocket/tests/hybi/workers/resources/close-in-onmessage-crash.js: Added.
(runTests.try.ws.onopen):
(runTests.try.ws.onmessage):
(runTests.try.ws.onclose):
(runTests):
* http/tests/websocket/tests/hybi/workers/resources/close-in-worker.js: Added.
(handleConnect.self.postMessage):
(handleConnect):
(runTests.try.ws.onopen):
(runTests.try.ws.onclose):
(runTests):
* http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py: Added.
* http/tests/websocket/tests/hybi/workers/resources/echo_wsh.py: Added.
* http/tests/websocket/tests/hybi/workers/resources/simple_wsh.py: Added.
* http/tests/websocket/tests/hybi/workers/resources/worker-handshake-challenge-randomness.js: Added.
(endTest):
(runTests.try.ws1.onmessage):
(runTests.try.ws1.onclose.ws2.onmessage):
(runTests.try.ws1.onclose.ws2.onclose):
(runTests.try.ws1.onclose):
(runTests):
* http/tests/websocket/tests/hybi/workers/resources/worker-simple.js: Added.
(handleConnect.self.postMessage):
(handleConnect):
(runTests.try.ws.onopen):
(runTests.try.ws.onmessage):
(runTests.try.ws.onclose):
(runTests):
* http/tests/websocket/tests/hybi/workers/shared-worker-simple-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/shared-worker-simple.html: Added.
* http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness.html: Added.
* http/tests/websocket/tests/hybi/workers/worker-simple-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/worker-simple.html: Added.
* platform/chromium/test_expectations.txt:
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
A category "failing websocket tests" is listed at the beginning of Skipped file,
but there is no such section in the lists. Thus, a new section is inserted.
* platform/win/Skipped:
* platform/wk2/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90726 268f45cc-cd09-0410-ab3c-d52691b4dbfc

161 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/client-close-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/client-close.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/client-close_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-before-open-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-before-open.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-event-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-event.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-on-unload_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/cross-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/cross-origin.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/echo-challenge_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/echo-cookie_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/echo-location_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/echo_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/error-detect-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/error-detect.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/fixed-origin_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-lengths-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/frame-lengths.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-error-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-error.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-error_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/hanging-handshake_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie.pl [new file with mode: 0755]
LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/multiple-connections-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/multiple-connections.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/no-query_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/null-character-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/null-character.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/origin-test_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/protocol-test_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/reload-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/reload-crash.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe-reference-in-parent.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/resources/reload-crash-iframe.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send-throw-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send-throw.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send2_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/send_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/server-close-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/server-close.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/server-close_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/simple-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/simple-stress-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/simple-stress.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/simple.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/simple_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/sub-protocol.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/unicode-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/unicode.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/unicode_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/unknown-frame-type_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-parsing-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-parsing.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-credential-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-credential.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-query-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/url-with-query.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-onmessage-crash.js [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-worker.js [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/simple_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-handshake-challenge-randomness.js [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-simple.js [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wk2/Skipped

index ba31bbf..7a56fd6 100644 (file)
@@ -1,3 +1,203 @@
+2011-07-10  Yuta Kitamura  <yutak@chromium.org>
+
+        WebSocket: Copy existing WebSocket tests
+        https://bugs.webkit.org/show_bug.cgi?id=64242
+
+        Reviewed by Kent Tamura.
+
+        Copy the existing WebSocket tests under http/tests/websocket/tests/hybi/ and skip them.
+
+        These tests will be used to test the latest WebSocket protocol implementation. They are skipped
+        in all ports for now, and will be unskipped when the new protocol implementation is landed in WebCore.
+
+        The following modifications are applied to the new tests:
+        - Change paths and URLs appeared in the tests and the test results so they fit for the new location.
+        - Call layoutTestController.overridePreferences() to enable the new protocol implementation.
+
+        * http/tests/websocket/tests/hybi/alert-in-event-handler-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/alert-in-event-handler.html: Added.
+        * http/tests/websocket/tests/hybi/bad-handshake-crash-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/bad-handshake-crash.html: Added.
+        * http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars.html: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-empty-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-empty.html: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii.html: Added.
+        * http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/bufferedAmount-after-close.html: Added.
+        * http/tests/websocket/tests/hybi/client-close-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/client-close.html: Added.
+        * http/tests/websocket/tests/hybi/client-close_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/close-before-open-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-before-open.html: Added.
+        * http/tests/websocket/tests/hybi/close-event-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-event.html: Added.
+        * http/tests/websocket/tests/hybi/close-on-navigate-new-location-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-on-navigate-new-location.html: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload-and-force-gc-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload-and-force-gc.html: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent.html: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload.html: Added.
+        * http/tests/websocket/tests/hybi/close-on-unload_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/close-unref-websocket-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/close-unref-websocket.html: Added.
+        * http/tests/websocket/tests/hybi/cross-origin-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/cross-origin.html: Added.
+        * http/tests/websocket/tests/hybi/echo-challenge_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/echo-cookie_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/echo-location_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/echo_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/error-detect-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/error-detect.html: Added.
+        * http/tests/websocket/tests/hybi/fixed-origin_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/frame-length-longer-than-buffer-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/frame-length-longer-than-buffer.html: Added.
+        * http/tests/websocket/tests/hybi/frame-length-longer-than-buffer_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/frame-length-overflow-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/frame-length-overflow.html: Added.
+        * http/tests/websocket/tests/hybi/frame-length-overflow_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/frame-length-skip-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/frame-length-skip.html: Added.
+        * http/tests/websocket/tests/hybi/frame-length-skip_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/frame-lengths-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/frame-lengths.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-challenge-randomness-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-challenge-randomness.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-error-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-error.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-error_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-maxlength-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-maxlength.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-cr-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-cr.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch.html: Added.
+        * http/tests/websocket/tests/hybi/hanging-handshake_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/httponly-cookie-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/httponly-cookie.pl: Added.
+        * http/tests/websocket/tests/hybi/long-invalid-header-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/long-invalid-header.html: Added.
+        * http/tests/websocket/tests/hybi/long-invalid-header_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/multiple-connections-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/multiple-connections.html: Added.
+        * http/tests/websocket/tests/hybi/no-query_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/null-character-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/null-character.html: Added.
+        * http/tests/websocket/tests/hybi/origin-test_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/protocol-test_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/reload-crash-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/reload-crash.html: Added.
+        * http/tests/websocket/tests/hybi/resources/close-on-unload-iframe-reference-in-parent.html: Added.
+        * http/tests/websocket/tests/hybi/resources/close-on-unload-iframe.html: Added.
+        * http/tests/websocket/tests/hybi/resources/reload-crash-iframe.html: Added.
+        * http/tests/websocket/tests/hybi/send-after-close-on-unload-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/send-after-close-on-unload.html: Added.
+        * http/tests/websocket/tests/hybi/send-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/send-throw-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/send-throw.html: Added.
+        * http/tests/websocket/tests/hybi/send.html: Added.
+        * http/tests/websocket/tests/hybi/send2_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/send_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/server-close-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/server-close.html: Added.
+        * http/tests/websocket/tests/hybi/server-close_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/simple-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/simple-stress-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/simple-stress.html: Added.
+        * http/tests/websocket/tests/hybi/simple.html: Added.
+        * http/tests/websocket/tests/hybi/simple_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/sub-protocol-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/sub-protocol-with-space.html: Added.
+        * http/tests/websocket/tests/hybi/sub-protocol.html: Added.
+        * http/tests/websocket/tests/hybi/unicode-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/unicode.html: Added.
+        * http/tests/websocket/tests/hybi/unicode_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/unknown-frame-type_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/url-no-trailing-slash-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-no-trailing-slash.html: Added.
+        * http/tests/websocket/tests/hybi/url-parsing-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-parsing.html: Added.
+        * http/tests/websocket/tests/hybi/url-with-credential-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-with-credential.html: Added.
+        * http/tests/websocket/tests/hybi/url-with-empty-query-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-with-empty-query.html: Added.
+        * http/tests/websocket/tests/hybi/url-with-query-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-with-query-for-no-query-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/url-with-query-for-no-query.html: Added.
+        * http/tests/websocket/tests/hybi/url-with-query.html: Added.
+        * http/tests/websocket/tests/hybi/websocket-event-target-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/websocket-event-target.html: Added.
+        * http/tests/websocket/tests/hybi/websocket-pending-activity-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/websocket-pending-activity.html: Added.
+        * http/tests/websocket/tests/hybi/websocket-protocol-ignored-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/websocket-protocol-ignored.html: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash.html: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-shared-worker-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-worker-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/close-in-worker.html: Added.
+        * http/tests/websocket/tests/hybi/workers/resources/close-in-onmessage-crash.js: Added.
+        (runTests.try.ws.onopen):
+        (runTests.try.ws.onmessage):
+        (runTests.try.ws.onclose):
+        (runTests):
+        * http/tests/websocket/tests/hybi/workers/resources/close-in-worker.js: Added.
+        (handleConnect.self.postMessage):
+        (handleConnect):
+        (runTests.try.ws.onopen):
+        (runTests.try.ws.onclose):
+        (runTests):
+        * http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/workers/resources/echo_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/workers/resources/simple_wsh.py: Added.
+        * http/tests/websocket/tests/hybi/workers/resources/worker-handshake-challenge-randomness.js: Added.
+        (endTest):
+        (runTests.try.ws1.onmessage):
+        (runTests.try.ws1.onclose.ws2.onmessage):
+        (runTests.try.ws1.onclose.ws2.onclose):
+        (runTests.try.ws1.onclose):
+        (runTests):
+        * http/tests/websocket/tests/hybi/workers/resources/worker-simple.js: Added.
+        (handleConnect.self.postMessage):
+        (handleConnect):
+        (runTests.try.ws.onopen):
+        (runTests.try.ws.onmessage):
+        (runTests.try.ws.onclose):
+        (runTests):
+        * http/tests/websocket/tests/hybi/workers/shared-worker-simple-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/shared-worker-simple.html: Added.
+        * http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness.html: Added.
+        * http/tests/websocket/tests/hybi/workers/worker-simple-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/workers/worker-simple.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        A category "failing websocket tests" is listed at the beginning of Skipped file,
+        but there is no such section in the lists. Thus, a new section is inserted.
+        * platform/win/Skipped:
+        * platform/wk2/Skipped:
+
 2011-07-11  James Robinson  <jamesr@chromium.org>
 
         [chromium] Update win/linux pixel expectations for r90701 (part 11/??).
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler-expected.txt
new file mode 100644 (file)
index 0000000..5157ec0
--- /dev/null
@@ -0,0 +1,19 @@
+ALERT: waiting for open
+ALERT: message handled.first message
+ALERT: message handled.second message
+Make sure event handler called serially.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+alert will suspend/resume WebSocket.
+onopen should fire later.
+Connected
+Enter onmessage: first message
+Leave onmessage: first message
+Enter onmessage: second message
+Leave onmessage: second message
+Closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler.html b/LayoutTests/http/tests/websocket/tests/hybi/alert-in-event-handler.html
new file mode 100644 (file)
index 0000000..94f8ede
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure event handler called serially.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/send2");
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    debug("Enter onmessage: " + messageEvent.data);
+    // alert() will suspend/resume WebSocket.
+    alert("message handled." + messageEvent.data);
+    debug("Leave onmessage: " + messageEvent.data);
+};
+
+ws.onclose = function()
+{
+    debug("Closed");
+    finishJSTest();
+};
+
+debug("alert will suspend/resume WebSocket.");
+alert("waiting for open");
+debug("onopen should fire later.");
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash-expected.txt
new file mode 100644 (file)
index 0000000..a5f20f4
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: Invalid UTF-8 sequence in header name
+Make sure WebSocket doesn't crash with bad handshake message.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash.html b/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash.html
new file mode 100644 (file)
index 0000000..040367f
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket doesn't crash with bad handshake message.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/bad-handshake-crash");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py
new file mode 100644 (file)
index 0000000..7b425bc
--- /dev/null
@@ -0,0 +1,16 @@
+def web_socket_do_extra_handshake(request):
+    msg = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
+    msg += "Upgrade: WebSocket\r\n"
+    msg += "Connection: Upgrade\r\n"
+    msg += "Sec-WebSocket-Location: " + request.ws_location + "\r\n"
+    msg += "Sec-WebSocket-Origin: " + request.ws_origin + "\r\n"
+    msg += "\xa5:\r\n"
+    msg += "\r\n"
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    print msg
+    raise Exception("Abort the connection") # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars-expected.txt
new file mode 100644 (file)
index 0000000..215280c
--- /dev/null
@@ -0,0 +1,18 @@
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0000'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0009'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u001B'
+Test WebSocket bad sub-protocol names by control characters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "\0") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "     ") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "
+") threw exception SyntaxError: Unexpected EOF.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "
+") threw exception SyntaxError: Unexpected EOF.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "\e") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars.html b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-control-chars.html
new file mode 100644 (file)
index 0000000..c9e3ec4
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket bad sub-protocol names by control characters.");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+// Fails if protocol contains an character less than U+0020.
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u0000")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u0009")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u000A")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u000D")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u001B")');
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty-expected.txt
new file mode 100644 (file)
index 0000000..ca697ed
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket ''
+Test WebSocket bad sub-protocol names (empty).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty.html b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-empty.html
new file mode 100644 (file)
index 0000000..521d107
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket bad sub-protocol names (empty).");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+// Fails if protocol is an empty string.
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "")');
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii-expected.txt
new file mode 100644 (file)
index 0000000..cfc70f1
--- /dev/null
@@ -0,0 +1,22 @@
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u007F'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0080'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u3042'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFF'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFEFF'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFE'
+CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uD840\uDC0B'
+Test WebSocket bad sub-protocol names by non-ASCII chars.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "\7f") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "\80") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "あ") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "￿") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "￾") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:8880/simple", "𠀋") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii.html b/LayoutTests/http/tests/websocket/tests/hybi/bad-sub-protocol-non-ascii.html
new file mode 100644 (file)
index 0000000..2f66509
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket bad sub-protocol names by non-ASCII chars.");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+// Fails if protocol contains an character greater than U+007E.
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u007F")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u0080")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\u3042")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\uFFFF")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\uFEFF")');
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\uFFFE")');
+// Surrogate pairs
+shouldThrow('new WebSocket("ws://127.0.0.1:8880/simple", "\uD840\uDC0B")');
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt
new file mode 100644 (file)
index 0000000..91b4ec7
--- /dev/null
@@ -0,0 +1,14 @@
+Web Socket bufferedAmount after closed
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+Closed.
+PASS ws.readyState is 3
+PASS ws.bufferedAmount is 0
+PASS ws.send('send to closed socket') is false
+PASS ws.bufferedAmount is 23
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html b/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html
new file mode 100644 (file)
index 0000000..0d68131
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Web Socket bufferedAmount after closed");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/simple");
+
+ws.onopen = function()
+{
+    debug("Connected.");
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    shouldBe("ws.readyState", "3");
+    shouldBe("ws.bufferedAmount", "0");
+    shouldBeFalse("ws.send('send to closed socket')");
+    // If the connection is closed, bufferedAmount attribute's value will only
+    // increase with each call to the send() method.
+    // (the number does not reset to zero once the connection closes).
+    shouldBe("ws.bufferedAmount", "23");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/client-close-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/client-close-expected.txt
new file mode 100644 (file)
index 0000000..2668fd9
--- /dev/null
@@ -0,0 +1,13 @@
+WebSocket: Test client-initiated close.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected
+Received: close_frame='\xff\x00'
+Closed
+PASS receivedMessage is "close_frame='\\xff\\x00'"
+PASS closeEvent.wasClean is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/client-close.html b/LayoutTests/http/tests/websocket/tests/hybi/client-close.html
new file mode 100644 (file)
index 0000000..bda5143
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("WebSocket: Test client-initiated close.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/client-close");
+var closeEvent;
+var receivedMessage;
+
+ws.onopen = function()
+{
+    debug("Connected");
+    ws.close();
+};
+
+ws.onmessage = function(messageEvent)
+{
+    debug("Received: " + messageEvent.data);
+    receivedMessage = messageEvent.data;
+};
+
+ws.onclose = function(event)
+{
+    debug("Closed");
+    closeEvent = event;
+    shouldBeEqualToString("receivedMessage", "close_frame='\\xff\\x00'");
+    shouldBeTrue("closeEvent.wasClean");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/client-close_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/client-close_wsh.py
new file mode 100644 (file)
index 0000000..7ed28bf
--- /dev/null
@@ -0,0 +1,23 @@
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    # Wait for a close frame sent from the client.
+    close_frame = request.ws_stream.receive_bytes(2)
+
+    # Tell the client what we have received.
+    msgutil.send_message(request, 'close_frame=%r' % close_frame)
+
+    # If the following assertion fails, AssertionError will be raised,
+    # which will prevent pywebsocket from sending a close frame.
+    # In this case, the client will fail to finish closing handshake, thus
+    # closeEvent.wasClean will become false.
+    assert close_frame == '\xff\x00'
+
+    # Pretend we have received a close frame from the client.
+    # After this function exits, pywebsocket will send a close frame automatically.
+    request.client_terminated = True
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-before-open-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-before-open-expected.txt
new file mode 100644 (file)
index 0000000..57a542a
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
+Test if Web Socket fires close event when WebSocket is opened and closed fore open event is received.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-before-open.html b/LayoutTests/http/tests/websocket/tests/hybi/close-before-open.html
new file mode 100644 (file)
index 0000000..bb3b1d3
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket fires close event when WebSocket is opened and closed fore open event is received.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/hanging-handshake");
+ws.onclose = function() {
+    debug("closed");
+    finishJSTest();
+};
+var successfullyParsed = true;
+ws.close();
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-event-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-event-expected.txt
new file mode 100644 (file)
index 0000000..a605cc9
--- /dev/null
@@ -0,0 +1,16 @@
+Make sure WebSocket fires CloseEvent when closed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+Received: 'Hello from Simple WSH.'
+Closed
+PASS closeEventType is "close"
+PASS 'wasClean' in closeEvent is true
+PASS closeEvent.wasClean is true
+PASS Object.getPrototypeOf(closeEvent) === CloseEvent.prototype is true
+PASS Object.getPrototypeOf(closeEvent) !== Event.prototype is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-event.html b/LayoutTests/http/tests/websocket/tests/hybi/close-event.html
new file mode 100644 (file)
index 0000000..4cefea5
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket fires CloseEvent when closed.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple");
+
+ws.onopen = function()
+{
+    debug("WebSocket is open");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    debug("Received: '" + messageEvent.data + "'");
+};
+
+var closeEvent;
+var closeEventType;
+ws.onclose = function(event)
+{
+    debug("Closed");
+    closeEvent = event;
+    closeEventType = closeEvent.type;
+    shouldBe("closeEventType", '"close"')
+    shouldBeTrue("'wasClean' in closeEvent");
+    shouldBeTrue("closeEvent.wasClean");
+    shouldBeTrue("Object.getPrototypeOf(closeEvent) === CloseEvent.prototype");
+    shouldBeTrue("Object.getPrototypeOf(closeEvent) !== Event.prototype");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location-expected.txt
new file mode 100644 (file)
index 0000000..176427e
--- /dev/null
@@ -0,0 +1,12 @@
+Test if Web Socket is closed when navigating to new location.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS 'socket1' is sent to the server. navigate to new location. expect receiving 'socket1' on ws...
+PASS closedSocket is "socket1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location.html b/LayoutTests/http/tests/websocket/tests/hybi/close-on-navigate-new-location.html
new file mode 100644 (file)
index 0000000..3bfcde7
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket is closed when navigating to new location.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var frameDiv;
+var closedSocket;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    shouldBe("closedSocket", '"socket1"');
+    finishJSTest();
+};
+
+document.iframeReady = function()
+{
+    debug("PASS 'socket1' is sent to the server. navigate to new location. expect receiving 'socket1' on ws...");
+    frameDiv.src = "handler_map.txt";
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc-expected.txt
new file mode 100644 (file)
index 0000000..6a347a4
--- /dev/null
@@ -0,0 +1,12 @@
+Test if Web Socket is closed on unload and not crashed if garbage collected
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS 'socket1' is sent to the server. unload the iframe and force garbage collection. expect receiving 'socket1' on ws and no crash...
+PASS closedSocket is "socket1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc.html b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-and-force-gc.html
new file mode 100644 (file)
index 0000000..05317ac
--- /dev/null
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket is closed on unload and not crashed if garbage collected");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function gc()
+{
+    if (window.GCController)
+        return GCController.collect();
+
+    for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect)
+        var s = new String("abc");
+    }
+};
+
+var frameDiv;
+var closedSocket;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    shouldBe("closedSocket", '"socket1"');
+    finishJSTest();
+};
+
+document.iframeReady = function()
+{
+    debug("PASS 'socket1' is sent to the server. unload the iframe and force garbage collection. expect receiving 'socket1' on ws and no crash...");
+    document.body.removeChild(frameDiv);
+    gc();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-expected.txt
new file mode 100644 (file)
index 0000000..cf45278
--- /dev/null
@@ -0,0 +1,12 @@
+Test if Web Socket is closed on unload
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...
+PASS closedSocket is "socket1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent-expected.txt
new file mode 100644 (file)
index 0000000..f91116d
--- /dev/null
@@ -0,0 +1,14 @@
+Test if Web Socket opened in iframe but referred in parent document is closed on unloading the frame.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS document.childWebSocket is non-null.
+PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...
+PASS closedSocket is "socket1"
+PASS document.childWebSocket.readyState is 3
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent.html b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload-reference-in-parent.html
new file mode 100644 (file)
index 0000000..628de0c
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket opened in iframe but referred in parent document is closed on unloading the frame.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var frameDiv;
+var closedSocket;
+document.childWebSocket = null;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe-reference-in-parent.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    shouldBe("closedSocket", '"socket1"');
+    shouldBe("document.childWebSocket.readyState", "3");
+    finishJSTest();
+};
+
+document.iframeReady = function()
+{
+    shouldBeNonNull("document.childWebSocket");
+    debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
+    document.body.removeChild(frameDiv);
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload.html b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload.html
new file mode 100644 (file)
index 0000000..38ae586
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket is closed on unload");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var frameDiv;
+var closedSocket;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    shouldBe("closedSocket", '"socket1"');
+    finishJSTest();
+};
+
+document.iframeReady = function()
+{
+    debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
+    document.body.removeChild(frameDiv);
+}; 
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/close-on-unload_wsh.py
new file mode 100644 (file)
index 0000000..4c13115
--- /dev/null
@@ -0,0 +1,56 @@
+# Copyright 2009, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+# we don't use set() here, because python on mac tiger doesn't support it.
+connections = {}
+
+
+def web_socket_do_extra_handshake(request):
+    pass  # Always accept.
+
+
+def web_socket_transfer_data(request):
+    global connections
+    connections[request] = True
+    socketName = None
+    try:
+        socketName = msgutil.receive_message(request)
+        # notify to client that socketName is received by server.
+        msgutil.send_message(request, socketName)
+        msgutil.receive_message(request)  # wait, and exception by close.
+        socketName = socketName + ': receive next message'
+    finally:
+        # request is closed. notify this socketName to other web sockets.
+        del connections[request]
+        for ws in connections.keys():
+            msgutil.send_message(ws, socketName)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket-expected.txt
new file mode 100644 (file)
index 0000000..39f5555
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
+Test if Web Socket is closed while handshaking and unreferenced, it should fire close event at most once.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS 1 is >= countCloseEvent
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket.html b/LayoutTests/http/tests/websocket/tests/hybi/close-unref-websocket.html
new file mode 100644 (file)
index 0000000..4c936f5
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket is closed while handshaking and unreferenced, it should fire close event at most once.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var countCloseEvent = 0;
+
+function endTest()
+{
+    shouldBeGreaterThanOrEqual("1", "countCloseEvent");
+    finishJSTest();
+};
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/hanging-handshake");
+ws.onclose = function() {
+    countCloseEvent += 1;
+};
+ws.close();
+ws = null;
+gc();
+setTimeout("endTest()", 100);
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/cross-origin-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/cross-origin-expected.txt
new file mode 100644 (file)
index 0000000..4c9f09e
--- /dev/null
@@ -0,0 +1,12 @@
+Web Socket Cross Origin test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+document.domain=127.0.0.1
+ws.url=ws://localhost:8880/websocket/tests/hybi/origin-test
+Connected
+PASS origin is "http://127.0.0.1:8000"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/cross-origin.html b/LayoutTests/http/tests/websocket/tests/hybi/cross-origin.html
new file mode 100644 (file)
index 0000000..b2f647a
--- /dev/null
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Web Socket Cross Origin test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var origin;
+
+function endTest()
+{
+    shouldBe("origin", '"http://127.0.0.1:8000"');
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/origin-test";
+debug("document.domain=" + document.domain);
+debug("ws.url=" + url);
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function (messageEvent)
+{
+    origin = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/echo-challenge_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/echo-challenge_wsh.py
new file mode 100644 (file)
index 0000000..390d441
--- /dev/null
@@ -0,0 +1,13 @@
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, _hexify(request.ws_challenge))
+
+
+def _hexify(bytes):
+    return ':'.join(['%02X' % ord(byte) for byte in bytes])
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/echo-cookie_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/echo-cookie_wsh.py
new file mode 100644 (file)
index 0000000..faa25f9
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2010 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request,  request.headers_in['Cookie'])
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/echo-location_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/echo-location_wsh.py
new file mode 100644 (file)
index 0000000..3390570
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    print request.ws_location
+    msgutil.send_message(request, request.ws_location)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/echo_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/echo_wsh.py
new file mode 100644 (file)
index 0000000..79c3f10
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2009, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+_GOODBYE_MESSAGE = 'Goodbye'
+
+
+def web_socket_do_extra_handshake(request):
+    pass  # Always accept.
+
+
+def web_socket_transfer_data(request):
+    while True:
+        line = msgutil.receive_message(request)
+        msgutil.send_message(request, line)
+        if line == _GOODBYE_MESSAGE:
+            return
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/error-detect-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/error-detect-expected.txt
new file mode 100644 (file)
index 0000000..6c69eed
--- /dev/null
@@ -0,0 +1,12 @@
+Make sure WebSocket correctly fire error event for unknown frame type.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+received:done
+WebSocket is closed
+PASS errorCount is 255
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/error-detect.html b/LayoutTests/http/tests/websocket/tests/hybi/error-detect.html
new file mode 100644 (file)
index 0000000..cd534e5
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket correctly fire error event for unknown frame type.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var errorCount = 0;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/unknown-frame-type");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onmessage = function (evt) {
+    debug("received:" + evt.data);
+};
+ws.onerror = function () {
+    errorCount += 1;
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    shouldBe("errorCount", "255");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/fixed-origin_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/fixed-origin_wsh.py
new file mode 100644 (file)
index 0000000..938fb83
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    request.ws_origin = 'http://example.com'
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, request.ws_origin)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer-expected.txt
new file mode 100644 (file)
index 0000000..af37700
--- /dev/null
@@ -0,0 +1,13 @@
+Make sure WebSocket correctly skip lengthed frame even if received data has incomplete frame.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+received:hello
+WebSocket is closed
+1
+PASS areArraysEqual(received_messages, expected_messages) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer.html b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer.html
new file mode 100644 (file)
index 0000000..b978d16
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket correctly skip lengthed frame even if received data has incomplete frame.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var received_messages = [];
+var expected_messages = ["hello"];
+function finish() {
+    clearTimeout(timeoutID);
+    debug(received_messages.length);
+    for (var i = 0; i < received_messages; i++) {
+        debug("received[" + i + "]=" + received_messages[i]);
+    }
+
+    shouldBeTrue("areArraysEqual(received_messages, expected_messages)");
+
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/frame-length-longer-than-buffer");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onmessage = function (evt) {
+    debug("received:" + evt.data);
+    received_messages.push(evt.data);
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    finish();
+};
+var timeoutID = setTimeout("finish()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-longer-than-buffer_wsh.py
new file mode 100644 (file)
index 0000000..c34b4f1
--- /dev/null
@@ -0,0 +1,11 @@
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msg = "\0hello\xff"
+    msg += "\x80\x81\x01" # Skip 1*128+1 bytes.
+    msg += "\x01\xff"
+    msg += "\0should be skipped\xff"
+    request.connection.write(msg)
+    raise Exception("Abort the connection") # Prevents pywebsocket from starting closing handshake.
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow-expected.txt
new file mode 100644 (file)
index 0000000..dc216f4
--- /dev/null
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 0: WebSocket frame length too large
+Make sure WebSocket does not crash and report error when it sees length overflow
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+WebSocket received error frame
+WebSocket is closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow.html b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow.html
new file mode 100644 (file)
index 0000000..a1f61c7
--- /dev/null
@@ -0,0 +1,35 @@
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Make sure WebSocket does not crash and report error when it sees length overflow");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/frame-length-overflow");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onmessage = function (evt) {
+    debug("WebSocket received:" + evt.data);
+};
+ws.onerror = function () {
+    debug("WebSocket received error frame");
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-overflow_wsh.py
new file mode 100644 (file)
index 0000000..1c7c921
--- /dev/null
@@ -0,0 +1,8 @@
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msg = 16 * '\xff'
+    request.connection.write(msg)
+    raise Exception('Abort the connection') # Prevents pywebsocket from starting closing handshake.
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip-expected.txt
new file mode 100644 (file)
index 0000000..aa32fe4
--- /dev/null
@@ -0,0 +1,14 @@
+Make sure WebSocket correctly skip lengthed frame.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+received:hello
+received:world
+WebSocket is closed
+2
+PASS areArraysEqual(received_messages, expected_messages) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip.html b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip.html
new file mode 100644 (file)
index 0000000..072be6a
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket correctly skip lengthed frame.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var received_messages = [];
+var expected_messages = ["hello", "world"];
+function finish() {
+    clearTimeout(timeoutID);
+    debug(received_messages.length);
+    for (var i = 0; i < received_messages; i++) {
+        debug("received[" + i + "]=" + received_messages[i]);
+    }
+
+    shouldBeTrue("areArraysEqual(received_messages, expected_messages)");
+
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/frame-length-skip");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onmessage = function (evt) {
+    debug("received:" + evt.data);
+    received_messages.push(evt.data);
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    finish();
+};
+var timeoutID = setTimeout("finish()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/frame-length-skip_wsh.py
new file mode 100644 (file)
index 0000000..fe87401
--- /dev/null
@@ -0,0 +1,12 @@
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msg = "\0hello\xff"
+    msg += "\x80\x81\x01"   # skip 1*128+1 bytes.
+    msg += "\x01"
+    msg += "\0should be skipped" + (" " * 109) + "\xff"
+    msg += "\0world\xff"
+    request.connection.write(msg)
+    print msg
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-lengths-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/frame-lengths-expected.txt
new file mode 100644 (file)
index 0000000..23ee459
--- /dev/null
@@ -0,0 +1,7 @@
+Test sending and receiving small messages of different lengths.
+
+Should say PASS:
+
+Running the test...
+PASS
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/frame-lengths.html b/LayoutTests/http/tests/websocket/tests/hybi/frame-lengths.html
new file mode 100644 (file)
index 0000000..e6ce309
--- /dev/null
@@ -0,0 +1,46 @@
+<p>Test sending and receiving small messages of different lengths.</p>
+<p>Should say PASS:</p>
+<pre id=log>Running the test...
+</pre>
+<script>
+var maxLength = 1025;
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+
+var lastString;
+var failed = false;
+ws.onopen = function() {
+    lastString = "";
+    ws.send(lastString);
+}
+
+ws.onmessage = function(msg) {
+    if (msg.data != lastString) {
+        log("FAIL - incorrect response. Expected '" + lastString + "', got '" + msg.data + "'.");
+        failed = true;
+    }
+
+    if (lastString.length == maxLength) {
+        if (!failed)
+            log("PASS");
+        ws.send("Goodbye");
+        ws.onmessage = null;
+        if (window.layoutTestController)
+            setTimeout("layoutTestController.notifyDone()", 0);
+    } else {
+        lastString += "*";
+        ws.send(lastString);
+    }
+}
+</script>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness-expected.txt
new file mode 100644 (file)
index 0000000..c1bdcd7
--- /dev/null
@@ -0,0 +1,9 @@
+Handshake request should contain random challenge values.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS challenge1 === challenge2 is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-challenge-randomness.html
new file mode 100644 (file)
index 0000000..58b7796
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description('Handshake request should contain random challenge values.');
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var challenge1;
+var challenge2;
+
+var url = 'ws://localhost:8880/websocket/tests/hybi/echo-challenge';
+var ws1 = new WebSocket(url);
+
+ws1.onmessage = function(messageEvent)
+{
+    challenge1 = messageEvent.data;
+    ws1.close();
+}
+
+ws1.onclose = function()
+{
+    var ws2 = new WebSocket(url);
+
+    ws2.onmessage = function(messageEvent)
+    {
+        challenge2 = messageEvent.data;
+        ws2.close();
+    }
+
+    ws2.onclose = function()
+    {
+        shouldBeFalse('challenge1 === challenge2');
+        if (challenge1 === challenge2)
+            debug('challenge was ' + challenge1);
+        finishJSTest();
+    }
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-error-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-error-expected.txt
new file mode 100644 (file)
index 0000000..0530828
--- /dev/null
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: line 0: No response code found: ThisWillCauseHandshakeError
+Handshake error test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Closed.
+PASS ws.readyState is 3
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-error.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-error.html
new file mode 100644 (file)
index 0000000..90f82db
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Handshake error test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/handshake-error");
+
+ws.onopen = function()
+{
+    testFailed("Unexpectedly Connected.");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    testFailed("Unexpectedly Received: '" + messageEvent.data + "'");
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    shouldBe("ws.readyState", "3")
+    endTest();
+};
+
+function timeOutCallback()
+{
+    testFailed("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-error_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-error_wsh.py
new file mode 100644 (file)
index 0000000..c851fa6
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    request.connection.write('ThisWillCauseHandshakeError\r\n')
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, 'Hello from Handshake Error WSH.')
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin-expected.txt
new file mode 100644 (file)
index 0000000..27c81d0
--- /dev/null
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 0: Error during WebSocket handshake: origin mismatch: http://127.0.0.1:8000 != http://example.com
+Make sure Web Socket connection failed if origin mismatches.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+document.domain=127.0.0.1
+ws.url=ws://localhost:8880/websocket/tests/hybi/fixed-origin
+PASS connected is false
+PASS origin is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-cross-origin.html
new file mode 100644 (file)
index 0000000..3e6a67f
--- /dev/null
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure Web Socket connection failed if origin mismatches.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var connected = false;
+var origin;
+
+function endTest()
+{
+    shouldBeFalse("connected");
+    shouldBeUndefined("origin");
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/fixed-origin";
+debug("document.domain=" + document.domain);
+debug("ws.url=" + url);
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug("Connected");
+    connected = true;
+};
+
+ws.onmessage = function (messageEvent)
+{
+    origin = messageEvent.data;
+    debug("origin=" + origin);
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength-expected.txt
new file mode 100644 (file)
index 0000000..61ee73b
--- /dev/null
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 0: Status line is too long
+Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if handshake is longer than 1024 bytes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS timedOut is false
+PASS connected is false
+PASS origin is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength.html
new file mode 100644 (file)
index 0000000..588b6a1
--- /dev/null
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description('Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if handshake is longer than 1024 bytes.');
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var timedOut = false;
+var connected = false;
+var origin;
+
+function endTest() {
+    shouldBeFalse('timedOut');
+    shouldBeFalse('connected');
+    shouldBeUndefined('origin');
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = 'ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-maxlength';
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug('Connected');
+    connected = true;
+}
+
+ws.onmessage = function(messageEvent)
+{
+    origin = messageEvent.data;
+    debug('origin = ' + origin);
+    ws.close();
+}
+
+ws.onclose = function()
+{
+    endTest();
+}
+
+function timeoutCallback()
+{
+    debug('Timed out (state = ' + ws.readyState + ')');
+    timedOut = true;
+    endTest();
+}
+
+var timeoutID = setTimeout(timeoutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py
new file mode 100644 (file)
index 0000000..c039fb3
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) Research In Motion Limited 2011. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+# following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
+# following disclaimer in the documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+def web_socket_do_extra_handshake(request):
+    # This will cause the handshake to fail because it pushes the length of the
+    # status line past 1024 characters
+    msg = '.' * 1024
+    msg += 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
+    msg += 'Upgrade: WebSocket\r\n'
+    msg += 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
+    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
+    msg += '\r\n'
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    raise Exception('abort the connection') # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header-expected.txt
new file mode 100644 (file)
index 0000000..ef62d5b
--- /dev/null
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 0: Error during WebSocket handshake: 'Connection' header is missing
+Test that WebSocket handshake fails if Connection header field isn't reflected by the server.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header.html
new file mode 100644 (file)
index 0000000..5844f26
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test that WebSocket handshake fails if Connection header field isn't reflected by the server.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-no-connection-header";
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug("FAIL: Connected");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py
new file mode 100644 (file)
index 0000000..7efc87a
--- /dev/null
@@ -0,0 +1,15 @@
+def web_socket_do_extra_handshake(request):
+    msg = 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
+    msg += 'Upgrade: WebSocket\r\n'
+#   Missing 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
+    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
+    msg += '\r\n'
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr-expected.txt
new file mode 100644 (file)
index 0000000..3e56eb7
--- /dev/null
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: line 0: Status line does not end with CRLF
+Handshake should fail when the first line does not end with CRLF.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS connected is false
+PASS origin is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr.html
new file mode 100644 (file)
index 0000000..44b5ad9
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description('Handshake should fail when the first line does not end with CRLF.');
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var connected = false;
+var origin;
+
+function endTest() {
+    shouldBeFalse('connected');
+    shouldBeUndefined('origin');
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = 'ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-no-cr';
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug('Connected');
+    connected = true;
+}
+
+ws.onmessage = function(messageEvent)
+{
+    origin = messageEvent.data;
+    debug('origin = ' + origin);
+    ws.close();
+}
+
+ws.onclose = function()
+{
+    endTest();
+}
+
+function timeoutCallback()
+{
+    debug('Timed out (state = ' + ws.readyState + ')');
+    endTest();
+}
+
+var timeoutID = setTimeout(timeoutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py
new file mode 100644 (file)
index 0000000..978924a
--- /dev/null
@@ -0,0 +1,15 @@
+def web_socket_do_extra_handshake(request):
+    msg = 'HTTP/1.1 101 WebSocket Protocol Handshake\n' # Does not end with "\r\n".
+    msg += 'Upgrade: WebSocket\r\n'
+    msg += 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
+    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
+    msg += '\r\n'
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header-expected.txt
new file mode 100644 (file)
index 0000000..7f0667d
--- /dev/null
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 0: Error during WebSocket handshake: 'Upgrade' header is missing
+Test that WebSocket handshake fails if Upgrade header field isn't reflected by the server.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header.html
new file mode 100644 (file)
index 0000000..f4113b5
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test that WebSocket handshake fails if Upgrade header field isn't reflected by the server.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-no-upgrade-header";
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug("FAIL: Connected");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py
new file mode 100644 (file)
index 0000000..114de75
--- /dev/null
@@ -0,0 +1,15 @@
+def web_socket_do_extra_handshake(request):
+    msg = 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
+#   Missing 'Upgrade: WebSocket\r\n'
+    msg += 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
+    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
+    msg += '\r\n'
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null-expected.txt
new file mode 100644 (file)
index 0000000..5db17c8
--- /dev/null
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 0: Status line contains embedded null
+Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if a null byte is received before the handshake.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS timedOut is false
+PASS connected is false
+PASS origin is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null.html
new file mode 100644 (file)
index 0000000..de0e440
--- /dev/null
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description('Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if a null byte is received before the handshake.');
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var timedOut = false;
+var connected = false;
+var origin;
+
+function endTest() {
+    shouldBeFalse('timedOut');
+    shouldBeFalse('connected');
+    shouldBeUndefined('origin');
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = 'ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-prepended-null';
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug('Connected');
+    connected = true;
+}
+
+ws.onmessage = function(messageEvent)
+{
+    origin = messageEvent.data;
+    debug('origin = ' + origin);
+    ws.close();
+}
+
+ws.onclose = function()
+{
+    endTest();
+}
+
+function timeoutCallback()
+{
+    debug('Timed out (state = ' + ws.readyState + ')');
+    timedOut = true;
+    endTest();
+}
+
+var timeoutID = setTimeout(timeoutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py
new file mode 100644 (file)
index 0000000..0735184
--- /dev/null
@@ -0,0 +1,51 @@
+# Copyright (C) Research In Motion Limited 2011. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+# following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
+# following disclaimer in the documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import time
+
+
+def web_socket_do_extra_handshake(request):
+    # This simulates a broken server that sends a WebSocket frame before the
+    # handshake, and more frames afterwards.  It is important that if this
+    # happens the client does not buffer all the frames as the server continues
+    # to send more data - it should abort after reading a reasonable number of
+    # bytes (set arbitrarily to 1024).
+    frame = '\0Frame-contains-thirty-two-bytes'
+
+    msg = frame
+    msg += 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
+    msg += 'Upgrade: WebSocket\r\n'
+    msg += 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Location: ' + request.ws_location + '\r\n'
+    msg += 'Sec-WebSocket-Origin: ' + request.ws_origin + '\r\n'
+    msg += '\r\n'
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    # continue writing data until the client disconnects
+    while True:
+        time.sleep(1)
+        numFrames = 1024 / len(frame) # write over 1024 bytes including the above handshake
+        for i in range(0, numFrames):
+            request.connection.write(frame)
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch-expected.txt
new file mode 100644 (file)
index 0000000..164642b
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: Error during WebSocket handshake: protocol mismatch: requestting-protocol != available-protocol
+Test WebSocket handshake fail if sub protocol name mismatches.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS protocol is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch.html b/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-sub-protocol-mismatch.html
new file mode 100644 (file)
index 0000000..f6d792f
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket handshake fail if sub protocol name mismatches.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var protocol;
+
+function endTest()
+{
+    shouldBeUndefined("protocol");
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=available-protocol";
+var ws = new WebSocket(url, "requestting-protocol");
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function (messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/hanging-handshake_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/hanging-handshake_wsh.py
new file mode 100644 (file)
index 0000000..8391bd8
--- /dev/null
@@ -0,0 +1,6 @@
+def web_socket_do_extra_handshake(request):
+    request.connection.read()
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie-expected.txt
new file mode 100644 (file)
index 0000000..7b92ec3
--- /dev/null
@@ -0,0 +1,11 @@
+Test WebSocket sends HttpOnly cookies.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket open
+WebSocket closed
+PASS cookie is "WK-websocket-test-httponly=1; WK-websocket-test=1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie.pl b/LayoutTests/http/tests/websocket/tests/hybi/httponly-cookie.pl
new file mode 100755 (executable)
index 0000000..0d61446
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/perl -wT
+use strict;
+
+if ($ENV{"QUERY_STRING"} eq "clear=1") {
+    print "Content-Type: text/plain\r\n";
+    print "Set-Cookie: WK-websocket-test=0; Max-Age=0\r\n";
+    print "Set-Cookie: WK-websocket-test-httponly=0; HttpOnly; Max-Age=0\r\n";
+    print "\r\n";
+    print "Cookies are cleared.";
+    exit;
+}
+
+print "Content-Type: text/html\r\n";
+print "Set-Cookie: WK-websocket-test=1\r\n";
+print "Set-Cookie: WK-websocket-test-httponly=1; HttpOnly\r\n";
+print "\r\n";
+print <<HTML
+<html>
+<head>
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>Test WebSocket sends HttpOnly cookies.</p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<div id="console"></div>
+<script>
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var cookie;
+
+// Normalize a cookie string
+function normalizeCookie(cookie)
+{
+    // Split the cookie string, sort it and then put it back together.
+    return cookie.split('; ').sort().join('; ');
+}
+
+function clearCookies()
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", "httponly-cookie.pl?clear=1", false);
+    xhr.send(null);
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo-cookie");
+ws.onopen = function() {
+    debug("WebSocket open");
+};
+ws.onmessage = function(evt) {
+    cookie = evt.data;
+    ws.close();
+};
+ws.onclose = function() {
+    debug("WebSocket closed");
+    cookie = normalizeCookie(cookie);
+    shouldBe("cookie", '"WK-websocket-test-httponly=1; WK-websocket-test=1"');
+    clearCookies();
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
+HTML
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header-expected.txt
new file mode 100644 (file)
index 0000000..70fa4f1
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 0: Unexpected CR in name at pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp…
+Make sure WebSocket gives errors on long invalid upgrade header.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header.html b/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header.html
new file mode 100644 (file)
index 0000000..34f6e49
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket gives errors on long invalid upgrade header.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function finish() {
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/long-invalid-header");
+ws.onopen = function () {
+    debug("WebSocket is open");
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    finish();
+};
+var timeoutID = setTimeout("finish()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header_wsh.py
new file mode 100644 (file)
index 0000000..4a169f3
--- /dev/null
@@ -0,0 +1,11 @@
+def web_socket_do_extra_handshake(request):
+    msg = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
+    msg += ("p" * 1024) + "\r\n"
+    msg += "\r\n"
+    msg += request.ws_challenge_md5
+    request.connection.write(msg)
+    raise Exception("Abort the connection") # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/multiple-connections-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/multiple-connections-expected.txt
new file mode 100644 (file)
index 0000000..cee1efb
--- /dev/null
@@ -0,0 +1,3 @@
+Test that WebSocket is not subject to HTTP connection limit. Should say PASS:
+
+PASS
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/multiple-connections.html b/LayoutTests/http/tests/websocket/tests/hybi/multiple-connections.html
new file mode 100644 (file)
index 0000000..ca441e5
--- /dev/null
@@ -0,0 +1,35 @@
+<p>Test that WebSocket is not subject to HTTP connection limit. Should say PASS:</p>
+<p id=result>Running...</p>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+var socketCount = 50;
+var result = document.getElementById("result");
+var sockets = [];
+
+for (i = 0; i < socketCount; ++i) {
+    var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+    sockets[i] = ws;
+    ws.onopen = function() {
+        var num = parseInt(result.innerHTML);
+        if (!num)
+            num = 0;
+        if (num != socketCount - 1)
+            result.innerHTML = num + 1;
+        else {
+            result.innerHTML = "PASS";
+            for (j = 0; j < socketCount; ++j) {
+                sockets[j].onclose = null;
+                sockets[j].close();
+            }
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }
+    }
+    ws.onclose = function() { alert("FAIL: unexpected close event") }
+}
+</script>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/no-query_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/no-query_wsh.py
new file mode 100644 (file)
index 0000000..2b79615
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    request.ws_location = request.ws_resource.split('?', 1)[0]
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, request.ws_location)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/null-character-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/null-character-expected.txt
new file mode 100644 (file)
index 0000000..6fca377
--- /dev/null
@@ -0,0 +1,12 @@
+Make sure WebSocket transfer null character
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket open
+msg should not be split by frame char \xff\0
+PASS msg is expectedMessage
+WebSocket closed
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/null-character.html b/LayoutTests/http/tests/websocket/tests/hybi/null-character.html
new file mode 100644 (file)
index 0000000..8412c07
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket transfer null character");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+// \xff in string would be \xc3\xbf on websocket connection (UTF-8)
+var expectedMessage = "Should Not\xff\0Split";
+
+ws.onopen = function()
+{
+    debug("WebSocket open");
+    ws.send(expectedMessage);
+};
+
+var msg;
+ws.onmessage = function(messageEvent)
+{
+    msg = messageEvent.data;
+    debug("msg should not be split by frame char \\xff\\0");
+    shouldBe("msg", "expectedMessage");
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    debug("WebSocket closed");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/origin-test_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/origin-test_wsh.py
new file mode 100644 (file)
index 0000000..988d6af
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, request.ws_origin)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/protocol-test_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/protocol-test_wsh.py
new file mode 100644 (file)
index 0000000..f43d8e6
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+import cgi
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    r = request.ws_resource.split('?', 1)
+    if len(r) == 1:
+        return
+    param = cgi.parse_qs(r[1])
+    if 'protocol' in param:
+        request.ws_protocol = param['protocol'][0]
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, request.ws_protocol)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/reload-crash-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/reload-crash-expected.txt
new file mode 100644 (file)
index 0000000..0175dee
--- /dev/null
@@ -0,0 +1,11 @@
+Test if it doesn't crash when reloading while Web Socket is busy
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS insert a iframe
+PASS iframe is ready.
+PASS reloaded iframe while WebSocket is busy
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/reload-crash.html b/LayoutTests/http/tests/websocket/tests/hybi/reload-crash.html
new file mode 100644 (file)
index 0000000..5cd45ce
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if it doesn't crash when reloading while Web Socket is busy");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var frameDiv;
+var reloadCount = 0;
+
+document.iframeReady = function ()
+{
+    if (reloadCount == 0)
+       debug("PASS iframe is ready.");
+    if (reloadCount == 1) {
+       debug("PASS reloaded iframe while WebSocket is busy");
+       finishJSTest();
+       return;
+    }
+    reloadCount += 1;
+};
+
+frameDiv = document.createElement("iframe");
+frameDiv.src = "resources/reload-crash-iframe.html";
+document.body.appendChild(frameDiv);
+debug("PASS insert a iframe");
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe-reference-in-parent.html b/LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe-reference-in-parent.html
new file mode 100644 (file)
index 0000000..1251309
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+<script src="../../../../../js-test-resources/js-test-pre.js"></script>
+<script src="../../../../../js-test-resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+parent.document.childWebSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+
+parent.document.childWebSocket.onopen = function()
+{
+    // send "socket1" to server, so that "socket1" will be broadcasted to web sockets connected to close-on-unload when this web socket is closed.
+    parent.document.childWebSocket.send("socket1");
+};
+parent.document.childWebSocket.onmessage = function(evt)
+{
+    // "socket1" is received by server, so ready to unload this document.
+    parent.document.iframeReady(evt.data);
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe.html b/LayoutTests/http/tests/websocket/tests/hybi/resources/close-on-unload-iframe.html
new file mode 100644 (file)
index 0000000..89d18a1
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script src="../../../../../js-test-resources/js-test-pre.js"></script>
+<script src="../../../../../js-test-resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    // send "socket1" to server, so that "socket1" will be broadcasted to web sockets connected to close-on-unload when this web socket is closed.
+    ws.send("socket1");
+};
+ws.onmessage = function(evt)
+{
+    // "socket1" is received by server, so ready to unload this document.
+    parent.document.iframeReady(evt.data);
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/resources/reload-crash-iframe.html b/LayoutTests/http/tests/websocket/tests/hybi/resources/reload-crash-iframe.html
new file mode 100644 (file)
index 0000000..81ab507
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+<head>
+<script src="../../../../../js-test-resources/js-test-pre.js"></script>
+<script src="../../../../../js-test-resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+parent.document.iframeReady();
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+location.reload();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload-expected.txt
new file mode 100644 (file)
index 0000000..cff48b1
--- /dev/null
@@ -0,0 +1,15 @@
+Test if Web Socket opened in iframe, referred in parent document is, and try to send() returns false.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS document.childWebSocket is non-null.
+PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...
+PASS document.childWebSocket.send('send to closed socket') is false
+PASS closedSocket is "socket1"
+PASS document.childWebSocket.readyState is 3
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload.html b/LayoutTests/http/tests/websocket/tests/hybi/send-after-close-on-unload.html
new file mode 100644 (file)
index 0000000..2d3b5b5
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket opened in iframe, referred in parent document is, and try to send() returns false.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var frameDiv;
+var closedSocket;
+document.childWebSocket = null;
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe-reference-in-parent.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    shouldBe("closedSocket", '"socket1"');
+    shouldBe("document.childWebSocket.readyState", "3");
+    finishJSTest();
+};
+
+document.iframeReady = function()
+{
+    shouldBeNonNull("document.childWebSocket");
+    debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
+    document.body.removeChild(frameDiv);
+    shouldBeFalse("document.childWebSocket.send('send to closed socket')");
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/send-expected.txt
new file mode 100644 (file)
index 0000000..cb3c7f5
--- /dev/null
@@ -0,0 +1,12 @@
+Web Socket send test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+PASS data is FIRST_MESSAGE_TO_SEND
+PASS data is SECOND_MESSAGE_TO_SEND
+Closed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send-throw-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/send-throw-expected.txt
new file mode 100644 (file)
index 0000000..aa74ba3
--- /dev/null
@@ -0,0 +1,11 @@
+Web Socket send test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+Caught exception: Pickles
+Closed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send-throw.html b/LayoutTests/http/tests/websocket/tests/hybi/send-throw.html
new file mode 100644 (file)
index 0000000..756bdb5
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Web Socket send test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/send");
+
+var FIRST_MESSAGE_TO_SEND = {
+    toString: function() { throw "Pickles"; }
+};
+// data needs to be global to be accessbile from shouldBe().
+var data = "";
+
+ws.onopen = function()
+{
+    debug("Connected.");
+    try {
+        ws.send(FIRST_MESSAGE_TO_SEND);
+    } catch (ex) {
+        debug("Caught exception: " + ex);
+    }
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    endTest();
+};
+
+function timeOutCallback()
+{
+    testFailed("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send.html b/LayoutTests/http/tests/websocket/tests/hybi/send.html
new file mode 100644 (file)
index 0000000..feca580
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Web Socket send test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/send");
+
+var FIRST_MESSAGE_TO_SEND = "This is the first message to send to the server.";
+var SECOND_MESSAGE_TO_SEND = "This is the second.";
+// data needs to be global to be accessbile from shouldBe().
+var data = "";
+
+ws.onopen = function()
+{
+    debug("Connected.");
+    ws.send(FIRST_MESSAGE_TO_SEND);
+};
+
+ws.onmessage = function(messageEvent)
+{
+    // The server should echo back the first message.
+    data = messageEvent.data;
+    shouldBe("data", "FIRST_MESSAGE_TO_SEND");
+    ws.onmessage = function(messageEvent) {
+        // The server should echo back the second message.
+        data = messageEvent.data;
+        shouldBe("data", "SECOND_MESSAGE_TO_SEND");
+    };
+    ws.send(SECOND_MESSAGE_TO_SEND);
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    endTest();
+};
+
+function timeOutCallback()
+{
+    testFailed("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send2_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/send2_wsh.py
new file mode 100644 (file)
index 0000000..e2217fa
--- /dev/null
@@ -0,0 +1,8 @@
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    # send 2 messages in one packet.
+    request.connection.write("\x00" + "first message" + "\xff" +
+                             "\x00" + "second message" + "\xff")
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/send_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/send_wsh.py
new file mode 100644 (file)
index 0000000..25104b3
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    # Receive and echo back messages twice.
+    for unused in range(2):
+        message = msgutil.receive_message(request)
+        msgutil.send_message(request, message)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/server-close-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/server-close-expected.txt
new file mode 100644 (file)
index 0000000..feeda9e
--- /dev/null
@@ -0,0 +1,11 @@
+WebSocket: Test server-initiated close.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected
+Closed
+PASS closeEvent.wasClean is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/server-close.html b/LayoutTests/http/tests/websocket/tests/hybi/server-close.html
new file mode 100644 (file)
index 0000000..2d51303
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("WebSocket: Test server-initiated close.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/server-close");
+var closeEvent;
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function(messageEvent)
+{
+    debug("Received: " + messageEvent.data);
+};
+
+ws.onclose = function(event)
+{
+    debug("Closed");
+    closeEvent = event;
+    shouldBeTrue("closeEvent.wasClean");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/server-close_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/server-close_wsh.py
new file mode 100644 (file)
index 0000000..a0698a3
--- /dev/null
@@ -0,0 +1,7 @@
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    # After this handler exits, pywebsocket initiates the closing handshake.
+    pass
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/simple-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/simple-expected.txt
new file mode 100644 (file)
index 0000000..f57c463
--- /dev/null
@@ -0,0 +1,12 @@
+Simple Web Socket test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Created a socket to 'ws://127.0.0.1:8880/websocket/tests/hybi/simple'; readyState 0.
+Connected; readyState 1
+Received: 'Hello from Simple WSH.'; readyState 1
+Closed; readyState 3.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/simple-stress-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/simple-stress-expected.txt
new file mode 100644 (file)
index 0000000..f57c3ec
--- /dev/null
@@ -0,0 +1,7 @@
+Test sending many messages, and sending a large message.
+
+Should say PASS:
+
+Running the test...
+PASS
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/simple-stress.html b/LayoutTests/http/tests/websocket/tests/hybi/simple-stress.html
new file mode 100644 (file)
index 0000000..1dccb7d
--- /dev/null
@@ -0,0 +1,53 @@
+<p>Test sending many messages, and sending a large message.</p>
+<p>Should say PASS:</p>
+<pre id=log>Running the test...
+</pre>
+<script>
+var numSmallMessages = 1000;
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+
+ws.onopen = function() {
+    for (i = 0; i < numSmallMessages; ++i) {
+        ws.send(i);
+    }
+
+}
+
+var lastMessage = -1;
+ws.onmessage = function(msg) {
+    if (parseInt(msg.data) != lastMessage + 1)
+        log("FAIL - out of sequence response. Expected " + lastMessage + 1 + ", got " + msg.data);
+    ++lastMessage;
+    if (lastMessage == numSmallMessages - 1)
+        testLargeString();
+}
+
+function testLargeString()
+{
+    // Build a string 256K in length.
+    var str = " ";
+    for (i = 0; i < 18; ++i)
+        str += str;
+
+    ws.send(str);
+    ws.onmessage = function(msg) {
+        log(msg.data.length == str.length ? "PASS" : "FAIL - wrong response length");
+        ws.send("Goodbye");
+        ws.onmessage = null;
+        if (window.layoutTestController)
+            setTimeout("layoutTestController.notifyDone()", 0);
+    }
+}
+</script>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/simple.html b/LayoutTests/http/tests/websocket/tests/hybi/simple.html
new file mode 100644 (file)
index 0000000..38a72ed
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Simple Web Socket test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple");
+debug("Created a socket to '" + ws.URL + "'; readyState " + ws.readyState + ".");
+
+ws.onopen = function()
+{
+    debug("Connected; readyState " + ws.readyState);
+};
+
+ws.onmessage = function(messageEvent)
+{
+    debug("Received: '" + messageEvent.data + "'; readyState " + ws.readyState);
+};
+
+ws.onclose = function()
+{
+    debug("Closed; readyState " + ws.readyState + ".");
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/simple_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/simple_wsh.py
new file mode 100644 (file)
index 0000000..fc0271c
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, 'Hello from Simple WSH.')
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-expected.txt
new file mode 100644 (file)
index 0000000..bcc1ec1
--- /dev/null
@@ -0,0 +1,10 @@
+Test WebSocket handshake success with sub protocol.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected
+PASS protocol is "sub-protocol"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt
new file mode 100644 (file)
index 0000000..021a749
--- /dev/null
@@ -0,0 +1,10 @@
+Test WebSocket handshake success with sub protocol contains space.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected
+PASS protocol is "sub protocol"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space.html b/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space.html
new file mode 100644 (file)
index 0000000..75db447
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket handshake success with sub protocol contains space.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var protocol;
+
+function endTest()
+{
+    shouldBe("protocol", '"sub protocol"');
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=sub%20protocol";
+var ws = new WebSocket(url, "sub protocol");
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function (messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol.html b/LayoutTests/http/tests/websocket/tests/hybi/sub-protocol.html
new file mode 100644 (file)
index 0000000..a4203a5
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket handshake success with sub protocol.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var protocol;
+
+function endTest()
+{
+    shouldBe("protocol", '"sub-protocol"');
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=sub-protocol";
+var ws = new WebSocket(url, "sub-protocol");
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function (messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/unicode-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/unicode-expected.txt
new file mode 100644 (file)
index 0000000..a89eb83
--- /dev/null
@@ -0,0 +1,12 @@
+Web Socket unicode message test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+Send UNICODE_HELLO.
+PASS data is UNICODE_GOODBYE
+Closed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/unicode.html b/LayoutTests/http/tests/websocket/tests/hybi/unicode.html
new file mode 100644 (file)
index 0000000..6d834c9
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Web Socket unicode message test");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/unicode");
+
+// Hello in Japanese
+var UNICODE_HELLO = "\u3053\u3093\u306b\u3061\u306f";
+// Goodbye in Japanese
+var UNICODE_GOODBYE = "\u3055\u3088\u3046\u306a\u3089";
+
+// data needs to be global to be accessbile from shouldBe().
+var data = "";
+
+ws.onopen = function()
+{
+    debug("Connected.");
+    debug("Send UNICODE_HELLO.");
+    ws.send(UNICODE_HELLO);
+};
+
+ws.onmessage = function(messageEvent)
+{
+    // The server should send back Goodbye if it receives Hello.
+    data = messageEvent.data;
+    shouldBe("data", "UNICODE_GOODBYE");
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    endTest();
+};
+
+function timeOutCallback()
+{
+    testFailed("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/unicode_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/unicode_wsh.py
new file mode 100644 (file)
index 0000000..9e31237
--- /dev/null
@@ -0,0 +1,52 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+# Hello in Japanese
+_UNICODE_HELLO = u"\u3053\u3093\u306b\u3061\u306f"
+
+# Goodbye in Japanese
+_UNICODE_GOODBYE = u"\u3055\u3088\u3046\u306a\u3089"
+
+# Error message
+_ERROR_MESSAGE = "What did you say?"
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    hello = msgutil.receive_message(request)
+    if hello != _UNICODE_HELLO:
+        msgutil.send_message(request, _ERROR_MESSAGE)
+        return
+    msgutil.send_message(request, _UNICODE_GOODBYE)
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/unknown-frame-type_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/unknown-frame-type_wsh.py
new file mode 100644 (file)
index 0000000..feff974
--- /dev/null
@@ -0,0 +1,14 @@
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    for i in range(1, 128):
+        request.connection.write(chr(i) + str(i) + '\xff')
+    for i in range(128, 256):
+        msg = str(i)
+        request.connection.write(chr(i) + chr(len(msg)) + msg)
+    msgutil.send_message(request, 'done')
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash-expected.txt
new file mode 100644 (file)
index 0000000..75c90cf
--- /dev/null
@@ -0,0 +1,13 @@
+URL that doesn't have trailing slash should not emit empty Request-URI.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+WebSocket is open
+received:ws://127.0.0.1:8880/
+WebSocket is closed
+PASS handshake_success is true
+PASS ws_location is "ws://127.0.0.1:8880/"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash.html b/LayoutTests/http/tests/websocket/tests/hybi/url-no-trailing-slash.html
new file mode 100644 (file)
index 0000000..387e802
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("URL that doesn't have trailing slash should not emit empty Request-URI.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var url = "ws://127.0.0.1:8880";
+var handshake_success = false;
+var ws_location;
+
+var ws = new WebSocket(url);
+ws.onopen = function () {
+    debug("WebSocket is open");
+    handshake_success = true;
+};
+ws.onmessage = function (evt) {
+    ws_location = evt.data;
+    debug("received:" + ws_location);
+    ws.close();
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    shouldBeTrue("handshake_success");
+    shouldBe("ws_location", '"ws://127.0.0.1:8880/"');
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-parsing-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-parsing-expected.txt
new file mode 100644 (file)
index 0000000..e49c59f
--- /dev/null
@@ -0,0 +1,23 @@
+CONSOLE MESSAGE: line 0: Invalid url for WebSocket ws://javascript:a
+CONSOLE MESSAGE: line 0: Invalid url for WebSocket /applet
+CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket javascript:a
+CONSOLE MESSAGE: line 0: WebSocket port 25 blocked
+CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path#
+CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path#fragment
+Test WebSocket URL parsing.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS new WebSocket("ws://javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("/applet") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1:25/") threw exception Error: SECURITY_ERR: DOM Exception 18.
+PASS (new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/hybi/simple")).URL is "ws://127.0.0.1:8880/websocket/tests/hybi/simple"
+PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?")).URL is "ws://127.0.0.1:8880/websocket/tests/hybi/simple?"
+PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v")).URL is "ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v"
+PASS new WebSocket("ws://127.0.0.1/path#") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS new WebSocket("ws://127.0.0.1/path#fragment") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-parsing.html b/LayoutTests/http/tests/websocket/tests/hybi/url-parsing.html
new file mode 100644 (file)
index 0000000..a0c4908
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket URL parsing.");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+// Invalid url will fail to be parsed.
+shouldThrow('new WebSocket("ws://javascript:a")');
+
+// Can't use relative URLs - because spec says so, and because the scheme is different anyway.
+shouldThrow('new WebSocket("/applet")');
+
+// Non ws URL is not allowed.
+shouldThrow('new WebSocket("javascript:a")');
+
+// UA is allowed to block access to some ports, which we do.
+shouldThrow('new WebSocket("ws://127.0.0.1:25/")');
+
+// Resolve the url string using the resolve a Web address algorithm.
+// Use 127.0.0.1:8880 and existing ws handler to make sure we don't receive unexpected response (so no console message appears)
+shouldBe('(new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/hybi/simple")).URL', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple"');
+shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?")).URL', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple?"');
+shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v")).URL', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v"');
+
+// draft-hixie-thewebsocketprotocol-60 says If /url/ has a <fragment>
+// component, then fail the parsing Web Socket URLs, so throw a SYNTAX_ERR
+// exception.
+shouldThrow('new WebSocket("ws://127.0.0.1/path#")');
+shouldThrow('new WebSocket("ws://127.0.0.1/path#fragment")');
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-credential-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-with-credential-expected.txt
new file mode 100644 (file)
index 0000000..f7ebc69
--- /dev/null
@@ -0,0 +1,14 @@
+Make sure handshake with URL with credentail info success.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+url=ws://user:pass@127.0.0.1:8880/websocket/tests/hybi/echo-location
+WebSocket is open
+received:ws://127.0.0.1:8880/websocket/tests/hybi/echo-location
+WebSocket is closed
+PASS handshake_success is true
+PASS ws_location is "ws://127.0.0.1:8880/websocket/tests/hybi/echo-location"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-credential.html b/LayoutTests/http/tests/websocket/tests/hybi/url-with-credential.html
new file mode 100644 (file)
index 0000000..b1de2b2
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure handshake with URL with credentail info success.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var url = "ws://user:pass@127.0.0.1:8880/websocket/tests/hybi/echo-location";
+var handshake_success = false;
+var ws_location;
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    shouldBeTrue("handshake_success");
+    shouldBe("ws_location", '"ws://127.0.0.1:8880/websocket/tests/hybi/echo-location"');
+    finishJSTest();
+}
+
+debug("url=" + url);
+var ws = new WebSocket(url);
+ws.onopen = function () {
+    debug("WebSocket is open");
+    handshake_success = true;
+};
+ws.onmessage = function (evt) {
+    ws_location = evt.data;
+    debug("received:" + ws_location);
+    ws.close();
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    endTest();
+};
+var timeoutID = setTimeout("endTest()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query-expected.txt
new file mode 100644 (file)
index 0000000..c994eec
--- /dev/null
@@ -0,0 +1,14 @@
+Make sure handshake with URL with empty query components success.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+url=ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?
+WebSocket is open
+received:ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?
+WebSocket is closed
+PASS handshake_success is true
+PASS ws_location is url
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query.html b/LayoutTests/http/tests/websocket/tests/hybi/url-with-empty-query.html
new file mode 100644 (file)
index 0000000..49e6995
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure handshake with URL with empty query components success.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var url = "ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?";
+var handshake_success = false;
+var ws_location;
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    shouldBeTrue("handshake_success");
+    shouldBe("ws_location", "url");
+    finishJSTest();
+}
+
+debug("url=" + url);
+var ws = new WebSocket(url);
+ws.onopen = function () {
+    debug("WebSocket is open");
+    handshake_success = true;
+};
+ws.onmessage = function (evt) {
+    ws_location = evt.data;
+    debug("received:" + ws_location);
+    ws.close();
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    endTest();
+};
+var timeoutID = setTimeout("endTest()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-expected.txt
new file mode 100644 (file)
index 0000000..f687ada
--- /dev/null
@@ -0,0 +1,14 @@
+Make sure handshake with URL with query components success.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+url=ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?q=v
+WebSocket is open
+received:ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?q=v
+WebSocket is closed
+PASS handshake_success is true
+PASS ws_location is url
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query-expected.txt
new file mode 100644 (file)
index 0000000..a071a03
--- /dev/null
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 0: Error during WebSocket handshake: location mismatch: ws://127.0.0.1:8880/websocket/tests/hybi/no-query? != /websocket/tests/hybi/no-query
+Make sure handshake with URL with query components fails against server that doesn't support query component.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+url=ws://127.0.0.1:8880/websocket/tests/hybi/no-query?
+WebSocket is closed
+PASS handshake_success is false
+PASS ws_location is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query.html b/LayoutTests/http/tests/websocket/tests/hybi/url-with-query-for-no-query.html
new file mode 100644 (file)
index 0000000..410d0d2
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure handshake with URL with query components fails against server that doesn't support query component.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var url = "ws://127.0.0.1:8880/websocket/tests/hybi/no-query?";
+var handshake_success = false;
+var ws_location;
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    shouldBeFalse("handshake_success");
+    shouldBeUndefined("ws_location");
+    finishJSTest();
+}
+
+debug("url=" + url);
+var ws = new WebSocket(url);
+ws.onopen = function () {
+    debug("WebSocket is open");
+    handshake_success = true;
+};
+ws.onmessge = function (evt) {
+    ws_location = evt.data;
+    debug("received:" + ws_location);
+    ws.close();
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    endTest();
+};
+var timeoutID = setTimeout("endTest()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/url-with-query.html b/LayoutTests/http/tests/websocket/tests/hybi/url-with-query.html
new file mode 100644 (file)
index 0000000..09902ae
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure handshake with URL with query components success.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var url = "ws://127.0.0.1:8880/websocket/tests/hybi/echo-location?q=v";
+var handshake_success = false;
+var ws_location;
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    shouldBeTrue("handshake_success");
+    shouldBe("ws_location", "url");
+    finishJSTest();
+}
+
+debug("url=" + url);
+var ws = new WebSocket(url);
+ws.onopen = function () {
+    debug("WebSocket is open");
+    handshake_success = true;
+};
+ws.onmessage = function (evt) {
+    ws_location = evt.data;
+    debug("received:" + ws_location);
+    ws.close();
+};
+ws.onclose = function () {
+    debug("WebSocket is closed");
+    endTest();
+};
+var timeoutID = setTimeout("endTest()", 2000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target-expected.txt
new file mode 100644 (file)
index 0000000..379a44e
--- /dev/null
@@ -0,0 +1,18 @@
+CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
+Make sure WebSocket object acts as EventTarget.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS open_event_handled is false
+PASS message_event_handled is false
+PASS close_event_handled is false
+PASS open_event_handled is true
+PASS open_event_handled is false
+PASS message_event_handled is true
+PASS message_event_handled is false
+PASS close_event_handled is true
+PASS close_event_handled is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target.html b/LayoutTests/http/tests/websocket/tests/hybi/websocket-event-target.html
new file mode 100644 (file)
index 0000000..496a64d
--- /dev/null
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Make sure WebSocket object acts as EventTarget.");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple");
+ws.close(); // That is not a test with a WebSocket server, prevent logging an error to console.
+var open_event_handled = false;
+var message_event_handled = false;
+var close_event_handled = false;
+function openListener() {
+    open_event_handled = true;
+};
+function messageListener() {
+    message_event_handled = true;
+};
+function closeListener() {
+    close_event_handled = true;
+}
+ws.addEventListener('open', openListener, false);
+ws.addEventListener('message', messageListener, false);
+ws.addEventListener('close', closeListener, false);
+
+shouldBe("open_event_handled", "false");
+shouldBe("message_event_handled", "false");
+shouldBe("close_event_handled", "false");
+
+var evt = document.createEvent("Events");
+evt.initEvent("open", true, false);
+ws.dispatchEvent(evt);
+shouldBe("open_event_handled", "true");
+
+open_event_handled = false;
+ws.removeEventListener('open', openListener);
+ws.dispatchEvent(evt);
+shouldBe("open_event_handled", "false");
+
+evt = document.createEvent("MessageEvent");
+evt.initEvent("message", true, false);
+ws.dispatchEvent(evt);
+shouldBe("message_event_handled", "true");
+
+message_event_handled = false;
+ws.removeEventListener('message', messageListener);
+ws.dispatchEvent(evt);
+shouldBe("message_event_handled", "false");
+
+evt = document.createEvent("Events");
+evt.initEvent("close", true, false);
+ws.dispatchEvent(evt);
+shouldBe("close_event_handled", "true");
+
+close_event_handled = false;
+ws.removeEventListener('close', closeListener);
+ws.dispatchEvent(evt);
+shouldBe("close_event_handled", "false");
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity-expected.txt
new file mode 100644 (file)
index 0000000..7340bc0
--- /dev/null
@@ -0,0 +1,2 @@
+ALERT: PASS
+Should alert "PASS".
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity.html b/LayoutTests/http/tests/websocket/tests/hybi/websocket-pending-activity.html
new file mode 100644 (file)
index 0000000..edecc0b
--- /dev/null
@@ -0,0 +1,34 @@
+<body onload="test()">
+<p>Should alert "PASS".</p>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function gc()
+{
+    if (window.GCController)
+        return GCController.collect();
+
+    for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect)
+        var s = new String("abc");
+    }
+}
+
+function test()
+{
+    var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+    ws.onopen = function() {
+        this.send("PASS");
+    }
+    ws.onmessage = function(msg) {
+        alert(msg.data);
+        if (window.layoutTestController)
+            layoutTestController.notifyDone();
+    }
+    ws = null;
+    gc();
+}
+</script>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored-expected.txt
new file mode 100644 (file)
index 0000000..4de6d71
--- /dev/null
@@ -0,0 +1,10 @@
+Test WebSocket handshake success without protocol and ignore WebSocket-Protocol from server.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected
+PASS protocol is "sub-protocol"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored.html b/LayoutTests/http/tests/websocket/tests/hybi/websocket-protocol-ignored.html
new file mode 100644 (file)
index 0000000..e537314
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test WebSocket handshake success without protocol and ignore WebSocket-Protocol from server.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var protocol;
+
+function endTest()
+{
+    shouldBe("protocol", '"sub-protocol"');
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol=sub-protocol";
+var ws = new WebSocket(url);
+
+ws.onopen = function()
+{
+    debug("Connected");
+};
+
+ws.onmessage = function (messageEvent)
+{
+    protocol = messageEvent.data;
+    ws.close();
+};
+
+ws.onclose = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
+</script>
+<script src="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash-expected.txt
new file mode 100644 (file)
index 0000000..dda2387
--- /dev/null
@@ -0,0 +1,11 @@
+Nested creation of two WebSockets should not cause a crash.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: Parsed successfully.
+PASS: worker: Connected.
+PASS: worker: Received message: "Hello from Simple WSH."
+PASS: worker: Closed.
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-onmessage-crash.html
new file mode 100644 (file)
index 0000000..2805949
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Nested creation of two WebSockets should not cause a crash.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new Worker('resources/close-in-onmessage-crash.js');
+worker.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker-expected.txt
new file mode 100644 (file)
index 0000000..1ac33ee
--- /dev/null
@@ -0,0 +1,12 @@
+Test for Web Socket close in SharedWorker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: init
+PASS: worker: WebSocket exists
+PASS: worker: successfullyParsed:[object WebSocket]
+PASS: worker: Connected.
+PASS: worker: Closed.
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-shared-worker.html
new file mode 100644 (file)
index 0000000..ae83520
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Test for Web Socket close in SharedWorker.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new SharedWorker('resources/close-in-worker.js', 'websocketCloseInWorker');
+worker.port.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker-expected.txt
new file mode 100644 (file)
index 0000000..7b9f905
--- /dev/null
@@ -0,0 +1,12 @@
+Test for Web Socket close in Worker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: init
+PASS: worker: WebSocket exists
+PASS: worker: successfullyParsed:[object WebSocket]
+PASS: worker: Connected.
+PASS: worker: Closed.
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/close-in-worker.html
new file mode 100644 (file)
index 0000000..ccf342a
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Test for Web Socket close in Worker.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new Worker('resources/close-in-worker.js');
+worker.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-onmessage-crash.js b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-onmessage-crash.js
new file mode 100644 (file)
index 0000000..9abcc9e
--- /dev/null
@@ -0,0 +1,30 @@
+function runTests()
+{
+    try {
+        var url = 'ws://localhost:8880/websocket/tests/hybi/workers/resources/simple';
+        var ws = new WebSocket(url);
+
+        ws.onopen = function()
+        {
+            postMessage('PASS: worker: Connected.');
+        };
+
+        ws.onmessage = function(messageEvent)
+        {
+            postMessage('PASS: worker: Received message: "' + messageEvent.data + '"');
+            ws.close();
+        };
+
+        ws.onclose = function()
+        {
+            postMessage('PASS: worker: Closed.');
+            postMessage('DONE');
+        };
+    } catch (e) {
+        postMessage('FAIL: worker: Unexpected exception: ' + e);
+    } finally {
+        postMessage('PASS: worker: Parsed successfully.');
+    }
+}
+
+runTests();
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-worker.js b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/close-in-worker.js
new file mode 100644 (file)
index 0000000..60ab959
--- /dev/null
@@ -0,0 +1,36 @@
+if (self.postMessage)
+    runTests();
+else
+    onconnect = handleConnect;
+
+function handleConnect(event)
+{
+    // For shared workers, create a faux postMessage() API to send message back to the parent page.
+    self.postMessage = function (message) { event.ports[0].postMessage(message); };
+    runTests();
+};
+
+function runTests()
+{
+    var ws;
+    try {
+        postMessage("PASS: worker: init");
+        if ('WebSocket' in self)
+            postMessage("PASS: worker: WebSocket exists");
+        else
+            postMessage("FAIL: worker: no WebSocket");
+        ws = new WebSocket('ws://localhost:8880/websocket/tests/hybi/workers/resources/echo');
+        ws.onopen = function() {
+            postMessage("PASS: worker: Connected.");
+            ws.close();
+        };
+        ws.onclose = function() {
+            postMessage("PASS: worker: Closed.");
+            postMessage("DONE");
+        };
+    } catch (e) {
+        postMessage("FAIL: worker: Unexpected exception: " + e);
+    } finally {
+        postMessage("PASS: worker: successfullyParsed:" + ws);
+    }
+};
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py
new file mode 100644 (file)
index 0000000..390d441
--- /dev/null
@@ -0,0 +1,13 @@
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, _hexify(request.ws_challenge))
+
+
+def _hexify(bytes):
+    return ':'.join(['%02X' % ord(byte) for byte in bytes])
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo_wsh.py
new file mode 100644 (file)
index 0000000..429f581
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2010, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+_GOODBYE_MESSAGE = 'Goodbye'
+
+
+def web_socket_do_extra_handshake(request):
+    pass  # Always accept.
+
+
+def web_socket_transfer_data(request):
+    while True:
+        line = msgutil.receive_message(request)
+        msgutil.send_message(request, line)
+        if line == _GOODBYE_MESSAGE:
+            return
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/simple_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/simple_wsh.py
new file mode 100644 (file)
index 0000000..fc0271c
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    msgutil.send_message(request, 'Hello from Simple WSH.')
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-handshake-challenge-randomness.js b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-handshake-challenge-randomness.js
new file mode 100644 (file)
index 0000000..0a1c1fe
--- /dev/null
@@ -0,0 +1,48 @@
+var challenge1;
+var challenge2;
+
+function endTest()
+{
+    if (challenge1 === challenge2)
+        postMessage('FAIL: worker: challenge1 === challenge2 (challenge was ' + challenge1 + ')');
+    else
+        postMessage('PASS: worker: challenge1 !== challenge2');
+
+    postMessage('DONE');
+}
+
+function runTests()
+{
+    try {
+        var url = 'ws://localhost:8880/websocket/tests/hybi/workers/resources/echo-challenge';
+        var ws1 = new WebSocket(url);
+
+        ws1.onmessage = function(messageEvent)
+        {
+            challenge1 = messageEvent.data;
+            ws1.close();
+        }
+
+        ws1.onclose = function()
+        {
+            var ws2 = new WebSocket(url);
+
+            ws2.onmessage = function(messageEvent)
+            {
+                challenge2 = messageEvent.data;
+                ws2.close();
+            }
+
+            ws2.onclose = function()
+            {
+                endTest();
+            }
+        }
+    } catch (e) {
+        postMessage('FAIL: worker: Unexpected exception: ' + e);
+    } finally {
+        postMessage('PASS: worker: Parsed successfully.');
+    }
+}
+
+runTests();
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-simple.js b/LayoutTests/http/tests/websocket/tests/hybi/workers/resources/worker-simple.js
new file mode 100644 (file)
index 0000000..5008301
--- /dev/null
@@ -0,0 +1,38 @@
+if (self.postMessage)
+    runTests();
+else
+    onconnect = handleConnect;
+
+function handleConnect(event)
+{
+    // For shared workers, create a faux postMessage() API to send message back to the parent page.
+    self.postMessage = function (message) { event.ports[0].postMessage(message); };
+    runTests();
+};
+
+function runTests()
+{
+    var ws;
+    try {
+        postMessage("PASS: worker: init");
+        if ('WebSocket' in self)
+            postMessage("PASS: worker: WebSocket exists");
+        else
+            postMessage("PASS: worker: no WebSocket");
+        ws = new WebSocket('ws://localhost:8880/websocket/tests/hybi/workers/resources/simple');
+        ws.onopen = function() {
+            postMessage("PASS: worker: Connected.");
+        };
+        ws.onmessage = function(evt) {
+            postMessage("PASS: worker: Received: '" + evt.data + "'");
+        };
+        ws.onclose = function() {
+            postMessage("PASS: worker: Closed.");
+            postMessage("DONE");
+        };
+    } catch (e) {
+        postMessage("FAIL: worker: Unexpected exception: " + e);
+    } finally {
+        postMessage("PASS: worker: successfullyParsed:" + ws);
+    }
+};
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple-expected.txt
new file mode 100644 (file)
index 0000000..86b6bdc
--- /dev/null
@@ -0,0 +1,13 @@
+Test for Web Socket in SharedWorker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: init
+PASS: worker: WebSocket exists
+PASS: worker: successfullyParsed:[object WebSocket]
+PASS: worker: Connected.
+PASS: worker: Received: 'Hello from Simple WSH.'
+PASS: worker: Closed.
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/shared-worker-simple.html
new file mode 100644 (file)
index 0000000..5bd6ed9
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Test for Web Socket in SharedWorker.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new SharedWorker('resources/worker-simple.js', 'websocketSimple');
+worker.port.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness-expected.txt
new file mode 100644 (file)
index 0000000..18c9880
--- /dev/null
@@ -0,0 +1,9 @@
+Handshake request should contain random challenge values (in a worker process).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: Parsed successfully.
+PASS: worker: challenge1 !== challenge2
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-handshake-challenge-randomness.html
new file mode 100644 (file)
index 0000000..114bf10
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Handshake request should contain random challenge values (in a worker process).</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new Worker('resources/worker-handshake-challenge-randomness.js');
+worker.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple-expected.txt
new file mode 100644 (file)
index 0000000..165a842
--- /dev/null
@@ -0,0 +1,13 @@
+Test for Web Socket in Worker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS: worker: init
+PASS: worker: WebSocket exists
+PASS: worker: successfullyParsed:[object WebSocket]
+PASS: worker: Connected.
+PASS: worker: Received: 'Hello from Simple WSH.'
+PASS: worker: Closed.
+DONE
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple.html b/LayoutTests/http/tests/websocket/tests/hybi/workers/worker-simple.html
new file mode 100644 (file)
index 0000000..0671cf7
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head></head>
+<body>
+<p>Test for Web Socket in Worker.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+var worker = new Worker('resources/worker-simple.js');
+worker.onmessage = function (evt) {
+    log(evt.data);
+    if (evt.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>
index b07153d..11fd81b 100644 (file)
@@ -212,6 +212,9 @@ WONTFIX SKIP : animations/animation-api-1.html = FAIL
 // Unskip after implementing LayoutTestController::setDefersLoading and ::goBack.
 BUGWK60877 SKIP : loader/navigation-while-deferring-loads.html = FAIL
 
+// Skipped until new WebSocket protocol is implemented.
+BUGWK50099 SKIP : http/tests/websocket/tests/hybi/ = PASS FAIL TIMEOUT
+
 // -----------------------------------------------------------------
 // WONTFIX TESTS
 // -----------------------------------------------------------------
index 03dbe0a..e8a26d1 100644 (file)
@@ -1558,3 +1558,6 @@ http/tests/misc/iframe-reparenting-id-collision.html
 http/tests/inspector
 http/tests/inspector-enabled
 inspector/
+
+# Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
+http/tests/websocket/tests/hybi/
index c49666c..8825d11 100644 (file)
@@ -386,3 +386,6 @@ compositing/rtl/rtl-iframe-fixed-overflow-scrolled.html
 compositing/rtl/rtl-iframe-fixed-overflow.html
 compositing/rtl/rtl-iframe-fixed.html
 compositing/rtl/rtl-iframe-relative.html
+
+# Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
+http/tests/websocket/tests/hybi/
index 6098971..f8e0f51 100644 (file)
@@ -1940,6 +1940,13 @@ printing/compositing-layer-printing.html
 printing/media-queries-print.html
 
 # ============================================================================= #
+# failing websocket tests
+# ============================================================================= #
+
+# Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
+http/tests/websocket/tests/hybi/
+
+# ============================================================================= #
 # new tests without expected results
 # ============================================================================= #
 editing/selection/transformed-selection-rects.html
index a7337db..a848066 100644 (file)
@@ -1346,3 +1346,6 @@ fast/workers/worker-crash-with-invalid-location.html
 
 # Need to implement getFormValue().
 plugins/form-value.html
+
+# Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
+http/tests/websocket/tests/hybi/
index b74b049..ba7b846 100644 (file)
@@ -1613,6 +1613,9 @@ platform/mac/fast/text/rounding-hacks.html
 # http://webkit.org/b/58990
 editing/undo/undo-iframe-location-change.html
 
+# Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
+http/tests/websocket/tests/hybi/
+
 ### END OF (1) Classified failures with bug reports
 ########################################