| 
									
										
										
										
											2016-08-03 15:00:07 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | import {convertPerfProfileToEvents} from '../../src/firefox_extension/lib/parser_util'; | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | function assertEventsEqual(actualEvents: any[], expectedEvents: any[]) { | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |   expect(actualEvents.length == expectedEvents.length); | 
					
						
							|  |  |  |   for (var i = 0; i < actualEvents.length; ++i) { | 
					
						
							|  |  |  |     var actualEvent = actualEvents[i]; | 
					
						
							|  |  |  |     var expectedEvent = expectedEvents[i]; | 
					
						
							|  |  |  |     for (var key in actualEvent) { | 
					
						
							|  |  |  |       expect(actualEvent[key]).toEqual(expectedEvent[key]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('convertPerfProfileToEvents', function() { | 
					
						
							|  |  |  |     it('should convert single instantaneous event', function() { | 
					
						
							|  |  |  |       var profileData = { | 
					
						
							|  |  |  |         threads: [ | 
					
						
							|  |  |  |           {samples: [{time: 1, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}]} | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							|  |  |  |       assertEventsEqual(perfEvents, [{ph: 'X', ts: 1, name: 'script'}]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should convert single non-instantaneous event', function() { | 
					
						
							|  |  |  |       var profileData = { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         threads: [{ | 
					
						
							|  |  |  |           samples: [ | 
					
						
							|  |  |  |             {time: 1, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 2, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 100, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]} | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         }] | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |       }; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |       assertEventsEqual( | 
					
						
							|  |  |  |           perfEvents, [{ph: 'B', ts: 1, name: 'script'}, {ph: 'E', ts: 100, name: 'script'}]); | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should convert multiple instantaneous events', function() { | 
					
						
							|  |  |  |       var profileData = { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         threads: [{ | 
					
						
							|  |  |  |           samples: [ | 
					
						
							|  |  |  |             {time: 1, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 2, frames: [{location: 'PresShell::Paint'}]} | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         }] | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |       }; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |       assertEventsEqual( | 
					
						
							|  |  |  |           perfEvents, [{ph: 'X', ts: 1, name: 'script'}, {ph: 'X', ts: 2, name: 'render'}]); | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should convert multiple mixed events', function() { | 
					
						
							|  |  |  |       var profileData = { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         threads: [{ | 
					
						
							|  |  |  |           samples: [ | 
					
						
							|  |  |  |             {time: 1, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 2, frames: [{location: 'PresShell::Paint'}]}, | 
					
						
							|  |  |  |             {time: 5, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 10, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]} | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         }] | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |       }; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							|  |  |  |       assertEventsEqual(perfEvents, [ | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         {ph: 'X', ts: 1, name: 'script'}, {ph: 'X', ts: 2, name: 'render'}, | 
					
						
							|  |  |  |         {ph: 'B', ts: 5, name: 'script'}, {ph: 'E', ts: 10, name: 'script'} | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should add args to gc events', function() { | 
					
						
							|  |  |  |       var profileData = {threads: [{samples: [{time: 1, frames: [{location: 'forceGC'}]}]}]}; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							|  |  |  |       assertEventsEqual(perfEvents, [{ph: 'X', ts: 1, name: 'gc', args: {usedHeapSize: 0}}]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should skip unknown events', function() { | 
					
						
							|  |  |  |       var profileData = { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |         threads: [{ | 
					
						
							|  |  |  |           samples: [ | 
					
						
							|  |  |  |             {time: 1, frames: [{location: 'FirefoxDriver.prototype.executeScript'}]}, | 
					
						
							|  |  |  |             {time: 2, frames: [{location: 'foo'}]} | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         }] | 
					
						
							| 
									
										
										
										
											2015-06-08 13:51:10 -07:00
										 |  |  |       }; | 
					
						
							|  |  |  |       var perfEvents = convertPerfProfileToEvents(profileData); | 
					
						
							|  |  |  |       assertEventsEqual(perfEvents, [{ph: 'X', ts: 1, name: 'script'}]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; |