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
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/files/file_util.h"
12 #include "base/optional.h"
13 #include "base/path_service.h"
14 #include "base/stl_util.h"
15 #include "base/test/scoped_feature_list.h"
16 #include "base/test/test_timeouts.h"
17 #include "base/threading/thread_restrictions.h"
18 #include "build/build_config.h"
19 #include "chrome/browser/apps/app_service/app_launch_params.h"
20 #include "chrome/browser/apps/app_service/app_service_proxy.h"
21 #include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
22 #include "chrome/browser/apps/app_service/browser_app_launcher.h"
23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
24 #include "chrome/browser/extensions/extension_browsertest.h"
25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_navigator_params.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_paths.h"
30 #include "chrome/test/base/ui_test_utils.h"
31 #include "chrome/test/nacl/nacl_browsertest_util.h"
32 #include "chrome/test/ppapi/ppapi_test.h"
33 #include "chrome/test/ppapi/ppapi_test_select_file_dialog_factory.h"
34 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/nacl/common/buildflags.h"
36 #include "components/nacl/common/nacl_switches.h"
37 #include "content/public/browser/network_service_instance.h"
38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/render_widget_host_view.h"
40 #include "content/public/browser/storage_partition.h"
41 #include "content/public/browser/web_contents.h"
42 #include "content/public/common/content_features.h"
43 #include "content/public/common/content_switches.h"
44 #include "content/public/common/network_service_util.h"
45 #include "content/public/common/url_constants.h"
46 #include "content/public/test/browser_test.h"
47 #include "content/public/test/browser_test_utils.h"
48 #include "content/public/test/javascript_test_observer.h"
49 #include "content/public/test/ppapi_test_utils.h"
50 #include "content/public/test/test_renderer_host.h"
51 #include "extensions/common/constants.h"
52 #include "extensions/test/extension_test_message_listener.h"
53 #include "mojo/public/cpp/bindings/pending_receiver.h"
54 #include "mojo/public/cpp/bindings/pending_remote.h"
55 #include "mojo/public/cpp/bindings/receiver.h"
56 #include "mojo/public/cpp/bindings/remote.h"
57 #include "mojo/public/cpp/system/data_pipe.h"
58 #include "net/base/net_errors.h"
59 #include "net/base/network_isolation_key.h"
60 #include "net/dns/public/resolve_error_info.h"
61 #include "net/ssl/ssl_info.h"
62 #include "ppapi/shared_impl/test_utils.h"
63 #include "rlz/buildflags/buildflags.h"
64 #include "services/network/public/mojom/host_resolver.mojom.h"
65 #include "services/network/public/mojom/network_context.mojom.h"
66 #include "services/network/public/mojom/network_service_test.mojom.h"
67 #include "services/network/public/mojom/tcp_socket.mojom.h"
68 #include "services/network/public/mojom/tls_socket.mojom.h"
69 #include "services/network/public/mojom/udp_socket.mojom.h"
70 #include "services/network/test/test_dns_util.h"
71 #include "services/network/test/test_network_context.h"
72 #include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
73 #include "third_party/blink/public/common/input/web_input_event.h"
74
75 #if defined(OS_MAC)
76 #include "base/mac/mac_util.h"
77 #endif
78
79 #if defined(OS_WIN)
80 #include "base/win/windows_version.h"
81 #endif
82
83 using content::RenderViewHost;
84
85 // This macro finesses macro expansion to do what we want.
86 #define STRIP_PREFIXES(test_name) ppapi::StripTestPrefixes(#test_name)
87 // Turn the given token into a string. This allows us to use precompiler stuff
88 // to turn names into DISABLED_Foo, but still pass a string to RunTest.
89 #define STRINGIFY(test_name) #test_name
90 #define LIST_TEST(test_name) STRINGIFY(test_name) ","
91
92 // Use these macros to run the tests for a specific interface.
93 // Most interfaces should be tested with both macros.
94 #define TEST_PPAPI_OUT_OF_PROCESS(test_name) \
95 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
96 RunTest(STRIP_PREFIXES(test_name)); \
97 }
98
99 // Similar macros that test over HTTP.
100 #define TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(test_name) \
101 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
102 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
103 }
104
105 // Similar macros that test with an SSL server.
106 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(test_name) \
107 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
108 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
109 }
110
111 // Disable all NaCl tests for --disable-nacl flag and on Mac ASAN builds.
112 // Flaky on Mac ASAN:
113 // http://crbug.com/428670
114
115 #if !BUILDFLAG(ENABLE_NACL) || (defined(OS_MAC) && defined(ADDRESS_SANITIZER))
116
117 #define MAYBE_PPAPI_NACL(test_name) DISABLED_##test_name
118 #define MAYBE_PPAPI_PNACL(test_name) DISABLED_##test_name
119
120 #define TEST_PPAPI_NACL_NATIVE(test_name)
121 #define TEST_PPAPI_NACL(test_name)
122 #define TEST_PPAPI_NACL_DISALLOWED_SOCKETS(test_name)
123 #define TEST_PPAPI_NACL_WITH_SSL_SERVER(test_name)
124 #define TEST_PPAPI_NACL_SUBTESTS(test_name, run_statement)
125
126 #else
127
128 #define MAYBE_PPAPI_NACL(test_name) test_name
129 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \
130 defined(ADDRESS_SANITIZER)
131 // http://crbug.com/633067, http://crbug.com/727989
132 #define MAYBE_PPAPI_PNACL(test_name) DISABLED_##test_name
133 #else
134 #define MAYBE_PPAPI_PNACL(test_name) test_name
135 #endif
136
137 // NaCl based PPAPI tests (direct-to-native NaCl only, no PNaCl)
138 #define TEST_PPAPI_NACL_NATIVE(test_name) \
139 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, test_name) { \
140 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
141 }
142
143 // NaCl based PPAPI tests
144 #define TEST_PPAPI_NACL(test_name) \
145 TEST_PPAPI_NACL_NATIVE(test_name) \
146 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, \
147 MAYBE_PPAPI_PNACL(test_name)) { \
148 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
149 } \
150 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
151 MAYBE_PNACL_NONSFI(test_name)) { \
152 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
153 }
154
155 // NaCl based PPAPI tests
156 #define TEST_PPAPI_NACL_SUBTESTS(test_name, run_statement) \
157 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, test_name) { \
158 run_statement; \
159 } \
160 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, \
161 MAYBE_PPAPI_PNACL(test_name)) { \
162 run_statement; \
163 } \
164 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
165 MAYBE_PNACL_NONSFI(test_name)) { \
166 run_statement; \
167 }
168
169 // NaCl based PPAPI tests with disallowed socket API
170 #define TEST_PPAPI_NACL_DISALLOWED_SOCKETS(test_name) \
171 IN_PROC_BROWSER_TEST_F(PPAPINaClTestDisallowedSockets, test_name) { \
172 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
173 }
174
175 // NaCl based PPAPI tests with SSL server
176 #define TEST_PPAPI_NACL_WITH_SSL_SERVER(test_name) \
177 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, test_name) { \
178 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
179 } \
180 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, \
181 MAYBE_PPAPI_PNACL(test_name)) { \
182 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
183 } \
184 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
185 MAYBE_PNACL_NONSFI(test_name)) { \
186 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
187 }
188
189 #endif // !BUILDFLAG(ENABLE_NACL)
190
191 //
192 // Interface tests.
193 //
194
195 // Flaky on Windows https://crbug.com/1059468
196 #if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
197 TEST_PPAPI_NACL(Console)
198 #endif
199
TEST_PPAPI_NACL(Core)200 TEST_PPAPI_NACL(Core)
201
202 // Non-NaCl TraceEvent tests are in content/test/ppapi/ppapi_browsertest.cc.
203 TEST_PPAPI_NACL(TraceEvent)
204
205 TEST_PPAPI_NACL(InputEvent)
206
207 // Graphics2D_Dev isn't supported in NaCl, only test the other interfaces
208 // TODO(jhorwich) Enable when Graphics2D_Dev interfaces are proxied in NaCl.
209 TEST_PPAPI_NACL(Graphics2D_InvalidResource)
210 TEST_PPAPI_NACL(Graphics2D_InvalidSize)
211 TEST_PPAPI_NACL(Graphics2D_Humongous)
212 TEST_PPAPI_NACL(Graphics2D_InitToZero)
213 TEST_PPAPI_NACL(Graphics2D_Describe)
214 TEST_PPAPI_NACL(Graphics2D_Paint)
215 TEST_PPAPI_NACL(Graphics2D_Scroll)
216 TEST_PPAPI_NACL(Graphics2D_Replace)
217 TEST_PPAPI_NACL(Graphics2D_Flush)
218 // TODO(crbug.com/682275): Flaky on Ubuntu.
219 // TEST_PPAPI_NACL(Graphics2D_FlushOffscreenUpdate)
220 TEST_PPAPI_NACL(Graphics2D_BindNull)
221
222 #if defined(OS_WIN)
223 #if defined(USE_AURA)
224 // These tests fail with the test compositor which is what's used by default for
225 // browser tests on Windows Aura. Renable when the software compositor is
226 // available.
227 #define MAYBE_OUT_Graphics3D DISABLED_Graphics3D
228 #define MAYBE_NACL_Graphics3D DISABLED_Graphics3D
229 #else // defined(USE_AURA)
230 // NaCl tests are having flaky failures on Win: crbug.com/242252
231 #define MAYBE_OUT_Graphics3D Graphics3D
232 #define MAYBE_NACL_Graphics3D DISABLED_Graphics3D
233 #endif // defined(USE_AURA)
234 #elif defined(OS_MAC)
235 // These tests fail when using the legacy software mode. Reenable when the
236 // software compositor is enabled crbug.com/286038
237 #define MAYBE_OUT_Graphics3D DISABLED_Graphics3D
238 #define MAYBE_NACL_Graphics3D DISABLED_Graphics3D
239 #else
240 #define MAYBE_OUT_Graphics3D Graphics3D
241 #define MAYBE_NACL_Graphics3D Graphics3D
242 #endif
243 TEST_PPAPI_OUT_OF_PROCESS(MAYBE_OUT_Graphics3D)
244 TEST_PPAPI_NACL(MAYBE_NACL_Graphics3D)
245
246 TEST_PPAPI_NACL(ImageData)
247
248 // TCPSocket and TCPSocketPrivate tests.
249 #define PPAPI_SOCKET_TEST(_test) \
250 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, _test) { \
251 RunTestViaHTTP(LIST_TEST(_test)); \
252 } \
253 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(_test)) { \
254 RunTestViaHTTP(LIST_TEST(_test)); \
255 } \
256 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(_test)) { \
257 RunTestViaHTTP(LIST_TEST(_test)); \
258 } \
259 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(_test)) { \
260 RunTestViaHTTP(LIST_TEST(_test)); \
261 } \
262 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
263 MAYBE_PNACL_NONSFI(_test)) { \
264 RunTestViaHTTP(LIST_TEST(_test)); \
265 }
266
267 // Split tests into multiple tests, making it easier to isolate which tests are
268 // failing, and reducing chance of timeout.
269 PPAPI_SOCKET_TEST(TCPSocket_Connect)
270 PPAPI_SOCKET_TEST(TCPSocket_ReadWrite)
271 // Flaky on Windows https://crbug.com/1059468#c18
272 #if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
273 PPAPI_SOCKET_TEST(TCPSocket_SetOption)
274 PPAPI_SOCKET_TEST(TCPSocket_Backlog)
275 #endif
276 PPAPI_SOCKET_TEST(TCPSocket_Listen)
277 PPAPI_SOCKET_TEST(TCPSocket_Interface_1_0)
278
279 // Flaky on Windows https://crbug.com/1143728
280 #if !defined(OS_WIN)
281 PPAPI_SOCKET_TEST(TCPSocket_UnexpectedCalls)
282 #endif
283
284 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(TCPServerSocketPrivate_Listen)
285 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(TCPServerSocketPrivate_Backlog)
286 TEST_PPAPI_NACL(TCPServerSocketPrivate_Listen)
287 TEST_PPAPI_NACL(TCPServerSocketPrivate_Backlog)
288
289 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_Basic)
290 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_ReadWrite)
291 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_ReadWriteSSL)
292 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_ConnectAddress)
293 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_SetOption)
294 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate_LargeRead)
295
296 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_Basic)
297 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_ReadWrite)
298 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_ReadWriteSSL)
299 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_ConnectAddress)
300 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_SetOption)
301 TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate_LargeRead)
302
303 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivateTrusted)
304
305 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, TCPSocketPrivateCrash_Resolve) {
306 if (content::IsInProcessNetworkService())
307 return;
308
309 mojo::Remote<network::mojom::NetworkServiceTest> network_service_test;
310 content::GetNetworkService()->BindTestInterface(
311 network_service_test.BindNewPipeAndPassReceiver());
312 network_service_test->CrashOnResolveHost("crash.com");
313
314 RunTestViaHTTP(STRIP_PREFIXES(TCPSocketPrivateCrash_Resolve));
315 }
316
317 namespace {
318
319 // Different types of TCPSocket failures to simulate. *Error means to keep the
320 // pipe alive while invoking the callback with an error code, and *PipeError
321 // means to close the pipe that the method was invoked on (not the pipe passed
322 // to the callback, if there was one) without invoking the callback.
323 //
324 // Note that closing a pipe after a successful operation isn't too interesting,
325 // as it looks just like closing the pipe on the next operation, since the
326 // message filter classes don't generally watch for pipe closure.
327 enum class TCPFailureType {
328 // Makes creation calls for all socket types (server, connected, and bound)
329 // close all Mojo pipes without doing anything.
330 kClosePipeOnCreate,
331
332 kBindClosePipe,
333 kBindError,
334 kBindHangs,
335
336 // These apply to both CreateTCPServerSocket and TCPBoundSocket::Listen().
337 kCreateTCPServerSocketClosePipe,
338 kCreateTCPServerSocketError,
339 kCreateTCPServerSocketHangs,
340
341 kAcceptDropPipe,
342 kAcceptError,
343 kAcceptHangs,
344
345 kConnectClosePipe,
346 kConnectError,
347 kConnectHangs,
348 kWriteClosePipe,
349 kWriteError,
350 kReadClosePipe,
351 kReadError,
352
353 // These apply to all TCPConnectedSocket configuration methods.
354 kSetOptionsClosePipe,
355 kSetOptionsError,
356
357 kUpgradeToTLSClosePipe,
358 kUpgradeToTLSError,
359 kUpgradeToTLSHangs,
360 kSSLWriteClosePipe,
361 kSSLWriteError,
362 kSSLReadClosePipe,
363 kSSLReadError,
364 };
365
LocalAddress()366 net::IPEndPoint LocalAddress() {
367 return net::IPEndPoint(net::IPAddress::IPv4Localhost(), 1234);
368 }
369
RemoteAddress()370 net::IPEndPoint RemoteAddress() {
371 return net::IPEndPoint(net::IPAddress::IPv4Localhost(), 12345);
372 }
373
374 // Use the same class for TCPConnectedSocket and, if it's upgraded,
375 // TLSClientSocket, since the TLSClientSocket interface doesn't do anything.
376 class MockTCPConnectedSocket : public network::mojom::TCPConnectedSocket,
377 public network::mojom::TLSClientSocket {
378 public:
MockTCPConnectedSocket(TCPFailureType tcp_failure_type,mojo::PendingReceiver<network::mojom::TCPConnectedSocket> receiver,mojo::PendingRemote<network::mojom::SocketObserver> observer,network::mojom::NetworkContext::CreateTCPConnectedSocketCallback callback)379 MockTCPConnectedSocket(
380 TCPFailureType tcp_failure_type,
381 mojo::PendingReceiver<network::mojom::TCPConnectedSocket> receiver,
382 mojo::PendingRemote<network::mojom::SocketObserver> observer,
383 network::mojom::NetworkContext::CreateTCPConnectedSocketCallback callback)
384 : tcp_failure_type_(tcp_failure_type),
385 observer_(std::move(observer)),
386 receiver_(this, std::move(receiver)) {
387 if (tcp_failure_type_ == TCPFailureType::kConnectError) {
388 std::move(callback).Run(
389 net::ERR_FAILED, base::nullopt /* local_addr */,
390 base::nullopt /* peer_addr */,
391 mojo::ScopedDataPipeConsumerHandle() /* receive_stream */,
392 mojo::ScopedDataPipeProducerHandle() /* send_stream */);
393 return;
394 }
395
396 if (tcp_failure_type_ == TCPFailureType::kConnectHangs) {
397 create_connected_socket_callback_ = std::move(callback);
398 return;
399 }
400
401 mojo::DataPipe send_pipe;
402 mojo::DataPipe receive_pipe;
403
404 receive_pipe_handle_ = std::move(receive_pipe.producer_handle);
405 send_pipe_handle_ = std::move(send_pipe.consumer_handle);
406
407 std::move(callback).Run(net::OK, LocalAddress(), RemoteAddress(),
408 std::move(receive_pipe.consumer_handle),
409 std::move(send_pipe.producer_handle));
410 ClosePipeIfNeeded();
411 }
412
MockTCPConnectedSocket(TCPFailureType tcp_failure_type,mojo::PendingRemote<network::mojom::SocketObserver> observer,network::mojom::TCPServerSocket::AcceptCallback callback)413 MockTCPConnectedSocket(
414 TCPFailureType tcp_failure_type,
415 mojo::PendingRemote<network::mojom::SocketObserver> observer,
416 network::mojom::TCPServerSocket::AcceptCallback callback)
417 : tcp_failure_type_(tcp_failure_type),
418 observer_(std::move(observer)),
419 receiver_(this) {
420 if (tcp_failure_type_ == TCPFailureType::kAcceptError) {
421 std::move(callback).Run(
422 net::ERR_FAILED, base::nullopt /* remote_addr */,
423 mojo::NullRemote() /* connected_socket */,
424 mojo::ScopedDataPipeConsumerHandle() /* receive_stream */,
425 mojo::ScopedDataPipeProducerHandle() /* send_stream */);
426 return;
427 }
428
429 if (tcp_failure_type_ == TCPFailureType::kAcceptHangs) {
430 accept_callback_ = std::move(callback);
431 return;
432 }
433
434 mojo::DataPipe send_pipe;
435 mojo::DataPipe receive_pipe;
436
437 receive_pipe_handle_ = std::move(receive_pipe.producer_handle);
438 send_pipe_handle_ = std::move(send_pipe.consumer_handle);
439
440 std::move(callback).Run(net::OK, RemoteAddress(),
441 receiver_.BindNewPipeAndPassRemote(),
442 std::move(receive_pipe.consumer_handle),
443 std::move(send_pipe.producer_handle));
444 ClosePipeIfNeeded();
445 }
446
~MockTCPConnectedSocket()447 ~MockTCPConnectedSocket() override {}
448
449 // mojom::TCPConnectedSocket implementation:
450
UpgradeToTLS(const net::HostPortPair & host_port_pair,network::mojom::TLSClientSocketOptionsPtr socket_options,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,mojo::PendingReceiver<network::mojom::TLSClientSocket> receiver,mojo::PendingRemote<network::mojom::SocketObserver> observer,network::mojom::TCPConnectedSocket::UpgradeToTLSCallback callback)451 void UpgradeToTLS(
452 const net::HostPortPair& host_port_pair,
453 network::mojom::TLSClientSocketOptionsPtr socket_options,
454 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
455 mojo::PendingReceiver<network::mojom::TLSClientSocket> receiver,
456 mojo::PendingRemote<network::mojom::SocketObserver> observer,
457 network::mojom::TCPConnectedSocket::UpgradeToTLSCallback callback)
458 override {
459 observer_.reset();
460
461 // Succeed or fail, keep these pipes open (Their state shouldn't matter when
462 // checking for failures).
463 observer_.Bind(std::move(observer));
464 tls_client_socket_receiver_.Bind(std::move(receiver));
465
466 if (tcp_failure_type_ == TCPFailureType::kUpgradeToTLSClosePipe) {
467 receiver_.reset();
468 return;
469 }
470 if (tcp_failure_type_ == TCPFailureType::kUpgradeToTLSError) {
471 std::move(callback).Run(
472 net::ERR_FAILED, mojo::ScopedDataPipeConsumerHandle(),
473 mojo::ScopedDataPipeProducerHandle(), base::nullopt /* ssl_info */);
474 return;
475 }
476
477 if (tcp_failure_type_ == TCPFailureType::kUpgradeToTLSHangs) {
478 upgrade_to_tls_callback_ = std::move(callback);
479 return;
480 }
481
482 // Invoke callback immediately, without waiting for pipes to close - tests
483 // that use a real NetworkContext already make sure that the class correctly
484 // closes the sockets when upgrading.
485
486 mojo::DataPipe send_pipe;
487 mojo::DataPipe receive_pipe;
488 receive_pipe_handle_ = std::move(receive_pipe.producer_handle);
489 send_pipe_handle_ = std::move(send_pipe.consumer_handle);
490
491 std::move(callback).Run(net::OK, std::move(receive_pipe.consumer_handle),
492 std::move(send_pipe.producer_handle),
493 net::SSLInfo());
494
495 if (tcp_failure_type_ == TCPFailureType::kSSLWriteClosePipe) {
496 observer_.reset();
497 send_pipe_handle_.reset();
498 } else if (tcp_failure_type_ == TCPFailureType::kSSLWriteError) {
499 observer_->OnWriteError(net::ERR_FAILED);
500 send_pipe_handle_.reset();
501 } else if (tcp_failure_type_ == TCPFailureType::kSSLReadClosePipe) {
502 observer_.reset();
503 receive_pipe_handle_.reset();
504 } else if (tcp_failure_type_ == TCPFailureType::kSSLReadError) {
505 observer_->OnReadError(net::ERR_FAILED);
506 receive_pipe_handle_.reset();
507 }
508 }
509
SetSendBufferSize(int send_buffer_size,SetSendBufferSizeCallback callback)510 void SetSendBufferSize(int send_buffer_size,
511 SetSendBufferSizeCallback callback) override {
512 if (tcp_failure_type_ == TCPFailureType::kSetOptionsClosePipe) {
513 receiver_.reset();
514 return;
515 }
516 DCHECK_EQ(tcp_failure_type_, TCPFailureType::kSetOptionsError);
517 std::move(callback).Run(net::ERR_FAILED);
518 }
519
SetReceiveBufferSize(int send_buffer_size,SetSendBufferSizeCallback callback)520 void SetReceiveBufferSize(int send_buffer_size,
521 SetSendBufferSizeCallback callback) override {
522 if (tcp_failure_type_ == TCPFailureType::kSetOptionsClosePipe) {
523 receiver_.reset();
524 return;
525 }
526 DCHECK_EQ(tcp_failure_type_, TCPFailureType::kSetOptionsError);
527 std::move(callback).Run(net::ERR_FAILED);
528 }
529
SetNoDelay(bool no_delay,SetNoDelayCallback callback)530 void SetNoDelay(bool no_delay, SetNoDelayCallback callback) override {
531 if (tcp_failure_type_ == TCPFailureType::kSetOptionsClosePipe) {
532 receiver_.reset();
533 return;
534 }
535 DCHECK_EQ(tcp_failure_type_, TCPFailureType::kSetOptionsError);
536 std::move(callback).Run(false);
537 }
538
SetKeepAlive(bool enable,int32_t delay_secs,SetKeepAliveCallback callback)539 void SetKeepAlive(bool enable,
540 int32_t delay_secs,
541 SetKeepAliveCallback callback) override {
542 NOTREACHED();
543 }
544
545 private:
ClosePipeIfNeeded()546 void ClosePipeIfNeeded() {
547 if (tcp_failure_type_ == TCPFailureType::kWriteClosePipe) {
548 observer_.reset();
549 send_pipe_handle_.reset();
550 } else if (tcp_failure_type_ == TCPFailureType::kWriteError) {
551 observer_->OnWriteError(net::ERR_FAILED);
552 send_pipe_handle_.reset();
553 } else if (tcp_failure_type_ == TCPFailureType::kReadClosePipe) {
554 observer_.reset();
555 receive_pipe_handle_.reset();
556 } else if (tcp_failure_type_ == TCPFailureType::kReadError) {
557 observer_->OnReadError(net::ERR_FAILED);
558 receive_pipe_handle_.reset();
559 }
560 }
561
562 const TCPFailureType tcp_failure_type_;
563
564 mojo::Remote<network::mojom::SocketObserver> observer_;
565
566 // Callbacks held onto when simulating a hang.
567 network::mojom::NetworkContext::CreateTCPConnectedSocketCallback
568 create_connected_socket_callback_;
569 network::mojom::TCPServerSocket::AcceptCallback accept_callback_;
570 network::mojom::TCPConnectedSocket::UpgradeToTLSCallback
571 upgrade_to_tls_callback_;
572
573 mojo::ScopedDataPipeProducerHandle receive_pipe_handle_;
574 mojo::ScopedDataPipeConsumerHandle send_pipe_handle_;
575
576 mojo::Receiver<network::mojom::TCPConnectedSocket> receiver_;
577 mojo::Receiver<network::mojom::TLSClientSocket> tls_client_socket_receiver_{
578 this};
579
580 DISALLOW_COPY_AND_ASSIGN(MockTCPConnectedSocket);
581 };
582
583 class MockTCPServerSocket : public network::mojom::TCPServerSocket {
584 public:
585 // CreateTCPServerSocket constructor.
MockTCPServerSocket(TCPFailureType tcp_failure_type,mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,network::mojom::NetworkContext::CreateTCPServerSocketCallback callback)586 MockTCPServerSocket(
587 TCPFailureType tcp_failure_type,
588 mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,
589 network::mojom::NetworkContext::CreateTCPServerSocketCallback callback)
590 : tcp_failure_type_(tcp_failure_type),
591 receiver_(this, std::move(receiver)) {
592 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketError) {
593 std::move(callback).Run(net::ERR_FAILED, base::nullopt /* local_addr */);
594 return;
595 }
596 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketHangs) {
597 create_server_socket_callback_ = std::move(callback);
598 return;
599 }
600 std::move(callback).Run(net::OK, LocalAddress());
601 }
602
603 // TCPBoundSocket::Listen constructor.
MockTCPServerSocket(TCPFailureType tcp_failure_type,mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,network::mojom::TCPBoundSocket::ListenCallback callback)604 MockTCPServerSocket(
605 TCPFailureType tcp_failure_type,
606 mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,
607 network::mojom::TCPBoundSocket::ListenCallback callback)
608 : tcp_failure_type_(tcp_failure_type),
609 receiver_(this, std::move(receiver)) {
610 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketError) {
611 std::move(callback).Run(net::ERR_FAILED);
612 return;
613 }
614 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketHangs) {
615 listen_callback_ = std::move(callback);
616 return;
617 }
618 std::move(callback).Run(net::OK);
619 }
620
~MockTCPServerSocket()621 ~MockTCPServerSocket() override {}
622
623 // TCPServerSocket implementation:
Accept(mojo::PendingRemote<network::mojom::SocketObserver> observer,AcceptCallback callback)624 void Accept(mojo::PendingRemote<network::mojom::SocketObserver> observer,
625 AcceptCallback callback) override {
626 // This falls through just to keep the observer alive.
627 if (tcp_failure_type_ == TCPFailureType::kAcceptDropPipe)
628 receiver_.reset();
629 connected_socket_ = std::make_unique<MockTCPConnectedSocket>(
630 tcp_failure_type_, std::move(observer), std::move(callback));
631 }
632
633 private:
634 const TCPFailureType tcp_failure_type_;
635
636 std::unique_ptr<MockTCPConnectedSocket> connected_socket_;
637
638 // Callbacks held onto when simulating a hang.
639 network::mojom::NetworkContext::CreateTCPServerSocketCallback
640 create_server_socket_callback_;
641 network::mojom::TCPBoundSocket::ListenCallback listen_callback_;
642
643 mojo::Receiver<network::mojom::TCPServerSocket> receiver_;
644
645 DISALLOW_COPY_AND_ASSIGN(MockTCPServerSocket);
646 };
647
648 class MockTCPBoundSocket : public network::mojom::TCPBoundSocket {
649 public:
MockTCPBoundSocket(TCPFailureType tcp_failure_type,mojo::PendingReceiver<network::mojom::TCPBoundSocket> receiver,network::mojom::NetworkContext::CreateTCPBoundSocketCallback callback)650 MockTCPBoundSocket(
651 TCPFailureType tcp_failure_type,
652 mojo::PendingReceiver<network::mojom::TCPBoundSocket> receiver,
653 network::mojom::NetworkContext::CreateTCPBoundSocketCallback callback)
654 : tcp_failure_type_(tcp_failure_type),
655 receiver_(this, std::move(receiver)) {
656 if (tcp_failure_type_ == TCPFailureType::kBindError) {
657 std::move(callback).Run(net::ERR_FAILED, base::nullopt /* local_addr */);
658 return;
659 }
660 if (tcp_failure_type_ == TCPFailureType::kBindHangs) {
661 callback_ = std::move(callback);
662 return;
663 }
664 std::move(callback).Run(net::OK, LocalAddress());
665 }
666
~MockTCPBoundSocket()667 ~MockTCPBoundSocket() override {}
668
669 // mojom::TCPBoundSocket implementation:
Listen(uint32_t backlog,mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,ListenCallback callback)670 void Listen(uint32_t backlog,
671 mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,
672 ListenCallback callback) override {
673 // If closing the pipe, create ServerSocket anyways, to keep |receiver|
674 // alive. The callback invocation will have no effect, since it uses the
675 // TCPBoundSocket's pipe, which was just closed.
676 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketClosePipe)
677 receiver_.reset();
678 server_socket_ = std::make_unique<MockTCPServerSocket>(
679 tcp_failure_type_, std::move(receiver), std::move(callback));
680 }
681
Connect(const net::AddressList & remote_addr,network::mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,mojo::PendingReceiver<network::mojom::TCPConnectedSocket> receiver,mojo::PendingRemote<network::mojom::SocketObserver> observer,ConnectCallback callback)682 void Connect(
683 const net::AddressList& remote_addr,
684 network::mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,
685 mojo::PendingReceiver<network::mojom::TCPConnectedSocket> receiver,
686 mojo::PendingRemote<network::mojom::SocketObserver> observer,
687 ConnectCallback callback) override {
688 if (tcp_failure_type_ == TCPFailureType::kConnectClosePipe)
689 receiver_.reset();
690 connected_socket_ = std::make_unique<MockTCPConnectedSocket>(
691 tcp_failure_type_, std::move(receiver), std::move(observer),
692 std::move(callback));
693 }
694
695 private:
696 const TCPFailureType tcp_failure_type_;
697
698 // Needs to be destroyed after |receiver_|, as it may be holding onto a
699 // callback bound to the Receiver.
700 std::unique_ptr<MockTCPServerSocket> server_socket_;
701 std::unique_ptr<MockTCPConnectedSocket> connected_socket_;
702
703 // Callback held onto when simulating a hang.
704 network::mojom::NetworkContext::CreateTCPBoundSocketCallback callback_;
705
706 mojo::Receiver<network::mojom::TCPBoundSocket> receiver_;
707
708 DISALLOW_COPY_AND_ASSIGN(MockTCPBoundSocket);
709 };
710
711 class MockNetworkContext : public network::TestNetworkContext {
712 public:
MockNetworkContext(TCPFailureType tcp_failure_type,Browser * browser,mojo::PendingReceiver<network::mojom::NetworkContext> receiver)713 explicit MockNetworkContext(
714 TCPFailureType tcp_failure_type,
715 Browser* browser,
716 mojo::PendingReceiver<network::mojom::NetworkContext> receiver)
717 : tcp_failure_type_(tcp_failure_type),
718 browser_(browser),
719 receiver_(this, std::move(receiver)) {}
720
~MockNetworkContext()721 ~MockNetworkContext() override {}
722
723 // network::mojom::NetworkContext implementation:
724
CreateTCPServerSocket(const net::IPEndPoint & local_addr,uint32_t backlog,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,CreateTCPServerSocketCallback callback)725 void CreateTCPServerSocket(
726 const net::IPEndPoint& local_addr,
727 uint32_t backlog,
728 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
729 mojo::PendingReceiver<network::mojom::TCPServerSocket> receiver,
730 CreateTCPServerSocketCallback callback) override {
731 // If closing the pipe, create ServerSocket anyways, to keep |receiver|
732 // alive. The callback invocation will have no effect, since it uses the
733 // TCPBoundSocket's pipe, which was just closed.
734 if (tcp_failure_type_ == TCPFailureType::kCreateTCPServerSocketClosePipe)
735 receiver_.reset();
736 server_sockets_.emplace_back(std::make_unique<MockTCPServerSocket>(
737 tcp_failure_type_, std::move(receiver), std::move(callback)));
738 }
739
CreateTCPConnectedSocket(const base::Optional<net::IPEndPoint> & local_addr,const net::AddressList & remote_addr_list,network::mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,mojo::PendingReceiver<network::mojom::TCPConnectedSocket> socket,mojo::PendingRemote<network::mojom::SocketObserver> observer,CreateTCPConnectedSocketCallback callback)740 void CreateTCPConnectedSocket(
741 const base::Optional<net::IPEndPoint>& local_addr,
742 const net::AddressList& remote_addr_list,
743 network::mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,
744 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
745 mojo::PendingReceiver<network::mojom::TCPConnectedSocket> socket,
746 mojo::PendingRemote<network::mojom::SocketObserver> observer,
747 CreateTCPConnectedSocketCallback callback) override {
748 if (tcp_failure_type_ == TCPFailureType::kConnectClosePipe)
749 receiver_.reset();
750 connected_sockets_.emplace_back(std::make_unique<MockTCPConnectedSocket>(
751 tcp_failure_type_, std::move(socket), std::move(observer),
752 std::move(callback)));
753 }
754
CreateTCPBoundSocket(const net::IPEndPoint & local_addr,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,mojo::PendingReceiver<network::mojom::TCPBoundSocket> receiver,CreateTCPBoundSocketCallback callback)755 void CreateTCPBoundSocket(
756 const net::IPEndPoint& local_addr,
757 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
758 mojo::PendingReceiver<network::mojom::TCPBoundSocket> receiver,
759 CreateTCPBoundSocketCallback callback) override {
760 if (tcp_failure_type_ == TCPFailureType::kBindClosePipe)
761 receiver_.reset();
762 // These tests only create at most one object of a given type at a time.
763 bound_sockets_.emplace_back(std::make_unique<MockTCPBoundSocket>(
764 tcp_failure_type_, std::move(receiver), std::move(callback)));
765 }
766
ResolveHost(const net::HostPortPair & host,const net::NetworkIsolationKey & network_isolation_key,network::mojom::ResolveHostParametersPtr optional_parameters,mojo::PendingRemote<network::mojom::ResolveHostClient> pending_response_client)767 void ResolveHost(const net::HostPortPair& host,
768 const net::NetworkIsolationKey& network_isolation_key,
769 network::mojom::ResolveHostParametersPtr optional_parameters,
770 mojo::PendingRemote<network::mojom::ResolveHostClient>
771 pending_response_client) override {
772 EXPECT_EQ(browser_->tab_strip_model()
773 ->GetActiveWebContents()
774 ->GetMainFrame()
775 ->GetNetworkIsolationKey(),
776 network_isolation_key);
777 mojo::Remote<network::mojom::ResolveHostClient> response_client(
778 std::move(pending_response_client));
779 response_client->OnComplete(net::OK, net::ResolveErrorInfo(net::OK),
780 net::AddressList(LocalAddress()));
781 }
782
783 private:
784 TCPFailureType tcp_failure_type_;
785 Browser* const browser_;
786
787 std::vector<std::unique_ptr<MockTCPServerSocket>> server_sockets_;
788 std::vector<std::unique_ptr<MockTCPBoundSocket>> bound_sockets_;
789 std::vector<std::unique_ptr<MockTCPConnectedSocket>> connected_sockets_;
790
791 mojo::Receiver<network::mojom::NetworkContext> receiver_;
792
793 DISALLOW_COPY_AND_ASSIGN(MockNetworkContext);
794 };
795
796 // Runs a TCP test using a MockNetworkContext, through a Mojo pipe. Using a Mojo
797 // pipe makes sure that everything happens asynchronously through a pipe.
798 #define RUN_TCP_FAILURE_TEST(test_name, failure_type) \
799 do { \
800 mojo::Remote<network::mojom::NetworkContext> network_context_proxy; \
801 MockNetworkContext network_context( \
802 failure_type, browser(), \
803 network_context_proxy.BindNewPipeAndPassReceiver()); \
804 ppapi::SetPepperTCPNetworkContextForTesting(network_context_proxy.get()); \
805 RunTestViaHTTP(LIST_TEST(test_name)); \
806 ppapi::SetPepperTCPNetworkContextForTesting(nullptr); \
807 } while (false)
808
809 } // namespace
810
811 // Macro for tests that use |WrappedUDPSocket| to simulate errors. |test_name|
812 // and |_test| are separate values because there are often multiple ways to get
813 // the same error pattern (Dropped mojo pipe and failed call, generally).
814 #define TCP_SOCKET_FAILURE_TEST(test_name, _test, failure_type) \
815 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
816 RUN_TCP_FAILURE_TEST(_test, failure_type); \
817 } \
818 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(test_name)) { \
819 RUN_TCP_FAILURE_TEST(_test, failure_type); \
820 } \
821 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(test_name)) { \
822 RUN_TCP_FAILURE_TEST(_test, failure_type); \
823 } \
824 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(test_name)) { \
825 RUN_TCP_FAILURE_TEST(_test, failure_type); \
826 } \
827 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
828 MAYBE_PNACL_NONSFI(test_name)) { \
829 RUN_TCP_FAILURE_TEST(_test, failure_type); \
830 }
831
832 TCP_SOCKET_FAILURE_TEST(TCPSocket_ConnectClosePipe,
833 TCPSocket_ConnectFails,
834 TCPFailureType::kConnectClosePipe)
835 TCP_SOCKET_FAILURE_TEST(TCPSocket_ConnectError,
836 TCPSocket_ConnectFails,
837 TCPFailureType::kConnectError)
838 TCP_SOCKET_FAILURE_TEST(TCPSocket_ConnectHangs,
839 TCPSocket_ConnectHangs,
840 TCPFailureType::kConnectHangs)
841 TCP_SOCKET_FAILURE_TEST(TCPSocket_WriteClosePipe,
842 TCPSocket_WriteFails,
843 TCPFailureType::kWriteClosePipe)
844 TCP_SOCKET_FAILURE_TEST(TCPSocket_WriteError,
845 TCPSocket_WriteFails,
846 TCPFailureType::kWriteError)
847 TCP_SOCKET_FAILURE_TEST(TCPSocket_ReadClosePipe,
848 TCPSocket_ReadFails,
849 TCPFailureType::kReadClosePipe)
850 TCP_SOCKET_FAILURE_TEST(TCPSocket_ReadError,
851 TCPSocket_ReadFails,
852 TCPFailureType::kReadError)
853
854 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetSendBufferSizeClosePipe,
855 TCPSocket_SetSendBufferSizeFails,
856 TCPFailureType::kSetOptionsClosePipe)
857 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetSendBufferSizeError,
858 TCPSocket_SetSendBufferSizeFails,
859 TCPFailureType::kSetOptionsError)
860 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetReceiveBufferSizeClosePipe,
861 TCPSocket_SetReceiveBufferSizeFails,
862 TCPFailureType::kSetOptionsClosePipe)
863 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetReceiveBufferSizeError,
864 TCPSocket_SetReceiveBufferSizeFails,
865 TCPFailureType::kSetOptionsError)
866 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetNoDelayClosePipe,
867 TCPSocket_SetNoDelayFails,
868 TCPFailureType::kSetOptionsClosePipe)
869 TCP_SOCKET_FAILURE_TEST(TCPSocket_SetNoDelayError,
870 TCPSocket_SetNoDelayFails,
871 TCPFailureType::kSetOptionsError)
872
873 // Can't use TCPSocket_BindFailsConnectSucceeds for this one, because
874 // BindClosePipe has to close the NetworkContext pipe.
875 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindClosePipe,
876 TCPSocket_BindFails,
877 TCPFailureType::kBindClosePipe)
878 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindError,
879 TCPSocket_BindFailsConnectSucceeds,
880 TCPFailureType::kBindError)
881 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindHangs,
882 TCPSocket_BindHangs,
883 TCPFailureType::kBindHangs)
884 // https://crbug.com/997840. Flaky.
885 TCP_SOCKET_FAILURE_TEST(DISABLED_TCPSocket_ListenClosePipe,
886 TCPSocket_ListenFails,
887 TCPFailureType::kCreateTCPServerSocketClosePipe)
888 TCP_SOCKET_FAILURE_TEST(TCPSocket_ListenError,
889 TCPSocket_ListenFails,
890 TCPFailureType::kCreateTCPServerSocketError)
891 TCP_SOCKET_FAILURE_TEST(TCPSocket_ListenHangs,
892 TCPSocket_ListenHangs,
893 TCPFailureType::kCreateTCPServerSocketHangs)
894 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptClosePipe,
895 TCPSocket_AcceptFails,
896 TCPFailureType::kAcceptDropPipe)
897 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptError,
898 TCPSocket_AcceptFails,
899 TCPFailureType::kAcceptError)
900 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptHangs,
901 TCPSocket_AcceptHangs,
902 TCPFailureType::kAcceptHangs)
903 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptedSocketWriteClosePipe,
904 TCPSocket_AcceptedSocketWriteFails,
905 TCPFailureType::kWriteClosePipe)
906 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptedSocketWriteError,
907 TCPSocket_AcceptedSocketWriteFails,
908 TCPFailureType::kWriteError)
909 // https://crbug.com/997840. Flaky.
910 TCP_SOCKET_FAILURE_TEST(DISABLED_TCPSocket_AcceptedSocketReadClosePipe,
911 TCPSocket_AcceptedSocketReadFails,
912 TCPFailureType::kReadClosePipe)
913 TCP_SOCKET_FAILURE_TEST(TCPSocket_AcceptedSocketReadError,
914 TCPSocket_AcceptedSocketReadFails,
915 TCPFailureType::kReadError)
916 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindConnectClosePipe,
917 TCPSocket_BindConnectFails,
918 TCPFailureType::kConnectClosePipe)
919 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindConnectError,
920 TCPSocket_BindConnectFails,
921 TCPFailureType::kConnectError)
922 TCP_SOCKET_FAILURE_TEST(TCPSocket_BindConnectHangs,
923 TCPSocket_BindConnectHangs,
924 TCPFailureType::kConnectHangs)
925
926 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLHandshakeClosePipe,
927 TCPSocketPrivate_SSLHandshakeFails,
928 TCPFailureType::kUpgradeToTLSClosePipe)
929 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLHandshakeError,
930 TCPSocketPrivate_SSLHandshakeFails,
931 TCPFailureType::kUpgradeToTLSError)
932 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLHandshakeHangs,
933 TCPSocketPrivate_SSLHandshakeHangs,
934 TCPFailureType::kUpgradeToTLSHangs)
935 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLWriteClosePipe,
936 TCPSocketPrivate_SSLWriteFails,
937 TCPFailureType::kSSLWriteClosePipe)
938 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLWriteError,
939 TCPSocketPrivate_SSLWriteFails,
940 TCPFailureType::kSSLWriteError)
941 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLReadClosePipe,
942 TCPSocketPrivate_SSLReadFails,
943 TCPFailureType::kSSLReadClosePipe)
944 TCP_SOCKET_FAILURE_TEST(TCPSocketPrivate_SSLReadError,
945 TCPSocketPrivate_SSLReadFails,
946 TCPFailureType::kSSLReadError)
947
948 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_ListenClosePipe,
949 TCPServerSocketPrivate_ListenFails,
950 TCPFailureType::kCreateTCPServerSocketClosePipe)
951 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_ListenError,
952 TCPServerSocketPrivate_ListenFails,
953 TCPFailureType::kCreateTCPServerSocketError)
954 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_ListenHangs,
955 TCPServerSocketPrivate_ListenHangs,
956 TCPFailureType::kCreateTCPServerSocketHangs)
957 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_AcceptClosePipe,
958 TCPServerSocketPrivate_AcceptFails,
959 TCPFailureType::kAcceptDropPipe)
960 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_AcceptError,
961 TCPServerSocketPrivate_AcceptFails,
962 TCPFailureType::kAcceptError)
963 TCP_SOCKET_FAILURE_TEST(TCPServerSocketPrivate_AcceptHangs,
964 TCPServerSocketPrivate_AcceptHangs,
965 TCPFailureType::kAcceptHangs)
966
967 // UDPSocket tests.
968
969 // Split tests into multiple tests, making it easier to isolate which tests are
970 // failing.
971 PPAPI_SOCKET_TEST(UDPSocket_ReadWrite)
972 PPAPI_SOCKET_TEST(UDPSocket_SetOption)
973 PPAPI_SOCKET_TEST(UDPSocket_SetOption_1_0)
974 PPAPI_SOCKET_TEST(UDPSocket_SetOption_1_1)
975 PPAPI_SOCKET_TEST(UDPSocket_Broadcast)
976 PPAPI_SOCKET_TEST(UDPSocket_ParallelSend)
977 PPAPI_SOCKET_TEST(UDPSocket_Multicast)
978
979 // UDPSocketPrivate tests.
980 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate_Connect)
981 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate_ConnectFailure)
982 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate_Broadcast)
983 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate_SetSocketFeatureErrors)
984 TEST_PPAPI_NACL(UDPSocketPrivate_Connect)
985 TEST_PPAPI_NACL(UDPSocketPrivate_ConnectFailure)
986 TEST_PPAPI_NACL(UDPSocketPrivate_Broadcast)
987 TEST_PPAPI_NACL(UDPSocketPrivate_SetSocketFeatureErrors)
988
989 namespace {
990
991 // UDPSocket subclass that wraps a real network::mojom::UDPSocket, and can
992 // simulate certain failures. Owns itself, and destroys itself when one of
993 // its Mojo pipes is closed.
994 class WrappedUDPSocket : public network::mojom::UDPSocket {
995 public:
996 // Type of failure to simulate. "DropPipe" failures correspond to dropping a
997 // Mojo pipe (Which typically happens if the network service crashes, or the
998 // parent NetworkContext is torn down). "Error" failures correspond to
999 // returning net::ERR_FAILED.
1000 enum class FailureType {
1001 kBindError,
1002 kBindDropPipe,
1003 kBroadcastError,
1004 kBroadcastDropPipe,
1005 kSendToDropPipe,
1006 kSendToError,
1007 kDropListenerPipeOnConstruction,
1008 kDropListenerPipeOnReceiveMore,
1009 kReadError,
1010 };
WrappedUDPSocket(FailureType failure_type,network::mojom::NetworkContext * network_context,mojo::PendingReceiver<network::mojom::UDPSocket> socket_receiver,mojo::PendingRemote<network::mojom::UDPSocketListener> socket_listener)1011 WrappedUDPSocket(
1012 FailureType failure_type,
1013 network::mojom::NetworkContext* network_context,
1014 mojo::PendingReceiver<network::mojom::UDPSocket> socket_receiver,
1015 mojo::PendingRemote<network::mojom::UDPSocketListener> socket_listener)
1016 : failure_type_(failure_type),
1017 receiver_(this, std::move(socket_receiver)) {
1018 if (failure_type == FailureType::kDropListenerPipeOnConstruction)
1019 socket_listener.reset();
1020 else
1021 socket_listener_.Bind(std::move(socket_listener));
1022 network_context->CreateUDPSocket(
1023 wrapped_socket_.BindNewPipeAndPassReceiver(), mojo::NullRemote());
1024 receiver_.set_disconnect_handler(
1025 base::BindOnce(&WrappedUDPSocket::Close, base::Unretained(this)));
1026 wrapped_socket_.set_disconnect_handler(
1027 base::BindOnce(&WrappedUDPSocket::Close, base::Unretained(this)));
1028 }
1029
1030 // network::mojom::UDPSocket implementation.
Connect(const net::IPEndPoint & remote_addr,network::mojom::UDPSocketOptionsPtr options,ConnectCallback callback)1031 void Connect(const net::IPEndPoint& remote_addr,
1032 network::mojom::UDPSocketOptionsPtr options,
1033 ConnectCallback callback) override {
1034 NOTREACHED();
1035 }
Bind(const net::IPEndPoint & local_addr,network::mojom::UDPSocketOptionsPtr options,BindCallback callback)1036 void Bind(const net::IPEndPoint& local_addr,
1037 network::mojom::UDPSocketOptionsPtr options,
1038 BindCallback callback) override {
1039 if (failure_type_ == FailureType::kBindError) {
1040 std::move(callback).Run(net::ERR_FAILED, base::nullopt);
1041 return;
1042 }
1043 if (failure_type_ == FailureType::kBindDropPipe) {
1044 Close();
1045 return;
1046 }
1047 wrapped_socket_->Bind(local_addr, std::move(options), std::move(callback));
1048 }
SetBroadcast(bool broadcast,SetBroadcastCallback callback)1049 void SetBroadcast(bool broadcast, SetBroadcastCallback callback) override {
1050 if (failure_type_ == FailureType::kBroadcastError) {
1051 std::move(callback).Run(net::ERR_FAILED);
1052 return;
1053 }
1054 if (failure_type_ == FailureType::kBroadcastDropPipe) {
1055 Close();
1056 return;
1057 }
1058 wrapped_socket_->SetBroadcast(broadcast, std::move(callback));
1059 }
SetSendBufferSize(int32_t send_buffer_size,SetSendBufferSizeCallback callback)1060 void SetSendBufferSize(int32_t send_buffer_size,
1061 SetSendBufferSizeCallback callback) override {
1062 wrapped_socket_->SetSendBufferSize(send_buffer_size, std::move(callback));
1063 }
SetReceiveBufferSize(int32_t receive_buffer_size,SetReceiveBufferSizeCallback callback)1064 void SetReceiveBufferSize(int32_t receive_buffer_size,
1065 SetReceiveBufferSizeCallback callback) override {
1066 wrapped_socket_->SetReceiveBufferSize(receive_buffer_size,
1067 std::move(callback));
1068 }
JoinGroup(const net::IPAddress & group_address,JoinGroupCallback callback)1069 void JoinGroup(const net::IPAddress& group_address,
1070 JoinGroupCallback callback) override {
1071 wrapped_socket_->JoinGroup(group_address, std::move(callback));
1072 }
LeaveGroup(const net::IPAddress & group_address,LeaveGroupCallback callback)1073 void LeaveGroup(const net::IPAddress& group_address,
1074 LeaveGroupCallback callback) override {
1075 wrapped_socket_->LeaveGroup(group_address, std::move(callback));
1076 }
ReceiveMore(uint32_t num_additional_datagrams)1077 void ReceiveMore(uint32_t num_additional_datagrams) override {
1078 if (failure_type_ == FailureType::kDropListenerPipeOnReceiveMore) {
1079 socket_listener_.reset();
1080 return;
1081 }
1082 if (failure_type_ == FailureType::kReadError) {
1083 for (uint32_t i = 0; i < num_additional_datagrams; ++i) {
1084 socket_listener_->OnReceived(net::ERR_FAILED, base::nullopt,
1085 base::nullopt);
1086 }
1087 return;
1088 }
1089 // None of the tests using this fixture expect to read anything
1090 // successfully, so just ignore this call if it isn't supposed to result in
1091 // an error of some sort.
1092 }
ReceiveMoreWithBufferSize(uint32_t num_additional_datagrams,uint32_t buffer_size)1093 void ReceiveMoreWithBufferSize(uint32_t num_additional_datagrams,
1094 uint32_t buffer_size) override {
1095 NOTREACHED();
1096 }
SendTo(const net::IPEndPoint & dest_addr,base::span<const uint8_t> data,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,SendToCallback callback)1097 void SendTo(const net::IPEndPoint& dest_addr,
1098 base::span<const uint8_t> data,
1099 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
1100 SendToCallback callback) override {
1101 if (failure_type_ == FailureType::kSendToError) {
1102 std::move(callback).Run(net::ERR_FAILED);
1103 return;
1104 }
1105 if (failure_type_ == FailureType::kSendToDropPipe) {
1106 Close();
1107 return;
1108 }
1109 wrapped_socket_->SendTo(dest_addr, data, traffic_annotation,
1110 std::move(callback));
1111 }
Send(base::span<const uint8_t> data,const net::MutableNetworkTrafficAnnotationTag & traffic_annotation,SendCallback callback)1112 void Send(base::span<const uint8_t> data,
1113 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
1114 SendCallback callback) override {
1115 NOTREACHED();
1116 }
Close()1117 void Close() override {
1118 // Deleting |this| before closing the bindings can cause Mojo to DCHECK if
1119 // there's a pending callback.
1120 receiver_.reset();
1121 socket_listener_.reset();
1122 delete this;
1123 }
1124
1125 private:
1126 const FailureType failure_type_;
1127 mojo::Receiver<network::mojom::UDPSocket> receiver_;
1128 mojo::Remote<network::mojom::UDPSocket> wrapped_socket_;
1129
1130 // Only populated on certain read FailureTypes.
1131 mojo::Remote<network::mojom::UDPSocketListener> socket_listener_;
1132
1133 DISALLOW_COPY_AND_ASSIGN(WrappedUDPSocket);
1134 };
1135
TestCreateUDPSocketCallback(WrappedUDPSocket::FailureType failure_type,network::mojom::NetworkContext * network_context,mojo::PendingReceiver<network::mojom::UDPSocket> socket_receiver,mojo::PendingRemote<network::mojom::UDPSocketListener> socket_listener)1136 void TestCreateUDPSocketCallback(
1137 WrappedUDPSocket::FailureType failure_type,
1138 network::mojom::NetworkContext* network_context,
1139 mojo::PendingReceiver<network::mojom::UDPSocket> socket_receiver,
1140 mojo::PendingRemote<network::mojom::UDPSocketListener> socket_listener) {
1141 // This will delete itself when one of its Mojo pipes is closed.
1142 new WrappedUDPSocket(failure_type, network_context,
1143 std::move(socket_receiver), std::move(socket_listener));
1144 }
1145
1146 #define RUN_UDP_FAILURE_TEST(test_name, failure_type) \
1147 do { \
1148 auto callback = \
1149 base::BindRepeating(&TestCreateUDPSocketCallback, failure_type); \
1150 ppapi::SetPepperUDPSocketCallackForTesting(&callback); \
1151 RunTestViaHTTP(LIST_TEST(test_name)); \
1152 ppapi::SetPepperUDPSocketCallackForTesting(nullptr); \
1153 } while (false)
1154
1155 } // namespace
1156
1157 // Macro for tests that use |WrappedUDPSocket| to simulate errors. |test_name|
1158 // and |_test| are separate values because there are often multiple ways to get
1159 // the same error pattern (Dropped mojo pipe and failed call, generally).
1160 #define UDPSOCKET_FAILURE_TEST(test_name, _test, failure_type) \
1161 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
1162 RUN_UDP_FAILURE_TEST(_test, failure_type); \
1163 } \
1164 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(test_name)) { \
1165 RUN_UDP_FAILURE_TEST(_test, failure_type); \
1166 } \
1167 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(test_name)) { \
1168 RUN_UDP_FAILURE_TEST(_test, failure_type); \
1169 } \
1170 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(test_name)) { \
1171 RUN_UDP_FAILURE_TEST(_test, failure_type); \
1172 } \
1173 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, \
1174 MAYBE_PNACL_NONSFI(test_name)) { \
1175 RUN_UDP_FAILURE_TEST(_test, failure_type); \
1176 }
1177
UDPSOCKET_FAILURE_TEST(UDPSocket_BindError,UDPSocket_BindFails,WrappedUDPSocket::FailureType::kBindError)1178 UDPSOCKET_FAILURE_TEST(UDPSocket_BindError,
1179 UDPSocket_BindFails,
1180 WrappedUDPSocket::FailureType::kBindError)
1181 UDPSOCKET_FAILURE_TEST(UDPSocket_BindDropPipe,
1182 UDPSocket_BindFails,
1183 WrappedUDPSocket::FailureType::kBindDropPipe)
1184 // Flaky on Windows https://crbug.com/1059468#c18
1185 #if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
1186 UDPSOCKET_FAILURE_TEST(UDPSocket_SetBroadcastError,
1187 UDPSocket_SetBroadcastFails,
1188 WrappedUDPSocket::FailureType::kBroadcastError)
1189 #endif
1190 UDPSOCKET_FAILURE_TEST(UDPSocket_SetBroadcastDropPipe,
1191 UDPSocket_SetBroadcastFails,
1192 WrappedUDPSocket::FailureType::kBroadcastDropPipe)
1193 UDPSOCKET_FAILURE_TEST(UDPSocket_SendToBeforeDropPipeFails,
1194 UDPSocket_SendToFails,
1195 WrappedUDPSocket::FailureType::kSendToDropPipe)
1196 UDPSOCKET_FAILURE_TEST(UDPSocket_DropPipeAfterBindSendToFails,
1197 UDPSocket_SendToFails,
1198 WrappedUDPSocket::FailureType::kSendToError)
1199 // https://crbug.com/997840. Flaky.
1200 UDPSOCKET_FAILURE_TEST(DISABLED_UDPSocket_ReadError,
1201 UDPSocket_ReadFails,
1202 WrappedUDPSocket::FailureType::kReadError)
1203 // https://crbug.com/997840. Flaky.
1204 UDPSOCKET_FAILURE_TEST(
1205 DISABLED_UDPSocket_DropListenerPipeOnConstruction,
1206 UDPSocket_ReadFails,
1207 WrappedUDPSocket::FailureType::kDropListenerPipeOnConstruction)
1208 // Flaky on all platforms. http://crbug.com/997785.
1209 UDPSOCKET_FAILURE_TEST(
1210 DISABLED_UDPSocket_DropListenerPipeOnReceiveMore,
1211 UDPSocket_ReadFails,
1212 WrappedUDPSocket::FailureType::kDropListenerPipeOnReceiveMore)
1213
1214 // Disallowed socket tests.
1215 TEST_PPAPI_NACL_DISALLOWED_SOCKETS(HostResolverPrivateDisallowed)
1216 TEST_PPAPI_NACL_DISALLOWED_SOCKETS(TCPServerSocketPrivateDisallowed)
1217 TEST_PPAPI_NACL_DISALLOWED_SOCKETS(TCPSocketPrivateDisallowed)
1218 TEST_PPAPI_NACL_DISALLOWED_SOCKETS(UDPSocketPrivateDisallowed)
1219
1220 // Checks that a hostname used by the HostResolver tests ("host_resolver.test")
1221 // is present in the DNS cache with the NetworkIsolationKey associated with the
1222 // foreground WebContents - this is needed so as not to leak what hostnames were
1223 // looked up across tabs with different first party origins.
1224 void CheckTestHostNameUsedWithCorrectNetworkIsolationKey(Browser* browser) {
1225 network::mojom::NetworkContext* network_context =
1226 content::BrowserContext::GetDefaultStoragePartition(browser->profile())
1227 ->GetNetworkContext();
1228 const net::HostPortPair kHostPortPair(
1229 net::HostPortPair("host_resolver.test", 80));
1230
1231 network::mojom::ResolveHostParametersPtr params =
1232 network::mojom::ResolveHostParameters::New();
1233 // Cache only lookup.
1234 params->source = net::HostResolverSource::LOCAL_ONLY;
1235 // Match the parameters used by the test.
1236 params->include_canonical_name = true;
1237 net::NetworkIsolationKey network_isolation_key =
1238 browser->tab_strip_model()
1239 ->GetActiveWebContents()
1240 ->GetMainFrame()
1241 ->GetNetworkIsolationKey();
1242 network::DnsLookupResult result1 = network::BlockingDnsLookup(
1243 network_context, kHostPortPair, std::move(params), network_isolation_key);
1244 EXPECT_EQ(net::OK, result1.error);
1245 ASSERT_TRUE(result1.resolved_addresses.has_value());
1246 ASSERT_EQ(1u, result1.resolved_addresses->size());
1247 EXPECT_EQ(browser->tab_strip_model()->GetActiveWebContents()->GetURL().host(),
1248 result1.resolved_addresses.value()[0].ToStringWithoutPort());
1249
1250 // Check that the entry isn't present in the cache with the empty
1251 // NetworkIsolationKey().
1252 params = network::mojom::ResolveHostParameters::New();
1253 // Cache only lookup.
1254 params->source = net::HostResolverSource::LOCAL_ONLY;
1255 // Match the parameters used by the test.
1256 params->include_canonical_name = true;
1257 network::DnsLookupResult result2 =
1258 network::BlockingDnsLookup(network_context, kHostPortPair,
1259 std::move(params), net::NetworkIsolationKey());
1260 EXPECT_EQ(net::ERR_NAME_NOT_RESOLVED, result2.error);
1261 }
1262
1263 // HostResolver and HostResolverPrivate tests. The PPAPI code used by these
1264 // tests is in ppapi/tests/test_host_resolver.cc.
1265 #define RUN_HOST_RESOLVER_SUBTESTS \
1266 RunTestViaHTTP(LIST_TEST(HostResolver_Empty) LIST_TEST(HostResolver_Resolve) \
1267 LIST_TEST(HostResolver_ResolveIPv4)); \
1268 CheckTestHostNameUsedWithCorrectNetworkIsolationKey(browser())
1269
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,HostResolverCrash_Basic)1270 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, HostResolverCrash_Basic) {
1271 if (content::IsInProcessNetworkService())
1272 return;
1273
1274 mojo::Remote<network::mojom::NetworkServiceTest> network_service_test;
1275 content::GetNetworkService()->BindTestInterface(
1276 network_service_test.BindNewPipeAndPassReceiver());
1277 network_service_test->CrashOnResolveHost("crash.com");
1278
1279 RunTestViaHTTP(STRIP_PREFIXES(HostResolverCrash_Basic));
1280 }
1281
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,HostResolver)1282 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, HostResolver) {
1283 RUN_HOST_RESOLVER_SUBTESTS;
1284 }
1285
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (HostResolver))1286 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(HostResolver)) {
1287 RUN_HOST_RESOLVER_SUBTESTS;
1288 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (HostResolver))1289 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(HostResolver)) {
1290 RUN_HOST_RESOLVER_SUBTESTS;
1291 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (HostResolver))1292 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1293 MAYBE_PNACL_NONSFI(HostResolver)) {
1294 RUN_HOST_RESOLVER_SUBTESTS;
1295 }
1296
1297 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_Resolve)
TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_ResolveIPv4)1298 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_ResolveIPv4)
1299 TEST_PPAPI_NACL(HostResolverPrivate_Resolve)
1300 TEST_PPAPI_NACL(HostResolverPrivate_ResolveIPv4)
1301
1302 // URLLoader tests. These are split into multiple test fixtures because if we
1303 // run them all together, they tend to time out.
1304 #define RUN_URLLOADER_SUBTESTS_0 \
1305 RunTestViaHTTP( \
1306 LIST_TEST(URLLoader_BasicGET) \
1307 LIST_TEST(URLLoader_BasicPOST) \
1308 LIST_TEST(URLLoader_BasicFilePOST) \
1309 LIST_TEST(URLLoader_BasicFileRangePOST) \
1310 LIST_TEST(URLLoader_CompoundBodyPOST) \
1311 )
1312
1313 #define RUN_URLLOADER_SUBTESTS_1 \
1314 RunTestViaHTTP( \
1315 LIST_TEST(URLLoader_EmptyDataPOST) \
1316 LIST_TEST(URLLoader_BinaryDataPOST) \
1317 LIST_TEST(URLLoader_CustomRequestHeader) \
1318 LIST_TEST(URLLoader_FailsBogusContentLength) \
1319 LIST_TEST(URLLoader_StreamToFile) \
1320 )
1321
1322 // TODO(bbudge) Fix Javascript URLs for trusted loaders.
1323 // http://crbug.com/103062
1324 #define RUN_URLLOADER_SUBTESTS_2 \
1325 RunTestViaHTTP( \
1326 LIST_TEST(URLLoader_UntrustedSameOriginRestriction) \
1327 LIST_TEST(URLLoader_UntrustedCrossOriginRequest) \
1328 LIST_TEST(URLLoader_UntrustedCorbEligibleRequest) \
1329 LIST_TEST(URLLoader_UntrustedJavascriptURLRestriction) \
1330 LIST_TEST(DISABLED_URLLoader_TrustedJavascriptURLRestriction) \
1331 )
1332
1333 #define RUN_URLLOADER_NACL_SUBTESTS_2 \
1334 RunTestViaHTTP( \
1335 LIST_TEST(URLLoader_UntrustedSameOriginRestriction) \
1336 LIST_TEST(URLLoader_UntrustedCrossOriginRequest) \
1337 LIST_TEST(URLLoader_UntrustedCorbEligibleRequest) \
1338 LIST_TEST(URLLoader_UntrustedJavascriptURLRestriction) \
1339 LIST_TEST(DISABLED_URLLoader_TrustedJavascriptURLRestriction) \
1340 )
1341
1342 #define RUN_URLLOADER_SUBTESTS_3 \
1343 RunTestViaHTTP( \
1344 LIST_TEST(URLLoader_UntrustedHttpRequests) \
1345 LIST_TEST(URLLoader_FollowURLRedirect) \
1346 LIST_TEST(URLLoader_AuditURLRedirect) \
1347 LIST_TEST(URLLoader_RestrictURLRedirectCommon) \
1348 LIST_TEST(URLLoader_RestrictURLRedirectEnabled) \
1349 LIST_TEST(URLLoader_AbortCalls) \
1350 LIST_TEST(URLLoader_UntendedLoad) \
1351 LIST_TEST(URLLoader_PrefetchBufferThreshold) \
1352 )
1353
1354 // Note: we do not support Trusted APIs in NaCl, so these will be skipped.
1355 // XRequestedWithHeader isn't trusted per-se, but the header isn't provided
1356 // for NaCl and thus must be skipped.
1357 #define RUN_URLLOADER_TRUSTED_SUBTESTS \
1358 RunTestViaHTTP( \
1359 LIST_TEST(URLLoader_TrustedSameOriginRestriction) \
1360 LIST_TEST(URLLoader_TrustedCrossOriginRequest) \
1361 LIST_TEST(URLLoader_TrustedCorbEligibleRequest) \
1362 LIST_TEST(URLLoader_TrustedHttpRequests) \
1363 LIST_TEST(URLLoader_XRequestedWithHeader) \
1364 )
1365
1366 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, URLLoader0) {
1367 RUN_URLLOADER_SUBTESTS_0;
1368 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,URLLoader1)1369 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, URLLoader1) {
1370 RUN_URLLOADER_SUBTESTS_1;
1371 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,URLLoader2)1372 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, URLLoader2) {
1373 RUN_URLLOADER_SUBTESTS_2;
1374 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,URLLoader3)1375 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, URLLoader3) {
1376 RUN_URLLOADER_SUBTESTS_3;
1377 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,URLLoaderTrusted)1378 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, URLLoaderTrusted) {
1379 RUN_URLLOADER_TRUSTED_SUBTESTS;
1380 }
1381
1382 class OutOfProcessWithoutPepperCrossOriginRestrictionPPAPITest
1383 : public OutOfProcessPPAPITest {
1384 public:
OutOfProcessWithoutPepperCrossOriginRestrictionPPAPITest()1385 OutOfProcessWithoutPepperCrossOriginRestrictionPPAPITest() {
1386 scoped_feature_list_.InitAndDisableFeature(
1387 features::kPepperCrossOriginRedirectRestriction);
1388 }
1389
1390 private:
1391 base::test::ScopedFeatureList scoped_feature_list_;
1392 };
1393
IN_PROC_BROWSER_TEST_F(OutOfProcessWithoutPepperCrossOriginRestrictionPPAPITest,URLLoaderRestrictURLRedirectDisabled)1394 IN_PROC_BROWSER_TEST_F(OutOfProcessWithoutPepperCrossOriginRestrictionPPAPITest,
1395 URLLoaderRestrictURLRedirectDisabled) {
1396 // This test verifies if the restriction in the pepper_url_loader_host.cc
1397 // can be managed via base::FeatureList, and does not need to run with various
1398 // NaCl sandbox modes.
1399 RunTestViaHTTP(LIST_TEST(URLLoader_RestrictURLRedirectCommon)
1400 LIST_TEST(URLLoader_RestrictURLRedirectDisabled));
1401 }
1402
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (URLLoader0))1403 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(URLLoader0)) {
1404 RUN_URLLOADER_SUBTESTS_0;
1405 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (URLLoader1))1406 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(URLLoader1)) {
1407 RUN_URLLOADER_SUBTESTS_1;
1408 }
1409
1410 // Flaky on Windows https://crbug.com/1059468#c18
1411 #if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (URLLoader2))1412 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(URLLoader2)) {
1413 RUN_URLLOADER_SUBTESTS_2;
1414 }
1415 #endif
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (URLLoader3))1416 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(URLLoader3)) {
1417 RUN_URLLOADER_SUBTESTS_3;
1418 }
1419
1420 // Flaky on 32-bit linux bot; http://crbug.com/308906
1421 #if (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(ARCH_CPU_X86)
1422 #define MAYBE_URLLoader_BasicFilePOST DISABLED_URLLoader_BasicFilePOST
1423 #else
1424 #define MAYBE_URLLoader_BasicFilePOST URLLoader_BasicFilePOST
1425 #endif
1426
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (URLLoader0))1427 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(URLLoader0)) {
1428 RUN_URLLOADER_SUBTESTS_0;
1429 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (URLLoader1))1430 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(URLLoader1)) {
1431 RUN_URLLOADER_SUBTESTS_1;
1432 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (URLLoader2))1433 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(URLLoader2)) {
1434 RUN_URLLOADER_SUBTESTS_2;
1435 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (URLLoader3))1436 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(URLLoader3)) {
1437 RUN_URLLOADER_SUBTESTS_3;
1438 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (URLLoader0))1439 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1440 MAYBE_PNACL_NONSFI(URLLoader0)) {
1441 RUN_URLLOADER_SUBTESTS_0;
1442 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (URLLoader1))1443 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1444 MAYBE_PNACL_NONSFI(URLLoader1)) {
1445 RUN_URLLOADER_SUBTESTS_1;
1446 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (URLLoader2))1447 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1448 MAYBE_PNACL_NONSFI(URLLoader2)) {
1449 RUN_URLLOADER_SUBTESTS_2;
1450 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (URLLoader3))1451 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1452 MAYBE_PNACL_NONSFI(URLLoader3)) {
1453 RUN_URLLOADER_SUBTESTS_3;
1454 }
1455
1456
1457 // URLRequestInfo tests.
1458 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(URLRequest_CreateAndIsURLRequestInfo)
1459
1460 // Timing out on Windows. http://crbug.com/129571
1461 #if defined(OS_WIN)
1462 #define MAYBE_URLRequest_CreateAndIsURLRequestInfo \
1463 DISABLED_URLRequest_CreateAndIsURLRequestInfo
1464 #else
1465 #define MAYBE_URLRequest_CreateAndIsURLRequestInfo \
1466 URLRequest_CreateAndIsURLRequestInfo
1467 #endif
TEST_PPAPI_NACL(MAYBE_URLRequest_CreateAndIsURLRequestInfo)1468 TEST_PPAPI_NACL(MAYBE_URLRequest_CreateAndIsURLRequestInfo)
1469
1470 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(URLRequest_SetProperty)
1471 TEST_PPAPI_NACL(URLRequest_SetProperty)
1472 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(URLRequest_AppendDataToBody)
1473 TEST_PPAPI_NACL(URLRequest_AppendDataToBody)
1474 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(DISABLED_URLRequest_AppendFileToBody)
1475 TEST_PPAPI_NACL(DISABLED_URLRequest_AppendFileToBody)
1476 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(URLRequest_Stress)
1477 TEST_PPAPI_NACL(URLRequest_Stress)
1478
1479 TEST_PPAPI_OUT_OF_PROCESS(PaintAggregator)
1480 TEST_PPAPI_NACL(PaintAggregator)
1481
1482 // TODO(danakj): http://crbug.com/115286
1483 TEST_PPAPI_NACL(DISABLED_Scrollbar)
1484
1485 TEST_PPAPI_NACL(Var)
1486
1487 TEST_PPAPI_NACL(VarResource)
1488
1489 // This test is only for x86-32 NaCl.
1490 #if defined(ARCH_CPU_X86)
1491 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, NaClIRTStackAlignment) {
1492 bool is32 = true;
1493 #if defined(OS_WIN)
1494 // On Windows, we don't know statically if NaCl will actually be 32-bit
1495 // NaCl or if it will be 64-bit NaCl. Even chrome (and browser_tests) is
1496 // built for 32-bit Windows, when the system is actually using a 64-bit
1497 // Windows kernel, only 64-bit NaCl works. This test matches the condition
1498 // used in //components/nacl/browser/nacl_browser.cc::NaClIrtName to
1499 // choose which kind of NaCl nexe to load, so it better be right.
1500 is32 = (base::win::OSInfo::GetInstance()->wow64_status() !=
1501 base::win::OSInfo::WOW64_ENABLED);
1502 #endif
1503 if (is32)
1504 RunTestViaHTTP(STRIP_PREFIXES(NaClIRTStackAlignment));
1505 }
1506 #endif
1507
1508 // PostMessage tests.
1509 #define RUN_POSTMESSAGE_SUBTESTS \
1510 RunTestViaHTTP( \
1511 LIST_TEST(PostMessage_SendInInit) \
1512 LIST_TEST(PostMessage_SendingData) \
1513 LIST_TEST(PostMessage_SendingString) \
1514 LIST_TEST(PostMessage_SendingArrayBuffer) \
1515 LIST_TEST(PostMessage_SendingArray) \
1516 LIST_TEST(PostMessage_SendingDictionary) \
1517 LIST_TEST(PostMessage_SendingResource) \
1518 LIST_TEST(PostMessage_SendingComplexVar) \
1519 LIST_TEST(PostMessage_MessageEvent) \
1520 LIST_TEST(PostMessage_NoHandler) \
1521 LIST_TEST(PostMessage_ExtraParam) \
1522 LIST_TEST(PostMessage_NonMainThread) \
1523 )
1524
1525 // Windows defines 'PostMessage', so we have to undef it.
1526 #ifdef PostMessage
1527 #undef PostMessage
1528 #endif
1529
1530 #if defined(OS_WIN)
1531 // http://crbug.com/95557
1532 #define MAYBE_PostMessage DISABLED_PostMessage
1533 #else
1534 #define MAYBE_PostMessage PostMessage
1535 #endif
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,MAYBE_PostMessage)1536 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, MAYBE_PostMessage) {
1537 RUN_POSTMESSAGE_SUBTESTS;
1538 }
1539
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (PostMessage))1540 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(PostMessage)) {
1541 RUN_POSTMESSAGE_SUBTESTS;
1542 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (PostMessage))1543 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(PostMessage)) {
1544 RUN_POSTMESSAGE_SUBTESTS;
1545 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (PostMessage))1546 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1547 MAYBE_PNACL_NONSFI(PostMessage)) {
1548 RUN_POSTMESSAGE_SUBTESTS;
1549 }
1550
1551 TEST_PPAPI_NACL(Memory)
1552
1553 // FileIO tests.
1554 #define RUN_FILEIO_SUBTESTS \
1555 RunTestViaHTTP( \
1556 LIST_TEST(FileIO_Open) \
1557 LIST_TEST(FileIO_OpenDirectory) \
1558 LIST_TEST(FileIO_AbortCalls) \
1559 LIST_TEST(FileIO_ParallelReads) \
1560 LIST_TEST(FileIO_ParallelWrites) \
1561 LIST_TEST(FileIO_NotAllowMixedReadWrite) \
1562 LIST_TEST(FileIO_ReadWriteSetLength) \
1563 LIST_TEST(FileIO_ReadToArrayWriteSetLength) \
1564 LIST_TEST(FileIO_TouchQuery) \
1565 )
1566
1567 #define RUN_FILEIO_PRIVATE_SUBTESTS \
1568 RunTestViaHTTP( \
1569 LIST_TEST(FileIO_RequestOSFileHandle) \
1570 LIST_TEST(FileIO_RequestOSFileHandleWithOpenExclusive) \
1571 LIST_TEST(FileIO_Mmap) \
1572 )
1573
IN_PROC_BROWSER_TEST_F(PPAPIPrivateTest,FileIO_Private)1574 IN_PROC_BROWSER_TEST_F(PPAPIPrivateTest, FileIO_Private) {
1575 RUN_FILEIO_PRIVATE_SUBTESTS;
1576 }
1577
1578 // See: crbug.com/421284
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,DISABLED_FileIO)1579 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, DISABLED_FileIO) {
1580 RUN_FILEIO_SUBTESTS;
1581 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPIPrivateTest,FileIO_Private)1582 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPIPrivateTest, FileIO_Private) {
1583 RUN_FILEIO_PRIVATE_SUBTESTS;
1584 }
1585
1586 // http://crbug.com/313401
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,DISABLED_FileIO)1587 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, DISABLED_FileIO) {
1588 RUN_FILEIO_SUBTESTS;
1589 }
1590 // http://crbug.com/313401
IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClNewlibTest,DISABLED_NaCl_Newlib_FileIO_Private)1591 IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClNewlibTest,
1592 DISABLED_NaCl_Newlib_FileIO_Private) {
1593 RUN_FILEIO_PRIVATE_SUBTESTS;
1594 }
1595
1596 // http://crbug.com/313205
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,DISABLED_FileIO)1597 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, DISABLED_FileIO) {
1598 RUN_FILEIO_SUBTESTS;
1599 }
IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClPNaClTest,DISABLED_PNaCl_FileIO_Private)1600 IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClPNaClTest,
1601 DISABLED_PNaCl_FileIO_Private) {
1602 RUN_FILEIO_PRIVATE_SUBTESTS;
1603 }
1604
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (FileIO))1605 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, MAYBE_PNACL_NONSFI(FileIO)) {
1606 RUN_FILEIO_SUBTESTS;
1607 }
IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (FILEIO_Private))1608 IN_PROC_BROWSER_TEST_F(PPAPIPrivateNaClPNaClNonSfiTest,
1609 MAYBE_PNACL_NONSFI(FILEIO_Private)) {
1610 RUN_FILEIO_PRIVATE_SUBTESTS;
1611 }
1612
1613 #define SETUP_FOR_FILEREF_TESTS \
1614 const char kContents[] = "Hello from browser"; \
1615 base::ScopedAllowBlockingForTesting allow_blocking; \
1616 base::ScopedTempDir temp_dir; \
1617 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); \
1618 base::FilePath existing_filename = temp_dir.GetPath().AppendASCII("foo"); \
1619 ASSERT_EQ( \
1620 static_cast<int>(sizeof(kContents) - 1), \
1621 base::WriteFile(existing_filename, kContents, sizeof(kContents) - 1)); \
1622 PPAPITestSelectFileDialogFactory::SelectedFileInfoList file_info_list; \
1623 file_info_list.push_back( \
1624 ui::SelectedFileInfo(existing_filename, existing_filename)); \
1625 PPAPITestSelectFileDialogFactory test_dialog_factory( \
1626 PPAPITestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, \
1627 file_info_list);
1628
1629 // FileRef tests.
1630 #define RUN_FILEREF_SUBTESTS_1 \
1631 SETUP_FOR_FILEREF_TESTS \
1632 RunTestViaHTTP( \
1633 LIST_TEST(FileRef_Create) \
1634 LIST_TEST(FileRef_GetFileSystemType) \
1635 LIST_TEST(FileRef_GetName) \
1636 LIST_TEST(FileRef_GetPath) \
1637 LIST_TEST(FileRef_GetParent) \
1638 LIST_TEST(FileRef_MakeDirectory) \
1639 )
1640
1641 #define RUN_FILEREF_SUBTESTS_2 \
1642 SETUP_FOR_FILEREF_TESTS \
1643 RunTestViaHTTP( \
1644 LIST_TEST(FileRef_QueryAndTouchFile) \
1645 LIST_TEST(FileRef_DeleteFileAndDirectory) \
1646 LIST_TEST(FileRef_RenameFileAndDirectory) \
1647 LIST_TEST(FileRef_Query) \
1648 LIST_TEST(FileRef_FileNameEscaping) \
1649 )
1650
1651 // Note, the FileRef tests are split into two, because all of them together
1652 // sometimes take too long on windows: crbug.com/336999
1653 // FileRef_ReadDirectoryEntries is flaky, so left out. See crbug.com/241646.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,FileRef1)1654 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, FileRef1) {
1655 RUN_FILEREF_SUBTESTS_1;
1656 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,FileRef2)1657 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, FileRef2) {
1658 RUN_FILEREF_SUBTESTS_2;
1659 }
1660
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (FileRef1))1661 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(FileRef1)) {
1662 RUN_FILEREF_SUBTESTS_1;
1663 }
1664 // Flaky on Windows https://crbug.com/1059468#c18
1665 #if !defined(OS_WIN) || !defined(ARCH_CPU_32_BITS)
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (FileRef2))1666 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(FileRef2)) {
1667 RUN_FILEREF_SUBTESTS_2;
1668 }
1669 #endif
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (FileRef1))1670 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(FileRef1)) {
1671 RUN_FILEREF_SUBTESTS_1;
1672 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (FileRef2))1673 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(FileRef2)) {
1674 RUN_FILEREF_SUBTESTS_2;
1675 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (FileRef1))1676 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1677 MAYBE_PNACL_NONSFI(FileRef1)) {
1678 RUN_FILEREF_SUBTESTS_1;
1679 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (FileRef2))1680 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1681 MAYBE_PNACL_NONSFI(FileRef2)) {
1682 RUN_FILEREF_SUBTESTS_2;
1683 }
1684
1685 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(FileSystem)
1686
1687 // PPAPINaClTest.FileSystem times out consistently on Windows and Mac.
1688 // http://crbug.com/130372
1689 #if defined(OS_MAC) || defined(OS_WIN)
1690 #define MAYBE_FileSystem DISABLED_FileSystem
1691 #else
1692 #define MAYBE_FileSystem FileSystem
1693 #endif
1694
TEST_PPAPI_NACL(MAYBE_FileSystem)1695 TEST_PPAPI_NACL(MAYBE_FileSystem)
1696
1697 #if defined(OS_MAC)
1698 // http://crbug.com/103912
1699 #define MAYBE_Fullscreen DISABLED_Fullscreen
1700 #elif defined(OS_LINUX) || defined(OS_CHROMEOS)
1701 // http://crbug.com/146008
1702 #define MAYBE_Fullscreen DISABLED_Fullscreen
1703 #elif defined(OS_WIN)
1704 // http://crbug.com/342269
1705 #define MAYBE_Fullscreen DISABLED_Fullscreen
1706 #else
1707 #define MAYBE_Fullscreen Fullscreen
1708 #endif
1709
1710 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(MAYBE_Fullscreen)
1711 TEST_PPAPI_NACL(MAYBE_Fullscreen)
1712
1713 TEST_PPAPI_OUT_OF_PROCESS(X509CertificatePrivate)
1714
1715 TEST_PPAPI_OUT_OF_PROCESS(UMA)
1716 TEST_PPAPI_NACL(UMA)
1717
1718 // NetAddress tests.
1719 #define RUN_NETADDRESS_SUBTESTS \
1720 RunTestViaHTTP( \
1721 LIST_TEST(NetAddress_IPv4Address) \
1722 LIST_TEST(NetAddress_IPv6Address) \
1723 LIST_TEST(NetAddress_DescribeAsString) \
1724 )
1725
1726 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, NetAddress) {
1727 RUN_NETADDRESS_SUBTESTS;
1728 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (NetAddress))1729 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(NetAddress)) {
1730 RUN_NETADDRESS_SUBTESTS;
1731 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (NetAddress))1732 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(NetAddress)) {
1733 RUN_NETADDRESS_SUBTESTS;
1734 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (NetAddress))1735 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1736 MAYBE_PNACL_NONSFI(NetAddress)) {
1737 RUN_NETADDRESS_SUBTESTS;
1738 }
1739
1740 // NetAddressPrivate tests.
1741 #define RUN_NETADDRESS_PRIVATE_SUBTESTS \
1742 RunTestViaHTTP( \
1743 LIST_TEST(NetAddressPrivate_AreEqual) \
1744 LIST_TEST(NetAddressPrivate_AreHostsEqual) \
1745 LIST_TEST(NetAddressPrivate_Describe) \
1746 LIST_TEST(NetAddressPrivate_ReplacePort) \
1747 LIST_TEST(NetAddressPrivate_GetAnyAddress) \
1748 LIST_TEST(NetAddressPrivate_DescribeIPv6) \
1749 LIST_TEST(NetAddressPrivate_GetFamily) \
1750 LIST_TEST(NetAddressPrivate_GetPort) \
1751 LIST_TEST(NetAddressPrivate_GetAddress) \
1752 LIST_TEST(NetAddressPrivate_GetScopeID) \
1753 )
1754
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,NetAddressPrivate)1755 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, NetAddressPrivate) {
1756 RUN_NETADDRESS_PRIVATE_SUBTESTS;
1757 }
1758
1759 #define RUN_NETADDRESS_PRIVATE_UNTRUSTED_SUBTESTS \
1760 RunTestViaHTTP( \
1761 LIST_TEST(NetAddressPrivateUntrusted_AreEqual) \
1762 LIST_TEST(NetAddressPrivateUntrusted_AreHostsEqual) \
1763 LIST_TEST(NetAddressPrivateUntrusted_Describe) \
1764 LIST_TEST(NetAddressPrivateUntrusted_ReplacePort) \
1765 LIST_TEST(NetAddressPrivateUntrusted_GetAnyAddress) \
1766 LIST_TEST(NetAddressPrivateUntrusted_GetFamily) \
1767 LIST_TEST(NetAddressPrivateUntrusted_GetPort) \
1768 LIST_TEST(NetAddressPrivateUntrusted_GetAddress) \
1769 )
1770
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (NetAddressPrivate))1771 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,
1772 MAYBE_PPAPI_NACL(NetAddressPrivate)) {
1773 RUN_NETADDRESS_PRIVATE_UNTRUSTED_SUBTESTS;
1774 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (NetAddressPrivate))1775 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,
1776 MAYBE_PPAPI_PNACL(NetAddressPrivate)) {
1777 RUN_NETADDRESS_PRIVATE_UNTRUSTED_SUBTESTS;
1778 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (NetAddressPrivate))1779 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1780 MAYBE_PNACL_NONSFI(NetAddressPrivate)) {
1781 RUN_NETADDRESS_PRIVATE_UNTRUSTED_SUBTESTS;
1782 }
1783
1784 // NetworkMonitor tests.
1785 #define RUN_NETWORK_MONITOR_SUBTESTS \
1786 RunTestViaHTTP( \
1787 LIST_TEST(NetworkMonitor_Basic) \
1788 LIST_TEST(NetworkMonitor_2Monitors) \
1789 LIST_TEST(NetworkMonitor_DeleteInCallback) \
1790 )
1791
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,NetworkMonitor)1792 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, NetworkMonitor) {
1793 RUN_NETWORK_MONITOR_SUBTESTS;
1794 }
1795 // https://crbug.com/997840. Universally flaky.
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,DISABLED_NetworkMonitor)1796 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, DISABLED_NetworkMonitor) {
1797 RUN_NETWORK_MONITOR_SUBTESTS;
1798 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (NetworkMonitor))1799 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(NetworkMonitor)) {
1800 RUN_NETWORK_MONITOR_SUBTESTS;
1801 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (NetworkMonitor))1802 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1803 MAYBE_PNACL_NONSFI(NetworkMonitor)) {
1804 RUN_NETWORK_MONITOR_SUBTESTS;
1805 }
1806
1807 // In-process WebSocket tests. Note, the WebSocket tests are split into two,
1808 // because all of them together sometimes take too long on windows:
1809 // crbug.com/336999
1810 #define RUN_WEBSOCKET_SUBTESTS_1 \
1811 RunTestWithWebSocketServer( \
1812 LIST_TEST(WebSocket_IsWebSocket) \
1813 LIST_TEST(WebSocket_UninitializedPropertiesAccess) \
1814 LIST_TEST(WebSocket_InvalidConnect) \
1815 LIST_TEST(WebSocket_Protocols) \
1816 LIST_TEST(WebSocket_GetURL) \
1817 LIST_TEST(WebSocket_ValidConnect) \
1818 LIST_TEST(WebSocket_InvalidClose) \
1819 LIST_TEST(WebSocket_ValidClose) \
1820 LIST_TEST(WebSocket_GetProtocol) \
1821 LIST_TEST(WebSocket_TextSendReceive) \
1822 LIST_TEST(WebSocket_BinarySendReceive) \
1823 LIST_TEST(WebSocket_StressedSendReceive) \
1824 LIST_TEST(WebSocket_BufferedAmount) \
1825 )
1826
1827 #define RUN_WEBSOCKET_SUBTESTS_2 \
1828 RunTestWithWebSocketServer( \
1829 LIST_TEST(WebSocket_AbortCallsWithCallback) \
1830 LIST_TEST(WebSocket_AbortSendMessageCall) \
1831 LIST_TEST(WebSocket_AbortCloseCall) \
1832 LIST_TEST(WebSocket_AbortReceiveMessageCall) \
1833 LIST_TEST(WebSocket_ClosedFromServerWhileSending) \
1834 LIST_TEST(WebSocket_CcInterfaces) \
1835 LIST_TEST(WebSocket_UtilityInvalidConnect) \
1836 LIST_TEST(WebSocket_UtilityProtocols) \
1837 LIST_TEST(WebSocket_UtilityGetURL) \
1838 LIST_TEST(WebSocket_UtilityValidConnect) \
1839 LIST_TEST(WebSocket_UtilityInvalidClose) \
1840 LIST_TEST(WebSocket_UtilityValidClose) \
1841 LIST_TEST(WebSocket_UtilityGetProtocol) \
1842 LIST_TEST(WebSocket_UtilityTextSendReceive) \
1843 LIST_TEST(WebSocket_UtilityBinarySendReceive) \
1844 LIST_TEST(WebSocket_UtilityBufferedAmount) \
1845 )
1846
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,WebSocket1)1847 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, WebSocket1) {
1848 RUN_WEBSOCKET_SUBTESTS_1;
1849 }
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,WebSocket2)1850 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, WebSocket2) {
1851 RUN_WEBSOCKET_SUBTESTS_2;
1852 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (WebSocket1))1853 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(WebSocket1)) {
1854 RUN_WEBSOCKET_SUBTESTS_1;
1855 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (WebSocket2))1856 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(WebSocket2)) {
1857 RUN_WEBSOCKET_SUBTESTS_2;
1858 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (WebSocket1))1859 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(WebSocket1)) {
1860 RUN_WEBSOCKET_SUBTESTS_1;
1861 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (WebSocket2))1862 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(WebSocket2)) {
1863 RUN_WEBSOCKET_SUBTESTS_2;
1864 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (WebSocket1))1865 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1866 MAYBE_PNACL_NONSFI(WebSocket1)) {
1867 RUN_WEBSOCKET_SUBTESTS_1;
1868 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (WebSocket2))1869 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1870 MAYBE_PNACL_NONSFI(WebSocket2)) {
1871 RUN_WEBSOCKET_SUBTESTS_2;
1872 }
1873
1874 // AudioConfig tests
1875 #define RUN_AUDIO_CONFIG_SUBTESTS \
1876 RunTestViaHTTP( \
1877 LIST_TEST(AudioConfig_RecommendSampleRate) \
1878 LIST_TEST(AudioConfig_ValidConfigs) \
1879 LIST_TEST(AudioConfig_InvalidConfigs) \
1880 )
1881
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,AudioConfig)1882 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, AudioConfig) {
1883 RUN_AUDIO_CONFIG_SUBTESTS;
1884 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (AudioConfig))1885 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(AudioConfig)) {
1886 RUN_AUDIO_CONFIG_SUBTESTS;
1887 }
IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest,MAYBE_GLIBC (AudioConfig))1888 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(AudioConfig)) {
1889 RUN_AUDIO_CONFIG_SUBTESTS;
1890 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (AudioConfig))1891 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(AudioConfig)) {
1892 RUN_AUDIO_CONFIG_SUBTESTS;
1893 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (AudioConfig))1894 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1895 MAYBE_PNACL_NONSFI(AudioConfig)) {
1896 RUN_AUDIO_CONFIG_SUBTESTS;
1897 }
1898
1899 // PPB_Audio tests.
1900 #define RUN_AUDIO_SUBTESTS \
1901 RunTestViaHTTP( \
1902 LIST_TEST(Audio_Creation) \
1903 LIST_TEST(Audio_DestroyNoStop) \
1904 LIST_TEST(Audio_Failures) \
1905 LIST_TEST(Audio_AudioCallback1) \
1906 LIST_TEST(Audio_AudioCallback2) \
1907 LIST_TEST(Audio_AudioCallback3) \
1908 LIST_TEST(Audio_AudioCallback4) \
1909 )
1910
1911 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
1912 // http://crbug.com/396464
1913 #define MAYBE_Audio DISABLED_Audio
1914 #else
1915 // Tests are flaky: http://crbug.com/629680
1916 #define MAYBE_Audio DISABLED_Audio
1917 #endif
1918 // PPB_Audio is not supported in-process.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,MAYBE_Audio)1919 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, MAYBE_Audio) {
1920 RUN_AUDIO_SUBTESTS;
1921 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (MAYBE_Audio))1922 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(MAYBE_Audio)) {
1923 RUN_AUDIO_SUBTESTS;
1924 }
IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest,MAYBE_GLIBC (MAYBE_Audio))1925 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(MAYBE_Audio)) {
1926 RUN_AUDIO_SUBTESTS;
1927 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (MAYBE_Audio))1928 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(MAYBE_Audio)) {
1929 RUN_AUDIO_SUBTESTS;
1930 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (MAYBE_Audio))1931 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1932 MAYBE_PNACL_NONSFI(MAYBE_Audio)) {
1933 RUN_AUDIO_SUBTESTS;
1934 }
1935
1936 #define RUN_AUDIO_THREAD_CREATOR_SUBTESTS \
1937 RunTestViaHTTP( \
1938 LIST_TEST(Audio_AudioThreadCreatorIsRequired) \
1939 LIST_TEST(Audio_AudioThreadCreatorIsCalled) \
1940 )
1941
1942 // Tests are flaky: http://crbug.com/629680
1943 #define MAYBE_AudioThreadCreator DISABLED_AudioThreadCreator
1944
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (MAYBE_AudioThreadCreator))1945 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,
1946 MAYBE_PPAPI_NACL(MAYBE_AudioThreadCreator)) {
1947 RUN_AUDIO_THREAD_CREATOR_SUBTESTS;
1948 }
IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest,MAYBE_GLIBC (MAYBE_AudioThreadCreator))1949 IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest,
1950 MAYBE_GLIBC(MAYBE_AudioThreadCreator)) {
1951 RUN_AUDIO_THREAD_CREATOR_SUBTESTS;
1952 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (MAYBE_AudioThreadCreator))1953 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,
1954 MAYBE_PPAPI_PNACL(MAYBE_AudioThreadCreator)) {
1955 RUN_AUDIO_THREAD_CREATOR_SUBTESTS;
1956 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (MAYBE_AudioThreadCreator))1957 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,
1958 MAYBE_PNACL_NONSFI(MAYBE_AudioThreadCreator)) {
1959 RUN_AUDIO_THREAD_CREATOR_SUBTESTS;
1960 }
1961
1962 TEST_PPAPI_OUT_OF_PROCESS(View_CreatedVisible)
1963 #if defined(OS_MAC)
1964 // http://crbug.com/474399
1965 #define MAYBE_View_CreatedVisible DISABLED_View_CreatedVisible
1966 #else
1967 #define MAYBE_View_CreatedVisible View_CreatedVisible
1968 #endif
TEST_PPAPI_NACL(MAYBE_View_CreatedVisible)1969 TEST_PPAPI_NACL(MAYBE_View_CreatedVisible)
1970
1971 // This test ensures that plugins created in a background tab have their
1972 // initial visibility set to false. We don't bother testing in-process for this
1973 // custom test since the out of process code also exercises in-process.
1974 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_CreateInvisible) {
1975 // Make a second tab in the foreground.
1976 GURL url = GetTestFileUrl("View_CreatedInvisible");
1977 NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
1978 params.disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB;
1979 ui_test_utils::NavigateToURL(¶ms);
1980 }
1981
1982 // This test messes with tab visibility so is custom.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,DISABLED_View_PageHideShow)1983 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, DISABLED_View_PageHideShow) {
1984 // The plugin will be loaded in the foreground tab and will send us a message.
1985 PPAPITestMessageHandler handler;
1986 content::JavascriptTestObserver observer(
1987 browser()->tab_strip_model()->GetActiveWebContents(),
1988 &handler);
1989
1990 GURL url = GetTestFileUrl("View_PageHideShow");
1991 ui_test_utils::NavigateToURL(browser(), url);
1992
1993 ASSERT_TRUE(observer.Run()) << handler.error_message();
1994 EXPECT_STREQ("TestPageHideShow:Created", handler.message().c_str());
1995 observer.Reset();
1996
1997 // Make a new tab to cause the original one to hide, this should trigger the
1998 // next phase of the test.
1999 NavigateParams params(browser(), GURL(url::kAboutBlankURL),
2000 ui::PAGE_TRANSITION_LINK);
2001 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
2002 ui_test_utils::NavigateToURL(¶ms);
2003
2004 // Wait until the test acks that it got hidden.
2005 ASSERT_TRUE(observer.Run()) << handler.error_message();
2006 EXPECT_STREQ("TestPageHideShow:Hidden", handler.message().c_str());
2007 observer.Reset();
2008
2009 // Switch back to the test tab.
2010 browser()->tab_strip_model()->ActivateTabAt(
2011 0, {TabStripModel::GestureType::kOther});
2012
2013 ASSERT_TRUE(observer.Run()) << handler.error_message();
2014 EXPECT_STREQ("PASS", handler.message().c_str());
2015 }
2016
2017 // Tests that if a plugin accepts touch events, the browser knows to send touch
2018 // events to the renderer.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,InputEvent_AcceptTouchEvent1)2019 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, InputEvent_AcceptTouchEvent1) {
2020 RunTouchEventTest("InputEvent_AcceptTouchEvent_1");
2021 }
2022
2023 // The browser sends touch events to the renderer if the plugin registers for
2024 // touch events and then unregisters.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,InputEvent_AcceptTouchEvent2)2025 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, InputEvent_AcceptTouchEvent2) {
2026 RunTouchEventTest("InputEvent_AcceptTouchEvent_2");
2027 }
2028
2029 // Tests that if a plugin accepts touch events, the browser knows to send touch
2030 // events to the renderer. In this case, the plugin requests that input events
2031 // corresponding to touch events are delivered for filtering.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,InputEvent_AcceptTouchEvent3)2032 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, InputEvent_AcceptTouchEvent3) {
2033 RunTouchEventTest("InputEvent_AcceptTouchEvent_3");
2034 }
2035 // The plugin sends multiple RequestInputEvent() with the second
2036 // requesting touch events to be delivered.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,InputEvent_AcceptTouchEvent4)2037 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, InputEvent_AcceptTouchEvent4) {
2038 RunTouchEventTest("InputEvent_AcceptTouchEvent_4");
2039 }
2040 // View tests.
2041 #define RUN_VIEW_SUBTESTS \
2042 RunTestViaHTTP( \
2043 LIST_TEST(View_SizeChange) \
2044 LIST_TEST(View_ClipChange) \
2045 LIST_TEST(View_ScrollOffsetChange) \
2046 )
2047
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest,View)2048 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View) {
2049 RUN_VIEW_SUBTESTS;
2050 }
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest,MAYBE_PPAPI_NACL (View))2051 IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, MAYBE_PPAPI_NACL(View)) {
2052 RUN_VIEW_SUBTESTS;
2053 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest,MAYBE_PPAPI_PNACL (View))2054 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, MAYBE_PPAPI_PNACL(View)) {
2055 RUN_VIEW_SUBTESTS;
2056 }
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest,MAYBE_PNACL_NONSFI (View))2057 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, MAYBE_PNACL_NONSFI(View)) {
2058 RUN_VIEW_SUBTESTS;
2059 }
2060
2061 // The compositor test timeouts sometimes, so we have to split it to two
2062 // subtests.
2063 #define RUN_COMPOSITOR_SUBTESTS_0 \
2064 RunTestViaHTTP( \
2065 LIST_TEST(Compositor_BindUnbind) \
2066 LIST_TEST(Compositor_Release) \
2067 LIST_TEST(Compositor_ReleaseUnbound) \
2068 LIST_TEST(Compositor_ReleaseWithoutCommit) \
2069 LIST_TEST(Compositor_ReleaseWithoutCommitUnbound) \
2070 )
2071
2072 #define RUN_COMPOSITOR_SUBTESTS_1 \
2073 RunTestViaHTTP( \
2074 LIST_TEST(Compositor_CommitTwoTimesWithoutChange) \
2075 LIST_TEST(Compositor_CommitTwoTimesWithoutChangeUnbound) \
2076 LIST_TEST(Compositor_General) \
2077 LIST_TEST(Compositor_GeneralUnbound) \
2078 )
2079
2080 #if defined(OS_WIN)
2081 // This test fails with the test compositor which is what's used by default for
2082 // browser tests on Windows. Renable when the software compositor is available.
2083 #define MAYBE_Compositor0 DISABLED_Compositor0
2084 #define MAYBE_Compositor1 DISABLED_Compositor1
2085 #elif defined(OS_MAC)
2086 // This test fails when using the legacy software mode. Reenable when the
2087 // software compositor is enabled crbug.com/286038
2088 #define MAYBE_Compositor0 DISABLED_Compositor0
2089 #define MAYBE_Compositor1 DISABLED_Compositor1
2090 #else
2091 // flaky on Linux: http://crbug.com/396482
2092 #define MAYBE_Compositor0 DISABLED_Compositor0
2093 #define MAYBE_Compositor1 DISABLED_Compositor1
2094 #endif
2095
2096 TEST_PPAPI_NACL_SUBTESTS(MAYBE_Compositor0, RUN_COMPOSITOR_SUBTESTS_0)
2097 TEST_PPAPI_NACL_SUBTESTS(MAYBE_Compositor1, RUN_COMPOSITOR_SUBTESTS_1)
2098
2099 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \
2100 defined(OS_MAC)
2101 // Flaky on ChromeOS, Linux, Windows, and Mac (crbug.com/438729)
2102 #define MAYBE_MediaStreamAudioTrack DISABLED_MediaStreamAudioTrack
2103 #else
2104 #define MAYBE_MediaStreamAudioTrack MediaStreamAudioTrack
2105 #endif
2106 TEST_PPAPI_NACL(MAYBE_MediaStreamAudioTrack)
2107
2108 #if defined(OS_WIN)
2109 // Flaky on Windows (crbug.com/633519)
2110 #define MAYBE_MediaStreamVideoTrack DISABLED_MediaStreamVideoTrack
2111 #else
2112 #define MAYBE_MediaStreamVideoTrack MediaStreamVideoTrack
2113 #endif
2114 TEST_PPAPI_NACL(MAYBE_MediaStreamVideoTrack)
2115
2116 TEST_PPAPI_NACL(MouseCursor)
2117
2118 TEST_PPAPI_NACL(NetworkProxy)
2119
2120 // TODO(crbug.com/602875), TODO(crbug.com/602876) Flaky on Win and CrOS.
2121 #if defined(OS_CHROMEOS) || defined(OS_WIN)
2122 #define MAYBE_VideoDecoder DISABLED_VideoDecoder
2123 #else
2124 #define MAYBE_VideoDecoder VideoDecoder
2125 #endif
2126 TEST_PPAPI_NACL(MAYBE_VideoDecoder)
2127
2128 // https://crbug.com/997840.
2129 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
2130 #define MAYBE_VideoEncoder DISABLED_VideoEncoder
2131 #else
2132 #define MAYBE_VideoEncoder VideoEncoder
2133 #endif
2134 TEST_PPAPI_NACL(MAYBE_VideoEncoder)
2135
2136 // Printing doesn't work in content_browsertests.
2137 TEST_PPAPI_OUT_OF_PROCESS(Printing)
2138
2139 // https://crbug.com/1038957.
2140 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
2141 #define MAYBE_MessageHandler DISABLED_MessageHandler
2142 #else
2143 #define MAYBE_MessageHandler MessageHandler
2144 #endif
2145 TEST_PPAPI_NACL(MAYBE_MessageHandler)
2146
2147 TEST_PPAPI_NACL(MessageLoop_Basics)
2148 TEST_PPAPI_NACL(MessageLoop_Post)
2149
2150 TEST_PPAPI_OUT_OF_PROCESS(PDF)
2151
2152 #if BUILDFLAG(ENABLE_NACL)
2153 class PackagedAppTest : public extensions::ExtensionBrowserTest {
2154 public:
PackagedAppTest(const std::string & toolchain)2155 explicit PackagedAppTest(const std::string& toolchain)
2156 : toolchain_(toolchain) { }
2157
LaunchTestingApp(const std::string & extension_dirname)2158 void LaunchTestingApp(const std::string& extension_dirname) {
2159 base::FilePath data_dir;
2160 {
2161 base::ScopedAllowBlockingForTesting allow_blocking;
2162 ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA, &data_dir));
2163 }
2164 base::FilePath app_dir = data_dir.AppendASCII("ppapi")
2165 .AppendASCII("tests")
2166 .AppendASCII("extensions")
2167 .AppendASCII(extension_dirname)
2168 .AppendASCII(toolchain_);
2169
2170 const extensions::Extension* extension = LoadExtension(app_dir);
2171 ASSERT_TRUE(extension);
2172
2173 apps::AppLaunchParams params(
2174 extension->id(), apps::mojom::LaunchContainer::kLaunchContainerNone,
2175 WindowOpenDisposition::NEW_WINDOW,
2176 apps::mojom::AppLaunchSource::kSourceTest);
2177 params.command_line = *base::CommandLine::ForCurrentProcess();
2178 apps::AppServiceProxyFactory::GetForProfile(browser()->profile())
2179 ->BrowserAppLauncher()
2180 ->LaunchAppWithParams(std::move(params));
2181 }
2182
RunTests(const std::string & extension_dirname)2183 void RunTests(const std::string& extension_dirname) {
2184 ExtensionTestMessageListener listener("PASS", false);
2185 LaunchTestingApp(extension_dirname);
2186 EXPECT_TRUE(listener.WaitUntilSatisfied());
2187 }
2188
2189 protected:
2190 std::string toolchain_;
2191 };
2192
2193 class NewlibPackagedAppTest : public PackagedAppTest {
2194 public:
NewlibPackagedAppTest()2195 NewlibPackagedAppTest() : PackagedAppTest("newlib") { }
2196 };
2197
2198 class NonSfiPackagedAppTest : public PackagedAppTest {
2199 public:
NonSfiPackagedAppTest()2200 NonSfiPackagedAppTest() : PackagedAppTest("nonsfi") { }
2201
SetUpCommandLine(base::CommandLine * command_line)2202 void SetUpCommandLine(base::CommandLine* command_line) override {
2203 PackagedAppTest::SetUpCommandLine(command_line);
2204 command_line->AppendSwitch(switches::kEnableNaClNonSfiMode);
2205 }
2206 };
2207
2208 // Load a packaged app, and wait for it to successfully post a "hello" message
2209 // back.
2210 #if defined(OS_WIN) || !defined(NDEBUG) || defined(OS_MAC)
2211 // flaky: crbug.com/707068
2212 // flaky on debug builds: crbug.com/709447
IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest,DISABLED_SuccessfulLoad)2213 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest, DISABLED_SuccessfulLoad) {
2214 #else
2215 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest,
2216 MAYBE_PPAPI_NACL(SuccessfulLoad)) {
2217 #endif
2218 RunTests("packaged_app");
2219 }
2220
2221 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
2222 // http://crbug.com/579804
2223 #define MAYBE_SuccessfulLoad DISABLED_SuccessfulLoad
2224 #else
2225 #define MAYBE_SuccessfulLoad MAYBE_PNACL_NONSFI(SuccessfulLoad)
2226 #endif
2227 IN_PROC_BROWSER_TEST_F(NonSfiPackagedAppTest, MAYBE_SuccessfulLoad) {
2228 RunTests("packaged_app");
2229 }
2230
2231 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest,
2232 MAYBE_PPAPI_NACL(MulticastPermissions)) {
2233 RunTests("multicast_permissions");
2234 }
2235
2236 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest,
2237 MAYBE_PPAPI_NACL(NoSocketPermissions)) {
2238 RunTests("no_socket_permissions");
2239 }
2240
2241 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest,
2242 MAYBE_PPAPI_NACL(SocketPermissions)) {
2243 RunTests("socket_permissions");
2244 }
2245
2246 #endif
2247