forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb_engine_integration_test.cc
599 lines (477 loc) · 23.3 KB
/
web_engine_integration_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/mem/cpp/fidl.h>
#include <zircon/rights.h>
#include <zircon/types.h>
#include <lib/zx/vmo.h>
#include "fuchsia/base/fit_adapter.h"
#include "fuchsia/base/frame_test_util.h"
#include "fuchsia/base/mem_buffer_util.h"
#include "fuchsia/base/result_receiver.h"
#include "fuchsia/base/test_devtools_list_fetcher.h"
#include "fuchsia/engine/web_engine_integration_test_base.h"
#include "media/base/media_switches.h"
#include "media/fuchsia/audio/fake_audio_consumer.h"
#include "media/fuchsia/camera/fake_fuchsia_camera.h"
#include "net/base/test_completion_callback.h"
#include "net/http/http_request_headers.h"
#include "net/socket/tcp_client_socket.h"
namespace {
constexpr char kValidUserAgentProduct[] = "TestProduct";
constexpr char kValidUserAgentVersion[] = "dev.12345";
constexpr char kValidUserAgentProductAndVersion[] = "TestProduct/dev.12345";
constexpr char kInvalidUserAgentProduct[] = "Test/Product";
constexpr char kInvalidUserAgentVersion[] = "dev/12345";
} // namespace
// Starts a WebEngine instance before running the test.
class WebEngineIntegrationTest : public WebEngineIntegrationTestBase {
protected:
WebEngineIntegrationTest() : WebEngineIntegrationTestBase() {}
void SetUp() override {
WebEngineIntegrationTestBase::SetUp();
StartWebEngine(base::CommandLine(base::CommandLine::NO_PROGRAM));
}
void RunPermissionTest(bool grant);
};
class WebEngineIntegrationMediaTest : public WebEngineIntegrationTest {
protected:
WebEngineIntegrationMediaTest() : WebEngineIntegrationTest() {}
// Returns a CreateContextParams that has AUDIO feature enabled with an
// injected FakeAudioConsumerService.
fuchsia::web::CreateContextParams ContextParamsWithAudio() {
// Use a FilteredServiceDirectory in order to inject a fake AudioConsumer
// service.
fuchsia::web::CreateContextParams create_params =
ContextParamsWithFilteredServiceDirectory();
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
fake_audio_consumer_service_ =
std::make_unique<media::FakeAudioConsumerService>(
filtered_service_directory_->outgoing_directory()
->GetOrCreateDirectory("svc"));
return create_params;
}
// Returns the same CreateContextParams as ContextParamsWithAudio() plus the
// testdata content directory.
fuchsia::web::CreateContextParams ContextParamsWithAudioAndTestData() {
fuchsia::web::CreateContextParams create_params = ContextParamsWithAudio();
create_params.mutable_content_directories()->push_back(
CreateTestDataDirectoryProvider());
return create_params;
}
std::unique_ptr<media::FakeAudioConsumerService> fake_audio_consumer_service_;
};
class WebEngineIntegrationUserAgentTest : public WebEngineIntegrationTest {
protected:
GURL GetEchoUserAgentUrl() {
static std::string echo_user_agent_header_path =
std::string("/echoheader?") + net::HttpRequestHeaders::kUserAgent;
return embedded_test_server_.GetURL(echo_user_agent_header_path);
}
};
TEST_F(WebEngineIntegrationUserAgentTest, ValidProductOnly) {
// Create a Context with just an embedder product specified.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_user_agent_product(kValidUserAgentProduct);
CreateContextAndFrameAndLoadUrl(std::move(create_params),
GetEchoUserAgentUrl());
// Query & verify that the header echoed into the document body contains
// the product tag.
std::string result =
ExecuteJavaScriptWithStringResult("document.body.innerText;");
EXPECT_TRUE(result.find(kValidUserAgentProduct) != std::string::npos);
// Query & verify that the navigator.userAgent contains the product tag.
result = ExecuteJavaScriptWithStringResult("navigator.userAgent;");
EXPECT_TRUE(result.find(kValidUserAgentProduct) != std::string::npos);
}
TEST_F(WebEngineIntegrationUserAgentTest, ValidProductAndVersion) {
// Create a Context with both product and version specified.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_user_agent_product(kValidUserAgentProduct);
create_params.set_user_agent_version(kValidUserAgentVersion);
CreateContextAndFrameAndLoadUrl(std::move(create_params),
GetEchoUserAgentUrl());
// Query & verify that the header echoed into the document body contains
// both product & version.
std::string result =
ExecuteJavaScriptWithStringResult("document.body.innerText;");
EXPECT_TRUE(result.find(kValidUserAgentProductAndVersion) !=
std::string::npos);
// Query & verify that the navigator.userAgent contains product & version.
result = ExecuteJavaScriptWithStringResult("navigator.userAgent;");
EXPECT_TRUE(result.find(kValidUserAgentProductAndVersion) !=
std::string::npos);
}
TEST_F(WebEngineIntegrationUserAgentTest, InvalidProduct) {
// Try to create a Context with an invalid embedder product tag.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_user_agent_product(kInvalidUserAgentProduct);
CreateContextAndExpectError(std::move(create_params), ZX_ERR_INVALID_ARGS);
}
TEST_F(WebEngineIntegrationUserAgentTest, VersionOnly) {
// Try to create a Context with an embedder version but no product.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_user_agent_version(kValidUserAgentVersion);
CreateContextAndExpectError(std::move(create_params), ZX_ERR_INVALID_ARGS);
}
TEST_F(WebEngineIntegrationUserAgentTest, ValidProductAndInvalidVersion) {
// Try to create a Context with valid product tag, but invalid version.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_user_agent_product(kValidUserAgentProduct);
create_params.set_user_agent_version(kInvalidUserAgentVersion);
CreateContextAndExpectError(std::move(create_params), ZX_ERR_INVALID_ARGS);
}
TEST_F(WebEngineIntegrationTest, CreateFrameWithUnclonableFrameParamsFails) {
CreateContext(DefaultContextParams());
zx_rights_t kReadRightsWithoutDuplicate =
ZX_RIGHT_TRANSFER | ZX_RIGHT_READ | ZX_RIGHT_MAP | ZX_RIGHT_GET_PROPERTY;
// Create a buffer and remove the ability clone it by changing its rights to
// not include ZX_RIGHT_DUPLICATE.
auto buffer = cr_fuchsia::MemBufferFromString("some data", "some name");
zx::vmo unclonable_readonly_vmo;
EXPECT_EQ(ZX_OK, buffer.vmo.duplicate(kReadRightsWithoutDuplicate,
&unclonable_readonly_vmo));
buffer.vmo = std::move(unclonable_readonly_vmo);
// Creation will fail, which will be reported in the error handler below.
fuchsia::web::CreateFrameParams create_frame_params;
create_frame_params.set_explicit_sites_filter_error_page(
fuchsia::mem::Data::WithBuffer(std::move(buffer)));
context_->CreateFrameWithParams(std::move(create_frame_params),
frame_.NewRequest());
base::RunLoop loop;
frame_.set_error_handler(
[quit_loop = loop.QuitClosure()](zx_status_t status) {
EXPECT_EQ(status, ZX_ERR_INVALID_ARGS);
quit_loop.Run();
});
loop.Run();
EXPECT_FALSE(frame_);
}
// Check that if the CreateContextParams has |remote_debugging_port| set then:
// - DevTools becomes available when the first debuggable Frame is created.
// - DevTools closes when the last debuggable Frame is closed.
TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) {
// Create a Context with remote debugging enabled via an ephemeral port.
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_remote_debugging_port(0);
// Create a Frame with remote debugging enabled.
fuchsia::web::CreateFrameParams create_frame_params;
create_frame_params.set_enable_remote_debugging(true);
CreateContextAndFrameWithParams(std::move(create_params),
std::move(create_frame_params));
// Expect to receive a notification of the selected DevTools port.
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<
fuchsia::web::Context_GetRemoteDebuggingPort_Result>
port_receiver(run_loop.QuitClosure());
context_->GetRemoteDebuggingPort(
cr_fuchsia::CallbackToFitFunction(port_receiver.GetReceiveCallback()));
run_loop.Run();
ASSERT_TRUE(port_receiver->is_response());
uint16_t remote_debugging_port = port_receiver->response().port;
ASSERT_TRUE(remote_debugging_port != 0);
// Navigate to a URL.
GURL url = embedded_test_server_.GetURL("/defaultresponse");
ASSERT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(), url.spec()));
navigation_listener_->RunUntilUrlEquals(url);
base::Value devtools_list =
cr_fuchsia::GetDevToolsListFromPort(remote_debugging_port);
ASSERT_TRUE(devtools_list.is_list());
EXPECT_EQ(devtools_list.GetList().size(), 1u);
base::Value* devtools_url = devtools_list.GetList()[0].FindPath("url");
ASSERT_TRUE(devtools_url->is_string());
EXPECT_EQ(devtools_url->GetString(), url);
// Create a second frame, without remote debugging enabled. The remote
// debugging service should still report a single Frame is present.
fuchsia::web::FramePtr web_frame2 = CreateFrame();
devtools_list = cr_fuchsia::GetDevToolsListFromPort(remote_debugging_port);
ASSERT_TRUE(devtools_list.is_list());
EXPECT_EQ(devtools_list.GetList().size(), 1u);
devtools_url = devtools_list.GetList()[0].FindPath("url");
ASSERT_TRUE(devtools_url->is_string());
EXPECT_EQ(devtools_url->GetString(), url);
// Tear down the debuggable Frame. The remote debugging service should have
// shut down.
base::RunLoop controller_run_loop;
navigation_controller_.set_error_handler(
[&controller_run_loop](zx_status_t) { controller_run_loop.Quit(); });
frame_.Unbind();
// Wait until the NavigationController shuts down to ensure WebEngine has
// handled the Frame tear down.
controller_run_loop.Run();
// Verify that devtools server is shut down properly. WebEngine may shutdown
// the socket after shutting down the Frame, so make several attempts to
// connect until it fails. Don't try to read or write from/to the socket to
// avoid fxb/49779.
bool failed_to_connect = false;
for (int i = 0; i < 10; ++i) {
net::TestCompletionCallback connect_callback;
net::TCPClientSocket connecting_socket(
net::AddressList(net::IPEndPoint(net::IPAddress::IPv4Localhost(),
remote_debugging_port)),
nullptr, nullptr, nullptr, net::NetLogSource());
int connect_result = connecting_socket.Connect(connect_callback.callback());
connect_result = connect_callback.GetResult(connect_result);
if (connect_result == net::OK) {
// If Connect() succeeded then try again a bit later.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
continue;
}
EXPECT_EQ(connect_result, net::ERR_CONNECTION_REFUSED);
failed_to_connect = true;
break;
}
EXPECT_TRUE(failed_to_connect);
}
// Check that remote debugging requests for Frames in non-debuggable Contexts
// cause an error to be reported.
TEST_F(WebEngineIntegrationTest, RequestDebuggableFrameInNonDebuggableContext) {
fuchsia::web::CreateFrameParams create_frame_params;
create_frame_params.set_enable_remote_debugging(true);
CreateContextAndFrameWithParams(DefaultContextParams(),
std::move(create_frame_params));
base::RunLoop loop;
frame_.set_error_handler(
[quit_loop = loop.QuitClosure()](zx_status_t status) {
EXPECT_EQ(status, ZX_ERR_INVALID_ARGS);
quit_loop.Run();
});
loop.Run();
}
// Navigates to a resource served under the "testdata" ContentDirectory.
TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {
const GURL kUrl("fuchsia-dir://testdata/title1.html");
constexpr char kTitle[] = "title 1";
CreateContextAndFrame(DefaultContextParamsWithTestData());
// Navigate to test1.html and verify that the resource was correctly
// downloaded and interpreted by inspecting the document title.
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
kUrl.spec()));
navigation_listener_->RunUntilUrlAndTitleEquals(kUrl, kTitle);
}
TEST_F(WebEngineIntegrationMediaTest, PlayAudio) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
static uint16_t kTestMediaSessionId = 43;
frame_->SetMediaSessionId(kTestMediaSessionId);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
navigation_listener_->RunUntilTitleEquals("ended");
ASSERT_EQ(fake_audio_consumer_service_->num_instances(), 1U);
auto pos = fake_audio_consumer_service_->instance(0)->GetMediaPosition();
EXPECT_GT(pos, base::TimeDelta::FromSecondsD(2.0));
EXPECT_LT(pos, base::TimeDelta::FromSecondsD(2.5));
EXPECT_EQ(fake_audio_consumer_service_->instance(0)->session_id(),
kTestMediaSessionId);
EXPECT_EQ(fake_audio_consumer_service_->instance(0)->volume(), 1.0);
EXPECT_FALSE(fake_audio_consumer_service_->instance(0)->is_muted());
}
// Check that audio cannot play when the AUDIO ContextFeatureFlag is not
// provided.
TEST_F(WebEngineIntegrationMediaTest, PlayAudio_NoFlag) {
// Both FilteredServiceDirectory and test data are needed.
fuchsia::web::CreateContextParams create_params =
ContextParamsWithFilteredServiceDirectory();
create_params.mutable_content_directories()->push_back(
CreateTestDataDirectoryProvider());
CreateContextAndFrame(std::move(create_params));
bool is_requested = false;
ASSERT_EQ(filtered_service_directory_->outgoing_directory()->AddPublicService(
std::make_unique<vfs::Service>(
[&is_requested](zx::channel channel,
async_dispatcher_t* dispatcher) {
is_requested = true;
}),
fuchsia::media::SessionAudioConsumerFactory::Name_),
ZX_OK);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
navigation_listener_->RunUntilTitleEquals("error");
EXPECT_FALSE(is_requested);
}
TEST_F(WebEngineIntegrationMediaTest, PlayVideo) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
}
void WebEngineIntegrationTest::RunPermissionTest(bool grant) {
CreateContextAndFrame(DefaultContextParamsWithTestData());
if (grant) {
GrantPermission(fuchsia::web::PermissionType::MICROPHONE,
"fuchsia-dir://testdata/");
}
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
"fuchsia-dir://testdata/check_mic_permission.html"));
navigation_listener_->RunUntilTitleEquals(grant ? "granted" : "denied");
}
TEST_F(WebEngineIntegrationTest, PermissionDenied) {
RunPermissionTest(false);
}
TEST_F(WebEngineIntegrationTest, PermissionGranted) {
RunPermissionTest(true);
}
TEST_F(WebEngineIntegrationMediaTest, MicrophoneAccess_WithPermission) {
CreateContextAndFrame(ContextParamsWithAudio());
GrantPermission(fuchsia::web::PermissionType::MICROPHONE,
embedded_test_server_.GetURL("/").GetOrigin().spec());
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL("/mic.html").spec()));
navigation_listener_->RunUntilTitleEquals("ended");
}
TEST_F(WebEngineIntegrationMediaTest, MicrophoneAccess_WithoutPermission) {
CreateContextAndFrame(ContextParamsWithAudio());
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL("/mic.html?NoPermission").spec()));
navigation_listener_->RunUntilTitleEquals("ended");
}
TEST_F(WebEngineIntegrationMediaTest, SetBlockMediaLoading_Blocked) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(true);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
// Check different indicators that media has not loaded and is not playing.
navigation_listener_->RunUntilTitleEquals("stalled");
EXPECT_EQ(0 /*HAVE_NOTHING*/,
ExecuteJavaScriptWithDoubleResult("bear.readyState"));
EXPECT_EQ(0.0, ExecuteJavaScriptWithDoubleResult("bear.currentTime"));
EXPECT_FALSE(ExecuteJavaScriptWithBoolResult("isMetadataLoaded"));
}
// Initially, set media blocking to be true. When media is unblocked, check that
// it begins playing, since autoplay=true.
TEST_F(WebEngineIntegrationMediaTest, SetBlockMediaLoading_AfterUnblock) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(true);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
// Check that media loading has been blocked.
navigation_listener_->RunUntilTitleEquals("stalled");
// Unblock media from loading and see if media loads and plays, since
// autoplay=true.
frame_->SetBlockMediaLoading(false);
navigation_listener_->RunUntilTitleEquals("playing");
EXPECT_TRUE(ExecuteJavaScriptWithBoolResult("isMetadataLoaded"));
}
// Check that when autoplay=false and media loading was blocked after the
// element has started loading that media will play when play() is called.
TEST_F(WebEngineIntegrationMediaTest,
SetBlockMediaLoading_SetBlockedAfterLoading) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html");
navigation_listener_->RunUntilTitleEquals("loaded");
frame_->SetBlockMediaLoading(true);
cr_fuchsia::ExecuteJavaScript(frame_.get(), "bear.play()");
navigation_listener_->RunUntilTitleEquals("playing");
}
TEST_F(WebEngineIntegrationTest, WebGLContextAbsentWithoutVulkanFeature) {
CreateContextAndFrame(DefaultContextParams());
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL("/webgl_presence.html").spec()));
navigation_listener_->RunUntilLoaded();
EXPECT_EQ(navigation_listener_->title(), "absent");
}
#if defined(ARCH_CPU_ARM_FAMILY)
// TODO(crbug.com/1058247): Support Vulkan in tests on ARM64.
#define MAYBE_VulkanWebEngineIntegrationTest \
DISABLED_VulkanWebEngineIntegrationTest
#else
#define MAYBE_VulkanWebEngineIntegrationTest VulkanWebEngineIntegrationTest
#endif
class MAYBE_VulkanWebEngineIntegrationTest
: public WebEngineIntegrationMediaTest {};
TEST_F(MAYBE_VulkanWebEngineIntegrationTest,
WebGLContextPresentWithVulkanFeature) {
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_features(fuchsia::web::ContextFeatureFlags::VULKAN);
CreateContextAndFrame(std::move(create_params));
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL("/webgl_presence.html").spec()));
navigation_listener_->RunUntilLoaded();
EXPECT_EQ(navigation_listener_->title(), "present");
}
// Does not start WebEngine automatically as one of the tests requires manually
// starting it.
class WebEngineIntegrationCameraTest : public WebEngineIntegrationTestBase {
protected:
WebEngineIntegrationCameraTest() : WebEngineIntegrationTestBase() {}
void RunCameraTest(bool grant_permission);
};
void WebEngineIntegrationCameraTest::RunCameraTest(bool grant_permission) {
fuchsia::web::CreateContextParams create_params =
ContextParamsWithFilteredServiceDirectory();
media::FakeCameraDeviceWatcher fake_camera_device_watcher(
filtered_service_directory_->outgoing_directory());
CreateContextAndFrame(std::move(create_params));
if (grant_permission) {
GrantPermission(fuchsia::web::PermissionType::CAMERA,
embedded_test_server_.GetURL("/").GetOrigin().spec());
}
const char* url =
grant_permission ? "/camera.html" : "/camera.html?NoPermission";
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL(url).spec()));
navigation_listener_->RunUntilTitleEquals("ended");
}
// TODO(crbug.com/1104562): Flakily times-out.
TEST_F(WebEngineIntegrationCameraTest, DISABLED_CameraAccess_WithPermission) {
StartWebEngine(base::CommandLine(base::CommandLine::NO_PROGRAM));
RunCameraTest(/*grant_permission=*/true);
}
TEST_F(WebEngineIntegrationCameraTest, CameraAccess_WithoutPermission) {
StartWebEngine(base::CommandLine(base::CommandLine::NO_PROGRAM));
RunCameraTest(/*grant_permission=*/false);
}
TEST_F(WebEngineIntegrationCameraTest, CameraNoVideoCaptureProcess) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII("disable-features", "MojoVideoCapture");
StartWebEngine(std::move(command_line));
RunCameraTest(/*grant_permission=*/true);
}
// Check that when the ContextFeatureFlag HARDWARE_VIDEO_DECODER is
// provided that the CodecFactory service is connected to.
TEST_F(MAYBE_VulkanWebEngineIntegrationTest,
HardwareVideoDecoderFlag_Provided) {
fuchsia::web::CreateContextParams create_params =
ContextParamsWithAudioAndTestData();
// The VULKAN flag is required for hardware video decoders to be available.
create_params.set_features(
fuchsia::web::ContextFeatureFlags::VULKAN |
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER |
fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));
// Check that the CodecFactory service is requested.
bool is_requested = false;
ASSERT_EQ(filtered_service_directory_->outgoing_directory()->AddPublicService(
std::make_unique<vfs::Service>(
[&is_requested](zx::channel channel,
async_dispatcher_t* dispatcher) {
is_requested = true;
}),
fuchsia::mediacodec::CodecFactory::Name_),
ZX_OK);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
EXPECT_TRUE(is_requested);
}
// Check that the CodecFactory service is not requested when
// HARDWARE_VIDEO_DECODER is not provided.
// The video should use software decoders and still play.
TEST_F(WebEngineIntegrationMediaTest, HardwareVideoDecoderFlag_NotProvided) {
fuchsia::web::CreateContextParams create_params =
ContextParamsWithAudioAndTestData();
CreateContextAndFrame(std::move(create_params));
bool is_requested = false;
ASSERT_EQ(filtered_service_directory_->outgoing_directory()->AddPublicService(
std::make_unique<vfs::Service>(
[&is_requested](zx::channel channel,
async_dispatcher_t* dispatcher) {
is_requested = true;
}),
fuchsia::mediacodec::CodecFactory::Name_),
ZX_OK);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
EXPECT_FALSE(is_requested);
}