forked from mirrors/gecko-dev
		
	Bug 1853883 - [bidi] Implement network.failRequest command r=webdriver-reviewers,necko-reviewers,jesup,whimboo
Depends on D197652 Differential Revision: https://phabricator.services.mozilla.com/D197653
This commit is contained in:
		
							parent
							
								
									b409a08fb3
								
							
						
					
					
						commit
						0ad981249f
					
				
					 3 changed files with 61 additions and 29 deletions
				
			
		|  | @ -1420,6 +1420,8 @@ interface nsILoadInfo : nsISupports | ||||||
|   const uint32_t BLOCKING_REASON_NOT_SAME_ORIGIN = 5000; |   const uint32_t BLOCKING_REASON_NOT_SAME_ORIGIN = 5000; | ||||||
|   // The reason used when an extension cancels the request via the WebRequest api. |   // The reason used when an extension cancels the request via the WebRequest api. | ||||||
|   const uint32_t BLOCKING_REASON_EXTENSION_WEBREQUEST = 6000; |   const uint32_t BLOCKING_REASON_EXTENSION_WEBREQUEST = 6000; | ||||||
|  |   // The reason used when a request is cancelled via WebDriver BiDi network interception. | ||||||
|  |   const uint32_t BLOCKING_REASON_WEBDRIVER_BIDI = 7000; | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * If the request associated with this load info was blocked by some of |    * If the request associated with this load info was blocked by some of | ||||||
|  |  | ||||||
|  | @ -462,6 +462,53 @@ class NetworkModule extends Module { | ||||||
|     resolveBlockedEvent(); |     resolveBlockedEvent(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    * Fails a request that is blocked by a network intercept. | ||||||
|  |    * | ||||||
|  |    * @param {object=} options | ||||||
|  |    * @param {string} options.request | ||||||
|  |    *     The id of the blocked request that should be continued. | ||||||
|  |    * | ||||||
|  |    * @throws {InvalidArgumentError} | ||||||
|  |    *     Raised if an argument is of an invalid type or value. | ||||||
|  |    * @throws {NoSuchRequestError} | ||||||
|  |    *     Raised if the request id does not match any request in the blocked | ||||||
|  |    *     requests map. | ||||||
|  |    */ | ||||||
|  |   async failRequest(options = {}) { | ||||||
|  |     this.assertExperimentalCommandsEnabled("network.failRequest"); | ||||||
|  |     const { request: requestId } = options; | ||||||
|  | 
 | ||||||
|  |     lazy.assert.string( | ||||||
|  |       requestId, | ||||||
|  |       `Expected "request" to be a string, got ${requestId}` | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     if (!this.#blockedRequests.has(requestId)) { | ||||||
|  |       throw new lazy.error.NoSuchRequestError( | ||||||
|  |         `Blocked request with id ${requestId} not found` | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const { phase, request, resolveBlockedEvent } = | ||||||
|  |       this.#blockedRequests.get(requestId); | ||||||
|  | 
 | ||||||
|  |     if (phase === InterceptPhase.AuthRequired) { | ||||||
|  |       throw new lazy.error.InvalidArgumentError( | ||||||
|  |         `Expected blocked request not to be in "authRequired" phase` | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const wrapper = ChannelWrapper.get(request); | ||||||
|  |     wrapper.resume(); | ||||||
|  |     wrapper.cancel( | ||||||
|  |       Cr.NS_ERROR_ABORT, | ||||||
|  |       Ci.nsILoadInfo.BLOCKING_REASON_WEBDRIVER_BIDI | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     resolveBlockedEvent(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   /** |   /** | ||||||
|    * Removes an existing network intercept. |    * Removes an existing network intercept. | ||||||
|    * |    * | ||||||
|  | @ -575,6 +622,10 @@ class NetworkModule extends Module { | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   #getSuspendMarkerText(requestData, phase) { | ||||||
|  |     return `Request (id: ${requestData.request}) suspended by WebDriver BiDi in ${phase} phase`; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   #getNetworkIntercepts(event, requestData) { |   #getNetworkIntercepts(event, requestData) { | ||||||
|     const intercepts = []; |     const intercepts = []; | ||||||
| 
 | 
 | ||||||
|  | @ -809,7 +860,10 @@ class NetworkModule extends Module { | ||||||
|     if (beforeRequestSentEvent.isBlocked) { |     if (beforeRequestSentEvent.isBlocked) { | ||||||
|       // TODO: Requests suspended in beforeRequestSent still reach the server at
 |       // TODO: Requests suspended in beforeRequestSent still reach the server at
 | ||||||
|       // the moment. https://bugzilla.mozilla.org/show_bug.cgi?id=1849686
 |       // the moment. https://bugzilla.mozilla.org/show_bug.cgi?id=1849686
 | ||||||
|       requestChannel.suspend(); |       const wrapper = ChannelWrapper.get(requestChannel); | ||||||
|  |       wrapper.suspend( | ||||||
|  |         this.#getSuspendMarkerText(requestData, "beforeRequestSent") | ||||||
|  |       ); | ||||||
| 
 | 
 | ||||||
|       this.#addBlockedRequest( |       this.#addBlockedRequest( | ||||||
|         beforeRequestSentEvent.request.request, |         beforeRequestSentEvent.request.request, | ||||||
|  | @ -982,7 +1036,10 @@ class NetworkModule extends Module { | ||||||
|       protocolEventName === "network.responseStarted" && |       protocolEventName === "network.responseStarted" && | ||||||
|       responseEvent.isBlocked |       responseEvent.isBlocked | ||||||
|     ) { |     ) { | ||||||
|       requestChannel.suspend(); |       const wrapper = ChannelWrapper.get(requestChannel); | ||||||
|  |       wrapper.suspend( | ||||||
|  |         this.#getSuspendMarkerText(requestData, "responseStarted") | ||||||
|  |       ); | ||||||
| 
 | 
 | ||||||
|       this.#addBlockedRequest( |       this.#addBlockedRequest( | ||||||
|         responseEvent.request.request, |         responseEvent.request.request, | ||||||
|  |  | ||||||
|  | @ -1,27 +0,0 @@ | ||||||
| [invalid.py] |  | ||||||
|   [test_params_request_invalid_phase] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_type[None\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_type[False\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_type[42\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_type[value3\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_type[value4\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_value[\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_invalid_value[foo\]] |  | ||||||
|     expected: FAIL |  | ||||||
| 
 |  | ||||||
|   [test_params_request_no_such_request] |  | ||||||
|     expected: FAIL |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Julian Descottes
						Julian Descottes