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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
headless / test / headless_protocol_browsertest.cc [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "headless/test/headless_protocol_browsertest.h"
#include "base/base64.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_refptr.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "content/public/common/content_switches.h"
#include "headless/lib/browser/headless_web_contents_impl.h"
#include "headless/public/switches.h"
#include "headless/test/headless_browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "third_party/blink/public/common/switches.h"
namespace headless {
namespace switches {
static const char kResetResults[] = "reset-results";
static const char kDumpConsoleMessages[] = "dump-console-messages";
static const char kDumpDevToolsProtocol[] = "dump-devtools-protocol";
static const char kDumpTestResult[] = "dump-test-result";
} // namespace switches
namespace {
static const base::FilePath kTestsDirectory(
FILE_PATH_LITERAL("headless/test/data/protocol"));
// This is a very simple command line switches parser intended to process '--'
// separated switches with or without values. It will not process nested command
// line switches specifications like --js-flags=--expose-gc. Use with caution!
void AppendCommandLineExtras(base::CommandLine* command_line,
std::string_view extras) {
std::vector<std::string> switches = base::SplitStringUsingSubstr(
extras, "--", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (const auto& a_switch : switches) {
if (size_t pos = a_switch.find('=', 1); pos != std::string::npos) {
command_line->AppendSwitchASCII(a_switch.substr(0, pos),
a_switch.substr(pos + 1));
} else {
command_line->AppendSwitch(a_switch);
}
}
}
} // namespace
HeadlessProtocolBrowserTest::HeadlessProtocolBrowserTest() {
embedded_test_server()->ServeFilesFromSourceDirectory(
"third_party/blink/web_tests/http/tests/inspector-protocol");
EXPECT_TRUE(embedded_test_server()->Start());
}
HeadlessProtocolBrowserTest::~HeadlessProtocolBrowserTest() = default;
void HeadlessProtocolBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) {
command_line->AppendSwitchASCII(::network::switches::kHostResolverRules,
"MAP *.test 127.0.0.1");
HeadlessDevTooledBrowserTest::SetUpCommandLine(command_line);
}
base::Value::Dict HeadlessProtocolBrowserTest::GetPageUrlExtraParams() {
return base::Value::Dict();
}
void HeadlessProtocolBrowserTest::RunDevTooledTest() {
scoped_refptr<content::DevToolsAgentHost> agent_host =
content::DevToolsAgentHost::GetOrCreateFor(
HeadlessWebContentsImpl::From(web_contents_)->web_contents());
// Set up Page domain.
devtools_client_.AddEventHandler(
"Page.loadEventFired",
base::BindRepeating(&HeadlessProtocolBrowserTest::OnLoadEventFired,
base::Unretained(this)));
devtools_client_.SendCommand("Page.enable");
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDumpConsoleMessages)) {
// Set up Runtime domain to intercept console messages.
devtools_client_.AddEventHandler(
"Runtime.consoleAPICalled",
base::BindRepeating(&HeadlessProtocolBrowserTest::OnConsoleAPICalled,
base::Unretained(this)));
devtools_client_.SendCommand("Runtime.enable");
}
// Expose DevTools protocol to the target.
browser_devtools_client_.SendCommand("Target.exposeDevToolsProtocol",
Param("targetId", agent_host->GetId()));
// Navigate to test harness page
GURL page_url = embedded_test_server()->GetURL(
"harness.test", "/protocol/inspector-protocol-test.html");
devtools_client_.SendCommand("Page.navigate", Param("url", page_url.spec()));
}
void HeadlessProtocolBrowserTest::OnLoadEventFired(
const base::Value::Dict& params) {
ASSERT_THAT(params, DictHasValue("method", "Page.loadEventFired"));
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath src_dir;
CHECK(base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &src_dir));
base::FilePath test_path =
src_dir.Append(kTestsDirectory).AppendASCII(script_name_);
std::string script;
if (!base::ReadFileToString(test_path, &script)) {
ADD_FAILURE() << "Unable to read test at " << test_path;
FinishTest();
return;
}
GURL test_url = embedded_test_server()->GetURL("harness.test",
"/protocol/" + script_name_);
GURL target_url =
embedded_test_server()->GetURL("127.0.0.1", "/protocol/" + script_name_);
base::Value::Dict test_params;
test_params.Set("test", test_url.spec());
test_params.Set("target", target_url.spec());
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDumpDevToolsProtocol)) {
test_params.Set("dumpDevToolsProtocol", true);
}
test_params.Merge(GetPageUrlExtraParams());
std::string json_test_params;
base::JSONWriter::Write(test_params, &json_test_params);
std::string evaluate_script = "runTest(" + json_test_params + ")";
base::Value::Dict evaluate_params;
evaluate_params.Set("expression", evaluate_script);
evaluate_params.Set("awaitPromise", true);
evaluate_params.Set("returnByValue", true);
devtools_client_.SendCommand(
"Runtime.evaluate", std::move(evaluate_params),
base::BindOnce(&HeadlessProtocolBrowserTest::OnEvaluateResult,
base::Unretained(this)));
}
void HeadlessProtocolBrowserTest::OnEvaluateResult(base::Value::Dict params) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDumpTestResult)) {
LOG(ERROR) << "Test result:\n" << params.DebugString();
}
ProcessTestResult(DictString(params, "result.result.value"));
FinishTest();
}
void HeadlessProtocolBrowserTest::ProcessTestResult(
const std::string& test_result) {
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath src_dir;
CHECK(base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &src_dir));
base::FilePath expectation_path =
src_dir.Append(kTestsDirectory)
.AppendASCII(script_name_.substr(0, script_name_.length() - 3) +
"-expected.txt");
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kResetResults)) {
LOG(INFO) << "Updating expectations at " << expectation_path;
bool succcess = base::WriteFile(expectation_path, test_result);
CHECK(succcess);
}
std::string expectation;
if (!base::ReadFileToString(expectation_path, &expectation)) {
ADD_FAILURE() << "Unable to read expectations at " << expectation_path;
}
EXPECT_EQ(expectation, test_result);
}
void HeadlessProtocolBrowserTest::OnConsoleAPICalled(
const base::Value::Dict& params) {
ASSERT_THAT(params, DictHasValue("method", "Runtime.consoleAPICalled"));
const base::Value::List* args = params.FindListByDottedPath("params.args");
if (!args || args->empty())
return;
const base::Value* value = args->front().GetDict().Find("value");
switch (value->type()) {
case base::Value::Type::NONE:
case base::Value::Type::BOOLEAN:
case base::Value::Type::INTEGER:
case base::Value::Type::DOUBLE:
case base::Value::Type::STRING:
LOG(INFO) << value->DebugString();
return;
default:
LOG(INFO) << "Unhandled value type: " << value->type();
return;
}
}
void HeadlessProtocolBrowserTest::FinishTest() {
test_finished_ = true;
FinishAsynchronousTest();
}
#define HEADLESS_PROTOCOL_TEST_CLASS(CLASS_NAME, TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(CLASS_NAME, TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
#define HEADLESS_PROTOCOL_TEST(TEST_NAME, SCRIPT_NAME) \
HEADLESS_PROTOCOL_TEST_CLASS(HeadlessProtocolBrowserTest, TEST_NAME, \
SCRIPT_NAME)
#define HEADLESS_PROTOCOL_TEST_P(CLASS_NAME, TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_P(CLASS_NAME, TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
// Headless-specific tests
HEADLESS_PROTOCOL_TEST(VirtualTimeBasics, "emulation/virtual-time-basics.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeInterrupt,
"emulation/virtual-time-interrupt.js")
// Flaky on Linux, Mac & Win. TODO(crbug.com/41440558): Re-enable.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || \
BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA)
#define MAYBE_VirtualTimeCrossProcessNavigation \
DISABLED_VirtualTimeCrossProcessNavigation
#else
#define MAYBE_VirtualTimeCrossProcessNavigation \
VirtualTimeCrossProcessNavigation
#endif
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeCrossProcessNavigation,
"emulation/virtual-time-cross-process-navigation.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeDetachFrame,
"emulation/virtual-time-detach-frame.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeNoBlock404, "emulation/virtual-time-404.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeLocalStorage,
"emulation/virtual-time-local-storage.js")
HEADLESS_PROTOCOL_TEST(VirtualTimePendingScript,
"emulation/virtual-time-pending-script.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeRedirect,
"emulation/virtual-time-redirect.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeSessionStorage,
"emulation/virtual-time-session-storage.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation,
"emulation/virtual-time-starvation.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeVideo, "emulation/virtual-time-video.js")
// Flaky on all platforms. https://crbug.com/1295644
HEADLESS_PROTOCOL_TEST(DISABLED_VirtualTimeErrorLoop,
"emulation/virtual-time-error-loop.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeFetchStream,
"emulation/virtual-time-fetch-stream.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeFetchReadBody,
"emulation/virtual-time-fetch-read-body.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeFetchBlobReadBodyBlob,
"emulation/virtual-time-fetch-read-body-blob.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeDialogWhileLoading,
"emulation/virtual-time-dialog-while-loading.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeHistoryNavigation,
"emulation/virtual-time-history-navigation.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeHistoryNavigationSameDoc,
"emulation/virtual-time-history-navigation-same-doc.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeSVG, "emulation/virtual-time-svg.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeWorkerBasic,
"emulation/virtual-time-worker-basic.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeWorkerLockstep,
"emulation/virtual-time-worker-lockstep.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeWorkerFetch,
"emulation/virtual-time-worker-fetch.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeWorkerTerminate,
"emulation/virtual-time-worker-terminate.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeFetchKeepalive,
"emulation/virtual-time-fetch-keepalive.js")
HEADLESS_PROTOCOL_TEST(VirtualTimeDisposeWhileRunning,
"emulation/virtual-time-dispose-while-running.js")
HEADLESS_PROTOCOL_TEST(VirtualTimePausesDocumentLoading,
"emulation/virtual-time-pauses-document-loading.js")
HEADLESS_PROTOCOL_TEST(PageBeforeUnload, "page/page-before-unload.js")
// http://crbug.com/633321
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_VirtualTimeTimerOrder DISABLED_VirtualTimeTimerOrder
#define MAYBE_VirtualTimeTimerSuspend DISABLED_VirtualTimeTimerSuspend
#else
#define MAYBE_VirtualTimeTimerOrder VirtualTimeTimerOrder
#define MAYBE_VirtualTimeTimerSuspend VirtualTimeTimerSuspend
#endif
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeTimerOrder,
"emulation/virtual-time-timer-order.js")
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeTimerSuspend,
"emulation/virtual-time-timer-suspended.js")
#undef MAYBE_VirtualTimeTimerOrder
#undef MAYBE_VirtualTimeTimerSuspend
HEADLESS_PROTOCOL_TEST(Geolocation, "emulation/geolocation-crash.js")
HEADLESS_PROTOCOL_TEST(DragStarted, "input/dragIntercepted.js")
// https://crbug.com/1414190
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_InputClipboardOps DISABLED_InputClipboardOps
#else
#define MAYBE_InputClipboardOps InputClipboardOps
#endif
HEADLESS_PROTOCOL_TEST(MAYBE_InputClipboardOps, "input/input-clipboard-ops.js")
HEADLESS_PROTOCOL_TEST(ClipboardApiCopyPaste,
"input/clipboard-api-copy-paste.js")
HEADLESS_PROTOCOL_TEST(FocusBlurNotifications,
"input/focus-blur-notifications.js")
HEADLESS_PROTOCOL_TEST(HeadlessSessionBasicsTest,
"sessions/headless-session-basics.js")
HEADLESS_PROTOCOL_TEST(HeadlessSessionCreateContextDisposeOnDetach,
"sessions/headless-createContext-disposeOnDetach.js")
HEADLESS_PROTOCOL_TEST(BrowserSetInitialProxyConfig,
"sanity/browser-set-initial-proxy-config.js")
HEADLESS_PROTOCOL_TEST(BrowserUniversalNetworkAccess,
"sanity/universal-network-access.js")
HEADLESS_PROTOCOL_TEST(ShowDirectoryPickerNoCrash,
"sanity/show-directory-picker-no-crash.js")
HEADLESS_PROTOCOL_TEST(ShowFilePickerInterception,
"sanity/show-file-picker-interception.js")
HEADLESS_PROTOCOL_TEST(ChangeWindowSize, "sanity/change-window-size.js")
HEADLESS_PROTOCOL_TEST(ChangeWindowState, "sanity/change-window-state.js")
HEADLESS_PROTOCOL_TEST(WindowOuterSize, "sanity/window-outer-size.js")
HEADLESS_PROTOCOL_TEST(WindowSizeOnStart, "sanity/window-size-on-start.js")
HEADLESS_PROTOCOL_TEST(LargeBrowserWindowSize,
"sanity/large-browser-window-size.js")
HEADLESS_PROTOCOL_TEST(ScreencastBasics, "sanity/screencast-basics.js")
HEADLESS_PROTOCOL_TEST(ScreencastViewport, "sanity/screencast-viewport.js")
HEADLESS_PROTOCOL_TEST(GrantPermissions, "sanity/grant_permissions.js")
#if !defined(HEADLESS_USE_EMBEDDED_RESOURCES)
HEADLESS_PROTOCOL_TEST(AutoHyphenation, "sanity/auto-hyphenation.js")
#endif
class HeadlessProtocolBrowserTestWithKnownPermission
: public HeadlessProtocolBrowserTest {
public:
HeadlessProtocolBrowserTestWithKnownPermission() = default;
protected:
base::Value::Dict GetPageUrlExtraParams() override {
base::Value::List permissions;
const std::vector<blink::PermissionType>& types =
blink::GetAllPermissionTypes();
for (blink::PermissionType type : types) {
std::string permission = blink::GetPermissionString(type);
NormalizePermissionName(permission);
permissions.Append(permission);
}
base::Value::Dict dict;
dict.Set("permissions", std::move(permissions));
return dict;
}
static void NormalizePermissionName(std::string& permission) {
if (IsAllAsciiUpper(permission)) {
permission = base::ToLowerASCII(permission);
} else {
permission[0] = base::ToLowerASCII(permission[0]);
}
// Handle known exceptions.
if (permission == "midiSysEx") {
permission = "midiSysex";
}
}
static bool IsAllAsciiUpper(const std::string& permission) {
for (char ch : permission) {
if (!base::IsAsciiUpper(ch)) {
return false;
}
}
return true;
}
};
HEADLESS_PROTOCOL_TEST_CLASS(HeadlessProtocolBrowserTestWithKnownPermission,
KnownPermissionTypes,
"sanity/known-permission-types.js")
class HeadlessProtocolBrowserTestWithProxy
: public HeadlessProtocolBrowserTest {
public:
HeadlessProtocolBrowserTestWithProxy()
: proxy_server_(net::EmbeddedTestServer::TYPE_HTTP) {
proxy_server_.AddDefaultHandlers(
base::FilePath(FILE_PATH_LITERAL("headless/test/data")));
}
void SetUp() override {
ASSERT_TRUE(proxy_server_.Start());
HeadlessProtocolBrowserTest::SetUp();
}
void TearDown() override {
EXPECT_TRUE(proxy_server_.ShutdownAndWaitUntilComplete());
HeadlessProtocolBrowserTest::TearDown();
}
net::EmbeddedTestServer* proxy_server() { return &proxy_server_; }
protected:
base::Value::Dict GetPageUrlExtraParams() override {
std::string proxy = proxy_server()->host_port_pair().ToString();
base::Value::Dict dict;
dict.Set("proxy", proxy);
return dict;
}
private:
net::EmbeddedTestServer proxy_server_;
};
HEADLESS_PROTOCOL_TEST_CLASS(HeadlessProtocolBrowserTestWithProxy,
BrowserSetProxyConfig,
"sanity/browser-set-proxy-config.js")
class HeadlessAllowedVideoCodecsTest
: public HeadlessDevTooledBrowserTest,
public testing::WithParamInterface<
std::tuple<std::string, std::string, bool>> {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII("allow-video-codecs", allowlist());
}
void RunDevTooledTest() override {
ASSERT_TRUE(embedded_test_server()->Start());
SendCommandSync(devtools_client_, "Page.enable");
devtools_client_.AddEventHandler(
"Page.loadEventFired",
base::BindRepeating(&HeadlessAllowedVideoCodecsTest::OnLoadEventFired,
base::Unretained(this)));
devtools_client_.SendCommand(
"Page.navigate",
Param("url", embedded_test_server()->GetURL("/hello.html").spec()));
}
void OnLoadEventFired(const base::Value::Dict& params) {
base::Value::Dict eval_params;
eval_params.Set("returnByValue", true);
eval_params.Set("awaitPromise", true);
eval_params.Set("expression", base::StringPrintf(R"(
VideoDecoder.isConfigSupported({codec: "%s"})
.then(result => result.supported)
)",
codec_name().c_str()));
base::Value::Dict result = SendCommandSync(
devtools_client_, "Runtime.evaluate", std::move(eval_params));
EXPECT_THAT(result.FindBoolByDottedPath("result.result.value"),
testing::Optional(is_codec_enabled()));
FinishAsynchronousTest();
}
const std::string& allowlist() const { return std::get<0>(GetParam()); }
const std::string& codec_name() const { return std::get<1>(GetParam()); }
bool is_codec_enabled() const { return std::get<2>(GetParam()); }
};
constexpr bool have_proprietary_codecs =
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
true;
#else
false;
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
INSTANTIATE_TEST_SUITE_P(
All,
HeadlessAllowedVideoCodecsTest,
testing::Values(
std::make_tuple("av1,-*", "av01.0.04M.08", true),
std::make_tuple("-av1,*", "av01.0.04M.08", false),
std::make_tuple("*", "avc1.64000b", have_proprietary_codecs)));
HEADLESS_DEVTOOLED_TEST_P(HeadlessAllowedVideoCodecsTest);
class PopupWindowOpenTest : public HeadlessProtocolBrowserTest,
public testing::WithParamInterface<bool> {
protected:
PopupWindowOpenTest() = default;
void CustomizeHeadlessBrowserContext(
HeadlessBrowserContext::Builder& builder) override {
builder.SetBlockNewWebContents(ShouldBlockNewWebContents());
}
base::Value::Dict GetPageUrlExtraParams() override {
base::Value::Dict params;
params.Set("blockingNewWebContents", ShouldBlockNewWebContents());
return params;
}
bool ShouldBlockNewWebContents() const { return GetParam(); }
};
INSTANTIATE_TEST_SUITE_P(/* no prefix */,
PopupWindowOpenTest,
::testing::Bool());
HEADLESS_PROTOCOL_TEST_P(PopupWindowOpenTest,
Open,
"sanity/popup-window-open.js")
class HeadlessProtocolBrowserTestWithoutSiteIsolation
: public HeadlessProtocolBrowserTest {
public:
HeadlessProtocolBrowserTestWithoutSiteIsolation() = default;
protected:
bool ShouldEnableSitePerProcess() override { return false; }
};
HEADLESS_PROTOCOL_TEST_CLASS(
HeadlessProtocolBrowserTestWithoutSiteIsolation,
VirtualTimeLocalStorageDetachedFrame,
"emulation/virtual-time-local-storage-detached-frame.js")
class HeadlessProtocolBrowserTestWithDataPath
: public HeadlessProtocolBrowserTest {
protected:
base::Value::Dict GetPageUrlExtraParams() override {
base::FilePath src_dir;
CHECK(base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &src_dir));
base::FilePath path =
src_dir.Append(kTestsDirectory).AppendASCII(data_path_);
base::Value::Dict dict;
dict.Set("data_path", path.AsUTF8Unsafe());
return dict;
}
std::string data_path_;
};
#define HEADLESS_PROTOCOL_TEST_WITH_DATA_PATH(TEST_NAME, SCRIPT_NAME, PATH) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolBrowserTestWithDataPath, TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
data_path_ = PATH; \
RunTest(); \
}
// TODO(crbug.com/40883155) Re-enable after resolving flaky failures.
HEADLESS_PROTOCOL_TEST_WITH_DATA_PATH(
FileInputDirectoryUpload,
"sanity/file-input-directory-upload.js",
"sanity/resources/file-input-directory-upload")
class HeadlessProtocolBrowserTestWithExposeGC
: public HeadlessProtocolBrowserTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
HeadlessProtocolBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(blink::switches::kJavaScriptFlags,
"--expose-gc");
}
};
HEADLESS_PROTOCOL_TEST_CLASS(HeadlessProtocolBrowserTestWithExposeGC,
GetDOMCountersForLeakDetection,
"sanity/get-dom-counters-for-leak-detection.js")
class HeadlessProtocolBrowserTestSitePerProcess
: public HeadlessProtocolBrowserTest,
public testing::WithParamInterface<bool> {
public:
bool ShouldEnableSitePerProcess() override { return GetParam(); }
base::Value::Dict GetPageUrlExtraParams() override {
base::Value::Dict params;
params.Set("sitePerProcessEnabled", ShouldEnableSitePerProcess());
return params;
}
};
INSTANTIATE_TEST_SUITE_P(/* no prefix */,
HeadlessProtocolBrowserTestSitePerProcess,
::testing::Bool());
HEADLESS_PROTOCOL_TEST_P(HeadlessProtocolBrowserTestSitePerProcess,
SitePerProcess,
"sanity/site-per-process.js")
#define HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS( \
TEST_NAME, SCRIPT_NAME, COMMAND_LINE_EXTRAS) \
\
class HeadlessProtocolBrowserTestWithCommandLineExtras_##TEST_NAME \
: public HeadlessProtocolBrowserTest { \
public: \
void SetUpCommandLine(base::CommandLine* command_line) override { \
HeadlessProtocolBrowserTest::SetUpCommandLine(command_line); \
AppendCommandLineExtras(command_line, COMMAND_LINE_EXTRAS); \
} \
}; \
\
IN_PROC_BROWSER_TEST_F( \
HeadlessProtocolBrowserTestWithCommandLineExtras_##TEST_NAME, \
TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenScaleFactor,
"sanity/screen-scale-factor.js",
"--screen-info={devicePixelRatio=3.0}")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenSizeOrientation,
"sanity/screen-size-orientation.js",
"--screen-info={600x800}")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenOrientationLockNaturalLandscape,
"sanity/screen-orientation-lock-natural-landscape.js",
"--screen-info={800x600}")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenOrientationLockNaturalPortrait,
"sanity/screen-orientation-lock-natural-portrait.js",
"--screen-info={600x800}")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenDetailsMultipleScreens,
"sanity/screen-details-multiple-screens.js",
"--screen-info={ label='1st screen' }{ 600x800 label='2nd screen' }")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
ScreenDetailsPixelRatioAndColorDepth,
"sanity/screen-details-pixel-ratio-and-color-depth.js",
"--screen-info={ label='Screen' devicePixelRatio=3.0 colorDepth=32 }")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
RequestFullscreen,
"sanity/request-fullscreen.js",
"--screen-info={ 800x600 } --window-size=400,200")
// https://crbug.com/380313546
#if BUILDFLAG(IS_MAC)
#define MAYBE_WindowOpenOnSecondaryScreen DISABLED_WindowOpenOnSecondaryScreen
#define MAYBE_RequestFullscreenOnSecondaryScreen \
DISABLED_RequestFullscreenOnSecondaryScreen
#define MAYBE_ScreenRotationSecondaryScreen \
DISABLED_ScreenRotationSecondaryScreen
#define MAYBE_MoveWindowBetweenScreens DISABLED_MoveWindowBetweenScreens
#else
#define MAYBE_WindowOpenOnSecondaryScreen WindowOpenOnSecondaryScreen
#define MAYBE_RequestFullscreenOnSecondaryScreen \
RequestFullscreenOnSecondaryScreen
#define MAYBE_ScreenRotationSecondaryScreen ScreenRotationSecondaryScreen
#define MAYBE_MoveWindowBetweenScreens MoveWindowBetweenScreens
#endif
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
MAYBE_WindowOpenOnSecondaryScreen,
"sanity/window-open-on-secondary-screen.js",
"--screen-info={ label='1st screen' }{ label='2nd screen' }")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
MAYBE_RequestFullscreenOnSecondaryScreen,
"sanity/request-fullscreen-on-secondary-screen.js",
"--screen-info={ label='1st screen' }{ 600x800 label='2nd screen' }")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
MAYBE_ScreenRotationSecondaryScreen,
"sanity/screen-rotation-secondary-screen.js",
"--screen-info={ label='1st screen' }{ 600x800 label='2nd screen' }")
HEADLESS_PROTOCOL_TEST_WITH_COMMAND_LINE_EXTRAS(
MAYBE_MoveWindowBetweenScreens,
"sanity/move-window-between-screens.js",
"--screen-info={label='#1'}{label='#2'}{0,600 label='#3'}{label='#4'}")
} // namespace headless