| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {$, by, element} from 'protractor'; | 
					
						
							|  |  |  | import {openBrowser, verifyNoBrowserErrors} from '../../../e2e_util/e2e_util'; | 
					
						
							|  |  |  | import {runBenchmark} from '../../../e2e_util/perf_util'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** List of possible scenarios that should be tested.  */ | 
					
						
							|  |  |  | const SCENARIOS = [ | 
					
						
							| 
									
										
										
										
											2020-01-23 16:45:35 +01:00
										 |  |  |   {optionIndex: 0, id: 'no_styling_involved'}, | 
					
						
							|  |  |  |   {optionIndex: 1, id: 'static_class'}, | 
					
						
							|  |  |  |   {optionIndex: 2, id: 'static_class_with_interpolation'}, | 
					
						
							|  |  |  |   {optionIndex: 3, id: 'class_binding'}, | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |   {optionIndex: 4, id: 'static_class_and_class_binding'}, | 
					
						
							|  |  |  |   {optionIndex: 5, id: 'static_class_and_ngclass_binding'}, | 
					
						
							| 
									
										
										
										
											2020-01-14 18:08:15 +01:00
										 |  |  |   {optionIndex: 6, id: 'static_class_and_ngstyle_binding_and_style_binding'}, | 
					
						
							| 
									
										
										
										
											2020-01-23 16:45:35 +01:00
										 |  |  |   {optionIndex: 7, id: 'static_style'}, | 
					
						
							|  |  |  |   {optionIndex: 8, id: 'style_property_bindings'}, | 
					
						
							|  |  |  |   {optionIndex: 9, id: 'static_style_and_property_binding'}, | 
					
						
							|  |  |  |   {optionIndex: 10, id: 'ng_style_with_units'}, | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('styling benchmark spec', () => { | 
					
						
							|  |  |  |   afterEach(verifyNoBrowserErrors); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   it('should render and interact to update and detect changes', async () => { | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |     openBrowser({url: '/', ignoreBrowserSynchronization: true}); | 
					
						
							|  |  |  |     create(); | 
					
						
							|  |  |  |     const items = element.all(by.css('styling-bindings button')); | 
					
						
							| 
									
										
										
										
											2020-02-03 10:59:39 -08:00
										 |  |  |     expect(await items.count()).toBe(2000); | 
					
						
							|  |  |  |     expect(await items.first().getAttribute('title')).toBe('bar'); | 
					
						
							| 
									
										
										
										
											2020-01-14 14:43:14 +01:00
										 |  |  |     update(); | 
					
						
							| 
									
										
										
										
											2020-02-03 10:59:39 -08:00
										 |  |  |     expect(await items.first().getAttribute('title')).toBe('baz'); | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   it('should render and run noop change detection', async () => { | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |     openBrowser({url: '/', ignoreBrowserSynchronization: true}); | 
					
						
							|  |  |  |     create(); | 
					
						
							|  |  |  |     const items = element.all(by.css('styling-bindings button')); | 
					
						
							| 
									
										
										
										
											2020-02-03 10:59:39 -08:00
										 |  |  |     expect(await items.count()).toBe(2000); | 
					
						
							|  |  |  |     expect(await items.first().getAttribute('title')).toBe('bar'); | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |     detectChanges(); | 
					
						
							| 
									
										
										
										
											2020-02-03 10:59:39 -08:00
										 |  |  |     expect(await items.first().getAttribute('title')).toBe('bar'); | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |   // Create benchmarks for each possible test scenario.
 | 
					
						
							|  |  |  |   SCENARIOS.forEach(({optionIndex, id}) => { | 
					
						
							|  |  |  |     describe(id, () => { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |       it('should run create benchmark', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         await runStylingBenchmark(`styling.${id}.create`, { | 
					
						
							| 
									
										
										
										
											2020-01-14 15:35:36 +01:00
										 |  |  |           work: () => create(), | 
					
						
							|  |  |  |           prepare: () => { | 
					
						
							|  |  |  |             selectScenario(optionIndex); | 
					
						
							|  |  |  |             destroy(); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-01-14 15:35:36 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |       it('should run update benchmark', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         await runStylingBenchmark(`styling.${id}.update`, { | 
					
						
							| 
									
										
										
										
											2020-01-14 14:43:14 +01:00
										 |  |  |           work: () => update(), | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |           prepare: () => { | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |             selectScenario(optionIndex); | 
					
						
							|  |  |  |             create(); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |       it('should run detect changes benchmark', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         await runStylingBenchmark(`styling.${id}.noop_cd`, { | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  |           work: () => detectChanges(), | 
					
						
							|  |  |  |           prepare: () => { | 
					
						
							|  |  |  |             selectScenario(optionIndex); | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |             create(); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2020-02-04 13:53:57 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  | function selectScenario(optionIndex: number) { | 
					
						
							|  |  |  |   // Switch to the current scenario by clicking the corresponding option.
 | 
					
						
							|  |  |  |   element.all(by.tagName('option')).get(optionIndex).click(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  | function create() { | 
					
						
							|  |  |  |   $('#create').click(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 15:35:36 +01:00
										 |  |  | function destroy() { | 
					
						
							|  |  |  |   $('#destroy').click(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 14:43:14 +01:00
										 |  |  | function update() { | 
					
						
							|  |  |  |   $('#update').click(); | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 15:15:09 +01:00
										 |  |  | function detectChanges() { | 
					
						
							|  |  |  |   $('#detect_changes').click(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 18:06:07 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Runs the styling benchmark with the given id and worker. The worker describes | 
					
						
							|  |  |  |  * the actions that should run for preparation and measurement. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function runStylingBenchmark(id: string, worker: {prepare: () => void, work: () => void}) { | 
					
						
							|  |  |  |   return runBenchmark({ | 
					
						
							|  |  |  |     id, | 
					
						
							|  |  |  |     url: '/', | 
					
						
							|  |  |  |     params: [], | 
					
						
							|  |  |  |     ignoreBrowserSynchronization: true, | 
					
						
							|  |  |  |     prepare: worker.prepare, | 
					
						
							|  |  |  |     work: worker.work | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |