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() { |
(...skipping 10 matching lines...) Expand all Loading... | |
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; | |
stevenjb
2017/05/11 17:46:54
nit: return new Promise( ...
khmel
2017/05/11 19:09:46
Done.
| |
104 } | |
86 | 105 |
87 setup(function() { | 106 setup(function() { |
88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; | 107 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; |
89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 108 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
90 .then(function() { | 109 .then(function() { |
91 androidAppsBrowserProxy.setAppReady(true); | 110 initialHRef = window.location.href; |
111 settings.navigateTo(settings.Route.ANDROID_APPS); | |
112 androidAppsBrowserProxy.setAndroidAppsState(true, false); | |
92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 113 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
93 Polymer.dom.flush(); | 114 Polymer.dom.flush(); |
94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 115 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
95 assertTrue(!!subpage); | 116 assertTrue(!!subpage); |
96 }); | 117 }); |
97 }); | 118 }); |
98 | 119 |
99 test('Sanity', function() { | 120 test('Sanity', function() { |
121 assertTrue(!!subpage.$$('#remove')); | |
100 assertTrue(!!subpage.$$('#manageApps')); | 122 assertTrue(!!subpage.$$('#manageApps')); |
101 assertTrue(!!subpage.$$('#remove')); | 123 }); |
124 | |
125 test('ManageAppsUpdate', function() { | |
126 var manageApps = subpage.$$('#manageApps'); | |
127 assertTrue(manageApps.hidden); | |
128 androidAppsBrowserProxy.setAndroidAppsState(true, true); | |
129 Polymer.dom.flush(); | |
130 assertFalse(manageApps.hidden); | |
131 androidAppsBrowserProxy.setAndroidAppsState(true, false); | |
132 Polymer.dom.flush(); | |
133 assertTrue(manageApps.hidden); | |
102 }); | 134 }); |
103 | 135 |
104 test('Disable', function() { | 136 test('Disable', function() { |
105 var dialog = subpage.$$('#confirmDisableDialog'); | 137 var dialog = subpage.$$('#confirmDisableDialog'); |
106 assertTrue(!!dialog); | 138 assertTrue(!!dialog); |
107 assertFalse(dialog.open); | 139 assertFalse(dialog.open); |
108 | 140 |
109 var remove = subpage.$$('#remove'); | 141 var remove = subpage.$$('#remove'); |
110 assertTrue(!!remove); | 142 assertTrue(!!remove); |
111 MockInteractions.tap(remove); | |
112 | 143 |
144 remove.click(); | |
stevenjb
2017/05/11 17:46:54
We avoid using click(). If this works... that's fi
khmel
2017/05/11 19:09:46
Done.
| |
113 Polymer.dom.flush(); | 145 Polymer.dom.flush(); |
114 assertTrue(dialog.open); | 146 assertTrue(dialog.open); |
115 }); | 147 }); |
148 | |
149 test('HideOnDisable', function() { | |
150 assertEquals(settings.getCurrentRoute(), | |
151 settings.Route.ANDROID_APPS_DETAILS); | |
152 androidAppsBrowserProxy.setAndroidAppsState(false, false); | |
153 Polymer.dom.flush(); | |
154 return whenPopState().then(function() { | |
155 assertEquals(settings.getCurrentRoute(), | |
156 settings.Route.ANDROID_APPS); | |
157 }); | |
158 }); | |
116 }); | 159 }); |
117 | 160 |
118 suite('Enforced', function() { | 161 suite('Enforced', function() { |
119 var subpage; | 162 var subpage; |
120 | 163 |
121 setup(function() { | 164 setup(function() { |
122 androidAppsPage.prefs = { | 165 androidAppsPage.prefs = { |
123 arc: { | 166 arc: { |
124 enabled: { | 167 enabled: { |
125 value: true, | 168 value: true, |
126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED | 169 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED |
127 } | 170 } |
128 } | 171 } |
129 }; | 172 }; |
130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 173 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
131 .then(function() { | 174 .then(function() { |
132 androidAppsBrowserProxy.setAppReady(true); | 175 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 176 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
134 Polymer.dom.flush(); | 177 Polymer.dom.flush(); |
135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 178 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
136 assertTrue(!!subpage); | 179 assertTrue(!!subpage); |
137 }); | 180 }); |
138 }); | 181 }); |
139 | 182 |
140 test('Sanity', function() { | 183 test('Sanity', function() { |
141 Polymer.dom.flush(); | 184 Polymer.dom.flush(); |
142 assertTrue(!!subpage.$$('#manageApps')); | 185 assertTrue(!!subpage.$$('#manageApps')); |
143 assertFalse(!!subpage.$$('#remove')); | 186 assertFalse(!!subpage.$$('#remove')); |
144 }); | 187 }); |
145 }); | 188 }); |
146 }); | 189 }); |
OLD | NEW |