Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('settings_people_page_change_picture', function() { | |
| 6 /** | |
| 7 * @constructor | |
| 8 * @implements {settings.ChangePictureBrowserProxy} | |
| 9 * @extends {settings.TestBrowserProxy} | |
| 10 */ | |
| 11 var TestChangePictureBrowserProxy = function() { | |
| 12 settings.TestBrowserProxy.call(this, [ | |
| 13 'initialize', | |
| 14 'selectDefaultImage', | |
| 15 'selectOldImage', | |
| 16 'selectProfileImage', | |
| 17 'photoTaken', | |
| 18 'chooseFile', | |
| 19 ]); | |
| 20 }; | |
| 21 | |
| 22 TestChangePictureBrowserProxy.prototype = { | |
| 23 __proto__: settings.TestBrowserProxy.prototype, | |
| 24 | |
| 25 /** @override */ | |
| 26 initialize: function() { | |
| 27 cr.webUIListenerCallback('profile-image-changed', | |
| 28 'fake-profile-image-url', | |
| 29 false /* selected */); | |
| 30 | |
| 31 var fakeDefaultImages = [ | |
| 32 { | |
| 33 author: 'Author1', | |
| 34 title: 'Title1', | |
| 35 url: 'chrome://theme/1.png', | |
| 36 website: 'http://foo1.com', | |
| 37 }, | |
| 38 { | |
| 39 author: 'Author2', | |
| 40 title: 'Title2', | |
| 41 url: 'chrome://theme/2.png', | |
| 42 website: 'http://foo2.com', | |
| 43 }, | |
| 44 ]; | |
| 45 cr.webUIListenerCallback('default-images-changed', fakeDefaultImages); | |
| 46 | |
| 47 this.methodCalled('initialize'); | |
| 48 }, | |
| 49 | |
| 50 /** @override */ | |
| 51 selectDefaultImage: function(imageUrl) { | |
| 52 cr.webUIListenerCallback('selected-image-changed', imageUrl); | |
| 53 this.methodCalled('selectDefaultImage', [imageUrl]); | |
| 54 }, | |
| 55 | |
| 56 /** @override */ | |
| 57 selectOldImage: function() { | |
| 58 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 59 this.methodCalled('selectOldImage'); | |
| 60 }, | |
| 61 | |
| 62 /** @override */ | |
| 63 selectProfileImage: function() { | |
| 64 cr.webUIListenerCallback('profile-image-changed', | |
| 65 'fake-profile-image-url', | |
| 66 true /* selected */); | |
| 67 this.methodCalled('selectProfileImage'); | |
| 68 }, | |
| 69 | |
| 70 /** @override */ | |
| 71 photoTaken: function() { | |
| 72 this.methodCalled('photoTaken'); | |
| 73 }, | |
| 74 | |
| 75 /** @override */ | |
| 76 chooseFile: function() { | |
| 77 this.methodCalled('chooseFile'); | |
| 78 }, | |
| 79 }; | |
| 80 | |
| 81 function registerChangePictureTests() { | |
| 82 suite('ChangePictureTests', function() { | |
| 83 var changePicture = null; | |
| 84 var browserProxy = null; | |
| 85 var settingsCamera = null; | |
| 86 var discardControlBar = null; | |
| 87 | |
| 88 suiteSetup(function() { | |
| 89 loadTimeData.overrideValues({ | |
| 90 profilePhoto: 'Fake Profile Photo description', | |
| 91 }); | |
| 92 }); | |
| 93 | |
| 94 setup(function() { | |
| 95 browserProxy = new TestChangePictureBrowserProxy(); | |
| 96 settings.ChangePictureBrowserProxyImpl.instance_ = browserProxy; | |
| 97 PolymerTest.clearBody(); | |
| 98 changePicture = document.createElement('settings-change-picture'); | |
| 99 document.body.appendChild(changePicture); | |
| 100 | |
| 101 settingsCamera = changePicture.$$('settings-camera'); | |
| 102 assertTrue(!!settingsCamera); | |
| 103 discardControlBar = changePicture.$.discardControlBar; | |
| 104 assertTrue(!!discardControlBar); | |
|
dpapad
2016/04/09 00:16:35
Could we move the following which is repeated at t
tommycli
2016/04/11 19:09:57
Done. I did not know that was even an option. The
| |
| 105 }); | |
| 106 | |
| 107 teardown(function() { changePicture.remove(); }); | |
| 108 | |
| 109 test('ChangePictureSelectCamera', function() { | |
| 110 return browserProxy.whenCalled('initialize').then(function() { | |
| 111 Polymer.dom.flush(); | |
| 112 | |
| 113 var cameraIcon = changePicture.$.cameraImage; | |
| 114 assertTrue(!!cameraIcon); | |
| 115 | |
| 116 // Force the camera to be absent, even if it's actually present. | |
| 117 cr.webUIListenerCallback('camera-presence-changed', false); | |
| 118 Polymer.dom.flush(); | |
| 119 | |
| 120 expectTrue(cameraIcon.hidden); | |
| 121 expectFalse(settingsCamera.cameraActive); | |
| 122 | |
| 123 cr.webUIListenerCallback('camera-presence-changed', true); | |
| 124 Polymer.dom.flush(); | |
| 125 | |
| 126 expectFalse(cameraIcon.hidden); | |
| 127 expectFalse(settingsCamera.cameraActive); | |
| 128 | |
| 129 MockInteractions.tap(cameraIcon); | |
| 130 | |
| 131 Polymer.dom.flush(); | |
| 132 expectFalse(cameraIcon.hidden); | |
| 133 expectTrue(settingsCamera.cameraActive); | |
| 134 expectEquals('camera', changePicture.selectedItem_.dataset.type); | |
|
dpapad
2016/04/09 00:16:35
Is there a way we can achieve the same assertion w
tommycli
2016/04/11 19:09:57
Done.
| |
| 135 expectTrue(discardControlBar.hidden); | |
| 136 }); | |
| 137 }); | |
| 138 | |
| 139 test('ChangePictureProfileImage', function() { | |
| 140 return browserProxy.whenCalled('initialize').then(function() { | |
| 141 Polymer.dom.flush(); | |
| 142 | |
| 143 var profileImage = changePicture.$.profileImage; | |
| 144 assertTrue(!!profileImage); | |
| 145 | |
| 146 expectEquals(null, changePicture.selectedItem_); | |
| 147 MockInteractions.tap(profileImage); | |
| 148 | |
| 149 return browserProxy.whenCalled('selectProfileImage').then(function() { | |
| 150 Polymer.dom.flush(); | |
| 151 | |
| 152 expectEquals('profile', changePicture.selectedItem_.dataset.type); | |
| 153 expectFalse(settingsCamera.cameraActive); | |
| 154 expectTrue(discardControlBar.hidden); | |
| 155 }); | |
| 156 }); | |
| 157 }); | |
| 158 | |
| 159 test('ChangePictureOldImage', function() { | |
| 160 return browserProxy.whenCalled('initialize').then(function() { | |
| 161 Polymer.dom.flush(); | |
| 162 | |
| 163 // By default there is no old image and the element is hidden. | |
| 164 var oldImage = changePicture.$.oldImage; | |
| 165 assertTrue(!!oldImage); | |
| 166 assertTrue(oldImage.hidden); | |
| 167 | |
| 168 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 169 Polymer.dom.flush(); | |
| 170 | |
| 171 // Expect the old image to be selected once an old image is sent via | |
| 172 // the native interface. | |
| 173 expectEquals('old', changePicture.selectedItem_.dataset.type); | |
| 174 expectFalse(oldImage.hidden); | |
| 175 expectFalse(settingsCamera.cameraActive); | |
| 176 expectFalse(discardControlBar.hidden); | |
| 177 }) | |
| 178 }); | |
| 179 | |
| 180 test('ChangePictureSelectFirstDefaultImage', function() { | |
| 181 return browserProxy.whenCalled('initialize').then(function() { | |
| 182 Polymer.dom.flush(); | |
| 183 | |
| 184 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 185 assertTrue(!!firstDefaultImage); | |
| 186 | |
| 187 MockInteractions.tap(firstDefaultImage); | |
| 188 | |
| 189 return browserProxy.whenCalled('selectDefaultImage').then( | |
| 190 function(args) { | |
| 191 expectEquals('chrome://theme/1.png', args[0]); | |
| 192 | |
| 193 Polymer.dom.flush(); | |
| 194 expectEquals('default', | |
| 195 changePicture.selectedItem_.dataset.type); | |
| 196 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 197 expectFalse(settingsCamera.cameraActive); | |
| 198 expectTrue(discardControlBar.hidden); | |
| 199 }); | |
| 200 }); | |
| 201 }); | |
| 202 | |
| 203 test('ChangePictureRestoreImageAfterDiscard', function() { | |
| 204 return browserProxy.whenCalled('initialize').then(function() { | |
| 205 Polymer.dom.flush(); | |
| 206 | |
| 207 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 208 assertTrue(!!firstDefaultImage); | |
| 209 var discardOldImage = changePicture.$.discardOldImage; | |
| 210 assertTrue(!!discardOldImage); | |
| 211 | |
| 212 MockInteractions.tap(firstDefaultImage); | |
| 213 | |
| 214 return browserProxy.whenCalled('selectDefaultImage').then(function() { | |
| 215 Polymer.dom.flush(); | |
| 216 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 217 | |
| 218 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 219 | |
| 220 Polymer.dom.flush(); | |
| 221 expectEquals('old', changePicture.selectedItem_.dataset.type); | |
| 222 | |
| 223 MockInteractions.tap(discardOldImage); | |
| 224 | |
| 225 Polymer.dom.flush(); | |
| 226 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 227 }); | |
| 228 }); | |
| 229 }); | |
| 230 }); | |
| 231 } | |
| 232 | |
| 233 return { | |
| 234 registerTests: function() { | |
| 235 registerChangePictureTests(); | |
| 236 }, | |
| 237 }; | |
| 238 }); | |
| OLD | NEW |