Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(696)

Side by Side Diff: third_party/WebKit/LayoutTests/webshare/resources/mock-share-service.js

Issue 1806253002: Added Web Share (navigator.share) experimental web API (stub). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add argument names. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 'use strict';
2
3 let mockShareService = loadMojoModules(
4 'mockShareService',
5 ['mojo/public/js/router',
6 'third_party/WebKit/public/platform/modules/webshare/webshare.mojom',
7 ]).then(mojo => {
8 let [router, webshare] = mojo.modules;
9
10 class MockShareService extends webshare.ShareService.stubClass {
11 constructor(serviceRegistry) {
12 super();
13 serviceRegistry.addServiceOverrideForTesting(
14 webshare.ShareService.name,
15 handle => this.connect_(handle));
16 }
17
18 // Returns a Promise that gets rejected if the test should fail.
19 init_() {
20 // sequence of [expectedTitle, expectedText, result].
21 this.shareResultQueue_ = [];
22
23 return new Promise((resolve, reject) => {this.reject_ = reject});
24 }
25
26 connect_(handle) {
27 this.router_ = new router.Router(handle);
28 this.router_.setIncomingReceiver(this);
29 }
30
31 share(title, text) {
32 let callback = null;
33 let result = new Promise(resolve => {callback = resolve;});
34
35 if (!this.shareResultQueue_.length) {
36 this.reject_('Unexpected call to mojo share method');
37 return result;
38 }
39
40 let expectedTitle, expectedText, error;
41 [expectedTitle, expectedText, error] = this.shareResultQueue_.shift();
42 try {
43 assert_equals(title, expectedTitle);
44 assert_equals(text, expectedText);
45 } catch (e) {
46 this.reject_(e);
47 return result;
48 }
49 callback({error: error});
50
51 return result;
52 }
53
54 pushShareResult(expectedTitle, expectedText, result) {
55 this.shareResultQueue_.push([expectedTitle, expectedText, result]);
56 }
57 }
58 return new MockShareService(mojo.frameServiceRegistry);
59 });
60
61 function share_test(func, name, properties) {
62 promise_test(t => mockShareService.then(mock => {
63 let mockPromise = mock.init_();
64 return Promise.race([func(t, mock), mockPromise]);
65 }), name, properties);
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698