Chromium Code Reviews| Index: chrome/test/data/webui/settings/android_apps_page_test.js |
| diff --git a/chrome/test/data/webui/settings/android_apps_page_test.js b/chrome/test/data/webui/settings/android_apps_page_test.js |
| index f5e2daceb010e04a6ff2d0a821576192b512d6ca..d16da63bf12bd99faf26bfe3120a4a13e4679080 100644 |
| --- a/chrome/test/data/webui/settings/android_apps_page_test.js |
| +++ b/chrome/test/data/webui/settings/android_apps_page_test.js |
| @@ -20,7 +20,7 @@ TestAndroidAppsBrowserProxy.prototype = { |
| /** @override */ |
| requestAndroidAppsInfo: function() { |
| this.methodCalled('requestAndroidAppsInfo'); |
| - cr.webUIListenerCallback('android-apps-info-update', {appReady: false}); |
| + this.setAndroidAppsState(false, false); |
| }, |
| /** override */ |
| @@ -28,10 +28,14 @@ TestAndroidAppsBrowserProxy.prototype = { |
| this.methodCalled('showAndroidAppsSettings'); |
| }, |
| - setAppReady: function(ready) { |
| + setAndroidAppsState: function(playStoreEnabled, settingsAppAvailable) { |
| // We need to make sure to pass a new object here, otherwise the property |
| // change event may not get fired in the listener. |
| - cr.webUIListenerCallback('android-apps-info-update', {appReady: ready}); |
| + var appsInfo = { |
| + playStoreEnabled: playStoreEnabled, |
| + settingsAppAvailable: settingsAppAvailable, |
| + }; |
| + cr.webUIListenerCallback('android-apps-info-update', appsInfo); |
| }, |
| }; |
| @@ -53,6 +57,7 @@ suite('AndroidAppsPageTests', function() { |
| teardown(function() { |
| androidAppsPage.remove(); |
| + androidAppsPage.discardForTest(); |
| }); |
| suite('Main Page', function() { |
| @@ -62,7 +67,7 @@ suite('AndroidAppsPageTests', function() { |
| return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| .then(function() { |
| - androidAppsBrowserProxy.setAppReady(false); |
| + androidAppsBrowserProxy.setAndroidAppsState(false, false); |
| }); |
| }); |
| @@ -75,7 +80,7 @@ suite('AndroidAppsPageTests', function() { |
| Polymer.dom.flush(); |
| assertTrue(androidAppsPage.prefs.arc.enabled.value); |
| - androidAppsBrowserProxy.setAppReady(true); |
| + androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| Polymer.dom.flush(); |
| assertTrue(!!androidAppsPage.$$('.subpage-arrow')); |
| }); |
| @@ -83,12 +88,47 @@ suite('AndroidAppsPageTests', function() { |
| suite('SubPage', function() { |
| var subpage; |
| + var initialHRef; |
| + |
| + /** |
| + * Returns a new promise that resolves after a window 'popstate' event. |
| + * @return {!Promise} |
| + */ |
| + function whenPopState() { |
| + var promise = new Promise(function(resolve) { |
| + window.addEventListener('popstate', function callback() { |
| + window.removeEventListener('popstate', callback); |
| + resolve(); |
| + }); |
| + }); |
| + return promise; |
| + } |
| + |
| + /** |
| + * Returns a new promise that resolves after a node becomes available for |
| + * interaction. |
| + * @return {!Promise} |
| + */ |
| + function whenNodeCanInteract(node) { |
| + var promise = new Promise(function(resolve) { |
| + var checkNode = function() { |
| + if (window.getComputedStyle(node)['pointer-events'] != 'none') |
| + resolve(); |
| + else |
| + setTimeout(checkNode, 1); |
| + } |
| + checkNode(); |
| + }); |
| + return promise; |
| + } |
| setup(function() { |
| androidAppsPage.prefs = {arc: {enabled: {value: true}}}; |
| return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| .then(function() { |
| - androidAppsBrowserProxy.setAppReady(true); |
| + initialHRef = window.location.href; |
| + settings.navigateTo(settings.Route.ANDROID_APPS); |
| + androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| Polymer.dom.flush(); |
| subpage = androidAppsPage.$$('settings-android-apps-subpage'); |
| @@ -97,8 +137,19 @@ suite('AndroidAppsPageTests', function() { |
| }); |
| test('Sanity', function() { |
| - assertTrue(!!subpage.$$('#manageApps')); |
| assertTrue(!!subpage.$$('#remove')); |
| + assertTrue(!!subpage.$$('#manageApps')); |
| + }); |
| + |
| + test('ManageAppsUpdate', function() { |
| + var manageApps = subpage.$$('#manageApps'); |
| + assertTrue(manageApps.hidden); |
| + androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| + Polymer.dom.flush(); |
| + assertFalse(manageApps.hidden); |
| + androidAppsBrowserProxy.setAndroidAppsState(true, false); |
| + Polymer.dom.flush(); |
| + assertTrue(manageApps.hidden); |
| }); |
| test('Disable', function() { |
| @@ -108,10 +159,25 @@ suite('AndroidAppsPageTests', function() { |
| var remove = subpage.$$('#remove'); |
| assertTrue(!!remove); |
| - MockInteractions.tap(remove); |
| + // remove button is not always visible immediately after dom flush. This |
| + // leads to tap ignoring and test failure. Simulate tap asynchronously. |
| + return whenNodeCanInteract(remove).then(function() { |
| + 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
|
| + Polymer.dom.flush(); |
| + assertTrue(dialog.open); |
| + }); |
| + }); |
| + |
| + test('HideOnDisable', function() { |
| + assertEquals(settings.getCurrentRoute(), |
| + settings.Route.ANDROID_APPS_DETAILS); |
| + androidAppsBrowserProxy.setAndroidAppsState(false, false); |
| Polymer.dom.flush(); |
| - assertTrue(dialog.open); |
| + return whenPopState().then(function() { |
| + assertEquals(settings.getCurrentRoute(), |
| + settings.Route.ANDROID_APPS); |
| + }); |
| }); |
| }); |
| @@ -129,7 +195,7 @@ suite('AndroidAppsPageTests', function() { |
| }; |
| return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| .then(function() { |
| - androidAppsBrowserProxy.setAppReady(true); |
| + androidAppsBrowserProxy.setAndroidAppsState(true, true); |
| MockInteractions.tap(androidAppsPage.$$('#android-apps')); |
| Polymer.dom.flush(); |
| subpage = androidAppsPage.$$('settings-android-apps-subpage'); |