OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SPDY_SPDY_TEST_UTILS_H_ | 5 #ifndef NET_SPDY_SPDY_TEST_UTILS_H_ |
6 #define NET_SPDY_SPDY_TEST_UTILS_H_ | 6 #define NET_SPDY_SPDY_TEST_UTILS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <string> | 11 #include "net/spdy/platform/api/spdy_string.h" |
12 | |
13 #include "net/spdy/platform/api/spdy_string_piece.h" | 12 #include "net/spdy/platform/api/spdy_string_piece.h" |
14 #include "net/spdy/server_push_delegate.h" | 13 #include "net/spdy/server_push_delegate.h" |
15 #include "net/spdy/spdy_bug_tracker.h" | 14 #include "net/spdy/spdy_bug_tracker.h" |
16 #include "net/spdy/spdy_header_block.h" | 15 #include "net/spdy/spdy_header_block.h" |
17 #include "net/spdy/spdy_headers_handler_interface.h" | 16 #include "net/spdy/spdy_headers_handler_interface.h" |
18 #include "net/spdy/spdy_protocol.h" | 17 #include "net/spdy/spdy_protocol.h" |
19 #include "net/test/gtest_util.h" | 18 #include "net/test/gtest_util.h" |
20 | 19 |
21 #define EXPECT_SPDY_BUG EXPECT_DFATAL | 20 #define EXPECT_SPDY_BUG EXPECT_DFATAL |
22 | 21 |
23 namespace net { | 22 namespace net { |
24 | 23 |
25 class HashValue; | 24 class HashValue; |
26 class TransportSecurityState; | 25 class TransportSecurityState; |
27 | 26 |
28 inline bool operator==(SpdyStringPiece x, | 27 inline bool operator==(SpdyStringPiece x, |
29 const SpdyHeaderBlock::ValueProxy& y) { | 28 const SpdyHeaderBlock::ValueProxy& y) { |
30 return x == y.as_string(); | 29 return x == y.as_string(); |
31 } | 30 } |
32 | 31 |
33 namespace test { | 32 namespace test { |
34 | 33 |
35 std::string HexDumpWithMarks(const unsigned char* data, int length, | 34 SpdyString HexDumpWithMarks(const unsigned char* data, |
36 const bool* marks, int mark_length); | 35 int length, |
| 36 const bool* marks, |
| 37 int mark_length); |
37 | 38 |
38 void CompareCharArraysWithHexError( | 39 void CompareCharArraysWithHexError(const SpdyString& description, |
39 const std::string& description, | 40 const unsigned char* actual, |
40 const unsigned char* actual, | 41 const int actual_len, |
41 const int actual_len, | 42 const unsigned char* expected, |
42 const unsigned char* expected, | 43 const int expected_len); |
43 const int expected_len); | |
44 | 44 |
45 void SetFrameFlags(SpdySerializedFrame* frame, uint8_t flags); | 45 void SetFrameFlags(SpdySerializedFrame* frame, uint8_t flags); |
46 | 46 |
47 void SetFrameLength(SpdySerializedFrame* frame, size_t length); | 47 void SetFrameLength(SpdySerializedFrame* frame, size_t length); |
48 | 48 |
49 std::string a2b_hex(const char* hex_data); | 49 SpdyString a2b_hex(const char* hex_data); |
50 | 50 |
51 // Returns a SHA1 HashValue in which each byte has the value |label|. | 51 // Returns a SHA1 HashValue in which each byte has the value |label|. |
52 HashValue GetTestHashValue(uint8_t label); | 52 HashValue GetTestHashValue(uint8_t label); |
53 | 53 |
54 // Returns SHA1 pinning header for the of the base64 encoding of | 54 // Returns SHA1 pinning header for the of the base64 encoding of |
55 // GetTestHashValue(|label|). | 55 // GetTestHashValue(|label|). |
56 std::string GetTestPin(uint8_t label); | 56 SpdyString GetTestPin(uint8_t label); |
57 | 57 |
58 // Adds a pin for |host| to |state|. | 58 // Adds a pin for |host| to |state|. |
59 void AddPin(TransportSecurityState* state, | 59 void AddPin(TransportSecurityState* state, |
60 const std::string& host, | 60 const SpdyString& host, |
61 uint8_t primary_label, | 61 uint8_t primary_label, |
62 uint8_t backup_label); | 62 uint8_t backup_label); |
63 | 63 |
64 // A test implementation of SpdyHeadersHandlerInterface that correctly | 64 // A test implementation of SpdyHeadersHandlerInterface that correctly |
65 // reconstructs multiple header values for the same name. | 65 // reconstructs multiple header values for the same name. |
66 class TestHeadersHandler : public SpdyHeadersHandlerInterface { | 66 class TestHeadersHandler : public SpdyHeadersHandlerInterface { |
67 public: | 67 public: |
68 TestHeadersHandler() : header_bytes_parsed_(0) {} | 68 TestHeadersHandler() : header_bytes_parsed_(0) {} |
69 | 69 |
70 void OnHeaderBlockStart() override; | 70 void OnHeaderBlockStart() override; |
(...skipping 28 matching lines...) Expand all Loading... |
99 bool CancelPush(GURL url); | 99 bool CancelPush(GURL url); |
100 | 100 |
101 private: | 101 private: |
102 std::map<GURL, std::unique_ptr<ServerPushHelper>> push_helpers; | 102 std::map<GURL, std::unique_ptr<ServerPushHelper>> push_helpers; |
103 }; | 103 }; |
104 | 104 |
105 } // namespace test | 105 } // namespace test |
106 } // namespace net | 106 } // namespace net |
107 | 107 |
108 #endif // NET_SPDY_SPDY_TEST_UTILS_H_ | 108 #endif // NET_SPDY_SPDY_TEST_UTILS_H_ |
OLD | NEW |