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