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

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

Issue 2671683002: getInstalledRelatedApps: Add browser-side Mojo service (stub). (Closed)
Patch Set: Respond to comments + increase test coverage. Created 3 years, 9 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
1 'use strict'; 1 'use strict';
2 2
3 function assert_relatedapplication_equals(actual, expected, description) { 3 function assert_relatedapplication_equals(actual, expected, description) {
4 assert_equals(actual.platform, expected.platform, description); 4 assert_equals(actual.platform, expected.platform, description);
5 assert_equals(actual.url, expected.url, description); 5 assert_equals(actual.url, expected.url, description);
6 assert_equals(actual.id, expected.id, description); 6 assert_equals(actual.id, expected.id, description);
7 } 7 }
8 8
9 function assert_array_relatedapplication_equals( 9 function assert_array_relatedapplication_equals(
10 actual, expected, description) { 10 actual, expected, description) {
11 assert_equals(actual.length, expected.length, description); 11 assert_equals(actual.length, expected.length, description);
12 12
13 for (let i = 0; i < actual.length; i++) 13 for (let i = 0; i < actual.length; i++)
14 assert_relatedapplication_equals(actual[i], expected[i], description); 14 assert_relatedapplication_equals(actual[i], expected[i], description);
15 } 15 }
16
17 let mockInstalledAppProvider = loadMojoModules(
18 'mockInstalledAppProvider',
19 ['mojo/public/js/bindings',
20 'third_party/WebKit/public/platform/modules/installedapp/installed_app_prov ider.mojom',
21 ]).then(mojo => {
22 let [bindings, installed_app_provider] = mojo.modules;
23
24 class MockInstalledAppProvider {
25 constructor(interfaceProvider) {
26 this.bindingSet_ =
27 new bindings.BindingSet(installed_app_provider.InstalledAppProvider);
28
29 interfaceProvider.addInterfaceOverrideForTesting(
30 installed_app_provider.InstalledAppProvider.name,
31 handle => this.bindingSet_.addBinding(this, handle));
32 }
33
34 // Returns a Promise that gets rejected if the test should fail.
35 init_() {
36 // sequence of [expectedRelatedApps, installedApps].
37 this.callQueue_ = [];
38
39 return new Promise((resolve, reject) => {this.reject_ = reject});
40 }
41
42 filterInstalledApps(relatedApps) {
43 let callback = null;
44 let result = new Promise(resolve => {callback = resolve;});
45
46 if (!this.callQueue_.length) {
47 this.reject_('Unexpected call to mojo FilterInstalledApps method');
48 return result;
49 }
50
51 let [expectedRelatedApps, installedApps] = this.callQueue_.shift();
52 try {
53 assert_array_relatedapplication_equals(
54 relatedApps, expectedRelatedApps);
55 } catch (e) {
56 this.reject_(e);
57 return result;
58 }
59 callback({installedApps: installedApps});
60
61 return result;
62 }
63
64 pushExpectedCall(expectedRelatedApps, installedApps) {
65 this.callQueue_.push([expectedRelatedApps, installedApps]);
66 }
67 }
68 return new MockInstalledAppProvider(mojo.frameInterfaces);
69 });
70
71 // Creates a test case that uses a mock InstalledAppProvider.
72 // |func| is a function that takes (t, mock), where |mock| is a
73 // MockInstalledAppProvider that can have expectations set with
74 // pushExpectedCall. It should return a promise, the result of
75 // getInstalledRelatedApps().
76 // |name| and |properties| are standard testharness arguments.
77 function installedapp_test(func, name, properties) {
78 promise_test(t => mockInstalledAppProvider.then(mock => {
79 let mockPromise = mock.init_();
80 return Promise.race([func(t, mock), mockPromise]);
81 }), name, properties);
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698