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 function getSelectedItem() { | |
| 89 return changePicture.$$('#selector .iron-selected'); | |
| 90 } | |
| 91 | |
| 92 suiteSetup(function() { | |
| 93 loadTimeData.overrideValues({ | |
| 94 profilePhoto: 'Fake Profile Photo description', | |
| 95 }); | |
| 96 }); | |
| 97 | |
| 98 setup(function() { | |
| 99 browserProxy = new TestChangePictureBrowserProxy(); | |
| 100 settings.ChangePictureBrowserProxyImpl.instance_ = browserProxy; | |
| 101 PolymerTest.clearBody(); | |
| 102 changePicture = document.createElement('settings-change-picture'); | |
| 103 document.body.appendChild(changePicture); | |
| 104 | |
| 105 settingsCamera = changePicture.$$('settings-camera'); | |
| 106 assertTrue(!!settingsCamera); | |
| 107 discardControlBar = changePicture.$.discardControlBar; | |
| 108 assertTrue(!!discardControlBar); | |
| 109 | |
| 110 return browserProxy.whenCalled('initialize').then(function() { | |
| 111 Polymer.dom.flush(); | |
| 112 }); | |
| 113 }); | |
| 114 | |
| 115 teardown(function() { changePicture.remove(); }); | |
| 116 | |
| 117 test('ChangePictureSelectCamera', function() { | |
| 118 var cameraIcon = changePicture.$.cameraImage; | |
| 119 assertTrue(!!cameraIcon); | |
| 120 | |
| 121 // Force the camera to be absent, even if it's actually present. | |
| 122 cr.webUIListenerCallback('camera-presence-changed', false); | |
| 123 Polymer.dom.flush(); | |
| 124 | |
| 125 expectTrue(cameraIcon.hidden); | |
| 126 expectFalse(settingsCamera.cameraActive); | |
| 127 | |
| 128 cr.webUIListenerCallback('camera-presence-changed', true); | |
| 129 Polymer.dom.flush(); | |
| 130 | |
| 131 expectFalse(cameraIcon.hidden); | |
| 132 expectFalse(settingsCamera.cameraActive); | |
| 133 | |
| 134 MockInteractions.tap(cameraIcon); | |
| 135 | |
| 136 Polymer.dom.flush(); | |
| 137 expectFalse(cameraIcon.hidden); | |
| 138 expectTrue(settingsCamera.cameraActive); | |
| 139 expectEquals('camera', getSelectedItem().dataset.type); | |
| 140 expectTrue(discardControlBar.hidden); | |
| 141 }); | |
| 142 | |
| 143 test('ChangePictureProfileImage', function() { | |
| 144 var profileImage = changePicture.$.profileImage; | |
| 145 assertTrue(!!profileImage); | |
| 146 | |
| 147 expectEquals(null, getSelectedItem()); | |
| 148 MockInteractions.tap(profileImage); | |
| 149 | |
| 150 return browserProxy.whenCalled('selectProfileImage').then(function() { | |
| 151 Polymer.dom.flush(); | |
| 152 | |
| 153 expectEquals('profile', getSelectedItem().dataset.type); | |
| 154 expectFalse(settingsCamera.cameraActive); | |
| 155 expectTrue(discardControlBar.hidden); | |
| 156 }); | |
| 157 }); | |
| 158 | |
| 159 test('ChangePictureOldImage', function() { | |
| 160 // By default there is no old image and the element is hidden. | |
| 161 var oldImage = changePicture.$.oldImage; | |
| 162 assertTrue(!!oldImage); | |
| 163 assertTrue(oldImage.hidden); | |
| 164 | |
| 165 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 166 Polymer.dom.flush(); | |
| 167 | |
| 168 // Expect the old image to be selected once an old image is sent via | |
| 169 // the native interface. | |
| 170 expectEquals('old', getSelectedItem().dataset.type); | |
|
dpapad
2016/04/11 19:36:38
Nit: Could we create an enum to hold the possible
tommycli
2016/04/11 21:20:52
Will do (in separate CL)
| |
| 171 expectFalse(oldImage.hidden); | |
| 172 expectFalse(settingsCamera.cameraActive); | |
| 173 expectFalse(discardControlBar.hidden); | |
| 174 }); | |
| 175 | |
| 176 test('ChangePictureSelectFirstDefaultImage', function() { | |
| 177 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 178 assertTrue(!!firstDefaultImage); | |
| 179 | |
| 180 MockInteractions.tap(firstDefaultImage); | |
| 181 | |
| 182 return browserProxy.whenCalled('selectDefaultImage').then( | |
| 183 function(args) { | |
| 184 expectEquals('chrome://theme/1.png', args[0]); | |
| 185 | |
| 186 Polymer.dom.flush(); | |
| 187 expectEquals('default', getSelectedItem().dataset.type); | |
| 188 expectEquals(firstDefaultImage, getSelectedItem()); | |
| 189 expectFalse(settingsCamera.cameraActive); | |
| 190 expectTrue(discardControlBar.hidden); | |
| 191 }); | |
| 192 }); | |
| 193 | |
| 194 test('ChangePictureRestoreImageAfterDiscard', function() { | |
| 195 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 196 assertTrue(!!firstDefaultImage); | |
| 197 var discardOldImage = changePicture.$.discardOldImage; | |
| 198 assertTrue(!!discardOldImage); | |
| 199 | |
| 200 MockInteractions.tap(firstDefaultImage); | |
| 201 | |
| 202 return browserProxy.whenCalled('selectDefaultImage').then(function() { | |
| 203 Polymer.dom.flush(); | |
| 204 expectEquals(firstDefaultImage, getSelectedItem()); | |
| 205 | |
| 206 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 207 | |
| 208 Polymer.dom.flush(); | |
| 209 expectEquals('old', getSelectedItem().dataset.type); | |
| 210 | |
| 211 MockInteractions.tap(discardOldImage); | |
| 212 | |
| 213 Polymer.dom.flush(); | |
| 214 expectEquals(firstDefaultImage, getSelectedItem()); | |
| 215 }); | |
| 216 }); | |
| 217 }); | |
| 218 } | |
| 219 | |
| 220 return { | |
| 221 registerTests: function() { | |
| 222 registerChangePictureTests(); | |
| 223 }, | |
| 224 }; | |
| 225 }); | |
| OLD | NEW |