| 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 /** @fileoverview Suite of tests for settings-change-picture. */ | |
| 6 | |
| 7 GEN_INCLUDE(['settings_page_browsertest.js']); | |
| 8 | |
| 9 /** | |
| 10 * @constructor | |
| 11 * @extends {SettingsPageBrowserTest} | |
| 12 */ | |
| 13 function SettingsChangePictureBrowserTest() { | |
| 14 } | |
| 15 | |
| 16 SettingsChangePictureBrowserTest.prototype = { | |
| 17 __proto__: SettingsPageBrowserTest.prototype, | |
| 18 | |
| 19 /** @override */ | |
| 20 browsePreload: 'chrome://md-settings/changePicture', | |
| 21 | |
| 22 /** @override */ | |
| 23 preLoad: function() { | |
| 24 SettingsPageBrowserTest.prototype.preLoad.call(this); | |
| 25 | |
| 26 cr.exportPath('settings_test').changePictureNotifyForTest = true; | |
| 27 }, | |
| 28 }; | |
| 29 | |
| 30 // Times out on debug builders and may time out on memory bots because | |
| 31 // the Settings page can take several seconds to load in a Release build | |
| 32 // and several times that in a Debug build. See https://crbug.com/558434. | |
| 33 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); | |
| 34 GEN('#define MAYBE_ChangePicture DISABLED_ChangePicture'); | |
| 35 GEN('#else'); | |
| 36 GEN('#define MAYBE_ChangePicture ChangePicture'); | |
| 37 GEN('#endif'); | |
| 38 | |
| 39 // Runs change picture tests. | |
| 40 TEST_F('SettingsChangePictureBrowserTest', 'MAYBE_ChangePicture', function() { | |
| 41 var basic = this.getPage('basic'); | |
| 42 assertTrue(!!basic); | |
| 43 var peopleSection = this.getSection(basic, 'people'); | |
| 44 assertTrue(!!peopleSection); | |
| 45 var peoplePage = peopleSection.querySelector('settings-people-page'); | |
| 46 assertTrue(!!peoplePage); | |
| 47 var changePicture = peoplePage.$$('settings-change-picture'); | |
| 48 assertTrue(!!changePicture); | |
| 49 var settingsCamera = changePicture.$$('settings-camera'); | |
| 50 assertTrue(!!settingsCamera); | |
| 51 var discardControlBar = changePicture.$.discardControlBar; | |
| 52 assertTrue(!!discardControlBar); | |
| 53 | |
| 54 /** | |
| 55 * Returns a promise that resolves once the selected item is updated. | |
| 56 * @param {function()} action is executed after the listener is set up. | |
| 57 * @return {!Promise} a Promise fulfilled when the selected item changes. | |
| 58 */ | |
| 59 function runAndResolveWhenSelectedItemChanged(action) { | |
| 60 return new Promise(function(resolve, reject) { | |
| 61 var handler = function() { | |
| 62 changePicture.removeEventListener('selected-item_-changed', handler); | |
| 63 resolve(); | |
| 64 }; | |
| 65 changePicture.addEventListener('selected-item_-changed', handler); | |
| 66 action(); | |
| 67 }); | |
| 68 } | |
| 69 | |
| 70 suite('SettingsChangePicturePage', function() { | |
| 71 setup(function() { | |
| 72 // Reset the selected image to nothing. | |
| 73 changePicture.$.selector.selected = -1; | |
| 74 }); | |
| 75 | |
| 76 test('select camera image', function() { | |
| 77 var cameraIcon = changePicture.$.cameraImage; | |
| 78 assertTrue(!!cameraIcon); | |
| 79 | |
| 80 // Force the camera to be absent, even if it's actually present. | |
| 81 cr.webUIListenerCallback('camera-presence-changed', false); | |
| 82 Polymer.dom.flush(); | |
| 83 | |
| 84 expectTrue(cameraIcon.hidden); | |
| 85 expectFalse(settingsCamera.cameraActive); | |
| 86 | |
| 87 cr.webUIListenerCallback('camera-presence-changed', true); | |
| 88 Polymer.dom.flush(); | |
| 89 | |
| 90 expectFalse(cameraIcon.hidden); | |
| 91 expectFalse(settingsCamera.cameraActive); | |
| 92 | |
| 93 MockInteractions.tap(cameraIcon); | |
| 94 | |
| 95 Polymer.dom.flush(); | |
| 96 expectFalse(cameraIcon.hidden); | |
| 97 expectTrue(settingsCamera.cameraActive); | |
| 98 expectEquals('camera', changePicture.selectedItem_.dataset.type); | |
| 99 expectTrue(discardControlBar.hidden); | |
| 100 }); | |
| 101 | |
| 102 test('select profile image', function() { | |
| 103 var profileImage = changePicture.$.profileImage; | |
| 104 assertTrue(!!profileImage); | |
| 105 | |
| 106 return runAndResolveWhenSelectedItemChanged(function() { | |
| 107 MockInteractions.tap(profileImage); | |
| 108 }).then(function() { | |
| 109 Polymer.dom.flush(); | |
| 110 expectEquals('profile', changePicture.selectedItem_.dataset.type); | |
| 111 expectFalse(settingsCamera.cameraActive); | |
| 112 expectTrue(discardControlBar.hidden); | |
| 113 }); | |
| 114 }); | |
| 115 | |
| 116 test('select old images', function() { | |
| 117 // By default there is no old image and the element is hidden. | |
| 118 var oldImage = changePicture.$.oldImage; | |
| 119 assertTrue(!!oldImage); | |
| 120 assertTrue(oldImage.hidden); | |
| 121 | |
| 122 return runAndResolveWhenSelectedItemChanged(function() { | |
| 123 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 124 }).then(function() { | |
| 125 Polymer.dom.flush(); | |
| 126 | |
| 127 // Expect the old image to be selected once an old image is sent via | |
| 128 // the native interface. | |
| 129 expectEquals('old', changePicture.selectedItem_.dataset.type); | |
| 130 expectFalse(oldImage.hidden); | |
| 131 expectFalse(settingsCamera.cameraActive); | |
| 132 expectFalse(discardControlBar.hidden); | |
| 133 }); | |
| 134 }); | |
| 135 | |
| 136 test('select first default image', function() { | |
| 137 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 138 assertTrue(!!firstDefaultImage); | |
| 139 | |
| 140 return runAndResolveWhenSelectedItemChanged(function() { | |
| 141 MockInteractions.tap(firstDefaultImage); | |
| 142 }).then(function() { | |
| 143 Polymer.dom.flush(); | |
| 144 expectEquals('default', changePicture.selectedItem_.dataset.type); | |
| 145 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 146 expectFalse(settingsCamera.cameraActive); | |
| 147 expectTrue(discardControlBar.hidden); | |
| 148 }); | |
| 149 }); | |
| 150 | |
| 151 test('restore image after discard', function() { | |
| 152 var firstDefaultImage = changePicture.$$('img[data-type="default"]'); | |
| 153 assertTrue(!!firstDefaultImage); | |
| 154 var discardOldImage = changePicture.$.discardOldImage; | |
| 155 assertTrue(!!discardOldImage); | |
| 156 | |
| 157 function tapAndVerifyFirstDefaultImage() { | |
| 158 return runAndResolveWhenSelectedItemChanged(function() { | |
| 159 MockInteractions.tap(firstDefaultImage); | |
| 160 }).then(function() { | |
| 161 Polymer.dom.flush(); | |
| 162 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 163 }); | |
| 164 } | |
| 165 | |
| 166 function injectAndVerifyOldImage() { | |
| 167 return runAndResolveWhenSelectedItemChanged(function() { | |
| 168 cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); | |
| 169 }).then(function() { | |
| 170 Polymer.dom.flush(); | |
| 171 expectEquals('old', changePicture.selectedItem_.dataset.type); | |
| 172 }); | |
| 173 } | |
| 174 | |
| 175 function discardImageAndVerifyFirstDefaultImageSelected() { | |
| 176 return runAndResolveWhenSelectedItemChanged(function() { | |
| 177 MockInteractions.tap(discardOldImage); | |
| 178 }).then(function() { | |
| 179 Polymer.dom.flush(); | |
| 180 expectEquals(firstDefaultImage, changePicture.selectedItem_); | |
| 181 }); | |
| 182 } | |
| 183 | |
| 184 return tapAndVerifyFirstDefaultImage() | |
| 185 .then(injectAndVerifyOldImage) | |
| 186 .then(discardImageAndVerifyFirstDefaultImageSelected); | |
| 187 }); | |
| 188 }); | |
| 189 | |
| 190 // Run all registered tests. | |
| 191 mocha.run(); | |
| 192 }); | |
| OLD | NEW |