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 cr.define('settings_test', function() { |
| 25 var changePictureOptions = { |
| 26 /** |
| 27 * True if property changes should fire events for testing purposes. |
| 28 * @type {boolean} |
| 29 */ |
| 30 notifyPropertyChangesForTest: true, |
| 31 }; |
| 32 return {changePictureOptions: changePictureOptions}; |
| 33 }); |
| 34 } |
| 35 }; |
| 36 |
| 37 // Times out on debug builders and may time out on memory bots because |
| 38 // the Settings page can take several seconds to load in a Release build |
| 39 // and several times that in a Debug build. See https://crbug.com/558434. |
| 40 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); |
| 41 GEN('#define MAYBE_ChangePicture DISABLED_ChangePicture'); |
| 42 GEN('#else'); |
| 43 GEN('#define MAYBE_ChangePicture ChangePicture'); |
| 44 GEN('#endif'); |
| 45 |
| 46 // Runs change picture tests. |
| 47 TEST_F('SettingsChangePictureBrowserTest', 'MAYBE_ChangePicture', function() { |
| 48 var basic = this.getPage('basic'); |
| 49 assertTrue(!!basic); |
| 50 var peopleSection = this.getSection(basic, 'people'); |
| 51 assertTrue(!!peopleSection); |
| 52 var peoplePage = peopleSection.querySelector('settings-people-page'); |
| 53 assertTrue(!!peoplePage); |
| 54 var changePicture = peoplePage.$$('settings-change-picture'); |
| 55 assertTrue(!!changePicture); |
| 56 |
| 57 /** |
| 58 * Registers a callback to be called once when the selected image URL changes. |
| 59 * @param {!function()} callback |
| 60 */ |
| 61 function whenSelectedImageUrlChanged() { |
| 62 return new Promise(function(resolve, reject) { |
| 63 var handler = function() { |
| 64 changePicture.removeEventListener('selected-image-url_-changed', |
| 65 handler); |
| 66 resolve(); |
| 67 }; |
| 68 changePicture.addEventListener('selected-image-url_-changed', handler); |
| 69 }); |
| 70 } |
| 71 |
| 72 suite('SettingsChangePicturePage', function() { |
| 73 setup(function() { |
| 74 // Reset the selected image to nothing. |
| 75 changePicture.selectedImageUrl_ = ''; |
| 76 }); |
| 77 |
| 78 test('select profile image', function() { |
| 79 var profileImage = changePicture.$$('#profile-image'); |
| 80 assertTrue(!!profileImage); |
| 81 |
| 82 MockInteractions.tap(profileImage); |
| 83 |
| 84 return whenSelectedImageUrlChanged().then(function() { |
| 85 expectEquals(changePicture.selectedImageUrl_, |
| 86 changePicture.profileImageUrl_); |
| 87 |
| 88 Polymer.dom.flush(); |
| 89 expectTrue(profileImage.active); |
| 90 }); |
| 91 }); |
| 92 |
| 93 test('select old images', function() { |
| 94 // By default there is no old image. |
| 95 var oldImage = changePicture.$$('#old-image'); |
| 96 assertFalse(!!oldImage); |
| 97 |
| 98 // The promise must start listening for the property change before |
| 99 // we make the fake API call. |
| 100 var promise = whenSelectedImageUrlChanged(); |
| 101 |
| 102 settings.ChangePicturePage.receiveOldImage('fake-old-image.jpg'); |
| 103 |
| 104 return promise.then(function() { |
| 105 // Expect the old image to be selected once an old image is sent via |
| 106 // the native interface. |
| 107 expectEquals(changePicture.selectedImageUrl_, |
| 108 changePicture.oldImageUrl_); |
| 109 |
| 110 Polymer.dom.flush(); |
| 111 var oldImage = changePicture.$$('#old-image'); |
| 112 assertTrue(!!oldImage); |
| 113 expectTrue(oldImage.active); |
| 114 }); |
| 115 }); |
| 116 |
| 117 test('select first default image', function() { |
| 118 var firstDefaultImage = changePicture.$$('.default-image'); |
| 119 console.log(firstDefaultImage); |
| 120 assertTrue(!!firstDefaultImage); |
| 121 |
| 122 MockInteractions.tap(firstDefaultImage); |
| 123 |
| 124 return whenSelectedImageUrlChanged().then(function() { |
| 125 // Expect the first default image to be selected. |
| 126 expectEquals(changePicture.selectedImageUrl_, |
| 127 changePicture.defaultImages_[0].url); |
| 128 |
| 129 Polymer.dom.flush(); |
| 130 expectTrue(firstDefaultImage.active); |
| 131 }); |
| 132 }); |
| 133 }); |
| 134 |
| 135 // Run all registered tests. |
| 136 mocha.run(); |
| 137 }); |
OLD | NEW |