| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  | import { | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { StringMap, ListWrapper } from 'angular2/src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2015-02-25 17:43:33 -08:00
										 |  |  | import { isPresent, StringWrapper } from 'angular2/src/facade/lang'; | 
					
						
							|  |  |  | import { PromiseWrapper } from 'angular2/src/facade/async'; | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 09:23:09 -08:00
										 |  |  | import { WebDriverExtension, bind, Injector, Options } from 'benchpress/common'; | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   function createExtension(ids, caps) { | 
					
						
							| 
									
										
										
										
											2015-04-10 17:05:31 -07:00
										 |  |  |     return Injector.resolveAndCreate([ | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       ListWrapper.map(ids, (id) => bind(id).toValue(new MockExtension(id)) ), | 
					
						
							|  |  |  |       bind(Options.CAPABILITIES).toValue(caps), | 
					
						
							|  |  |  |       WebDriverExtension.bindTo(ids) | 
					
						
							|  |  |  |     ]).asyncGet(WebDriverExtension); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('WebDriverExtension.bindTo', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should bind the extension that matches the capabilities', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then( (m) => { | 
					
						
							|  |  |  |         expect(m.id).toEqual('m2'); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should throw if there is no match', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-25 17:43:33 -08:00
										 |  |  |       PromiseWrapper.catchError( | 
					
						
							|  |  |  |         createExtension(['m1'], {'browser': 'm2'}), | 
					
						
							|  |  |  |         (err) => { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |           expect(isPresent(err)).toBe(true); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |           async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-25 17:43:33 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockExtension extends WebDriverExtension { | 
					
						
							|  |  |  |   id:string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor(id) { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |     this.id = id; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   supports(capabilities:StringMap):boolean { | 
					
						
							|  |  |  |     return StringWrapper.equals(capabilities['browser'], this.id); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |