OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // All data that is passed through a WebSocket with type "Text" needs to be | 5 // All data that is passed through a WebSocket with type "Text" needs to be |
6 // validated as UTF8. Since this is done on the IO thread, it needs to be | 6 // validated as UTF8. Since this is done on the IO thread, it needs to be |
7 // reasonably fast. | 7 // reasonably fast. |
8 | 8 |
9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will | 9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will |
10 // result in a connection failure, so is unlikely to become a source of | 10 // result in a connection failure, so is unlikely to become a source of |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 output = ConstructRepeatedTestString(output, length); | 127 output = ConstructRepeatedTestString(output, length); |
128 } | 128 } |
129 return output; | 129 return output; |
130 } | 130 } |
131 | 131 |
132 struct TestFunctionDescription { | 132 struct TestFunctionDescription { |
133 TestTargetType function; | 133 TestTargetType function; |
134 const char* function_name; | 134 const char* function_name; |
135 }; | 135 }; |
136 | 136 |
| 137 bool IsStringUTF8(const std::string& str) { |
| 138 return base::IsStringUTF8(base::StringPiece(str)); |
| 139 } |
| 140 |
137 // IsString7Bit is intentionally placed last so it can be excluded easily. | 141 // IsString7Bit is intentionally placed last so it can be excluded easily. |
138 const TestFunctionDescription kTestFunctions[] = { | 142 const TestFunctionDescription kTestFunctions[] = { |
139 {&StreamingUtf8Validator::Validate, "StreamingUtf8Validator"}, | 143 {&StreamingUtf8Validator::Validate, "StreamingUtf8Validator"}, |
140 {&IsStringUTF8, "IsStringUTF8"}, {&IsString7Bit, "IsString7Bit"}}; | 144 {&IsStringUTF8, "IsStringUTF8"}, {&IsString7Bit, "IsString7Bit"}}; |
141 | 145 |
142 // Construct a test string from |construct_test_string| for each of the lengths | 146 // Construct a test string from |construct_test_string| for each of the lengths |
143 // in |kTestLengths| in turn. For each string, run each test in |test_functions| | 147 // in |kTestLengths| in turn. For each string, run each test in |test_functions| |
144 // for a number of iterations such that the total number of bytes validated | 148 // for a number of iterations such that the total number of bytes validated |
145 // is around 16MB. | 149 // is around 16MB. |
146 void RunSomeTests( | 150 void RunSomeTests( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d", | 229 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d", |
226 base::Bind(ConstructRangedTestString, | 230 base::Bind(ConstructRangedTestString, |
227 kFourByteSeqRangeStart, | 231 kFourByteSeqRangeStart, |
228 kFourByteSeqRangeEnd), | 232 kFourByteSeqRangeEnd), |
229 kTestFunctions, | 233 kTestFunctions, |
230 2); | 234 2); |
231 } | 235 } |
232 | 236 |
233 } // namespace | 237 } // namespace |
234 } // namespace base | 238 } // namespace base |
OLD | NEW |