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

Unified Diff: third_party/WebKit/LayoutTests/installedapp/resources/installedapp-test-helper.js

Issue 2671683002: getInstalledRelatedApps: Add browser-side Mojo service (stub). (Closed)
Patch Set: Added self to OWNERS. Created 3 years, 10 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/installedapp/resources/installedapp-test-helper.js
diff --git a/third_party/WebKit/LayoutTests/installedapp/resources/installedapp-test-helper.js b/third_party/WebKit/LayoutTests/installedapp/resources/installedapp-test-helper.js
index 980831d6f11fbed82ac67fd4e67c1a53681499fe..0bf572becfad030fb7fe41b837d018e5625e619d 100644
--- a/third_party/WebKit/LayoutTests/installedapp/resources/installedapp-test-helper.js
+++ b/third_party/WebKit/LayoutTests/installedapp/resources/installedapp-test-helper.js
@@ -13,3 +13,73 @@ function assert_array_relatedapplication_equals(
for (let i = 0; i < actual.length; i++)
assert_relatedapplication_equals(actual[i], expected[i], description);
}
+
+let mockInstalledAppProvider = loadMojoModules(
+ 'mockInstalledAppProvider',
+ ['mojo/public/js/bindings',
+ 'third_party/WebKit/public/platform/modules/installedapp/installed_app_provider.mojom',
+ ]).then(mojo => {
+ let [bindings, installed_app_provider] = mojo.modules;
+
+ class MockInstalledAppProvider {
+ constructor(interfaceProvider) {
+ this.bindingSet_ =
+ new bindings.BindingSet(installed_app_provider.InstalledAppProvider);
+
+ interfaceProvider.addInterfaceOverrideForTesting(
+ installed_app_provider.InstalledAppProvider.name,
+ handle => this.bindingSet_.addBinding(this, handle));
+ }
+
+ // Returns a Promise that gets rejected if the test should fail.
+ init_() {
+ // sequence of [expectedRelatedApps, expectedOrigin, installedApps].
+ this.callQueue_ = [];
+
+ return new Promise((resolve, reject) => {this.reject_ = reject});
+ }
+
+ filterInstalledApps(relatedApps, origin) {
+ let callback = null;
+ let result = new Promise(resolve => {callback = resolve;});
+
+ if (!this.callQueue_.length) {
+ this.reject_('Unexpected call to mojo FilterInstalledApps method');
+ return result;
+ }
+
+ let [expectedRelatedApps, expectedOrigin, installedApps] =
+ this.callQueue_.shift();
+ try {
+ assert_array_relatedapplication_equals(
+ relatedApps, expectedRelatedApps);
+ assert_equals(origin, expectedOrigin);
+ } catch (e) {
+ this.reject_(e);
+ return result;
+ }
+ callback({installedApps: installedApps});
+
+ return result;
+ }
+
+ pushExpectedCall(expectedRelatedApps, expectedOrigin, installedApps) {
+ this.callQueue_.push(
+ [expectedRelatedApps, expectedOrigin, installedApps]);
+ }
+ }
+ return new MockInstalledAppProvider(mojo.frameInterfaces);
+});
+
+// Creates a test case that uses a mock InstalledAppProvider.
+// |func| is a function that takes (t, mock), where |mock| is a
+// MockInstalledAppProvider that can have expectations set with
+// pushExpectedCall. It should return a promise, the result of
+// getInstalledRelatedApps().
+// |name| and |properties| are standard testharness arguments.
+function installedapp_test(func, name, properties) {
+ promise_test(t => mockInstalledAppProvider.then(mock => {
+ let mockPromise = mock.init_();
+ return Promise.race([func(t, mock), mockPromise]);
+ }), name, properties);
+}

Powered by Google App Engine
This is Rietveld 408576698