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