| Index: third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/stream_testing.py
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/websocket/set-cookie_wsh.py b/third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/stream_testing.py
|
| similarity index 54%
|
| copy from third_party/WebKit/LayoutTests/http/tests/websocket/set-cookie_wsh.py
|
| copy to third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/stream_testing.py
|
| index 355cb2b1d2fbd5f1e4fa12e9c4d6fe2a391f906f..098a53d5e75d19caebfbcbdc89495d836e82ded7 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/websocket/set-cookie_wsh.py
|
| +++ b/third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/stream_testing.py
|
| @@ -1,4 +1,5 @@
|
| -# Copyright 2013, Google Inc. All rights reserved.
|
| +# Copyright 2015, 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
|
| @@ -26,29 +27,47 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| +"""Utilities for testing stream-related code."""
|
|
|
| -import urlparse
|
| +from grpc.framework.foundation import stream
|
|
|
|
|
| -def web_socket_do_extra_handshake(request):
|
| - query = urlparse.urlparse(request.uri)[4]
|
| - max_age = ''
|
| - if 'clear' in urlparse.parse_qs(query):
|
| - max_age = '; Max-Age=0'
|
| - request.extra_headers.append(
|
| - ('Set-Cookie', 'WK-WebSocket-test-domain-pass=1; Domain=127.0.0.1' + max_age))
|
| - request.extra_headers.append(
|
| - ('Set-Cookie', 'WK-WebSocket-test-domain-fail=1; Domain=example.com' + max_age))
|
| - request.extra_headers.append(
|
| - ('Set-Cookie', 'WK-WebSocket-test-path-pass=1; Path=/' + max_age))
|
| - request.extra_headers.append(
|
| - ('Set-Cookie', 'WK-WebSocket-test-path-fail=1; Path=/foo/bar' + max_age))
|
| - request.extra_headers.append(('Set-Cookie',
|
| - 'WK-WebSocket-test=1' + max_age))
|
| +class TestConsumer(stream.Consumer):
|
| + """A stream.Consumer instrumented for testing.
|
|
|
| + Attributes:
|
| + calls: A sequence of value-termination pairs describing the history of calls
|
| + made on this object.
|
| + """
|
|
|
| -def web_socket_transfer_data(request):
|
| - request.ws_stream.send_message('url = ' + request.uri)
|
| + def __init__(self):
|
| + self.calls = []
|
|
|
| + def consume(self, value):
|
| + """See stream.Consumer.consume for specification."""
|
| + self.calls.append((value, False))
|
|
|
| -# vi:sts=4 sw=4 et
|
| + def terminate(self):
|
| + """See stream.Consumer.terminate for specification."""
|
| + self.calls.append((None, True))
|
| +
|
| + def consume_and_terminate(self, value):
|
| + """See stream.Consumer.consume_and_terminate for specification."""
|
| + self.calls.append((value, True))
|
| +
|
| + def is_legal(self):
|
| + """Reports whether or not a legal sequence of calls has been made."""
|
| + terminated = False
|
| + for value, terminal in self.calls:
|
| + if terminated:
|
| + return False
|
| + elif terminal:
|
| + terminated = True
|
| + elif value is None:
|
| + return False
|
| + else: # pylint: disable=useless-else-on-loop
|
| + return True
|
| +
|
| + def values(self):
|
| + """Returns the sequence of values that have been passed to this Consumer."""
|
| + return [value for value, _ in self.calls if value]
|
|
|