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 |
| 16 /** @private {!AndroidAppsInfo} */ |
| 17 this.androidAppsInfo_ = {appReady: false}; |
15 } | 18 } |
16 | 19 |
17 TestAndroidAppsBrowserProxy.prototype = { | 20 TestAndroidAppsBrowserProxy.prototype = { |
18 __proto__: settings.TestBrowserProxy.prototype, | 21 __proto__: settings.TestBrowserProxy.prototype, |
19 | 22 |
20 /** @override */ | 23 /** @override */ |
21 requestAndroidAppsInfo: function() { | 24 requestAndroidAppsInfo: function() { |
22 this.methodCalled('requestAndroidAppsInfo'); | 25 this.methodCalled('requestAndroidAppsInfo'); |
23 cr.webUIListenerCallback('android-apps-info-update', {appReady: false}); | |
24 }, | 26 }, |
25 | 27 |
26 /** override */ | 28 /** override */ |
27 showAndroidAppsSettings: function(keyboardAction) { | 29 showAndroidAppsSettings: function(keyboardAction) { |
28 this.methodCalled('showAndroidAppsSettings'); | 30 this.methodCalled('showAndroidAppsSettings'); |
29 }, | 31 }, |
30 | |
31 setAppReady: function(ready) { | |
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. | |
34 cr.webUIListenerCallback('android-apps-info-update', {appReady: ready}); | |
35 }, | |
36 }; | 32 }; |
37 | 33 |
38 /** @type {?SettingsAndroidAppsPageElement} */ | 34 /** @type {?SettingsAndroidAppsPageElement} */ |
39 var androidAppsPage = null; | 35 var androidAppsPage = null; |
40 | 36 |
41 /** @type {?TestAndroidAppsBrowserProxy} */ | 37 /** @type {?TestAndroidAppsBrowserProxy} */ |
42 var androidAppsBrowserProxy = null; | 38 var androidAppsBrowserProxy = null; |
43 | 39 |
44 suite('AndroidAppsPageTests', function() { | 40 suite('AndroidAppsPageTests', function() { |
45 setup(function() { | 41 setup(function() { |
46 androidAppsBrowserProxy = new TestAndroidAppsBrowserProxy(); | 42 androidAppsBrowserProxy = new TestAndroidAppsBrowserProxy(); |
47 settings.AndroidAppsBrowserProxyImpl.instance_ = androidAppsBrowserProxy; | 43 settings.AndroidAppsBrowserProxyImpl.instance_ = androidAppsBrowserProxy; |
48 PolymerTest.clearBody(); | 44 PolymerTest.clearBody(); |
49 androidAppsPage = document.createElement('settings-android-apps-page'); | 45 androidAppsPage = document.createElement('settings-android-apps-page'); |
50 document.body.appendChild(androidAppsPage); | 46 document.body.appendChild(androidAppsPage); |
51 testing.Test.disableAnimationsAndTransitions(); | |
52 }); | 47 }); |
53 | 48 |
54 teardown(function() { | 49 teardown(function() { androidAppsPage.remove(); }); |
55 androidAppsPage.remove(); | 50 |
| 51 test('Enable', function() { |
| 52 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
| 53 .then(function() { |
| 54 androidAppsPage.prefs = { |
| 55 arc: { |
| 56 enabled: { |
| 57 value: false, |
| 58 }, |
| 59 }, |
| 60 }; |
| 61 cr.webUIListenerCallback( |
| 62 'android-apps-info-update', {appReady: false}); |
| 63 Polymer.dom.flush(); |
| 64 var control = androidAppsPage.$$('#enabled'); |
| 65 assertTrue(!!control); |
| 66 assertFalse(control.disabled); |
| 67 assertFalse(control.checked); |
| 68 var managed = androidAppsPage.$$('#manageApps'); |
| 69 assertTrue(!!managed); |
| 70 assertTrue(managed.hidden); |
| 71 |
| 72 MockInteractions.tap(control.$.control); |
| 73 Polymer.dom.flush(); |
| 74 assertTrue(control.checked); |
| 75 }); |
56 }); | 76 }); |
57 | 77 |
58 suite('Main Page', function() { | 78 test('Disable', function() { |
59 setup(function() { | 79 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') |
60 androidAppsPage.prefs = {arc: {enabled: {value: false}}}; | 80 .then(function() { |
61 Polymer.dom.flush(); | 81 androidAppsPage.prefs = { |
| 82 arc: { |
| 83 enabled: { |
| 84 value: true, |
| 85 }, |
| 86 }, |
| 87 }; |
| 88 cr.webUIListenerCallback( |
| 89 'android-apps-info-update', {appReady: true}); |
| 90 Polymer.dom.flush(); |
| 91 var control = androidAppsPage.$$('#enabled'); |
| 92 assertTrue(!!control); |
| 93 assertFalse(control.disabled); |
| 94 assertTrue(control.checked); |
| 95 var managed = androidAppsPage.$$('#manageApps'); |
| 96 assertTrue(!!managed); |
| 97 assertFalse(managed.hidden); |
62 | 98 |
63 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | 99 MockInteractions.tap(control.$.control); |
64 .then(function() { | 100 cr.webUIListenerCallback( |
65 androidAppsBrowserProxy.setAppReady(false); | 101 'android-apps-info-update', {appReady: false}); |
66 }); | 102 Polymer.dom.flush(); |
67 }); | 103 var dialog = androidAppsPage.$$('#confirmDisableDialog'); |
68 | 104 assertTrue(!!dialog); |
69 test('Enable', function() { | 105 assertTrue(dialog.open); |
70 var button = androidAppsPage.$$('#enable'); | 106 var actionButton = |
71 assertTrue(!!button); | 107 androidAppsPage.$$('dialog paper-button.action-button'); |
72 assertFalse(!!androidAppsPage.$$('.subpage-arrow')); | 108 assertTrue(!!actionButton); |
73 | 109 MockInteractions.tap(actionButton); |
74 MockInteractions.tap(button); | 110 Polymer.dom.flush(); |
75 Polymer.dom.flush(); | 111 assertFalse(control.checked); |
76 assertTrue(androidAppsPage.prefs.arc.enabled.value); | 112 assertTrue(managed.hidden); |
77 | 113 }); |
78 androidAppsBrowserProxy.setAppReady(true); | |
79 Polymer.dom.flush(); | |
80 assertTrue(!!androidAppsPage.$$('.subpage-arrow')); | |
81 }); | |
82 }); | |
83 | |
84 suite('SubPage', function() { | |
85 var subpage; | |
86 | |
87 setup(function() { | |
88 androidAppsPage.prefs = {arc: {enabled: {value: true}}}; | |
89 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | |
90 .then(function() { | |
91 androidAppsBrowserProxy.setAppReady(true); | |
92 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | |
93 Polymer.dom.flush(); | |
94 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | |
95 assertTrue(!!subpage); | |
96 }); | |
97 }); | |
98 | |
99 test('Sanity', function() { | |
100 assertTrue(!!subpage.$$('#manageApps')); | |
101 assertTrue(!!subpage.$$('#remove')); | |
102 }); | |
103 | |
104 test('Disable', function() { | |
105 var dialog = subpage.$$('#confirmDisableDialog'); | |
106 assertTrue(!!dialog); | |
107 assertFalse(dialog.open); | |
108 | |
109 var remove = subpage.$$('#remove'); | |
110 assertTrue(!!remove); | |
111 MockInteractions.tap(remove); | |
112 | |
113 Polymer.dom.flush(); | |
114 assertTrue(dialog.open); | |
115 }); | |
116 }); | |
117 | |
118 suite('Enforced', function() { | |
119 var subpage; | |
120 | |
121 setup(function() { | |
122 androidAppsPage.prefs = { | |
123 arc: { | |
124 enabled: { | |
125 value: true, | |
126 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED | |
127 } | |
128 } | |
129 }; | |
130 return androidAppsBrowserProxy.whenCalled('requestAndroidAppsInfo') | |
131 .then(function() { | |
132 androidAppsBrowserProxy.setAppReady(true); | |
133 MockInteractions.tap(androidAppsPage.$$('#android-apps')); | |
134 Polymer.dom.flush(); | |
135 subpage = androidAppsPage.$$('settings-android-apps-subpage'); | |
136 assertTrue(!!subpage); | |
137 }); | |
138 }); | |
139 | |
140 test('Sanity', function() { | |
141 Polymer.dom.flush(); | |
142 assertTrue(!!subpage.$$('#manageApps')); | |
143 assertFalse(!!subpage.$$('#remove')); | |
144 }); | |
145 }); | 114 }); |
146 }); | 115 }); |
OLD | NEW |