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

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

Issue 2748023002: getInstalledRelatedApps: Change internal url fields to URL type. (Closed)
Patch Set: 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 // |url| can be a string (if comparing IDL RelatedApplications) or a
6 // url.mojom.Url (if comparing Mojo RelatedApplications). Either can be null.
7 assert_equals(actual.url === null, expected.url === null, description);
8 assert_equals(typeof(actual.url), typeof(expected.url), description);
9 if (typeof(actual.url) === 'object' && actual.url !== null) {
10 assert_equals(actual.url.url, expected.url.url, description);
11 } else {
12 assert_equals(actual.url, expected.url, description);
13 }
6 assert_equals(actual.id, expected.id, description); 14 assert_equals(actual.id, expected.id, description);
7 } 15 }
8 16
9 function assert_array_relatedapplication_equals( 17 function assert_array_relatedapplication_equals(
10 actual, expected, description) { 18 actual, expected, description) {
11 assert_equals(actual.length, expected.length, description); 19 assert_equals(actual.length, expected.length, description);
12 20
13 for (let i = 0; i < actual.length; i++) 21 for (let i = 0; i < actual.length; i++)
14 assert_relatedapplication_equals(actual[i], expected[i], description); 22 assert_relatedapplication_equals(actual[i], expected[i], description);
15 } 23 }
16 24
17 let mockInstalledAppProvider = loadMojoModules( 25 let mockInstalledAppProvider = loadMojoModules(
18 'mockInstalledAppProvider', 26 'mockInstalledAppProvider',
19 ['mojo/public/js/bindings', 27 ['mojo/public/js/bindings',
28 'url/mojo/url.mojom',
20 'third_party/WebKit/public/platform/modules/installedapp/installed_app_prov ider.mojom', 29 'third_party/WebKit/public/platform/modules/installedapp/installed_app_prov ider.mojom',
21 ]).then(mojo => { 30 ]).then(mojo => {
22 let [bindings, installedAppProvider] = mojo.modules; 31 let [bindings, urlModule, installedAppProvider] = mojo.modules;
23 32
24 class MockInstalledAppProvider { 33 class MockInstalledAppProvider {
25 constructor(interfaceProvider) { 34 constructor(interfaceProvider) {
26 this.bindingSet_ = 35 this.bindingSet_ =
27 new bindings.BindingSet(installedAppProvider.InstalledAppProvider); 36 new bindings.BindingSet(installedAppProvider.InstalledAppProvider);
28 37
29 interfaceProvider.addInterfaceOverrideForTesting( 38 interfaceProvider.addInterfaceOverrideForTesting(
30 installedAppProvider.InstalledAppProvider.name, 39 installedAppProvider.InstalledAppProvider.name,
31 handle => this.bindingSet_.addBinding(this, handle)); 40 handle => this.bindingSet_.addBinding(this, handle));
32 } 41 }
33 42
34 // Returns a Promise that gets rejected if the test should fail. 43 // Returns a Promise that gets rejected if the test should fail.
35 init_() { 44 init_() {
36 // sequence of [expectedRelatedApps, installedApps]. 45 // sequence of [expectedRelatedApps, installedApps].
37 this.callQueue_ = []; 46 this.callQueue_ = [];
38 47
39 return new Promise((resolve, reject) => {this.reject_ = reject}); 48 return new Promise((resolve, reject) => {this.reject_ = reject});
40 } 49 }
41 50
51 // Creates a url.mojom.Url from a URL string.
52 makeUrl(url) {
53 return new urlModule.Url({url: url});
54 }
55
42 filterInstalledApps(relatedApps) { 56 filterInstalledApps(relatedApps) {
43 let callback = null; 57 let callback = null;
44 let result = new Promise(resolve => {callback = resolve;}); 58 let result = new Promise(resolve => {callback = resolve;});
45 59
46 if (!this.callQueue_.length) { 60 if (!this.callQueue_.length) {
47 this.reject_('Unexpected call to mojo FilterInstalledApps method'); 61 this.reject_('Unexpected call to mojo FilterInstalledApps method');
48 return result; 62 return result;
49 } 63 }
50 64
51 let [expectedRelatedApps, installedApps] = this.callQueue_.shift(); 65 let [expectedRelatedApps, installedApps] = this.callQueue_.shift();
(...skipping 21 matching lines...) Expand all
73 // MockInstalledAppProvider that can have expectations set with 87 // MockInstalledAppProvider that can have expectations set with
74 // pushExpectedCall. It should return a promise, the result of 88 // pushExpectedCall. It should return a promise, the result of
75 // getInstalledRelatedApps(). 89 // getInstalledRelatedApps().
76 // |name| and |properties| are standard testharness arguments. 90 // |name| and |properties| are standard testharness arguments.
77 function installedapp_test(func, name, properties) { 91 function installedapp_test(func, name, properties) {
78 promise_test(t => mockInstalledAppProvider.then(mock => { 92 promise_test(t => mockInstalledAppProvider.then(mock => {
79 let mockPromise = mock.init_(); 93 let mockPromise = mock.init_();
80 return Promise.race([func(t, mock), mockPromise]); 94 return Promise.race([func(t, mock), mockPromise]);
81 }), name, properties); 95 }), name, properties);
82 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698