Chromium Code Reviews| Index: chrome/test/data/webui/settings/change_picture_browsertest_chromeos.js |
| diff --git a/chrome/test/data/webui/settings/change_picture_browsertest_chromeos.js b/chrome/test/data/webui/settings/change_picture_browsertest_chromeos.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f33a040eb2781de0c0fe47f6ee42a770b187210b |
| --- /dev/null |
| +++ b/chrome/test/data/webui/settings/change_picture_browsertest_chromeos.js |
| @@ -0,0 +1,135 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +changePictureOptions = { |
| + /** |
| + * True if property changes should fire events for testing purposes. |
| + * @type {boolean} |
| + */ |
| + notifyPropertyChangesForTest: true, |
| +}; |
| + |
| +/** @fileoverview Suite of tests for settings-change-picture. */ |
| + |
| +GEN_INCLUDE(['settings_page_browsertest.js']); |
| + |
| +/** |
| + * @constructor |
| + * @extends {SettingsPageBrowserTest} |
| +*/ |
| +function SettingsChangePictureBrowserTest() { |
| +} |
| + |
| +SettingsChangePictureBrowserTest.prototype = { |
| + __proto__: SettingsPageBrowserTest.prototype, |
| + |
| + /** @override */ |
| + browsePreload: 'chrome://md-settings/changePicture', |
| +}; |
| + |
| +// Times out on debug builders and may time out on memory bots because |
| +// the Settings page can take several seconds to load in a Release build |
| +// and several times that in a Debug build. See https://crbug.com/558434. |
| +GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); |
| +GEN('#define MAYBE_ChangePicture DISABLED_ChangePicture'); |
| +GEN('#else'); |
| +GEN('#define MAYBE_ChangePicture ChangePicture'); |
| +GEN('#endif'); |
| + |
| +// Runs change picture tests. |
| +TEST_F('SettingsChangePictureBrowserTest', 'MAYBE_ChangePicture', function() { |
| + var basic = this.getPage('basic'); |
| + assertTrue(!!basic); |
| + var peopleSection = this.getSection(basic, 'people'); |
| + assertTrue(!!peopleSection); |
| + var peoplePage = peopleSection.querySelector('settings-people-page'); |
| + assertTrue(!!peoplePage); |
| + var changePicture = peoplePage.$$('settings-change-picture'); |
| + assertTrue(!!changePicture); |
| + |
| + /** |
| + * Registers a callback to be called once when the selected image URL changes. |
| + * @param {!function()} callback |
| + */ |
| + function onceSelectedImageUrlChanged(callback) { |
| + var handler = function() { |
|
dpapad
2016/01/19 19:44:59
function whenSelectedImageUrlChanged() {
return
tommycli
2016/01/20 00:30:27
Done.
|
| + callback(); |
| + changePicture.removeEventListener('selected-image-url_-changed', |
| + handler); |
| + }; |
| + changePicture.addEventListener('selected-image-url_-changed', handler); |
| + }; |
| + |
| + suite('SettingsChangePicturePage', function() { |
| + setup(function() { |
| + // Reset the selected image to nothing. |
| + changePicture.selectedImageUrl_ = ''; |
| + }); |
| + |
| + test('select profile image', function() { |
| + var profileImage = changePicture.$$('#profile-image'); |
| + assertTrue(!!profileImage); |
| + |
| + return new Promise(function(resolve) { |
| + // Expect the profile image to be selected. |
| + onceSelectedImageUrlChanged(function() { |
|
dpapad
2016/01/19 19:44:59
No need to pass your assertions as a callback. See
tommycli
2016/01/20 00:30:27
Done. That is much better.
|
| + expectEquals(changePicture.selectedImageUrl_, |
| + changePicture.profileImageUrl_); |
| + |
| + Polymer.dom.flush(); |
| + expectTrue(profileImage.active); |
| + |
| + resolve(); |
| + }); |
| + MockInteractions.tap(profileImage); |
| + }); |
| + }); |
| + |
| + test('select old images', function() { |
| + // By default there is no old image. |
| + var oldImage = changePicture.$$('#old-image'); |
| + assertFalse(!!oldImage); |
| + |
| + return new Promise(function(resolve) { |
| + // Expect the old image to be selected once an old image is sent via |
| + // the native interface. |
| + onceSelectedImageUrlChanged(function() { |
| + expectEquals(changePicture.selectedImageUrl_, |
| + changePicture.oldImageUrl_); |
| + |
| + Polymer.dom.flush(); |
| + var oldImage = changePicture.$$('#old-image'); |
| + assertTrue(!!oldImage); |
| + expectTrue(oldImage.active); |
| + |
| + resolve(); |
| + }); |
| + settings.ChangePicturePage.receiveOldImage('fake-old-image.jpg'); |
| + }); |
| + }); |
| + |
| + test('select first default image', function() { |
| + var firstDefaultImage = changePicture.$$('.default-image'); |
| + console.log(firstDefaultImage); |
| + assertTrue(!!firstDefaultImage); |
| + |
| + return new Promise(function(resolve) { |
| + // Expect the first default image to be selected. |
| + onceSelectedImageUrlChanged(function() { |
| + expectEquals(changePicture.selectedImageUrl_, |
| + changePicture.defaultImages_[0].url); |
| + |
| + Polymer.dom.flush(); |
| + expectTrue(firstDefaultImage.active); |
| + |
| + resolve(); |
| + }); |
| + MockInteractions.tap(firstDefaultImage); |
| + }); |
| + }); |
| + }); |
| + |
| + // Run all registered tests. |
| + mocha.run(); |
| +}); |