Add navigate test
This commit is contained in:
		
							parent
							
								
									c6c885345e
								
							
						
					
					
						commit
						82aad419a7
					
				
					 6 changed files with 78 additions and 6 deletions
				
			
		
							
								
								
									
										2
									
								
								QA.md
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								QA.md
									
										
									
									
									
								
							|  | @ -31,8 +31,6 @@ The behaviors of the console are tested in [Console section](#consoles). | ||||||
| - [ ] <kbd>H</kbd>, <kbd>L</kbd>: go back and forward in history | - [ ] <kbd>H</kbd>, <kbd>L</kbd>: go back and forward in history | ||||||
| - [ ] <kbd>[</kbd><kbd>[</kbd>, <kbd>]</kbd><kbd>]</kbd>: Open next/prev link in `<link>` tags. | - [ ] <kbd>[</kbd><kbd>[</kbd>, <kbd>]</kbd><kbd>]</kbd>: Open next/prev link in `<link>` tags. | ||||||
| - [ ] <kbd>[</kbd><kbd>[</kbd>, <kbd>]</kbd><kbd>]</kbd>: find prev and next links and open it | - [ ] <kbd>[</kbd><kbd>[</kbd>, <kbd>]</kbd><kbd>]</kbd>: find prev and next links and open it | ||||||
| - [ ] <kbd>g</kbd><kbd>u</kbd>: go to parent directory |  | ||||||
| - [ ] <kbd>g</kbd><kbd>U</kbd>: go to root directory |  | ||||||
| 
 | 
 | ||||||
| #### Misc | #### Misc | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { | import { | ||||||
|   WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET, |   WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET, | ||||||
|   TABS_CREATE, TABS_SELECT_AT, TABS_GET_ZOOM, TABS_SET_ZOOM, |   TABS_CREATE, TABS_SELECT_AT, TABS_GET, TABS_GET_ZOOM, TABS_SET_ZOOM, | ||||||
|   EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, |   EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, | ||||||
|   SCROLL_GET, SCROLL_SET, |   SCROLL_GET, SCROLL_SET, | ||||||
| } from '../shared/messages'; | } from '../shared/messages'; | ||||||
|  | @ -25,6 +25,8 @@ receiveContentMessage((message) => { | ||||||
|       windowId: message.windowId, |       windowId: message.windowId, | ||||||
|       index: message.index, |       index: message.index, | ||||||
|     }); |     }); | ||||||
|  |   case TABS_GET: | ||||||
|  |     return browser.tabs.get(message.tabId); | ||||||
|   case TABS_GET_ZOOM: |   case TABS_GET_ZOOM: | ||||||
|     return browser.tabs.getZoom(message.tabId); |     return browser.tabs.getZoom(message.tabId); | ||||||
|   case TABS_SET_ZOOM: |   case TABS_SET_ZOOM: | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ const create = (props = {}) => { | ||||||
|         if (tab.url !== 'about:blank' && tabId === createdTab.id && |         if (tab.url !== 'about:blank' && tabId === createdTab.id && | ||||||
|             changeInfo.status === 'complete') { |             changeInfo.status === 'complete') { | ||||||
|           browser.tabs.onUpdated.removeListener(callback); |           browser.tabs.onUpdated.removeListener(callback); | ||||||
|           resolve(tab); |           setTimeout(() => resolve(tab), 50) // wait for 50 milliseconds to ensure plugin loaded;
 | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       browser.tabs.onUpdated.addListener(callback); |       browser.tabs.onUpdated.addListener(callback); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { | import { | ||||||
|   TABS_CREATE, TABS_SELECT_AT, TABS_GET_ZOOM, TABS_SET_ZOOM, |   TABS_CREATE, TABS_SELECT_AT, TABS_GET, TABS_GET_ZOOM, TABS_SET_ZOOM, | ||||||
| } from '../shared/messages'; | } from '../shared/messages'; | ||||||
| import * as ipc from './ipc'; | import * as ipc from './ipc'; | ||||||
| 
 | 
 | ||||||
|  | @ -19,6 +19,13 @@ const selectAt = (windowId, index) => { | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | const get = (tabId) => { | ||||||
|  |   return ipc.send({ | ||||||
|  |     type: TABS_GET, | ||||||
|  |     tabId, | ||||||
|  |   }); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| const getZoom = (tabId) => { | const getZoom = (tabId) => { | ||||||
|   return ipc.send({ |   return ipc.send({ | ||||||
|     tabId, |     tabId, | ||||||
|  | @ -34,4 +41,4 @@ const setZoom = (tabId, factor) => { | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export { create, selectAt, getZoom, setZoom }; | export { create, selectAt, get, getZoom, setZoom }; | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ const WINDOWS_REMOVE = 'windows.remove'; | ||||||
| const WINDOWS_GET = 'windows.get'; | const WINDOWS_GET = 'windows.get'; | ||||||
| const TABS_CREATE = 'tabs.create'; | const TABS_CREATE = 'tabs.create'; | ||||||
| const TABS_SELECT_AT = 'tabs.selectAt'; | const TABS_SELECT_AT = 'tabs.selectAt'; | ||||||
|  | const TABS_GET = 'tabs.get'; | ||||||
| const TABS_GET_ZOOM = 'tabs.get.zoom'; | const TABS_GET_ZOOM = 'tabs.get.zoom'; | ||||||
| const TABS_SET_ZOOM = 'tabs.set.zoom'; | const TABS_SET_ZOOM = 'tabs.set.zoom'; | ||||||
| const EVENT_KEYPRESS = 'event.keypress'; | const EVENT_KEYPRESS = 'event.keypress'; | ||||||
|  | @ -21,6 +22,7 @@ export { | ||||||
|   WINDOWS_REMOVE, |   WINDOWS_REMOVE, | ||||||
|   WINDOWS_GET, |   WINDOWS_GET, | ||||||
| 
 | 
 | ||||||
|  |   TABS_GET, | ||||||
|   TABS_CREATE, |   TABS_CREATE, | ||||||
|   TABS_SELECT_AT, |   TABS_SELECT_AT, | ||||||
|   TABS_GET_ZOOM, |   TABS_GET_ZOOM, | ||||||
|  |  | ||||||
							
								
								
									
										63
									
								
								e2e/contents/navigate.test.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								e2e/contents/navigate.test.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,63 @@ | ||||||
|  | import * as windows from "../ambassador/src/client/windows"; | ||||||
|  | import * as tabs from "../ambassador/src/client/tabs"; | ||||||
|  | import * as keys from "../ambassador/src/client/keys"; | ||||||
|  | import * as scrolls from "../ambassador/src/client/scrolls"; | ||||||
|  | 
 | ||||||
|  | const SERVER_URL = "http://localhost:11111"; | ||||||
|  | 
 | ||||||
|  | describe("navigate test", () => { | ||||||
|  |   let targetWindow; | ||||||
|  | 
 | ||||||
|  |   before(() => { | ||||||
|  |     return windows.create().then((win) => { | ||||||
|  |       targetWindow = win; | ||||||
|  |       return tabs.create(targetWindow.id, SERVER_URL); | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   after(() => { | ||||||
|  |     return windows.remove(targetWindow.id); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('goes to parent', () => { | ||||||
|  |     let targetTab; | ||||||
|  |     return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c').then((tab) => { | ||||||
|  |       targetTab = tab; | ||||||
|  |       return keys.press(targetTab.id, 'g'); | ||||||
|  |     }).then(() => { | ||||||
|  |       return keys.press(targetTab.id, 'u'); | ||||||
|  |     }).then(() => { | ||||||
|  |       return tabs.get(targetTab.id); | ||||||
|  |     }).then((tab) => { | ||||||
|  |       expect(tab.url).to.be.equal(SERVER_URL + '/a/b/'); | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('removes hash', () => { | ||||||
|  |     let targetTab; | ||||||
|  |     return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c#navigate').then((tab) => { | ||||||
|  |       targetTab = tab; | ||||||
|  |       return keys.press(targetTab.id, 'g'); | ||||||
|  |     }).then(() => { | ||||||
|  |       return keys.press(targetTab.id, 'u'); | ||||||
|  |     }).then(() => { | ||||||
|  |       return tabs.get(targetTab.id); | ||||||
|  |     }).then((tab) => { | ||||||
|  |       expect(tab.url).to.be.equal(SERVER_URL + '/a/b/c#'); | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('goes to root', () => { | ||||||
|  |     let targetTab; | ||||||
|  |     return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c').then((tab) => { | ||||||
|  |       targetTab = tab; | ||||||
|  |       return keys.press(targetTab.id, 'g'); | ||||||
|  |     }).then(() => { | ||||||
|  |       return keys.press(targetTab.id, 'U', { shiftKey: true }); | ||||||
|  |     }).then(() => { | ||||||
|  |       return tabs.get(targetTab.id); | ||||||
|  |     }).then((tab) => { | ||||||
|  |       expect(tab.url).to.be.equal(SERVER_URL + '/'); | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
		Reference in a new issue