summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resources/chromium/mock-direct-sockets.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/resources/chromium/mock-direct-sockets.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/resources/chromium/mock-direct-sockets.js')
-rw-r--r--testing/web-platform/tests/resources/chromium/mock-direct-sockets.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/web-platform/tests/resources/chromium/mock-direct-sockets.js b/testing/web-platform/tests/resources/chromium/mock-direct-sockets.js
new file mode 100644
index 0000000000..caab177b98
--- /dev/null
+++ b/testing/web-platform/tests/resources/chromium/mock-direct-sockets.js
@@ -0,0 +1,75 @@
+'use strict';
+
+import {DirectSocketsService, DirectSocketsServiceReceiver} from '/gen/third_party/blink/public/mojom/direct_sockets/direct_sockets.mojom.m.js';
+
+self.DirectSocketsServiceTest = (() => {
+ // Class that mocks DirectSocketsService interface defined in
+ // https://source.chromium.org/chromium/chromium/src/third_party/blink/public/mojom/direct_sockets/direct_sockets.mojom
+ class MockDirectSocketsService {
+ constructor() {
+ this.interceptor_ = new MojoInterfaceInterceptor(DirectSocketsService.$interfaceName);
+ this.receiver_ = new DirectSocketsServiceReceiver(this);
+ this.interceptor_.oninterfacerequest = e =>
+ this.receiver_.$.bindHandle(e.handle);
+ this.interceptor_.start();
+ }
+
+ reset() {
+ this.receiver_.$.close();
+ this.interceptor_.stop();
+ }
+
+ openTcpSocket(
+ options,
+ receiver,
+ observer) {
+ return Promise.resolve({
+ // return result = net:Error::NOT_IMPLEMENTED (code -11)
+ result: -11
+ });
+ }
+
+ openUdpSocket(
+ options,
+ receiver,
+ listener) {
+ return Promise.resolve({
+ // return result = net:Error::NOT_IMPLEMENTED (code -11)
+ result: -11
+ });
+ }
+ }
+
+ let testInternal = {
+ initialized: false,
+ mockDirectSocketsService: null
+ }
+
+ class DirectSocketsServiceTestChromium {
+ constructor() {
+ Object.freeze(this); // Make it immutable.
+ }
+
+ initialize() {
+ if (!testInternal.initialized) {
+ testInternal = {
+ mockDirectSocketsService: new MockDirectSocketsService(),
+ initialized: true
+ };
+ }
+ }
+
+ async reset() {
+ if (testInternal.initialized) {
+ testInternal.mockDirectSocketsService.reset();
+ testInternal = {
+ mockDirectSocketsService: null,
+ initialized: false
+ };
+ await new Promise(resolve => setTimeout(resolve, 0));
+ }
+ }
+ }
+
+ return DirectSocketsServiceTestChromium;
+})();