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):
# - Enums: NamespaceUid.Enum.CONSTANT_NAME
# - Struct: NamespaceUid.Struct_CONSTANT_NAME
name_prefix = []
namespace_components = []
qualified = (not for_module) or (token.module is not self.module)
if token.module and qualified:
name_prefix.append(token.module.namespace)
namespace_components.append(token.module.namespace)
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 = []
if isinstance(token, mojom.EnumValue):
......@@ -1014,7 +1017,7 @@ class Generator(generator.Generator):
separator = "_"
if len(name_prefix) > 0:
return ".".join(name_prefix) + separator + ".".join(name)
return name_prefix + separator + ".".join(name)
return ".".join(name)
......
'use strict';
import {ShareService, ShareServiceReceiver} from '/gen/third_party/blink/public/mojom/webshare/webshare.mojom.m.js';
class MockShareService {
constructor(interfaceProvider) {
this.bindingSet_ = new mojo.BindingSet(blink.mojom.ShareService);
constructor() {
this.receiver_ = new ShareServiceReceiver(this);
this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.ShareService.name);
new MojoInterfaceInterceptor(ShareService.$interfaceName);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
e => this.receiver_.$.bindHandle(e.handle);
this.interceptor_.start();
}
......@@ -50,7 +50,7 @@ class MockShareService {
let mockShareService = new MockShareService();
function share_test(func, name, properties) {
export function share_test(func, name, properties) {
promise_test(() => {
let mockPromise = mockShareService.init_();
return Promise.race([func(mockShareService), mockPromise]);
......@@ -58,7 +58,7 @@ function share_test(func, name, properties) {
}
// Copied from resources/bluetooth/bluetooth-helpers.js.
function callWithKeyDown(functionCalledOnKeyPress) {
export function callWithKeyDown(functionCalledOnKeyPress) {
return new Promise((resolve, reject) => {
function onKeyPress() {
document.removeEventListener('keypress', onKeyPress, false);
......
<!DOCTYPE html>
<script src="/resources/testharness.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>
<script>
<script type="module">
import {callWithKeyDown, share_test} from './resources/share-test.js';
import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'data:the url',
blink.mojom.ShareError.OK);
ShareError.OK);
return callWithKeyDown(() => {
navigator.share({
title: 'the title',
......@@ -20,7 +19,7 @@ share_test(mock => {
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'data:the url',
blink.mojom.ShareError.OK);
ShareError.OK);
return callWithKeyDown(() => {
navigator.share({
title: 'the title',
......
<!DOCTYPE html>
<script src="/resources/testharness.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>
<script>
<script type="module">
import {callWithKeyDown, share_test} from './resources/share-test.js';
import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
async function assertRejectsWithError(promise, name) {
try {
......@@ -17,7 +16,7 @@ async function assertRejectsWithError(promise, name) {
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED);
ShareError.CANCELED);
return callWithKeyDown(() => assertRejectsWithError(
navigator.share({
title: 'the title',
......@@ -29,7 +28,7 @@ share_test(mock => {
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.INTERNAL_ERROR);
ShareError.INTERNAL_ERROR);
return callWithKeyDown(() => assertRejectsWithError(
navigator.share({
title: 'the title',
......@@ -65,7 +64,7 @@ share_test(mock => {
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED);
ShareError.CANCELED);
return callWithKeyDown(async () => {
const data = {
title: 'the title',
......@@ -88,7 +87,7 @@ share_test(mock => {
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED);
ShareError.CANCELED);
return callWithKeyDown(async () => {
const content = ['Hello'];
const name = 'hello.txt';
......
......@@ -2,10 +2,9 @@
<meta charset="windows-1252">
<script src="/resources/testharness.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>
<script>
<script type="module">
import {callWithKeyDown, share_test} from './resources/share-test.js';
import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
// 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
......@@ -16,7 +15,7 @@ share_test(mock => {
const title = 'f\xe1ncy \u5199\u4f5c \ud83d\ude31';
const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4';
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(
{title: title, text: '\ud9a3x', url: url}));
}, 'successful share with Unicode characters');
......
<!DOCTYPE html>
<script src="/resources/testharness.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>
<script>
<script type="module">
import {callWithKeyDown, share_test} from './resources/share-test.js';
import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
function getAbsoluteUrl(url) {
return new URL(url, document.baseURI).toString();
......@@ -13,7 +12,7 @@ function getAbsoluteUrl(url) {
share_test(mock => {
const url = 'https://www.example.com/some/path?some_query#some_fragment';
mock.pushShareResult('the title', 'the message', getAbsoluteUrl(url),
blink.mojom.ShareError.OK);
ShareError.OK);
return callWithKeyDown(() => navigator.share(
{title: 'the title', text: 'the message', url: url})).then(
result => assert_equals(result, undefined));
......@@ -21,25 +20,25 @@ share_test(mock => {
share_test(mock => {
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}));
}, 'successful share with URL without a scheme');
share_test(mock => {
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}));
}, 'successful share with a path-only URL');
share_test(mock => {
const url = 'foo';
mock.pushShareResult('', '', getAbsoluteUrl(url), blink.mojom.ShareError.OK);
mock.pushShareResult('', '', getAbsoluteUrl(url), ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a relative URL');
share_test(mock => {
const url = '';
mock.pushShareResult('', '', document.baseURI, blink.mojom.ShareError.OK);
mock.pushShareResult('', '', document.baseURI, ShareError.OK);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with an empty URL');
......@@ -48,7 +47,7 @@ share_test(mock => {
// 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.
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}));
}, 'successful share with percent-encoded URL characters');
......@@ -60,7 +59,7 @@ share_test(mock => {
const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4';
// Host is IDNA-encoded. Path is percent-encoded.
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(
{title: title, text: '\ud9a3x', url: url}));
}, 'successful share with Unicode characters');
......
<!DOCTYPE html>
<script src="/resources/testharness.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>
<script>
<script type="module">
import {callWithKeyDown, share_test} from './resources/share-test.js';
import {ShareError} from '/gen/third_party/blink/public/mojom/webshare/share_error.mojom.m.js';
function getAbsoluteUrl(url) {
return new URL(url, document.baseURI).toString();
......@@ -12,7 +11,7 @@ function getAbsoluteUrl(url) {
share_test(mock => {
mock.pushShareResult('true', 'the object', 'http://example.com/',
blink.mojom.ShareError.OK);
ShareError.OK);
const textWithToString = {toString() { return 'the object'; }};
const urlWithToString = {toString() { return 'http://example.com/'; }};
......@@ -23,8 +22,7 @@ share_test(mock => {
share_test(mock => {
// null fields should convert into the string 'null' (because the field is
// not nullable, it just converts to a string like any other type).
mock.pushShareResult('null', '', '',
blink.mojom.ShareError.OK);
mock.pushShareResult('null', '', '', ShareError.OK);
return callWithKeyDown(() => navigator.share(
{title: null, text: undefined}));
}, 'share of null/undefined dict values');
......
<!DOCTYPE html>
<script src="/resources/testharness.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">
<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 => {
const url = 'foo';
mock.pushShareResult('', '', 'https://www.example.com/some/foo',
blink.mojom.ShareError.OK);
ShareError.OK);
return callWithKeyDown(() => navigator.share({url: 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