| 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; |
| 86 | 90 |
| 91 /** |
| 92 * Returns a new promise that resolves after a window 'popstate' event. |
| 93 * @return {!Promise} |
| 94 */ |
| 95 function whenPopState() { |
| 96 return new Promise(function(resolve) { |
| 97 window.addEventListener('popstate', function callback() { |
| 98 window.removeEventListener('popstate', callback); |
| 99 resolve(); |
| 100 }); |
| 101 }); |
| 102 } |
| 103 |
| 87 setup(function() { | 104 setup(function() { |
| 88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; | 105 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; |
| 89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 106 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 90 .then(function() { | 107 .then(function() { |
| 91 androidAppsBrowserProxy.setAppReady(true); | 108 settings.navigateTo(settings.Route.ANDROID_APPS); |
| 109 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| 92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 110 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| 93 Polymer.dom.flush(); | 111 Polymer.dom.flush(); |
| 94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 112 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
| 95 assertTrue(!!subpage); | 113 assertTrue(!!subpage); |
| 96 }); | 114 }); |
| 97 }); | 115 }); |
| 98 | 116 |
| 99 test('Sanity', function() { | 117 test('Sanity', function() { |
| 118 assertTrue(!!subpage.$$('#remove')); |
| 100 assertTrue(!!subpage.$$('#manageApps')); | 119 assertTrue(!!subpage.$$('#manageApps')); |
| 101 assertTrue(!!subpage.$$('#remove')); | 120 }); |
| 121 |
| 122 test('ManageAppsUpdate', function() { |
| 123 var manageApps = subpage.$$('#manageApps'); |
| 124 assertTrue(manageApps.hidden); |
| 125 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| 126 Polymer.dom.flush(); |
| 127 assertFalse(manageApps.hidden); |
| 128 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| 129 Polymer.dom.flush(); |
| 130 assertTrue(manageApps.hidden); |
| 102 }); | 131 }); |
| 103 | 132 |
| 104 test('Disable', function() { | 133 test('Disable', function() { |
| 105 var dialog = subpage.$$('#confirmDisableDialog'); | 134 var dialog = subpage.$$('#confirmDisableDialog'); |
| 106 assertTrue(!!dialog); | 135 assertTrue(!!dialog); |
| 107 assertFalse(dialog.open); | 136 assertFalse(dialog.open); |
| 108 | 137 |
| 109 var remove = subpage.$$('#remove'); | 138 var remove = subpage.$$('#remove'); |
| 110 assertTrue(!!remove); | 139 assertTrue(!!remove); |
| 111 MockInteractions.tap(remove); | |
| 112 | 140 |
| 141 subpage.onRemoveTap_(); |
| 113 Polymer.dom.flush(); | 142 Polymer.dom.flush(); |
| 114 assertTrue(dialog.open); | 143 assertTrue(dialog.open); |
| 144 dialog.close(); |
| 145 }); |
| 146 |
| 147 test('HideOnDisable', function() { |
| 148 assertEquals(settings.getCurrentRoute(), |
| 149 settings.Route.ANDROID_APPS_DETAILS); |
| 150 androidAppsBrowserProxy.setAndroidAppsState(false, false); |
| 151 Polymer.dom.flush(); |
| 152 return whenPopState().then(function() { |
| 153 assertEquals(settings.getCurrentRoute(), |
| 154 settings.Route.ANDROID_APPS); |
| 155 }); |
| 115 }); | 156 }); |
| 116 }); | 157 }); |
| 117 | 158 |
| 118 suite('Enforced', function() { | 159 suite('Enforced', function() { |
| 119 var subpage; | 160 var subpage; |
| 120 | 161 |
| 121 setup(function() { | 162 setup(function() { |
| 122 androidAppsPage.prefs = { | 163 androidAppsPage.prefs = { |
| 123 arc: { | 164 arc: { |
| 124 enabled: { | 165 enabled: { |
| 125 value: true, | 166 value: true, |
| 126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED | 167 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED |
| 127 } | 168 } |
| 128 } | 169 } |
| 129 }; | 170 }; |
| 130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 171 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 131 .then(function() { | 172 .then(function() { |
| 132 androidAppsBrowserProxy.setAppReady(true); | 173 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| 133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 174 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| 134 Polymer.dom.flush(); | 175 Polymer.dom.flush(); |
| 135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 176 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
| 136 assertTrue(!!subpage); | 177 assertTrue(!!subpage); |
| 137 }); | 178 }); |
| 138 }); | 179 }); |
| 139 | 180 |
| 140 test('Sanity', function() { | 181 test('Sanity', function() { |
| 141 Polymer.dom.flush(); | 182 Polymer.dom.flush(); |
| 142 assertTrue(!!subpage.$$('#manageApps')); | 183 assertTrue(!!subpage.$$('#manageApps')); |
| 143 assertFalse(!!subpage.$$('#remove')); | 184 assertFalse(!!subpage.$$('#remove')); |
| 144 }); | 185 }); |
| 145 }); | 186 }); |
| 146 }); | 187 }); |
| OLD | NEW |