| 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, appSettingsAvailable) { |
| 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 appsInfo.playStoreEnabled = playStoreEnabled; |
| 36 appsInfo.appSettingsAvailable = appSettingsAvailable; |
| 37 cr.webUIListenerCallback('android-apps-info-update', appsInfo); |
| 35 }, | 38 }, |
| 36 }; | 39 }; |
| 37 | 40 |
| 38 /** @type {?SettingsAndroidAppsPageElement} */ | 41 /** @type {?SettingsAndroidAppsPageElement} */ |
| 39 var androidAppsPage = null; | 42 var androidAppsPage = null; |
| 40 | 43 |
| 41 /** @type {?TestAndroidAppsBrowserProxy} */ | 44 /** @type {?TestAndroidAppsBrowserProxy} */ |
| 42 var androidAppsBrowserProxy = null; | 45 var androidAppsBrowserProxy = null; |
| 43 | 46 |
| 44 suite('AndroidAppsPageTests', function() { | 47 suite('AndroidAppsPageTests', function() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 androidAppsPage.remove(); | 58 androidAppsPage.remove(); |
| 56 }); | 59 }); |
| 57 | 60 |
| 58 suite('Main Page', function() { | 61 suite('Main Page', function() { |
| 59 setup(function() { | 62 setup(function() { |
| 60 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; | 63 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; |
| 61 Polymer.dom.flush(); | 64 Polymer.dom.flush(); |
| 62 | 65 |
| 63 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 66 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 64 .then(function() { | 67 .then(function() { |
| 65 androidAppsBrowserProxy.setAppReady(false); | 68 androidAppsBrowserProxy.setAndroidAppsState(false, false); |
| 66 }); | 69 }); |
| 67 }); | 70 }); |
| 68 | 71 |
| 69 test('Enable', function() { | 72 test('Enable', function() { |
| 70 var button = androidAppsPage.$$('#enable'); | 73 var button = androidAppsPage.$$('#enable'); |
| 71 assertTrue(!!button); | 74 assertTrue(!!button); |
| 72 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); | 75 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); |
| 73 | 76 |
| 74 MockInteractions.tap(button); | 77 MockInteractions.tap(button); |
| 75 Polymer.dom.flush(); | 78 Polymer.dom.flush(); |
| 76 assertTrue(androidAppsPage.prefs.arc.enabled.value); | 79 assertTrue(androidAppsPage.prefs.arc.enabled.value); |
| 77 | 80 |
| 78 androidAppsBrowserProxy.setAppReady(true); | 81 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| 79 Polymer.dom.flush(); | 82 Polymer.dom.flush(); |
| 80 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); | 83 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); |
| 81 }); | 84 }); |
| 82 }); | 85 }); |
| 83 | 86 |
| 84 suite('SubPage', function() { | 87 suite('SubPage', function() { |
| 85 var subpage; | 88 var subpage; |
| 86 | 89 |
| 87 setup(function() { | 90 setup(function() { |
| 88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; | 91 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; |
| 89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 92 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 90 .then(function() { | 93 .then(function() { |
| 91 androidAppsBrowserProxy.setAppReady(true); | 94 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| 92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 95 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| 93 Polymer.dom.flush(); | 96 Polymer.dom.flush(); |
| 94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 97 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
| 95 assertTrue(!!subpage); | 98 assertTrue(!!subpage); |
| 96 }); | 99 }); |
| 97 }); | 100 }); |
| 98 | 101 |
| 99 test('Sanity', function() { | 102 test('Sanity', function() { |
| 103 assertTrue(!!subpage.$$('#remove')); |
| 100 assertTrue(!!subpage.$$('#manageApps')); | 104 assertTrue(!!subpage.$$('#manageApps')); |
| 101 assertTrue(!!subpage.$$('#remove')); | 105 }); |
| 106 |
| 107 test('ManageAppsUpdate', function() { |
| 108 var manageApps = subpage.$$('#manageApps'); |
| 109 assertTrue(manageApps.hidden); |
| 110 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| 111 Polymer.dom.flush(); |
| 112 assertFalse(manageApps.hidden); |
| 113 androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| 114 Polymer.dom.flush(); |
| 115 assertTrue(manageApps.hidden); |
| 102 }); | 116 }); |
| 103 | 117 |
| 104 test('Disable', function() { | 118 test('Disable', function() { |
| 105 var dialog = subpage.$$('#confirmDisableDialog'); | 119 var dialog = subpage.$$('#confirmDisableDialog'); |
| 106 assertTrue(!!dialog); | 120 assertTrue(!!dialog); |
| 107 assertFalse(dialog.open); | 121 assertFalse(dialog.open); |
| 108 | 122 |
| 109 var remove = subpage.$$('#remove'); | 123 var remove = subpage.$$('#remove'); |
| 110 assertTrue(!!remove); | 124 assertTrue(!!remove); |
| 111 MockInteractions.tap(remove); | |
| 112 | 125 |
| 126 // remove button is not always visible immediately after dom flush. This |
| 127 // leads to tap ignoring and test failure. Simulate tap asynchronously. |
| 128 return new Promise(function(resolve, reject) { |
| 129 var validateDialog = function() { |
| 130 MockInteractions.tap(remove); |
| 131 Polymer.dom.flush(); |
| 132 assertTrue(dialog.open); |
| 133 resolve(); |
| 134 } |
| 135 setTimeout(validateDialog, 0) |
| 136 }); |
| 137 }); |
| 138 |
| 139 test('HideOnDisable', function() { |
| 140 assertEquals(settings.getCurrentRoute(), |
| 141 settings.Route.ANDROID_APPS_DETAILS); |
| 142 androidAppsBrowserProxy.setAndroidAppsState(false, false); |
| 113 Polymer.dom.flush(); | 143 Polymer.dom.flush(); |
| 114 assertTrue(dialog.open); | 144 assertEquals(settings.getCurrentRoute(), settings.Route.ANDROID_APPS); |
| 115 }); | 145 }); |
| 146 |
| 116 }); | 147 }); |
| 117 | 148 |
| 118 suite('Enforced', function() { | 149 suite('Enforced', function() { |
| 119 var subpage; | 150 var subpage; |
| 120 | 151 |
| 121 setup(function() { | 152 setup(function() { |
| 122 androidAppsPage.prefs = { | 153 androidAppsPage.prefs = { |
| 123 arc: { | 154 arc: { |
| 124 enabled: { | 155 enabled: { |
| 125 value: true, | 156 value: true, |
| 126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED | 157 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED |
| 127 } | 158 } |
| 128 } | 159 } |
| 129 }; | 160 }; |
| 130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 161 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 131 .then(function() { | 162 .then(function() { |
| 132 androidAppsBrowserProxy.setAppReady(true); | 163 androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| 133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | 164 MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| 134 Polymer.dom.flush(); | 165 Polymer.dom.flush(); |
| 135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | 166 subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
| 136 assertTrue(!!subpage); | 167 assertTrue(!!subpage); |
| 137 }); | 168 }); |
| 138 }); | 169 }); |
| 139 | 170 |
| 140 test('Sanity', function() { | 171 test('Sanity', function() { |
| 141 Polymer.dom.flush(); | 172 Polymer.dom.flush(); |
| 142 assertTrue(!!subpage.$$('#manageApps')); | 173 assertTrue(!!subpage.$$('#manageApps')); |
| 143 assertFalse(!!subpage.$$('#remove')); | 174 assertFalse(!!subpage.$$('#remove')); |
| 144 }); | 175 }); |
| 145 }); | 176 }); |
| 146 }); | 177 }); |
| OLD | NEW |