OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014 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 'use strict'; | |
6 | |
7 /** | |
8 * @type {string} | |
9 * @const | |
10 */ | |
11 var UNTIL_ADDED = 'untilAdded'; | |
12 | |
13 /** | |
14 * @type {string} | |
15 * @const | |
16 */ | |
17 var UNTIL_REMOVED = 'untilRemoved'; | |
18 | |
19 /** | |
20 * Waits for the 'move to profileId' menu to appear or to disappear. | |
21 * @param {string} windowId Window ID. | |
22 * @param {string} profileId Profile ID. | |
23 * @param {string} waitMode UNTIL_ADDED or UNTIL_REMOVED. | |
24 * @return {Promise} Promise to be fulfilled when the menu appears or | |
25 * disappears. | |
26 */ | |
27 function waitForVisitDesktopMenu(windowId, profileId, waitMode) { | |
28 if (waitMode !== UNTIL_ADDED && waitMode !== UNTIL_REMOVED) | |
29 throw new Error('Wait mode is invalid: ' + waitMode); | |
30 return repeatUntil(function() { | |
31 return callRemoteTestUtil('queryAllElements', windowId, ['.visit-desktop']). | |
32 then(function(elements) { | |
33 var found = false; | |
34 for (var i = 0; i < elements.length; i++) { | |
35 if (elements[i].text.indexOf(profileId) !== -1) { | |
36 found = true; | |
37 break; | |
38 } | |
39 } | |
40 if ((waitMode === UNTIL_ADDED && !found) || | |
41 (waitMode === UNTIL_REMOVED && found)) | |
42 return pending( | |
43 'Waiting for the visit desktop menu to %s: ' + | |
44 '%s, but currently it is %j.', | |
45 waitMode === UNTIL_ADDED ? 'contain' : 'exclude', | |
46 profileId, | |
47 elements); | |
48 }); | |
49 }); | |
50 } | |
51 | |
52 testcase.multiProfileBadge = function() { | |
53 var appId; | |
54 StepsRunner.run([ | |
55 function() { | |
56 setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); | |
57 }, | |
58 // Add all users. | |
59 function(inAppId) { | |
60 appId = inAppId; | |
61 chrome.test.sendMessage(JSON.stringify({name: 'addAllUsers'}), | |
62 this.next); | |
63 }, | |
64 // Get the badge element. | |
65 function(json) { | |
66 chrome.test.assertTrue(JSON.parse(json)); | |
67 waitForElement(appId, '#profile-badge').then(this.next); | |
68 }, | |
69 // Verify no badge image is shown yet. Move to other deskop. | |
70 function(element) { | |
71 chrome.test.assertTrue(element.hidden, 'Badge hidden initially'); | |
72 callRemoteTestUtil('visitDesktop', | |
73 appId, | |
74 ['bob@invalid.domain'], | |
75 this.next); | |
76 }, | |
77 // Get the badge element again. | |
78 function(result) { | |
79 chrome.test.assertTrue(result); | |
80 waitForElement(appId, '#profile-badge:not([hidden])').then(this.next); | |
81 }, | |
82 // Verify an image source is filled. Go back to the original desktop | |
83 function(element) { | |
84 callRemoteTestUtil('queryAllElements', | |
85 appId, | |
86 ['#profile-badge', | |
87 null, | |
88 ['background']]).then(this.next); | |
89 }, | |
90 function(elements) { | |
91 chrome.test.assertTrue( | |
92 elements[0].styles.background.indexOf('data:image') !== -1, | |
93 'Badge shown after moving desktop'); | |
94 callRemoteTestUtil('visitDesktop', | |
95 appId, | |
96 ['alice@invalid.domain'], | |
97 this.next); | |
98 }, | |
99 // Wait for #profile-badge element to disappear. | |
100 function(result) { | |
101 chrome.test.assertTrue(result); | |
102 waitForElementLost(appId, '#profile-badge:not([hidden])').then(this.next); | |
103 }, | |
104 // The image is gone. | |
105 function(result) { | |
106 checkIfNoErrorsOccured(this.next); | |
107 } | |
108 ]); | |
109 }; | |
110 | |
111 testcase.multiProfileVisitDesktopMenu = function() { | |
112 var appId; | |
113 StepsRunner.run([ | |
114 function() { | |
115 setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); | |
116 }, | |
117 // Add all users. | |
118 function(inAppId) { | |
119 appId = inAppId; | |
120 chrome.test.sendMessage(JSON.stringify({name: 'addAllUsers'}), | |
121 this.next); | |
122 }, | |
123 // Wait for menu items. Profiles for non-current desktop should appear and | |
124 // the profile for the current desktop (alice) should be hidden. | |
125 function(json) { | |
126 chrome.test.assertTrue(JSON.parse(json)); | |
127 Promise.all([ | |
128 waitForVisitDesktopMenu(appId, 'bob@invalid.domain', UNTIL_ADDED), | |
129 waitForVisitDesktopMenu(appId, 'charlie@invalid.domain', UNTIL_ADDED), | |
130 waitForVisitDesktopMenu(appId, 'alice@invalid.domain', UNTIL_REMOVED) | |
131 ]). | |
132 then(this.next, function(error) { | |
133 chrome.test.fail(error.stack || error); | |
134 }); | |
135 }, | |
136 // Activate the visit desktop menu. | |
137 function() { | |
138 callRemoteTestUtil('runVisitDesktopMenu', | |
139 appId, | |
140 ['bob@invalid.domain'], | |
141 this.next); | |
142 }, | |
143 // Wait for the new menu state. Now 'alice' is shown and 'bob' is hidden. | |
144 function(result) { | |
145 chrome.test.assertTrue(result); | |
146 Promise.all([ | |
147 waitForVisitDesktopMenu(appId, 'bob@invalid.domain', UNTIL_REMOVED), | |
148 waitForVisitDesktopMenu(appId, 'charlie@invalid.domain', UNTIL_ADDED), | |
149 waitForVisitDesktopMenu(appId, 'alice@invalid.domain', UNTIL_ADDED) | |
150 ]). | |
151 then(this.next, function(error) { | |
152 chrome.test.fail(error.stack || error); | |
153 }); | |
154 }, | |
155 // Check that the window owner has indeed been changed. | |
156 function() { | |
157 chrome.test.sendMessage(JSON.stringify({name: 'getWindowOwnerId'}), | |
158 this.next); | |
159 }, | |
160 function(result) { | |
161 chrome.test.assertEq('bob@invalid.domain', result); | |
162 checkIfNoErrorsOccured(this.next); | |
163 } | |
164 ]); | |
165 }; | |
OLD | NEW |