Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: chrome/test/data/webui/settings/change_picture_browsertest_chromeos.js

Issue 1615093003: Settings People Revamp: Switch Change Picture to use iron-selector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0073-settings-add-preview-pic-and-camera-button
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/people_page/compiled_resources.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @fileoverview Suite of tests for settings-change-picture. */ 5 /** @fileoverview Suite of tests for settings-change-picture. */
6 6
7 GEN_INCLUDE(['settings_page_browsertest.js']); 7 GEN_INCLUDE(['settings_page_browsertest.js']);
8 8
9 /** 9 /**
10 * @constructor 10 * @constructor
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 var basic = this.getPage('basic'); 48 var basic = this.getPage('basic');
49 assertTrue(!!basic); 49 assertTrue(!!basic);
50 var peopleSection = this.getSection(basic, 'people'); 50 var peopleSection = this.getSection(basic, 'people');
51 assertTrue(!!peopleSection); 51 assertTrue(!!peopleSection);
52 var peoplePage = peopleSection.querySelector('settings-people-page'); 52 var peoplePage = peopleSection.querySelector('settings-people-page');
53 assertTrue(!!peoplePage); 53 assertTrue(!!peoplePage);
54 var changePicture = peoplePage.$$('settings-change-picture'); 54 var changePicture = peoplePage.$$('settings-change-picture');
55 assertTrue(!!changePicture); 55 assertTrue(!!changePicture);
56 56
57 /** 57 /**
58 * Registers a callback to be called once when the selected image URL changes. 58 * Returns a promise that resolves once the selected item is updated.
59 * @param {!function()} callback 59 * @param {function()} action is executed after the listener is set up.
60 * @return {!Promise} a Promise fulfilled when the selected item changes.
60 */ 61 */
61 function whenSelectedImageUrlChanged() { 62 function runAndResolveWhenSelectedItemChanged(action) {
62 return new Promise(function(resolve, reject) { 63 return new Promise(function(resolve, reject) {
63 var handler = function() { 64 var handler = function() {
64 changePicture.removeEventListener('selected-image-url_-changed', 65 changePicture.removeEventListener('selected-item_-changed', handler);
65 handler);
66 resolve(); 66 resolve();
67 }; 67 };
68 changePicture.addEventListener('selected-image-url_-changed', handler); 68 changePicture.addEventListener('selected-item_-changed', handler);
69 action();
69 }); 70 });
70 } 71 }
71 72
72 suite('SettingsChangePicturePage', function() { 73 suite('SettingsChangePicturePage', function() {
73 setup(function() { 74 setup(function() {
74 // Reset the selected image to nothing. 75 // Reset the selected image to nothing.
75 changePicture.selectedImageUrl_ = ''; 76 changePicture.$.selector.selected = -1;
76 }); 77 });
77 78
78 test('select camera image', function() { 79 test('select camera image', function() {
79 var cameraImage = changePicture.$$('#camera-image'); 80 var cameraImage = changePicture.$$('img[data-type="camera"]');
80 assertTrue(!!cameraImage); 81 assertTrue(!!cameraImage);
81 82
82 assertFalse(changePicture.cameraActive_);
83 expectFalse(changePicture.$.previewImage.hidden); 83 expectFalse(changePicture.$.previewImage.hidden);
84 84
85 MockInteractions.tap(cameraImage); 85 MockInteractions.tap(cameraImage);
86 86
87 Polymer.dom.flush(); 87 Polymer.dom.flush();
88 88
89 expectTrue(changePicture.cameraActive_); 89 expectEquals('camera', changePicture.selectedItem_.dataset.type);
90 expectTrue(changePicture.$.previewImage.hidden); 90 expectTrue(changePicture.$.previewImage.hidden);
91 }); 91 });
92 92
93 test('select profile image', function() { 93 test('select profile image', function() {
94 var profileImage = changePicture.$$('#profile-image'); 94 var profileImage = changePicture.$$('img[data-type="profile"]');
95 assertTrue(!!profileImage); 95 assertTrue(!!profileImage);
96 96
97 MockInteractions.tap(profileImage); 97 return runAndResolveWhenSelectedItemChanged(function() {
98 98 MockInteractions.tap(profileImage);
99 return whenSelectedImageUrlChanged().then(function() { 99 }).then(function() {
100 expectEquals(changePicture.selectedImageUrl_,
101 changePicture.profileImageUrl_);
102
103 Polymer.dom.flush(); 100 Polymer.dom.flush();
104 expectTrue(profileImage.active); 101 expectEquals('profile', changePicture.selectedItem_.dataset.type);
105 expectFalse(changePicture.$.previewImage.hidden); 102 expectFalse(changePicture.$.previewImage.hidden);
106 }); 103 });
107 }); 104 });
108 105
109 test('select old images', function() { 106 test('select old images', function() {
110 // By default there is no old image. 107 // By default there is no old image and the element is hidden.
111 var oldImage = changePicture.$$('#old-image'); 108 var oldImage = changePicture.$$('img[data-type="old"]');
112 assertFalse(!!oldImage); 109 assertTrue(!!oldImage);
110 assertTrue(oldImage.hidden);
113 111
114 // The promise must start listening for the property change before 112 return runAndResolveWhenSelectedItemChanged(function() {
115 // we make the fake API call. 113 settings.ChangePicturePage.receiveOldImage('fake-old-image.jpg');
116 var promise = whenSelectedImageUrlChanged(); 114 }).then(function() {
115 Polymer.dom.flush();
117 116
118 settings.ChangePicturePage.receiveOldImage('fake-old-image.jpg');
119
120 return promise.then(function() {
121 // Expect the old image to be selected once an old image is sent via 117 // Expect the old image to be selected once an old image is sent via
122 // the native interface. 118 // the native interface.
123 expectEquals(changePicture.selectedImageUrl_, 119 expectEquals('old', changePicture.selectedItem_.dataset.type);
124 changePicture.oldImageUrl_); 120 expectFalse(oldImage.hidden);
125
126 Polymer.dom.flush();
127 var oldImage = changePicture.$$('#old-image');
128 assertTrue(!!oldImage);
129 expectTrue(oldImage.active);
130 expectFalse(changePicture.$.previewImage.hidden); 121 expectFalse(changePicture.$.previewImage.hidden);
131 }); 122 });
132 }); 123 });
133 124
134 test('select first default image', function() { 125 test('select first default image', function() {
135 var firstDefaultImage = changePicture.$$('.default-image'); 126 var firstDefaultImage = changePicture.$$('img[data-type="default"]');
136 assertTrue(!!firstDefaultImage); 127 assertTrue(!!firstDefaultImage);
137 128
138 MockInteractions.tap(firstDefaultImage); 129 return runAndResolveWhenSelectedItemChanged(function() {
139 130 MockInteractions.tap(firstDefaultImage);
140 return whenSelectedImageUrlChanged().then(function() { 131 }).then(function() {
141 // Expect the first default image to be selected.
142 expectEquals(changePicture.selectedImageUrl_,
143 changePicture.defaultImages_[0].url);
144
145 Polymer.dom.flush(); 132 Polymer.dom.flush();
146 expectTrue(firstDefaultImage.active); 133 expectEquals('default', changePicture.selectedItem_.dataset.type);
134 expectEquals(firstDefaultImage, changePicture.selectedItem_);
147 expectFalse(changePicture.$.previewImage.hidden); 135 expectFalse(changePicture.$.previewImage.hidden);
148 }); 136 });
149 }); 137 });
150 }); 138 });
151 139
152 // Run all registered tests. 140 // Run all registered tests.
153 mocha.run(); 141 mocha.run();
154 }); 142 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/people_page/compiled_resources.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698