forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_runner.cc
2609 lines (2213 loc) · 86.9 KB
/
test_runner.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
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2014 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 "content/shell/test_runner/test_runner.h"
#include <stddef.h>
#include <algorithm>
#include <limits>
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/nullable_string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "cc/paint/paint_canvas.h"
#include "content/shell/common/web_test/web_test_switches.h"
#include "content/shell/test_runner/layout_dump.h"
#include "content/shell/test_runner/mock_content_settings_client.h"
#include "content/shell/test_runner/mock_screen_orientation_client.h"
#include "content/shell/test_runner/mock_web_document_subresource_filter.h"
#include "content/shell/test_runner/pixel_dump.h"
#include "content/shell/test_runner/spell_check_client.h"
#include "content/shell/test_runner/test_common.h"
#include "content/shell/test_runner/test_interfaces.h"
#include "content/shell/test_runner/test_preferences.h"
#include "content/shell/test_runner/test_runner_for_specific_view.h"
#include "content/shell/test_runner/web_test_delegate.h"
#include "content/shell/test_runner/web_view_test_proxy.h"
#include "gin/arguments.h"
#include "gin/array_buffer.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "services/network/public/mojom/cors.mojom.h"
#include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/public/platform/web_point.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_array_buffer.h"
#include "third_party/blink/public/web/web_array_buffer_converter.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_document_loader.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/public/web/web_input_element.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_page_importance_signals.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "third_party/blink/public/web/web_security_policy.h"
#include "third_party/blink/public/web/web_serialized_script_value.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_surrounding_text.h"
#include "third_party/blink/public/web/web_view.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/skia_util.h"
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_FUCHSIA)
#include "third_party/blink/public/platform/web_font_render_style.h"
#endif
namespace test_runner {
namespace {
double GetDefaultDeviceScaleFactor() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) {
double scale;
std::string value =
command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
if (base::StringToDouble(value, &scale))
return scale;
}
return 1.f;
}
void ConvertAndSet(gin::Arguments* args, int* set_param) {
v8::Local<v8::Value> value = args->PeekNext();
v8::Maybe<int> result = value->Int32Value(args->GetHolderCreationContext());
if (result.IsNothing()) {
// Skip so the error is thrown for the correct argument as PeekNext doesn't
// update the current argument pointer.
args->Skip();
args->ThrowError();
return;
}
*set_param = result.ToChecked();
}
void ConvertAndSet(gin::Arguments* args, bool* set_param) {
v8::Local<v8::Value> value = args->PeekNext();
*set_param = value->BooleanValue(args->isolate());
}
void ConvertAndSet(gin::Arguments* args, blink::WebString* set_param) {
v8::Local<v8::Value> value = args->PeekNext();
v8::MaybeLocal<v8::String> result =
value->ToString(args->GetHolderCreationContext());
if (result.IsEmpty()) {
// Skip so the error is thrown for the correct argument as PeekNext doesn't
// update the current argument pointer.
args->Skip();
args->ThrowError();
return;
}
*set_param = V8StringToWebString(args->isolate(), result.ToLocalChecked());
}
} // namespace
class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
public:
static gin::WrapperInfo kWrapperInfo;
static void Install(base::WeakPtr<TestRunner> test_runner,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
blink::WebLocalFrame* frame,
bool is_wpt_reftest);
private:
explicit TestRunnerBindings(
base::WeakPtr<TestRunner> test_runner,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
~TestRunnerBindings() override;
// gin::Wrappable:
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
void AddOriginAccessAllowListEntry(const std::string& source_origin,
const std::string& destination_protocol,
const std::string& destination_host,
bool allow_destination_subdomains);
void AddWebPageOverlay();
void SetHighlightAds();
void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
void ClearAllDatabases();
void ClearPrinting();
void CopyImageAtAndCapturePixelsAsyncThen(int x,
int y,
v8::Local<v8::Function> callback);
void DidAcquirePointerLock();
void DidLosePointerLock();
void DidNotAcquirePointerLock();
void DisableMockScreenOrientation();
void DispatchBeforeInstallPromptEvent(
const std::vector<std::string>& event_platforms,
v8::Local<v8::Function> callback);
void DumpAsMarkup();
void DumpAsText();
void DumpAsTextWithPixelResults();
void DumpAsLayout();
void DumpAsLayoutWithPixelResults();
void DumpChildFrames();
void DumpBackForwardList();
void DumpCreateView();
void DumpDragImage();
void DumpEditingCallbacks();
void DumpFrameLoadCallbacks();
void DumpIconChanges();
void DumpNavigationPolicy();
void DumpPermissionClientCallbacks();
void DumpPingLoaderCallbacks();
void DumpResourceLoadCallbacks();
void DumpResourceResponseMIMETypes();
void DumpSelectionRect();
void DumpSpellCheckCallbacks();
void DumpTitleChanges();
void DumpUserGestureInFrameLoadCallbacks();
void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
void ExecCommand(gin::Arguments* args);
void ForceNextDrawingBufferCreationToFail();
void ForceNextWebGLContextCreationToFail();
void ForceRedSelectionColors();
void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
void GetManifestThen(v8::Local<v8::Function> callback);
void InsertStyleSheet(const std::string& source_code);
void UpdateAllLifecyclePhasesAndComposite();
void UpdateAllLifecyclePhasesAndCompositeThen(
v8::Local<v8::Function> callback);
void SetAnimationRequiresRaster(bool do_raster);
void LogToStderr(const std::string& output);
void NotImplemented(const gin::Arguments& args);
void NotifyDone();
void OverridePreference(gin::Arguments* args);
void QueueBackNavigation(int how_far_back);
void QueueForwardNavigation(int how_far_forward);
void QueueLoad(gin::Arguments* args);
void QueueLoadingScript(const std::string& script);
void QueueNonLoadingScript(const std::string& script);
void QueueReload();
void RemoveSpellCheckResolvedCallback();
void RemoveWebPageOverlay();
void ResetTestHelperControllers();
void ResolveBeforeInstallPromptPromise(const std::string& platform);
void RunIdleTasks(v8::Local<v8::Function> callback);
void SendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument);
void SetAcceptLanguages(const std::string& accept_languages);
void SetAllowFileAccessFromFileURLs(bool allow);
void SetAllowRunningOfInsecureContent(bool allowed);
void SetAutoplayAllowed(bool allowed);
void SetAllowUniversalAccessFromFileURLs(bool allow);
void SetBlockThirdPartyCookies(bool block);
void SetAudioData(const gin::ArrayBufferView& view);
void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
void SetBluetoothFakeAdapter(const std::string& adapter_name,
v8::Local<v8::Function> callback);
void SetBluetoothManualChooser(bool enable);
void SetCanOpenWindows();
void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
void SetColorProfile(const std::string& name,
v8::Local<v8::Function> callback);
void SetCustomPolicyDelegate(gin::Arguments* args);
void SetCustomTextOutput(const std::string& output);
void SetDatabaseQuota(int quota);
void SetDisallowedSubresourcePathSuffixes(
const std::vector<std::string>& suffixes,
bool block_subresources);
void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
const std::string& scheme);
void SetDumpConsoleMessages(bool value);
void SetDumpJavaScriptDialogs(bool value);
void SetEffectiveConnectionType(const std::string& connection_type);
void SetMockSpellCheckerEnabled(bool enabled);
void SetImagesAllowed(bool allowed);
void SetIsolatedWorldInfo(int world_id,
v8::Local<v8::Value> security_origin,
v8::Local<v8::Value> content_security_policy);
void SetJavaScriptCanAccessClipboard(bool can_access);
void SetMockScreenOrientation(const std::string& orientation);
void SetPOSIXLocale(const std::string& locale);
void SetPageVisibility(const std::string& new_visibility);
void SetPermission(const std::string& name,
const std::string& value,
const std::string& origin,
const std::string& embedding_origin);
void SetPluginsAllowed(bool allowed);
void SetPluginsEnabled(bool enabled);
void SetPointerLockWillFailSynchronously();
void SetPointerLockWillRespondAsynchronously();
void SetPopupBlockingEnabled(bool block_popups);
void SetPrinting();
void SetPrintingForFrame(const std::string& frame_name);
void SetScriptsAllowed(bool allowed);
void SetShouldGeneratePixelResults(bool);
void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
void SetSpellCheckResolvedCallback(v8::Local<v8::Function> callback);
void SetStorageAllowed(bool allowed);
void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
void SetTextDirection(const std::string& direction_name);
void SetTextSubpixelPositioning(bool value);
void SetUseMockTheme(bool use);
void SetViewSourceForFrame(const std::string& name, bool enabled);
void SetWillSendRequestClearHeader(const std::string& header);
void SetWindowIsKey(bool value);
void SetXSSAuditorEnabled(bool enabled);
void NavigateSecondaryWindow(const std::string& url);
void InspectSecondaryWindow();
void SimulateWebNotificationClick(gin::Arguments* args);
void SimulateWebNotificationClose(const std::string& title, bool by_user);
void UseUnfortunateSynchronousResizeMode();
void WaitForPolicyDelegate();
void WaitUntilDone();
void WaitUntilExternalURLLoad();
bool DisableAutoResizeMode(int new_width, int new_height);
bool EnableAutoResizeMode(int min_width,
int min_height,
int max_width,
int max_height);
v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
int world_id,
const std::string& script);
bool FindString(const std::string& search_text,
const std::vector<std::string>& options_array);
bool HasCustomPageSizeStyle(int page_index);
bool IsChooserShown();
bool IsCommandEnabled(const std::string& command);
std::string PathToLocalResource(const std::string& path);
std::string PlatformName();
std::string SelectionAsMarkup();
std::string TooltipText();
int WebHistoryItemCount();
int WindowCount();
base::WeakPtr<TestRunner> runner_;
base::WeakPtr<TestRunnerForSpecificView> view_runner_;
DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
};
gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {gin::kEmbedderNativeGin};
// static
void TestRunnerBindings::Install(
base::WeakPtr<TestRunner> test_runner,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
blink::WebLocalFrame* frame,
bool is_wpt_test) {
v8::Isolate* isolate = blink::MainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->MainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
TestRunnerBindings* wrapped =
new TestRunnerBindings(test_runner, view_test_runner);
gin::Handle<TestRunnerBindings> bindings =
gin::CreateHandle(isolate, wrapped);
if (bindings.IsEmpty())
return;
v8::Local<v8::Object> global = context->Global();
v8::Local<v8::Value> v8_bindings = bindings.ToV8();
global->Set(context, gin::StringToV8(isolate, "testRunner"), v8_bindings)
.Check();
// Inject some JavaScript to the top-level frame of a reftest in the
// web-platform-tests suite to have the same reftest screenshot timing as
// upstream WPT:
//
// 1. For normal reftest, we would like to take screenshots after web fonts
// are loaded, i.e. replicate the behavior of this injected script:
// https://github.com/web-platform-tests/wpt/blob/master/tools/wptrunner/wptrunner/executors/reftest-wait_webdriver.js
// 2. For reftests with a 'reftest-wait' class on the root element, reference
// comparison is delayed until that class attribute is removed. To support
// this feature, we use a mutation observer.
// https://web-platform-tests.org/writing-tests/reftests.html#controlling-when-comparison-occurs
//
// Note that this method may be called multiple times on a frame, so we put
// the code behind a flag. The flag is safe to be installed on testRunner
// because WPT reftests never access this object.
if (is_wpt_test && !frame->Parent() && !frame->Opener()) {
frame->ExecuteScript(blink::WebString(
R"(if (!window.testRunner._wpt_reftest_setup) {
window.testRunner._wpt_reftest_setup = true;
window.addEventListener('load', function() {
if (window.assert_equals) // In case of a testharness test.
return;
window.testRunner.waitUntilDone();
const target = document.documentElement;
if (target != null && target.classList.contains('reftest-wait')) {
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (!target.classList.contains('reftest-wait')) {
window.testRunner.notifyDone();
}
});
});
const config = {attributes: true};
observer.observe(target, config);
} else {
document.fonts.ready.then(() => window.testRunner.notifyDone());
}
});
})"));
}
}
TestRunnerBindings::TestRunnerBindings(
base::WeakPtr<TestRunner> runner,
base::WeakPtr<TestRunnerForSpecificView> view_runner)
: runner_(runner), view_runner_(view_runner) {}
TestRunnerBindings::~TestRunnerBindings() {}
gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
.SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
.SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
.SetMethod("addOriginAccessAllowListEntry",
&TestRunnerBindings::AddOriginAccessAllowListEntry)
.SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
.SetMethod("capturePixelsAsyncThen",
&TestRunnerBindings::CapturePixelsAsyncThen)
.SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
.SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
.SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting)
.SetMethod("copyImageAtAndCapturePixelsAsyncThen",
&TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
.SetMethod("didAcquirePointerLock",
&TestRunnerBindings::DidAcquirePointerLock)
.SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
.SetMethod("didNotAcquirePointerLock",
&TestRunnerBindings::DidNotAcquirePointerLock)
.SetMethod("disableAutoResizeMode",
&TestRunnerBindings::DisableAutoResizeMode)
.SetMethod("disableMockScreenOrientation",
&TestRunnerBindings::DisableMockScreenOrientation)
.SetMethod("setDisallowedSubresourcePathSuffixes",
&TestRunnerBindings::SetDisallowedSubresourcePathSuffixes)
.SetMethod("dispatchBeforeInstallPromptEvent",
&TestRunnerBindings::DispatchBeforeInstallPromptEvent)
.SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup)
.SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
.SetMethod("dumpAsTextWithPixelResults",
&TestRunnerBindings::DumpAsTextWithPixelResults)
.SetMethod("dumpAsLayout", &TestRunnerBindings::DumpAsLayout)
.SetMethod("dumpAsLayoutWithPixelResults",
&TestRunnerBindings::DumpAsLayoutWithPixelResults)
.SetMethod("dumpBackForwardList",
&TestRunnerBindings::DumpBackForwardList)
.SetMethod("dumpChildFrames", &TestRunnerBindings::DumpChildFrames)
.SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
.SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
.SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage)
.SetMethod("dumpEditingCallbacks",
&TestRunnerBindings::DumpEditingCallbacks)
.SetMethod("dumpFrameLoadCallbacks",
&TestRunnerBindings::DumpFrameLoadCallbacks)
.SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
.SetMethod("dumpNavigationPolicy",
&TestRunnerBindings::DumpNavigationPolicy)
.SetMethod("dumpPermissionClientCallbacks",
&TestRunnerBindings::DumpPermissionClientCallbacks)
.SetMethod("dumpPingLoaderCallbacks",
&TestRunnerBindings::DumpPingLoaderCallbacks)
.SetMethod("dumpResourceLoadCallbacks",
&TestRunnerBindings::DumpResourceLoadCallbacks)
.SetMethod("dumpResourceResponseMIMETypes",
&TestRunnerBindings::DumpResourceResponseMIMETypes)
.SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
.SetMethod("dumpSpellCheckCallbacks",
&TestRunnerBindings::DumpSpellCheckCallbacks)
.SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
.SetMethod("dumpUserGestureInFrameLoadCallbacks",
&TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
.SetMethod("enableAutoResizeMode",
&TestRunnerBindings::EnableAutoResizeMode)
.SetMethod("enableUseZoomForDSF",
&TestRunnerBindings::EnableUseZoomForDSF)
.SetMethod("evaluateScriptInIsolatedWorld",
&TestRunnerBindings::EvaluateScriptInIsolatedWorld)
.SetMethod(
"evaluateScriptInIsolatedWorldAndReturnValue",
&TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue)
.SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
.SetMethod("findString", &TestRunnerBindings::FindString)
.SetMethod("forceNextDrawingBufferCreationToFail",
&TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
.SetMethod("forceNextWebGLContextCreationToFail",
&TestRunnerBindings::ForceNextWebGLContextCreationToFail)
.SetMethod("forceRedSelectionColors",
&TestRunnerBindings::ForceRedSelectionColors)
// The Bluetooth functions are specified at
// https://webbluetoothcg.github.io/web-bluetooth/tests/.
.SetMethod("getBluetoothManualChooserEvents",
&TestRunnerBindings::GetBluetoothManualChooserEvents)
.SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
.SetMethod("hasCustomPageSizeStyle",
&TestRunnerBindings::HasCustomPageSizeStyle)
.SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet)
.SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
.SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
.SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
.SetMethod("updateAllLifecyclePhasesAndComposite",
&TestRunnerBindings::UpdateAllLifecyclePhasesAndComposite)
.SetMethod("updateAllLifecyclePhasesAndCompositeThen",
&TestRunnerBindings::UpdateAllLifecyclePhasesAndCompositeThen)
.SetMethod("setAnimationRequiresRaster",
&TestRunnerBindings::SetAnimationRequiresRaster)
.SetMethod("logToStderr", &TestRunnerBindings::LogToStderr)
.SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
.SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
.SetMethod("pathToLocalResource",
&TestRunnerBindings::PathToLocalResource)
.SetProperty("platformName", &TestRunnerBindings::PlatformName)
.SetMethod("queueBackNavigation",
&TestRunnerBindings::QueueBackNavigation)
.SetMethod("queueForwardNavigation",
&TestRunnerBindings::QueueForwardNavigation)
.SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
.SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
.SetMethod("queueNonLoadingScript",
&TestRunnerBindings::QueueNonLoadingScript)
.SetMethod("queueReload", &TestRunnerBindings::QueueReload)
.SetMethod("removeSpellCheckResolvedCallback",
&TestRunnerBindings::RemoveSpellCheckResolvedCallback)
.SetMethod("removeWebPageOverlay",
&TestRunnerBindings::RemoveWebPageOverlay)
.SetMethod("resetTestHelperControllers",
&TestRunnerBindings::ResetTestHelperControllers)
.SetMethod("resolveBeforeInstallPromptPromise",
&TestRunnerBindings::ResolveBeforeInstallPromptPromise)
.SetMethod("runIdleTasks", &TestRunnerBindings::RunIdleTasks)
.SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
// The Bluetooth functions are specified at
// https://webbluetoothcg.github.io/web-bluetooth/tests/.
.SetMethod("sendBluetoothManualChooserEvent",
&TestRunnerBindings::SendBluetoothManualChooserEvent)
.SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages)
.SetMethod("setAllowFileAccessFromFileURLs",
&TestRunnerBindings::SetAllowFileAccessFromFileURLs)
.SetMethod("setAllowRunningOfInsecureContent",
&TestRunnerBindings::SetAllowRunningOfInsecureContent)
.SetMethod("setAutoplayAllowed", &TestRunnerBindings::SetAutoplayAllowed)
.SetMethod("setAllowUniversalAccessFromFileURLs",
&TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
.SetMethod("setBlockThirdPartyCookies",
&TestRunnerBindings::SetBlockThirdPartyCookies)
.SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
.SetMethod("setBackingScaleFactor",
&TestRunnerBindings::SetBackingScaleFactor)
// The Bluetooth functions are specified at
// https://webbluetoothcg.github.io/web-bluetooth/tests/.
.SetMethod("setBluetoothFakeAdapter",
&TestRunnerBindings::SetBluetoothFakeAdapter)
.SetMethod("setBluetoothManualChooser",
&TestRunnerBindings::SetBluetoothManualChooser)
.SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
.SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
.SetMethod("setCloseRemainingWindowsWhenComplete",
&TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
.SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile)
.SetMethod("setCustomPolicyDelegate",
&TestRunnerBindings::SetCustomPolicyDelegate)
.SetMethod("setCustomTextOutput",
&TestRunnerBindings::SetCustomTextOutput)
.SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
.SetMethod("setDomainRelaxationForbiddenForURLScheme",
&TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
.SetMethod("setDumpConsoleMessages",
&TestRunnerBindings::SetDumpConsoleMessages)
.SetMethod("setDumpJavaScriptDialogs",
&TestRunnerBindings::SetDumpJavaScriptDialogs)
.SetMethod("setEffectiveConnectionType",
&TestRunnerBindings::SetEffectiveConnectionType)
.SetMethod("setHighlightAds", &TestRunnerBindings::SetHighlightAds)
.SetMethod("setMockSpellCheckerEnabled",
&TestRunnerBindings::SetMockSpellCheckerEnabled)
.SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
.SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
.SetMethod("setIsolatedWorldInfo",
&TestRunnerBindings::SetIsolatedWorldInfo)
.SetMethod("setJavaScriptCanAccessClipboard",
&TestRunnerBindings::SetJavaScriptCanAccessClipboard)
.SetMethod("setMainFrameIsFirstResponder",
&TestRunnerBindings::NotImplemented)
.SetMethod("setMockScreenOrientation",
&TestRunnerBindings::SetMockScreenOrientation)
.SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
.SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
.SetMethod("setPermission", &TestRunnerBindings::SetPermission)
.SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
.SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
.SetMethod("setPointerLockWillFailSynchronously",
&TestRunnerBindings::SetPointerLockWillFailSynchronously)
.SetMethod("setPointerLockWillRespondAsynchronously",
&TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
.SetMethod("setPopupBlockingEnabled",
&TestRunnerBindings::SetPopupBlockingEnabled)
.SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
.SetMethod("setPrintingForFrame",
&TestRunnerBindings::SetPrintingForFrame)
.SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
.SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
.SetMethod("setShouldGeneratePixelResults",
&TestRunnerBindings::SetShouldGeneratePixelResults)
.SetMethod(
"setShouldStayOnPageAfterHandlingBeforeUnload",
&TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload)
.SetMethod("setSpellCheckResolvedCallback",
&TestRunnerBindings::SetSpellCheckResolvedCallback)
.SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
.SetMethod("setTabKeyCyclesThroughElements",
&TestRunnerBindings::SetTabKeyCyclesThroughElements)
.SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
.SetMethod("setTextSubpixelPositioning",
&TestRunnerBindings::SetTextSubpixelPositioning)
.SetMethod("setUseDashboardCompatibilityMode",
&TestRunnerBindings::NotImplemented)
.SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
.SetMethod("setViewSourceForFrame",
&TestRunnerBindings::SetViewSourceForFrame)
.SetMethod("setWillSendRequestClearHeader",
&TestRunnerBindings::SetWillSendRequestClearHeader)
.SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
.SetMethod("setXSSAuditorEnabled",
&TestRunnerBindings::SetXSSAuditorEnabled)
.SetMethod("navigateSecondaryWindow",
&TestRunnerBindings::NavigateSecondaryWindow)
.SetMethod("inspectSecondaryWindow",
&TestRunnerBindings::InspectSecondaryWindow)
.SetMethod("simulateWebNotificationClick",
&TestRunnerBindings::SimulateWebNotificationClick)
.SetMethod("simulateWebNotificationClose",
&TestRunnerBindings::SimulateWebNotificationClose)
.SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
.SetMethod("useUnfortunateSynchronousResizeMode",
&TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
.SetMethod("waitForPolicyDelegate",
&TestRunnerBindings::WaitForPolicyDelegate)
.SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
.SetMethod("waitUntilExternalURLLoad",
&TestRunnerBindings::WaitUntilExternalURLLoad)
// webHistoryItemCount is used by tests in web_tests\http\tests\history
.SetProperty("webHistoryItemCount",
&TestRunnerBindings::WebHistoryItemCount)
.SetMethod("windowCount", &TestRunnerBindings::WindowCount);
}
void TestRunnerBindings::LogToStderr(const std::string& output) {
LOG(ERROR) << output;
}
void TestRunnerBindings::NotifyDone() {
if (runner_)
runner_->NotifyDone();
}
void TestRunnerBindings::WaitUntilDone() {
if (runner_)
runner_->WaitUntilDone();
}
void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
if (runner_)
runner_->QueueBackNavigation(how_far_back);
}
void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
if (runner_)
runner_->QueueForwardNavigation(how_far_forward);
}
void TestRunnerBindings::QueueReload() {
if (runner_)
runner_->QueueReload();
}
void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
if (runner_)
runner_->QueueLoadingScript(script);
}
void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
if (runner_)
runner_->QueueNonLoadingScript(script);
}
void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
if (runner_) {
std::string url;
std::string target;
args->GetNext(&url);
args->GetNext(&target);
runner_->QueueLoad(url, target);
}
}
void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
if (runner_)
runner_->SetCustomPolicyDelegate(args);
}
void TestRunnerBindings::WaitForPolicyDelegate() {
if (runner_)
runner_->WaitForPolicyDelegate();
}
int TestRunnerBindings::WindowCount() {
if (runner_)
return runner_->WindowCount();
return 0;
}
void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
gin::Arguments* args) {
if (!runner_)
return;
// In the original implementation, nothing happens if the argument is
// ommitted.
bool close_remaining_windows = false;
if (args->GetNext(&close_remaining_windows))
runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
}
void TestRunnerBindings::ResetTestHelperControllers() {
if (runner_)
runner_->ResetTestHelperControllers();
}
void TestRunnerBindings::SetTabKeyCyclesThroughElements(
bool tab_key_cycles_through_elements) {
if (view_runner_)
view_runner_->SetTabKeyCyclesThroughElements(
tab_key_cycles_through_elements);
}
void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
if (view_runner_)
view_runner_->ExecCommand(args);
}
bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
if (view_runner_)
return view_runner_->IsCommandEnabled(command);
return false;
}
void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
bool forbidden,
const std::string& scheme) {
if (view_runner_)
view_runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
}
void TestRunnerBindings::SetDumpConsoleMessages(bool enabled) {
if (runner_)
runner_->SetDumpConsoleMessages(enabled);
}
void TestRunnerBindings::SetDumpJavaScriptDialogs(bool enabled) {
if (runner_)
runner_->SetDumpJavaScriptDialogs(enabled);
}
void TestRunnerBindings::SetEffectiveConnectionType(
const std::string& connection_type) {
blink::WebEffectiveConnectionType web_type =
blink::WebEffectiveConnectionType::kTypeUnknown;
if (connection_type == "TypeUnknown")
web_type = blink::WebEffectiveConnectionType::kTypeUnknown;
else if (connection_type == "TypeOffline")
web_type = blink::WebEffectiveConnectionType::kTypeOffline;
else if (connection_type == "TypeSlow2G")
web_type = blink::WebEffectiveConnectionType::kTypeSlow2G;
else if (connection_type == "Type2G")
web_type = blink::WebEffectiveConnectionType::kType2G;
else if (connection_type == "Type3G")
web_type = blink::WebEffectiveConnectionType::kType3G;
else if (connection_type == "Type4G")
web_type = blink::WebEffectiveConnectionType::kType4G;
else
NOTREACHED();
if (runner_)
runner_->SetEffectiveConnectionType(web_type);
}
void TestRunnerBindings::SetMockSpellCheckerEnabled(bool enabled) {
if (runner_)
runner_->SetMockSpellCheckerEnabled(enabled);
}
void TestRunnerBindings::SetSpellCheckResolvedCallback(
v8::Local<v8::Function> callback) {
if (runner_)
runner_->spellcheck_->SetSpellCheckResolvedCallback(callback);
}
void TestRunnerBindings::RemoveSpellCheckResolvedCallback() {
if (runner_)
runner_->spellcheck_->RemoveSpellCheckResolvedCallback();
}
v8::Local<v8::Value>
TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
int world_id,
const std::string& script) {
if (!view_runner_ || world_id <= 0 || world_id >= (1 << 29))
return v8::Local<v8::Value>();
return view_runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
script);
}
void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
int world_id,
const std::string& script) {
if (view_runner_ && world_id > 0 && world_id < (1 << 29))
view_runner_->EvaluateScriptInIsolatedWorld(world_id, script);
}
void TestRunnerBindings::SetIsolatedWorldInfo(
int world_id,
v8::Local<v8::Value> security_origin,
v8::Local<v8::Value> content_security_policy) {
if (view_runner_) {
view_runner_->SetIsolatedWorldInfo(world_id, security_origin,
content_security_policy);
}
}
void TestRunnerBindings::AddOriginAccessAllowListEntry(
const std::string& source_origin,
const std::string& destination_protocol,
const std::string& destination_host,
bool allow_destination_subdomains) {
if (runner_) {
// Non-standard schemes should be added to the scheme registeries to use
// for the origin access whitelisting.
GURL url(source_origin);
DCHECK(url.is_valid());
DCHECK(url.has_scheme());
DCHECK(url.has_host());
runner_->AddOriginAccessAllowListEntry(source_origin, destination_protocol,
destination_host,
allow_destination_subdomains);
}
}
bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
if (view_runner_)
return view_runner_->HasCustomPageSizeStyle(page_index);
return false;
}
void TestRunnerBindings::ForceRedSelectionColors() {
if (view_runner_)
view_runner_->ForceRedSelectionColors();
}
void TestRunnerBindings::InsertStyleSheet(const std::string& source_code) {
if (runner_)
runner_->InsertStyleSheet(source_code);
}
bool TestRunnerBindings::FindString(
const std::string& search_text,
const std::vector<std::string>& options_array) {
if (view_runner_)
return view_runner_->FindString(search_text, options_array);
return false;
}
std::string TestRunnerBindings::SelectionAsMarkup() {
if (view_runner_)
return view_runner_->SelectionAsMarkup();
return std::string();
}
void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
if (runner_)
runner_->SetTextSubpixelPositioning(value);
}
void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
if (view_runner_)
view_runner_->SetPageVisibility(new_visibility);
}
void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
if (view_runner_)
view_runner_->SetTextDirection(direction_name);
}
void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
if (runner_)
runner_->UseUnfortunateSynchronousResizeMode();
}
bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
int min_height,
int max_width,
int max_height) {
if (runner_) {
return runner_->EnableAutoResizeMode(min_width, min_height, max_width,
max_height);
}
return false;
}
bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
if (runner_)
return runner_->DisableAutoResizeMode(new_width, new_height);
return false;
}
void TestRunnerBindings::SetMockScreenOrientation(
const std::string& orientation) {
if (!runner_)
return;
runner_->SetMockScreenOrientation(orientation);
}
void TestRunnerBindings::DisableMockScreenOrientation() {
if (runner_)
runner_->DisableMockScreenOrientation();
}
void TestRunnerBindings::SetDisallowedSubresourcePathSuffixes(
const std::vector<std::string>& suffixes,
bool block_subresources) {
if (runner_)
runner_->SetDisallowedSubresourcePathSuffixes(suffixes, block_subresources);
}
void TestRunnerBindings::DidAcquirePointerLock() {
if (view_runner_)
view_runner_->DidAcquirePointerLock();
}
void TestRunnerBindings::DidNotAcquirePointerLock() {
if (view_runner_)
view_runner_->DidNotAcquirePointerLock();
}
void TestRunnerBindings::DidLosePointerLock() {
if (view_runner_)
view_runner_->DidLosePointerLock();
}
void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
if (view_runner_)
view_runner_->SetPointerLockWillFailSynchronously();
}
void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
if (view_runner_)
view_runner_->SetPointerLockWillRespondAsynchronously();
}
void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
if (runner_)
runner_->SetPopupBlockingEnabled(block_popups);
}
void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
if (runner_)
runner_->SetJavaScriptCanAccessClipboard(can_access);
}
void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
if (runner_)
runner_->SetXSSAuditorEnabled(enabled);
}
void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
if (runner_)
runner_->SetAllowUniversalAccessFromFileURLs(allow);
}
void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
if (runner_)
runner_->SetAllowFileAccessFromFileURLs(allow);
}
void TestRunnerBindings::OverridePreference(gin::Arguments* args) {
if (runner_)
runner_->OverridePreference(args);
}
void TestRunnerBindings::SetAcceptLanguages(
const std::string& accept_languages) {
if (!runner_)
return;
runner_->SetAcceptLanguages(accept_languages);
}
void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
if (runner_)
runner_->SetPluginsEnabled(enabled);
}
void TestRunnerBindings::DumpEditingCallbacks() {
if (runner_)
runner_->DumpEditingCallbacks();
}
void TestRunnerBindings::DumpAsMarkup() {
if (runner_)
runner_->DumpAsMarkup();
}
void TestRunnerBindings::DumpAsText() {
if (runner_)
runner_->DumpAsText();
}
void TestRunnerBindings::DumpAsTextWithPixelResults() {
if (runner_)