OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * @suppress {checkTypes} | 6 * @suppress {checkTypes} |
7 * | 7 * |
8 * @fileoverview | 8 * @fileoverview |
9 * Browser test for the scenario below: | 9 * Browser test for the scenario below: |
10 * 1. Resize the client window to various sizes and verify the existence of | 10 * 1. Resize the client window to various sizes and verify the existence of |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 } | 46 } |
47 | 47 |
48 // Verify that scrollbars are added/removed correctly on the home screen. | 48 // Verify that scrollbars are added/removed correctly on the home screen. |
49 this.verifyHomeScreenScrollbars_() | 49 this.verifyHomeScreenScrollbars_() |
50 .then(browserTest.pass, browserTest.fail); | 50 .then(browserTest.pass, browserTest.fail); |
51 }; | 51 }; |
52 | 52 |
53 | 53 |
54 /** | 54 /** |
55 * Verify the test cases for the home-screen. | 55 * Verify the test cases for the home-screen. |
56 * @return {Promise} | |
Jamie
2015/02/18 00:51:33
Does Promise support a resolution type? In this ca
garykac
2015/02/18 02:06:49
Promise<boolean> works (as in, jscompile accepts i
| |
56 */ | 57 */ |
57 browserTest.Scrollbars.prototype.verifyHomeScreenScrollbars_ = function() { | 58 browserTest.Scrollbars.prototype.verifyHomeScreenScrollbars_ = function() { |
58 // Note that, due to crbug.com/240772, if the window already has | 59 // Note that, due to crbug.com/240772, if the window already has |
59 // scroll-bars, they will not be removed if the window size is | 60 // scroll-bars, they will not be removed if the window size is |
60 // increased by less than the scroll-bar width. We work around that | 61 // increased by less than the scroll-bar width. We work around that |
61 // when connected to a host because we know how big the content is | 62 // when connected to a host because we know how big the content is |
62 // (in fact, testing this work-around is the main motivation for | 63 // (in fact, testing this work-around is the main motivation for |
63 // writing this test), but it's not worth it for the home screen, | 64 // writing this test), but it's not worth it for the home screen, |
64 // so make the window large not to require scrollbars before each test. | 65 // so make the window large not to require scrollbars before each test. |
65 var tooWide = this.CONTENT_WIDTH_ + 100; | 66 var tooWide = this.CONTENT_WIDTH_ + 100; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 120 |
120 | 121 |
121 /** | 122 /** |
122 * Returns whether or not horizontal and vertical scroll-bars are expected | 123 * Returns whether or not horizontal and vertical scroll-bars are expected |
123 * and visible. To do this, it performs a hit-test close to the right and | 124 * and visible. To do this, it performs a hit-test close to the right and |
124 * bottom edges of the scroller <div>; since the content of that <div> fills | 125 * bottom edges of the scroller <div>; since the content of that <div> fills |
125 * it completely, the hit-test will return the content unless there is a | 126 * it completely, the hit-test will return the content unless there is a |
126 * scroll-bar visible on the corresponding edge, in which case it will return | 127 * scroll-bar visible on the corresponding edge, in which case it will return |
127 * the scroller <div> itself. | 128 * the scroller <div> itself. |
128 * | 129 * |
130 * @return {{horizontal: boolean, vertical:boolean}} | |
129 * @private | 131 * @private |
130 */ | 132 */ |
131 browserTest.Scrollbars.prototype.getScrollbarState_ = function() { | 133 browserTest.Scrollbars.prototype.getScrollbarState_ = function() { |
132 var rect = this.scroller_.getBoundingClientRect(); | 134 var rect = this.scroller_.getBoundingClientRect(); |
133 var rightElement = document.elementFromPoint( | 135 var rightElement = document.elementFromPoint( |
134 rect.right - 1, (rect.top + rect.bottom) / 2); | 136 rect.right - 1, (rect.top + rect.bottom) / 2); |
135 var bottomElement = document.elementFromPoint( | 137 var bottomElement = document.elementFromPoint( |
136 (rect.left + rect.right) / 2, rect.bottom - 1); | 138 (rect.left + rect.right) / 2, rect.bottom - 1); |
137 return { | 139 return { |
138 horizontal: bottomElement === this.scroller_, | 140 horizontal: bottomElement === this.scroller_, |
139 vertical: rightElement === this.scroller_ | 141 vertical: rightElement === this.scroller_ |
140 }; | 142 }; |
141 }; | 143 }; |
142 | 144 |
143 | 145 |
144 /** | 146 /** |
145 * Returns a promise that resolves if the scroll-bar state is as expected, or | 147 * Returns a promise that resolves if the scroll-bar state is as expected, or |
146 * rejects otherwise. | 148 * rejects otherwise. |
147 * | 149 * |
150 * @param {boolean} horizontalExpected | |
151 * @param {boolean} verticalExpected | |
152 * @return {Promise} | |
148 * @private | 153 * @private |
149 */ | 154 */ |
150 browserTest.Scrollbars.prototype.verifyScrollbarState_ = | 155 browserTest.Scrollbars.prototype.verifyScrollbarState_ = |
151 function(horizontalExpected, verticalExpected) { | 156 function(horizontalExpected, verticalExpected) { |
152 var scrollbarState = this.getScrollbarState_(); | 157 var scrollbarState = this.getScrollbarState_(); |
153 if (scrollbarState.horizontal && !horizontalExpected) { | 158 if (scrollbarState.horizontal && !horizontalExpected) { |
154 return Promise.reject(new Error( | 159 return Promise.reject(new Error( |
155 'Horizontal scrollbar present but not expected.')); | 160 'Horizontal scrollbar present but not expected.')); |
156 } else if (!scrollbarState.horizontal && horizontalExpected) { | 161 } else if (!scrollbarState.horizontal && horizontalExpected) { |
157 return Promise.reject(new Error( | 162 return Promise.reject(new Error( |
158 'Horizontal scrollbar expected but not present.')); | 163 'Horizontal scrollbar expected but not present.')); |
159 } else if (scrollbarState.vertical && !verticalExpected) { | 164 } else if (scrollbarState.vertical && !verticalExpected) { |
160 return Promise.reject(new Error( | 165 return Promise.reject(new Error( |
161 'Vertical scrollbar present but not expected.')); | 166 'Vertical scrollbar present but not expected.')); |
162 } else if (!scrollbarState.vertical && verticalExpected) { | 167 } else if (!scrollbarState.vertical && verticalExpected) { |
163 return Promise.reject(new Error( | 168 return Promise.reject(new Error( |
164 'Vertical scrollbar expected but not present.')); | 169 'Vertical scrollbar expected but not present.')); |
165 } | 170 } |
166 return Promise.resolve(); | 171 return Promise.resolve(); |
167 }; | 172 }; |
168 | 173 |
169 | 174 |
170 /** | 175 /** |
171 * @private | 176 * @param {number} width |
177 * @param {number} height | |
172 * @return {Promise} A promise that will be fulfilled when the window has | 178 * @return {Promise} A promise that will be fulfilled when the window has |
173 * been resized and it's safe to test scroll-bar visibility. | 179 * been resized and it's safe to test scroll-bar visibility. |
180 * @private | |
174 */ | 181 */ |
175 browserTest.Scrollbars.prototype.resize_ = function(width, height) { | 182 browserTest.Scrollbars.prototype.resize_ = function(width, height) { |
176 var win = chrome.app.window.current(); | 183 var win = chrome.app.window.current(); |
177 win.resizeTo(width, height); | 184 win.resizeTo(width, height); |
178 // Chrome takes a while to update the scroll-bars, so don't resolve | 185 // Chrome takes a while to update the scroll-bars, so don't resolve |
179 // immediately. Waiting for the onBoundsChanged event would be cleaner, | 186 // immediately. Waiting for the onBoundsChanged event would be cleaner, |
180 // but isn't reliable. | 187 // but isn't reliable. |
181 return base.Promise.sleep(500); | 188 return base.Promise.sleep(500); |
182 }; | 189 }; |
183 | 190 |
184 | 191 |
185 /** | 192 /** |
186 * @private | 193 * @param {number} width |
194 * @param {number} height | |
195 * @param {boolean} horizontalExpected | |
196 * @param {boolean} verticalExpected | |
187 * @return {Promise} A promise that will be fulfilled when the window has | 197 * @return {Promise} A promise that will be fulfilled when the window has |
188 * been resized and it's safe to test scroll-bar visibility. | 198 * been resized and it's safe to test scroll-bar visibility. |
199 * @private | |
189 */ | 200 */ |
190 browserTest.Scrollbars.prototype.resizeAndVerifyScroll_ = | 201 browserTest.Scrollbars.prototype.resizeAndVerifyScroll_ = |
191 function(width, height, horizontalExpected, verticalExpected) { | 202 function(width, height, horizontalExpected, verticalExpected) { |
192 return this.resize_(width, height).then( | 203 return this.resize_(width, height).then( |
193 this.verifyScrollbarState_.bind( | 204 this.verifyScrollbarState_.bind( |
194 this, horizontalExpected, verticalExpected)); | 205 this, horizontalExpected, verticalExpected)); |
195 }; | 206 }; |
OLD | NEW |