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

Side by Side Diff: chrome/test/data/webui/settings/android_apps_page_test.js

Issue 2873853002: arc: Handle ARC events in MD Settings (Closed)
Patch Set: updatge Created 3 years, 7 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @implements {settings.AndroidAppsBrowserProxy} 7 * @implements {settings.AndroidAppsBrowserProxy}
8 * @extends {settings.TestBrowserProxy} 8 * @extends {settings.TestBrowserProxy}
9 */ 9 */
10 function TestAndroidAppsBrowserProxy() { 10 function TestAndroidAppsBrowserProxy() {
11 settings.TestBrowserProxy.call(this, [ 11 settings.TestBrowserProxy.call(this, [
12 'requestAndroidAppsInfo', 12 'requestAndroidAppsInfo',
13 'showAndroidAppsSettings', 13 'showAndroidAppsSettings',
14 ]); 14 ]);
15 } 15 }
16 16
17 TestAndroidAppsBrowserProxy.prototype = { 17 TestAndroidAppsBrowserProxy.prototype = {
18 __proto__: settings.TestBrowserProxy.prototype, 18 __proto__: settings.TestBrowserProxy.prototype,
19 19
20 /** @override */ 20 /** @override */
21 requestAndroidAppsInfo: function() { 21 requestAndroidAppsInfo: function() {
22 this.methodCalled('requestAndroidAppsInfo'); 22 this.methodCalled('requestAndroidAppsInfo');
23 cr.webUIListenerCallback('android-apps-info-update', {appReady: false}); 23 this.setAndroidAppsState(false, false);
24 }, 24 },
25 25
26 /** override */ 26 /** override */
27 showAndroidAppsSettings: function(keyboardAction) { 27 showAndroidAppsSettings: function(keyboardAction) {
28 this.methodCalled('showAndroidAppsSettings'); 28 this.methodCalled('showAndroidAppsSettings');
29 }, 29 },
30 30
31 setAppReady: function(ready) { 31 setAndroidAppsState: function(playStoreEnabled, settingsAppAvailable) {
32 // We need to make sure to pass a new object here, otherwise the property 32 // We need to make sure to pass a new object here, otherwise the property
33 // change event may not get fired in the listener. 33 // change event may not get fired in the listener.
34 cr.webUIListenerCallback('android-apps-info-update', {appReady: ready}); 34 var appsInfo = {
35 playStoreEnabled: playStoreEnabled,
36 settingsAppAvailable: settingsAppAvailable,
37 };
38 cr.webUIListenerCallback('android-apps-info-update', appsInfo);
35 }, 39 },
36 }; 40 };
37 41
38 /** @type {?SettingsAndroidAppsPageElement} */ 42 /** @type {?SettingsAndroidAppsPageElement} */
39 var androidAppsPage = null; 43 var androidAppsPage = null;
40 44
41 /** @type {?TestAndroidAppsBrowserProxy} */ 45 /** @type {?TestAndroidAppsBrowserProxy} */
42 var androidAppsBrowserProxy = null; 46 var androidAppsBrowserProxy = null;
43 47
44 suite('AndroidAppsPageTests', function() { 48 suite('AndroidAppsPageTests', function() {
(...skipping 10 matching lines...) Expand all
55 androidAppsPage.remove(); 59 androidAppsPage.remove();
56 }); 60 });
57 61
58 suite('Main Page', function() { 62 suite('Main Page', function() {
59 setup(function() { 63 setup(function() {
60 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; 64 androidAppsPage.prefs = {arc: {enabled: {value: false}}};
61 Polymer.dom.flush(); 65 Polymer.dom.flush();
62 66
63 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') 67 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo')
64 .then(function() { 68 .then(function() {
65 androidAppsBrowserProxy.setAppReady(false); 69 androidAppsBrowserProxy.setAndroidAppsState(false, false);
66 }); 70 });
67 }); 71 });
68 72
69 test('Enable', function() { 73 test('Enable', function() {
70 var button = androidAppsPage.$$('#enable'); 74 var button = androidAppsPage.$$('#enable');
71 assertTrue(!!button); 75 assertTrue(!!button);
72 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); 76 assertFalse(!!androidAppsPage.$$('.subpage-arrow'));
73 77
74 MockInteractions.tap(button); 78 MockInteractions.tap(button);
75 Polymer.dom.flush(); 79 Polymer.dom.flush();
76 assertTrue(androidAppsPage.prefs.arc.enabled.value); 80 assertTrue(androidAppsPage.prefs.arc.enabled.value);
77 81
78 androidAppsBrowserProxy.setAppReady(true); 82 androidAppsBrowserProxy.setAndroidAppsState(true, false);
79 Polymer.dom.flush(); 83 Polymer.dom.flush();
80 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); 84 assertTrue(!!androidAppsPage.$$('.subpage-arrow'));
81 }); 85 });
82 }); 86 });
83 87
84 suite('SubPage', function() { 88 suite('SubPage', function() {
85 var subpage; 89 var subpage;
90 var initialHRef;
91
92 /**
93 * Returns a new promise that resolves after a window 'popstate' event.
94 * @return {!Promise}
95 */
96 function whenPopState() {
97 var promise = new Promise(function(resolve) {
98 window.addEventListener('popstate', function callback() {
99 window.removeEventListener('popstate', callback);
100 resolve();
101 });
102 });
103 return promise;
104 }
105
106 /**
107 * Returns a new promise that resolves after a node becomes available for
108 * interaction.
109 * @return {!Promise}
110 */
111 function whenNodeCanInteract(node) {
112 var promise = new Promise(function(resolve) {
113 var checkNode = function() {
114 if (window.getComputedStyle(node)['pointer-events'] != 'none')
115 resolve();
116 else
117 setTimeout(checkNode, 1);
118 }
119 checkNode();
120 });
121 return promise;
122 }
86 123
87 setup(function() { 124 setup(function() {
88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; 125 androidAppsPage.prefs = {arc: {enabled: {value: true}}};
89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') 126 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo')
90 .then(function() { 127 .then(function() {
91 androidAppsBrowserProxy.setAppReady(true); 128 initialHRef = window.location.href;
129 androidAppsBrowserProxy.setAndroidAppsState(true, false);
92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); 130 MockInteractions.tap(androidAppsPage.$$('#android-apps'));
93 Polymer.dom.flush(); 131 Polymer.dom.flush();
94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); 132 subpage = androidAppsPage.$$('settings-android-apps-subpage');
95 assertTrue(!!subpage); 133 assertTrue(!!subpage);
96 }); 134 });
97 }); 135 });
98 136
137 teardown(function() {
138 if (settings.getCurrentRoute() == settings.Route.ANDROID_APPS_DETAILS) {
khmel 2017/05/10 21:48:13 Need to go back after test. Otherwise multiple set
stevenjb 2017/05/10 22:35:44 Ugh. Can we just navigate directly to ANDROID_APPS
khmel 2017/05/11 00:10:30 Yes, but this would increase history stack.
139 settings.navigateToPreviousRoute();
140 return whenPopState().then(function() {});
141 }
142 });
143
99 test('Sanity', function() { 144 test('Sanity', function() {
145 assertTrue(!!subpage.$$('#remove'));
100 assertTrue(!!subpage.$$('#manageApps')); 146 assertTrue(!!subpage.$$('#manageApps'));
101 assertTrue(!!subpage.$$('#remove')); 147 });
148
149 test('ManageAppsUpdate', function() {
150 var manageApps = subpage.$$('#manageApps');
151 assertTrue(manageApps.hidden);
152 androidAppsBrowserProxy.setAndroidAppsState(true, true);
153 Polymer.dom.flush();
154 assertFalse(manageApps.hidden);
155 androidAppsBrowserProxy.setAndroidAppsState(true, false);
156 Polymer.dom.flush();
157 assertTrue(manageApps.hidden);
102 }); 158 });
103 159
104 test('Disable', function() { 160 test('Disable', function() {
105 var dialog = subpage.$$('#confirmDisableDialog'); 161 var dialog = subpage.$$('#confirmDisableDialog');
106 assertTrue(!!dialog); 162 assertTrue(!!dialog);
107 assertFalse(dialog.open); 163 assertFalse(dialog.open);
108 164
109 var remove = subpage.$$('#remove'); 165 var remove = subpage.$$('#remove');
110 assertTrue(!!remove); 166 assertTrue(!!remove);
111 MockInteractions.tap(remove);
112 167
168 // remove button is not always visible immediately after dom flush. This
169 // leads to tap ignoring and test failure. Simulate tap asynchronously.
170 return whenNodeCanInteract(remove).then(function() {
khmel 2017/05/10 21:48:13 Well, Polymer.async did not help. also SetTimeot 0
stevenjb 2017/05/10 22:35:44 Ugh. Timeout loops like that tend to be fragile in
khmel 2017/05/11 00:10:30 What is your suggestion? .click is not visible. .
171 MockInteractions.tap(remove);
172 Polymer.dom.flush();
173 assertTrue(dialog.open);
174 });
175 });
176
177 test('HideOnDisable', function() {
178 assertEquals(settings.getCurrentRoute(),
179 settings.Route.ANDROID_APPS_DETAILS);
180 androidAppsBrowserProxy.setAndroidAppsState(false, false);
113 Polymer.dom.flush(); 181 Polymer.dom.flush();
114 assertTrue(dialog.open); 182 return whenPopState().then(function() {
183 assertNotEquals(settings.getCurrentRoute(),
184 settings.Route.ANDROID_APPS_DETAILS);
185 assertEquals(initialHRef, window.location.href);
186 });
115 }); 187 });
116 }); 188 });
117 189
118 suite('Enforced', function() { 190 suite('Enforced', function() {
119 var subpage; 191 var subpage;
120 192
121 setup(function() { 193 setup(function() {
122 androidAppsPage.prefs = { 194 androidAppsPage.prefs = {
123 arc: { 195 arc: {
124 enabled: { 196 enabled: {
125 value: true, 197 value: true,
126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED 198 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED
127 } 199 }
128 } 200 }
129 }; 201 };
130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') 202 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo')
131 .then(function() { 203 .then(function() {
132 androidAppsBrowserProxy.setAppReady(true); 204 androidAppsBrowserProxy.setAndroidAppsState(true, true);
133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); 205 MockInteractions.tap(androidAppsPage.$$('#android-apps'));
134 Polymer.dom.flush(); 206 Polymer.dom.flush();
135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); 207 subpage = androidAppsPage.$$('settings-android-apps-subpage');
136 assertTrue(!!subpage); 208 assertTrue(!!subpage);
137 }); 209 });
138 }); 210 });
139 211
140 test('Sanity', function() { 212 test('Sanity', function() {
141 Polymer.dom.flush(); 213 Polymer.dom.flush();
142 assertTrue(!!subpage.$$('#manageApps')); 214 assertTrue(!!subpage.$$('#manageApps'));
143 assertFalse(!!subpage.$$('#remove')); 215 assertFalse(!!subpage.$$('#remove'));
144 }); 216 });
145 }); 217 });
146 }); 218 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698