| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2017 Google Inc. All rights reserved. | 
					
						
							| 
									
										
										
										
											2019-12-10 13:21:51 -08:00
										 |  |  |  * Modifications copyright (c) Microsoft Corporation. | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 16:36:36 -08:00
										 |  |  | const { makeUserDataDir, removeUserDataDir } = require('./utils'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 13:20:13 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @type {PageTestSuite} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-12 17:58:00 -07:00
										 |  |  | module.exports.describe = function ({ testRunner, expect, defaultBrowserOptions, browserType, WEBKIT }) { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   const {describe, xdescribe, fdescribe} = testRunner; | 
					
						
							| 
									
										
										
										
											2019-12-19 15:47:35 -08:00
										 |  |  |   const {it, fit, xit, dit} = testRunner; | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 01:10:48 +00:00
										 |  |  |   describe('launchPersistentContext()', function() { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     beforeEach(async state => { | 
					
						
							| 
									
										
										
										
											2020-02-05 16:36:36 -08:00
										 |  |  |       state.userDataDir = await makeUserDataDir(); | 
					
						
							| 
									
										
										
										
											2020-03-12 17:58:00 -07:00
										 |  |  |       state.browserContext = await browserType.launchPersistentContext(state.userDataDir, defaultBrowserOptions); | 
					
						
							| 
									
										
										
										
											2020-02-05 12:41:55 -08:00
										 |  |  |       state.page = await state.browserContext.newPage(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     afterEach(async state => { | 
					
						
							| 
									
										
										
										
											2020-02-05 12:41:55 -08:00
										 |  |  |       await state.browserContext.close(); | 
					
						
							|  |  |  |       delete state.browserContext; | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       delete state.page; | 
					
						
							| 
									
										
										
										
											2020-02-05 16:36:36 -08:00
										 |  |  |       await removeUserDataDir(state.userDataDir); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-01-29 14:39:43 -03:00
										 |  |  |     it('context.cookies() should work', async({page, server}) => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       await page.goto(server.EMPTY_PAGE); | 
					
						
							|  |  |  |       await page.evaluate(() => { | 
					
						
							|  |  |  |         document.cookie = 'username=John Doe'; | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-02-10 10:41:45 -08:00
										 |  |  |       expect(await page.context().cookies()).toEqual([{ | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         name: 'username', | 
					
						
							|  |  |  |         value: 'John Doe', | 
					
						
							|  |  |  |         domain: 'localhost', | 
					
						
							|  |  |  |         path: '/', | 
					
						
							|  |  |  |         expires: -1, | 
					
						
							|  |  |  |         httpOnly: false, | 
					
						
							|  |  |  |         secure: false, | 
					
						
							|  |  |  |         sameSite: 'None', | 
					
						
							|  |  |  |       }]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-12 17:32:33 -07:00
										 |  |  |     it('context.addCookies() should work', async({page, server}) => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-03-12 17:32:33 -07:00
										 |  |  |       await page.context().addCookies([{ | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |         url: server.EMPTY_PAGE, | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         name: 'username', | 
					
						
							|  |  |  |         value: 'John Doe' | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |       }]); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       expect(await page.evaluate(() => document.cookie)).toBe('username=John Doe'); | 
					
						
							| 
									
										
										
										
											2020-02-10 10:41:45 -08:00
										 |  |  |       expect(await page.context().cookies()).toEqual([{ | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         name: 'username', | 
					
						
							|  |  |  |         value: 'John Doe', | 
					
						
							|  |  |  |         domain: 'localhost', | 
					
						
							|  |  |  |         path: '/', | 
					
						
							|  |  |  |         expires: -1, | 
					
						
							|  |  |  |         httpOnly: false, | 
					
						
							|  |  |  |         secure: false, | 
					
						
							|  |  |  |         sameSite: 'None', | 
					
						
							|  |  |  |       }]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:06:09 -07:00
										 |  |  |     it('context.clearCookies() should work', async({page, server}) => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-03-12 17:32:33 -07:00
										 |  |  |       await page.context().addCookies([{ | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |         url: server.EMPTY_PAGE, | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         name: 'cookie1', | 
					
						
							|  |  |  |         value: '1' | 
					
						
							|  |  |  |       }, { | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |         url: server.EMPTY_PAGE, | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         name: 'cookie2', | 
					
						
							|  |  |  |         value: '2' | 
					
						
							|  |  |  |       }]); | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |       expect(await page.evaluate('document.cookie')).toBe('cookie1=1; cookie2=2'); | 
					
						
							| 
									
										
										
										
											2020-02-10 10:41:45 -08:00
										 |  |  |       await page.context().clearCookies(); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:06:09 -07:00
										 |  |  |       await page.reload(); | 
					
						
							|  |  |  |       expect(await page.context().cookies([])).toEqual([]); | 
					
						
							| 
									
										
										
										
											2019-11-26 14:29:21 -08:00
										 |  |  |       expect(await page.evaluate('document.cookie')).toBe(''); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; |