OLD | NEW |
---|---|
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() { |
45 setup(function() { | 49 setup(function() { |
46 androidAppsBrowserProxy = new TestAndroidAppsBrowserProxy(); | 50 androidAppsBrowserProxy = new TestAndroidAppsBrowserProxy(); |
47 settings.AndroidAppsBrowserProxyImpl.instance_ = androidAppsBrowserProxy; | 51 settings.AndroidAppsBrowserProxyImpl.instance_ = androidAppsBrowserProxy; |
48 PolymerTest.clearBody(); | 52 PolymerTest.clearBody(); |
49 androidAppsPage = document.createElement('settings-android-apps-page'); | 53 androidAppsPage = document.createElement('settings-android-apps-page'); |
50 document.body.appendChild(androidAppsPage); | 54 document.body.appendChild(androidAppsPage); |
51 testing.Test.disableAnimationsAndTransitions(); | 55 testing.Test.disableAnimationsAndTransitions(); |
52 }); | 56 }); |
53 | 57 |
54 teardown(function() { | 58 teardown(function() { |
55 androidAppsPage.remove(); | 59 androidAppsPage.remove(); |
60 androidAppsPage.discardForTest(); | |
56 }); | 61 }); |
57 | 62 |
58 suite('Main Page', function() { | 63 suite('Main Page', function() { |
59 setup(function() { | 64 setup(function() { |
60 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; | 65 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; |
61 Polymer.dom.flush(); | 66 Polymer.dom.flush(); |
62 | 67 |
63 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 68 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
64 .then(function() { | 69 .then(function() { |
65 androidAppsBrowserProxy.setAppReady(false); | 70 androidAppsBrowserProxy.setAndroidAppsState(false, false); |
66 }); | 71 }); |
67 }); | 72 }); |
68 | 73 |
69 test('Enable', function() { | 74 test('Enable', function() { |
70 var button = androidAppsPage.$$('#enable'); | 75 var button = androidAppsPage.$$('#enable'); |
71 assertTrue(!!button); | 76 assertTrue(!!button); |
72 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); | 77 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); |
73 | 78 |
74 MockInteractions.tap(button); | 79 MockInteractions.tap(button); |
75 Polymer.dom.flush(); | 80 Polymer.dom.flush(); |
76 assertTrue(androidAppsPage.prefs.arc.enabled.value); | 81 assertTrue(androidAppsPage.prefs.arc.enabled.value); |
77 | 82 |
78 androidAppsBrowserProxy.setAppReady(true); | 83 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
79 Polymer.dom.flush(); | 84 Polymer.dom.flush(); |
80 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); | 85 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); |
81 }); | 86 }); |
82 }); | 87 }); |
83 | 88 |
84 suite('SubPage', function() { | 89 suite('SubPage', function() { |
85 var subpage; | 90 var subpage; |
91 var initialHRef; | |
92 | |
93 /** | |
94 * Returns a new promise that resolves after a window 'popstate' event. | |
95 * @return {!Promise} | |
96 */ | |
97 function whenPopState() { | |
98 var promise = new Promise(function(resolve) { | |
99 window.addEventListener('popstate', function callback() { | |
100 window.removeEventListener('popstate', callback); | |
101 resolve(); | |
102 }); | |
103 }); | |
104 return promise; | |
105 } | |
106 | |
107 /** | |
108 * Returns a new promise that resolves after a node becomes available for | |
109 * interaction. | |
110 * @return {!Promise} | |
111 */ | |
112 function whenNodeCanInteract(node) { | |
113 var promise = new Promise(function(resolve) { | |
114 var checkNode = function() { | |
115 if (window.getComputedStyle(node)['pointer-events'] != 'none') | |
116 resolve(); | |
117 else | |
118 setTimeout(checkNode, 1); | |
119 } | |
120 checkNode(); | |
121 }); | |
122 return promise; | |
123 } | |
86 | 124 |
87 setup(function() { | 125 setup(function() { |
88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; | 126 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; |
89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 127 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
90 .then(function() { | 128 .then(function() { |
91 androidAppsBrowserProxy.setAppReady(true); | 129 initialHRef = window.location.href; |
130 settings.navigateTo(settings.Route.ANDROID_APPS); | |
131 androidAppsBrowserProxy.setAndroidAppsState(true, false); | |
92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 132 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
93 Polymer.dom.flush(); | 133 Polymer.dom.flush(); |
94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 134 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
95 assertTrue(!!subpage); | 135 assertTrue(!!subpage); |
96 }); | 136 }); |
97 }); | 137 }); |
98 | 138 |
99 test('Sanity', function() { | 139 test('Sanity', function() { |
140 assertTrue(!!subpage.$$('#remove')); | |
100 assertTrue(!!subpage.$$('#manageApps')); | 141 assertTrue(!!subpage.$$('#manageApps')); |
101 assertTrue(!!subpage.$$('#remove')); | 142 }); |
143 | |
144 test('ManageAppsUpdate', function() { | |
145 var manageApps = subpage.$$('#manageApps'); | |
146 assertTrue(manageApps.hidden); | |
147 androidAppsBrowserProxy.setAndroidAppsState(true, true); | |
148 Polymer.dom.flush(); | |
149 assertFalse(manageApps.hidden); | |
150 androidAppsBrowserProxy.setAndroidAppsState(true, false); | |
151 Polymer.dom.flush(); | |
152 assertTrue(manageApps.hidden); | |
102 }); | 153 }); |
103 | 154 |
104 test('Disable', function() { | 155 test('Disable', function() { |
105 var dialog = subpage.$$('#confirmDisableDialog'); | 156 var dialog = subpage.$$('#confirmDisableDialog'); |
106 assertTrue(!!dialog); | 157 assertTrue(!!dialog); |
107 assertFalse(dialog.open); | 158 assertFalse(dialog.open); |
108 | 159 |
109 var remove = subpage.$$('#remove'); | 160 var remove = subpage.$$('#remove'); |
110 assertTrue(!!remove); | 161 assertTrue(!!remove); |
111 MockInteractions.tap(remove); | |
112 | 162 |
163 // remove button is not always visible immediately after dom flush. This | |
164 // leads to tap ignoring and test failure. Simulate tap asynchronously. | |
165 return whenNodeCanInteract(remove).then(function() { | |
166 MockInteractions.tap(remove); | |
stevenjb
2017/05/11 16:58:14
Just call:
subpage.onRemoveTap_();
Then you shou
khmel
2017/05/11 17:32:22
Changed to remove.click(). It seems more close wha
| |
167 Polymer.dom.flush(); | |
168 assertTrue(dialog.open); | |
169 }); | |
170 }); | |
171 | |
172 test('HideOnDisable', function() { | |
173 assertEquals(settings.getCurrentRoute(), | |
174 settings.Route.ANDROID_APPS_DETAILS); | |
175 androidAppsBrowserProxy.setAndroidAppsState(false, false); | |
113 Polymer.dom.flush(); | 176 Polymer.dom.flush(); |
114 assertTrue(dialog.open); | 177 return whenPopState().then(function() { |
178 assertEquals(settings.getCurrentRoute(), | |
179 settings.Route.ANDROID_APPS); | |
180 }); | |
115 }); | 181 }); |
116 }); | 182 }); |
117 | 183 |
118 suite('Enforced', function() { | 184 suite('Enforced', function() { |
119 var subpage; | 185 var subpage; |
120 | 186 |
121 setup(function() { | 187 setup(function() { |
122 androidAppsPage.prefs = { | 188 androidAppsPage.prefs = { |
123 arc: { | 189 arc: { |
124 enabled: { | 190 enabled: { |
125 value: true, | 191 value: true, |
126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED | 192 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED |
127 } | 193 } |
128 } | 194 } |
129 }; | 195 }; |
130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 196 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
131 .then(function() { | 197 .then(function() { |
132 androidAppsBrowserProxy.setAppReady(true); | 198 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 199 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
134 Polymer.dom.flush(); | 200 Polymer.dom.flush(); |
135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 201 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
136 assertTrue(!!subpage); | 202 assertTrue(!!subpage); |
137 }); | 203 }); |
138 }); | 204 }); |
139 | 205 |
140 test('Sanity', function() { | 206 test('Sanity', function() { |
141 Polymer.dom.flush(); | 207 Polymer.dom.flush(); |
142 assertTrue(!!subpage.$$('#manageApps')); | 208 assertTrue(!!subpage.$$('#manageApps')); |
143 assertFalse(!!subpage.$$('#remove')); | 209 assertFalse(!!subpage.$$('#remove')); |
144 }); | 210 }); |
145 }); | 211 }); |
146 }); | 212 }); |
OLD | NEW |