| 
									
										
										
										
											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-09-27 17:12:25 -07:00
										 |  |  | import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {Options, ReflectiveInjector, WebDriverExtension} from '../index'; | 
					
						
							| 
									
										
										
										
											2016-10-06 15:10:27 -07:00
										 |  |  | import {isPresent} from '../src/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |   function createExtension(ids: any[], caps: any) { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     return new Promise<any>((res, rej) => { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         res(ReflectiveInjector | 
					
						
							|  |  |  |                 .resolveAndCreate([ | 
					
						
							| 
									
										
										
										
											2016-10-04 15:57:37 -07:00
										 |  |  |                   ids.map((id) => ({provide: id, useValue: new MockExtension(id)})), | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |                   {provide: Options.CAPABILITIES, useValue: caps}, | 
					
						
							|  |  |  |                   WebDriverExtension.provideFirstSupported(ids) | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |                 ]) | 
					
						
							|  |  |  |                 .get(WebDriverExtension)); | 
					
						
							|  |  |  |       } catch (e) { | 
					
						
							|  |  |  |         rej(e); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-06-26 15:59:18 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |   describe('WebDriverExtension.provideFirstSupported', () => { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |     it('should provide the extension that matches the capabilities', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:00:07 -07:00
										 |  |  |          createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => { | 
					
						
							|  |  |  |            expect(m.id).toEqual('m2'); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |     it('should throw if there is no match', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |          createExtension(['m1'], {'browser': 'm2'}).catch((err) => { | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |            expect(isPresent(err)).toBe(true); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockExtension extends WebDriverExtension { | 
					
						
							| 
									
										
										
										
											2016-08-26 16:34:08 -07:00
										 |  |  |   constructor(public id: string) { super(); } | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 16:47:54 -07:00
										 |  |  |   supports(capabilities: {[key: string]: any}): boolean { | 
					
						
							| 
									
										
										
										
											2016-10-06 15:10:27 -07:00
										 |  |  |     return capabilities['browser'] === this.id; | 
					
						
							| 
									
										
										
										
											2015-05-27 14:57:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } |