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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webshare/resources/mock-share-service.js
diff --git a/third_party/WebKit/LayoutTests/webshare/resources/mock-share-service.js b/third_party/WebKit/LayoutTests/webshare/resources/mock-share-service.js
new file mode 100644
index 0000000000000000000000000000000000000000..0e4165568fb04490bad07e499fba0af7f9582113
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webshare/resources/mock-share-service.js
@@ -0,0 +1,66 @@
+'use strict';
+
+let mockShareService = loadMojoModules(
+ 'mockShareService',
+ ['mojo/public/js/router',
+ 'third_party/WebKit/public/platform/modules/webshare/webshare.mojom',
+ ]).then(mojo => {
+ let [router, webshare] = mojo.modules;
+
+ class MockShareService extends webshare.ShareService.stubClass {
+ constructor(serviceRegistry) {
+ super();
+ serviceRegistry.addServiceOverrideForTesting(
+ webshare.ShareService.name,
+ handle => this.connect_(handle));
+ }
+
+ // Returns a Promise that gets rejected if the test should fail.
+ init_() {
+ // sequence of [expectedTitle, expectedText, result].
+ this.shareResultQueue_ = [];
+
+ return new Promise((resolve, reject) => {this.reject_ = reject});
+ }
+
+ connect_(handle) {
+ this.router_ = new router.Router(handle);
+ this.router_.setIncomingReceiver(this);
+ }
+
+ share(title, text) {
+ let callback = null;
+ let result = new Promise(resolve => {callback = resolve;});
+
+ if (!this.shareResultQueue_.length) {
+ this.reject_('Unexpected call to mojo share method');
+ return result;
+ }
+
+ let expectedTitle, expectedText, error;
+ [expectedTitle, expectedText, error] = this.shareResultQueue_.shift();
+ try {
+ assert_equals(title, expectedTitle);
+ assert_equals(text, expectedText);
+ } catch (e) {
+ this.reject_(e);
+ return result;
+ }
+ callback({error: error});
+
+ return result;
+ }
+
+ pushShareResult(expectedTitle, expectedText, result) {
+ this.shareResultQueue_.push([expectedTitle, expectedText, result]);
+ }
+ }
+ return new MockShareService(mojo.frameServiceRegistry);
+});
+
+function share_test(func, name, properties) {
+ promise_test(t => mockShareService.then(mock => {
+ let mockPromise = mock.init_();
+ return Promise.race([func(t, mock), mockPromise]);
+ }), name, properties);
+}

Powered by Google App Engine
This is Rietveld 408576698