Commit 68643364 authored by Ken Rockot's avatar Ken Rockot Committed by Chromium LUCI CQ

Migrate webshare internal WPT to Mojo JS modules

Bug: 1004256
Change-Id: Iabfb2720513f11d539b51458e87a323e95f4b513
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640932Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#846015}
parent 8b67fb47
...@@ -997,12 +997,15 @@ class Generator(generator.Generator): ...@@ -997,12 +997,15 @@ class Generator(generator.Generator):
# - Enums: NamespaceUid.Enum.CONSTANT_NAME # - Enums: NamespaceUid.Enum.CONSTANT_NAME
# - Struct: NamespaceUid.Struct_CONSTANT_NAME # - Struct: NamespaceUid.Struct_CONSTANT_NAME
name_prefix = [] namespace_components = []
qualified = (not for_module) or (token.module is not self.module) qualified = (not for_module) or (token.module is not self.module)
if token.module and qualified: if token.module and qualified:
name_prefix.append(token.module.namespace) namespace_components.append(token.module.namespace)
if token.parent_kind: if token.parent_kind:
name_prefix.append(token.parent_kind.name) namespace_components.append(token.parent_kind.name)
name_prefix = '.'.join(namespace_components)
if for_module:
name_prefix = name_prefix.replace('.', '_')
name = [] name = []
if isinstance(token, mojom.EnumValue): if isinstance(token, mojom.EnumValue):
...@@ -1014,7 +1017,7 @@ class Generator(generator.Generator): ...@@ -1014,7 +1017,7 @@ class Generator(generator.Generator):
separator = "_" separator = "_"
if len(name_prefix) > 0: if len(name_prefix) > 0:
return ".".join(name_prefix) + separator + ".".join(name) return name_prefix + separator + ".".join(name)
return ".".join(name) return ".".join(name)
......
'use strict'; import {ShareService, ShareServiceReceiver} from '/gen/third_party/blink/public/mojom/webshare/webshare.mojom.m.js';
class MockShareService { class MockShareService {
constructor(interfaceProvider) { constructor() {
this.bindingSet_ = new mojo.BindingSet(blink.mojom.ShareService); this.receiver_ = new ShareServiceReceiver(this);
this.interceptor_ = this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.ShareService.name); new MojoInterfaceInterceptor(ShareService.$interfaceName);
this.interceptor_.oninterfacerequest = this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle); e => this.receiver_.$.bindHandle(e.handle);
this.interceptor_.start(); this.interceptor_.start();
} }
...@@ -50,7 +50,7 @@ class MockShareService { ...@@ -50,7 +50,7 @@ class MockShareService {
let mockShareService = new MockShareService(); let mockShareService = new MockShareService();
function share_test(func, name, properties) { export function share_test(func, name, properties) {
promise_test(() => { promise_test(() => {
let mockPromise = mockShareService.init_(); let mockPromise = mockShareService.init_();
return Promise.race([func(mockShareService), mockPromise]); return Promise.race([func(mockShareService), mockPromise]);
...@@ -58,7 +58,7 @@ function share_test(func, name, properties) { ...@@ -58,7 +58,7 @@ function share_test(func, name, properties) {
} }
// Copied from resources/bluetooth/bluetooth-helpers.js. // Copied from resources/bluetooth/bluetooth-helpers.js.
function callWithKeyDown(functionCalledOnKeyPress) { export function callWithKeyDown(functionCalledOnKeyPress) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
function onKeyPress() { function onKeyPress() {
document.removeEventListener('keypress', onKeyPress, false); document.removeEventListener('keypress', onKeyPress, false);
......
<!DOCTYPE html> <!DOCTYPE html>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script> import {callWithKeyDown, share_test} from './resources/share-test.js';
<script src="resources/mock-share-service.js"></script> import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
<script>
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'data:the url', mock.pushShareResult('the title', 'the message', 'data:the url',
blink.mojom.ShareError.OK); ShareError.OK);
return callWithKeyDown(() => { return callWithKeyDown(() => {
navigator.share({ navigator.share({
title: 'the title', title: 'the title',
...@@ -20,7 +19,7 @@ share_test(mock => { ...@@ -20,7 +19,7 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'data:the url', mock.pushShareResult('the title', 'the message', 'data:the url',
blink.mojom.ShareError.OK); ShareError.OK);
return callWithKeyDown(() => { return callWithKeyDown(() => {
navigator.share({ navigator.share({
title: 'the title', title: 'the title',
......
<!DOCTYPE html> <!DOCTYPE html>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script> import {callWithKeyDown, share_test} from './resources/share-test.js';
<script src="resources/mock-share-service.js"></script> import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
<script>
async function assertRejectsWithError(promise, name) { async function assertRejectsWithError(promise, name) {
try { try {
...@@ -17,7 +16,7 @@ async function assertRejectsWithError(promise, name) { ...@@ -17,7 +16,7 @@ async function assertRejectsWithError(promise, name) {
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/', mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED); ShareError.CANCELED);
return callWithKeyDown(() => assertRejectsWithError( return callWithKeyDown(() => assertRejectsWithError(
navigator.share({ navigator.share({
title: 'the title', title: 'the title',
...@@ -29,7 +28,7 @@ share_test(mock => { ...@@ -29,7 +28,7 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/', mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.INTERNAL_ERROR); ShareError.INTERNAL_ERROR);
return callWithKeyDown(() => assertRejectsWithError( return callWithKeyDown(() => assertRejectsWithError(
navigator.share({ navigator.share({
title: 'the title', title: 'the title',
...@@ -65,7 +64,7 @@ share_test(mock => { ...@@ -65,7 +64,7 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/', mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED); ShareError.CANCELED);
return callWithKeyDown(async () => { return callWithKeyDown(async () => {
const data = { const data = {
title: 'the title', title: 'the title',
...@@ -88,7 +87,7 @@ share_test(mock => { ...@@ -88,7 +87,7 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/', mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED); ShareError.CANCELED);
return callWithKeyDown(async () => { return callWithKeyDown(async () => {
const content = ['Hello']; const content = ['Hello'];
const name = 'hello.txt'; const name = 'hello.txt';
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
<meta charset="windows-1252"> <meta charset="windows-1252">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script> import {callWithKeyDown, share_test} from './resources/share-test.js';
<script src="resources/mock-share-service.js"></script> import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
<script>
// Exact same test as in share-success.html, with same expectations. This tests // Exact same test as in share-success.html, with same expectations. This tests
// that the page's encoding (Windows-1252) is ignored and Unicode characters are // that the page's encoding (Windows-1252) is ignored and Unicode characters are
...@@ -16,7 +15,7 @@ share_test(mock => { ...@@ -16,7 +15,7 @@ share_test(mock => {
const title = 'f\xe1ncy \u5199\u4f5c \ud83d\ude31'; const title = 'f\xe1ncy \u5199\u4f5c \ud83d\ude31';
const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4'; const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4';
const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84'; const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84';
mock.pushShareResult(title, '\ufffdx', url_ascii, blink.mojom.ShareError.OK); mock.pushShareResult(title, '\ufffdx', url_ascii, ShareError.OK);
return callWithKeyDown(() => navigator.share( return callWithKeyDown(() => navigator.share(
{title: title, text: '\ud9a3x', url: url})); {title: title, text: '\ud9a3x', url: url}));
}, 'successful share with Unicode characters'); }, 'successful share with Unicode characters');
......
<!DOCTYPE html> <!DOCTYPE html>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script> import {callWithKeyDown, share_test} from './resources/share-test.js';
<script src="resources/mock-share-service.js"></script> import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
<script>
function getAbsoluteUrl(url) { function getAbsoluteUrl(url) {
return new URL(url, document.baseURI).toString(); return new URL(url, document.baseURI).toString();
...@@ -13,7 +12,7 @@ function getAbsoluteUrl(url) { ...@@ -13,7 +12,7 @@ function getAbsoluteUrl(url) {
share_test(mock => { share_test(mock => {
const url = 'https://www.example.com/some/path?some_query#some_fragment'; const url = 'https://www.example.com/some/path?some_query#some_fragment';
mock.pushShareResult('the title', 'the message', getAbsoluteUrl(url), mock.pushShareResult('the title', 'the message', getAbsoluteUrl(url),
blink.mojom.ShareError.OK); ShareError.OK);
return callWithKeyDown(() => navigator.share( return callWithKeyDown(() => navigator.share(
{title: 'the title', text: 'the message', url: url})).then( {title: 'the title', text: 'the message', url: url})).then(
result => assert_equals(result, undefined)); result => assert_equals(result, undefined));
...@@ -21,25 +20,25 @@ share_test(mock => { ...@@ -21,25 +20,25 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
const url = '//www.example.com/some/path?some_query#some_fragment'; const url = '//www.example.com/some/path?some_query#some_fragment';
mock.pushShareResult('', '', getAbsoluteUrl(url), blink.mojom.ShareError.OK); mock.pushShareResult('', '', getAbsoluteUrl(url), ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with URL without a scheme'); }, 'successful share with URL without a scheme');
share_test(mock => { share_test(mock => {
const url = '/some/path?some_query#some_fragment'; const url = '/some/path?some_query#some_fragment';
mock.pushShareResult('', '', getAbsoluteUrl(url), blink.mojom.ShareError.OK); mock.pushShareResult('', '', getAbsoluteUrl(url), ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a path-only URL'); }, 'successful share with a path-only URL');
share_test(mock => { share_test(mock => {
const url = 'foo'; const url = 'foo';
mock.pushShareResult('', '', getAbsoluteUrl(url), blink.mojom.ShareError.OK); mock.pushShareResult('', '', getAbsoluteUrl(url), ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a relative URL'); }, 'successful share with a relative URL');
share_test(mock => { share_test(mock => {
const url = ''; const url = '';
mock.pushShareResult('', '', document.baseURI, blink.mojom.ShareError.OK); mock.pushShareResult('', '', document.baseURI, ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with an empty URL'); }, 'successful share with an empty URL');
...@@ -48,7 +47,7 @@ share_test(mock => { ...@@ -48,7 +47,7 @@ share_test(mock => {
// Expect '\' to normalize to '/', "%63" to normalize to 'c', '\r\n\t' // Expect '\' to normalize to '/', "%63" to normalize to 'c', '\r\n\t'
// to be removed, and all the other illegal characters to be percent-escaped. // to be removed, and all the other illegal characters to be percent-escaped.
const url_encoded = 'http://example.com/foo/abc%20%22%3C%3E%60%7B%7D'; const url_encoded = 'http://example.com/foo/abc%20%22%3C%3E%60%7B%7D';
mock.pushShareResult('', '', url_encoded, blink.mojom.ShareError.OK); mock.pushShareResult('', '', url_encoded, ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with percent-encoded URL characters'); }, 'successful share with percent-encoded URL characters');
...@@ -60,7 +59,7 @@ share_test(mock => { ...@@ -60,7 +59,7 @@ share_test(mock => {
const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4'; const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4';
// Host is IDNA-encoded. Path is percent-encoded. // Host is IDNA-encoded. Path is percent-encoded.
const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84'; const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84';
mock.pushShareResult(title, '\ufffdx', url_ascii, blink.mojom.ShareError.OK); mock.pushShareResult(title, '\ufffdx', url_ascii, ShareError.OK);
return callWithKeyDown(() => navigator.share( return callWithKeyDown(() => navigator.share(
{title: title, text: '\ud9a3x', url: url})); {title: title, text: '\ud9a3x', url: url}));
}, 'successful share with Unicode characters'); }, 'successful share with Unicode characters');
......
<!DOCTYPE html> <!DOCTYPE html>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script> import {callWithKeyDown, share_test} from './resources/share-test.js';
<script src="resources/mock-share-service.js"></script> import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
<script>
function getAbsoluteUrl(url) { function getAbsoluteUrl(url) {
return new URL(url, document.baseURI).toString(); return new URL(url, document.baseURI).toString();
...@@ -12,7 +11,7 @@ function getAbsoluteUrl(url) { ...@@ -12,7 +11,7 @@ function getAbsoluteUrl(url) {
share_test(mock => { share_test(mock => {
mock.pushShareResult('true', 'the object', 'http://example.com/', mock.pushShareResult('true', 'the object', 'http://example.com/',
blink.mojom.ShareError.OK); ShareError.OK);
const textWithToString = {toString() { return 'the object'; }}; const textWithToString = {toString() { return 'the object'; }};
const urlWithToString = {toString() { return 'http://example.com/'; }}; const urlWithToString = {toString() { return 'http://example.com/'; }};
...@@ -23,8 +22,7 @@ share_test(mock => { ...@@ -23,8 +22,7 @@ share_test(mock => {
share_test(mock => { share_test(mock => {
// null fields should convert into the string 'null' (because the field is // null fields should convert into the string 'null' (because the field is
// not nullable, it just converts to a string like any other type). // not nullable, it just converts to a string like any other type).
mock.pushShareResult('null', '', '', mock.pushShareResult('null', '', '', ShareError.OK);
blink.mojom.ShareError.OK);
return callWithKeyDown(() => navigator.share( return callWithKeyDown(() => navigator.share(
{title: null, text: undefined})); {title: null, text: undefined}));
}, 'share of null/undefined dict values'); }, 'share of null/undefined dict values');
......
<!DOCTYPE html> <!DOCTYPE html>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="/gen/third_party/blink/public/mojom/webshare/webshare.mojom.js"></script>
<script src="resources/mock-share-service.js"></script>
<base href="https://www.example.com/some/path.html"> <base href="https://www.example.com/some/path.html">
<script> <script type="module">
import {callWithKeyDown, share_test} from 'https://{{host}}:{{ports[https][0]}}/wpt_internal/web-share/resources/share-test.js';
import {ShareError} from 'https://{{host}}:{{ports[https][0]}}/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
share_test(mock => { share_test(mock => {
const url = 'foo'; const url = 'foo';
mock.pushShareResult('', '', 'https://www.example.com/some/foo', mock.pushShareResult('', '', 'https://www.example.com/some/foo',
blink.mojom.ShareError.OK); ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url})); return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a URL relative to document base URL'); }, 'successful share with a URL relative to document base URL');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment