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

Unified Diff: third_party/WebKit/LayoutTests/ballista/resources/mock-ballista-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: Split test into four separate files. Created 4 years, 8 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/ballista/resources/mock-ballista-service.js
diff --git a/third_party/WebKit/LayoutTests/ballista/resources/mock-ballista-service.js b/third_party/WebKit/LayoutTests/ballista/resources/mock-ballista-service.js
new file mode 100644
index 0000000000000000000000000000000000000000..d926abebfa55a10086e3c9535ed31912e392e7c5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/ballista/resources/mock-ballista-service.js
@@ -0,0 +1,77 @@
+'use strict';
+
+// Globals for use with expectations.
+var title;
+var text;
+var expectTitle;
Sam McNally 2016/04/13 04:32:35 expectedTitle
Matt Giuca 2016/04/13 05:43:01 Done.
+var expectText;
Sam McNally 2016/04/13 04:32:35 expectedText
Matt Giuca 2016/04/13 05:43:01 Done.
+
+let mockBallistaService = loadMojoModules(
+ 'mockBallistaService',
+ ['third_party/WebKit/public/platform/modules/ballista/ballista.mojom',
Sam McNally 2016/04/13 04:32:35 Sort these.
Matt Giuca 2016/04/13 05:43:01 Done.
+ 'mojo/public/js/router',
+ ]).then(mojo => {
+ let [ballista, router] = mojo.modules;
+
+ class MockBallistaService extends ballista.BallistaService.stubClass {
+ constructor(serviceRegistry) {
+ super();
+ serviceRegistry.addServiceOverrideForTesting(
+ ballista.BallistaService.name,
+ handle => this.connect_(handle));
+
+ // sequence of [title, text, callback].
+ this.pendingRequests_ = [];
+ // sequence of [expectTitle, expectText, result].
+ this.shareResultQueue_ = [];
+ }
+
+ connect_(handle) {
+ this.router_ = new router.Router(handle);
+ this.router_.setIncomingReceiver(this);
+ }
+
+ share(title, text) {
+ let result = new Promise(resolve => this.pendingRequests_.push([title, text, resolve]));
Sam McNally 2016/04/13 04:32:35 Wrap to 80 chars.
Matt Giuca 2016/04/13 05:43:01 Done.
+ this.runCallbacks_();
+ return result;
+ }
+
+ pushShareResult(expectTitle, expectText, result) {
+ this.shareResultQueue_.push([expectTitle, expectText, result]);
+ this.runCallbacks_();
+ }
+
+ runCallbacks_() {
+ while (this.pendingRequests_.length && this.shareResultQueue_.length) {
+ let callback, result;
+ [title, text, callback] = this.pendingRequests_.shift();
+ [expectTitle, expectText, result] = this.shareResultQueue_.shift();
+ shouldBe('title', 'expectTitle');
+ shouldBe('text', 'expectText');
+ callback({error: result});
+ }
+ }
+ }
+ return new MockBallistaService(mojo.frameServiceRegistry);
+});
+
+// Pushes a result onto the queue. Results will be returned from the Mojo
+// service in the order they were pushed.
+function pushMockBallistaServiceResult(expectTitle, expectText, shareResult) {
+ mockBallistaService.then(mock => mock.pushShareResult(expectTitle, expectText, shareResult));
+}
+
+// Callbacks for use in the HTML files.
+
+function shareSuccess() {
+ debug('share completed successfully');
Sam McNally 2016/04/13 04:32:35 Be consistent with indentation.
Matt Giuca 2016/04/13 05:43:01 Done.
+ setTimeout(finishJSTest, 0);
+}
+
+function shareFailure(error) {
+ debug('share failed: ' + error);
+ setTimeout(finishJSTest, 0);
+}
+
+var mockBallistaServiceReady = mockBallistaService.then();

Powered by Google App Engine
This is Rietveld 408576698