Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #10100 - paulrouget:historyOnLocationChange, r=paulrouget
Add history information to mozbrowserlocationchange event This is a change in the Browser API itself. Before, on `mozbrowserlocationchange`, we would call `getCanGoBack()` and `getCanGoForward()`. Two asynchronous methods called on an event, which doesn't make much sense, especially because we already know on `mozbrowserlocationchange` if we can go back/forward. So here I'm adding 2 new properties to the event to tell if the iframe can go back/forward. The way `event.detail` is defined also changed. Before, `event.detail` was a string (the new uri), now it's an object (`{uri:String,canGoBack:bool,canGoForward:bool}`). This is one of the design flaw of the early Browser API: not using objects for the detail property, making it hard to extend the event payload. So that makes this event not backward compatible. We can: 1. just don't care. It's up to the client to test if event.detail is a string or not if it needs to be compatible with Gecko 2. fix it in Gecko. The client will still have to test `event.detail` to make it compatible with older version of gecko 3. rename `mozbrowserlocationchange` to something else (`mozbrowserlocationchange2` ?) Please advise. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10100) <!-- Reviewable:end -->
- Loading branch information
Showing
8 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/wpt/mozilla/tests/mozilla/mozbrowser/mozbrowserlocationchange_event.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<head> | ||
<title>Browser API; mozbrowserlocationchange event</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
async_test(function(t) { | ||
|
||
var url1 = "data:,1"; | ||
var url2 = "data:,2"; | ||
var url3 = "data:,3"; | ||
|
||
var received_events = [] | ||
var expected_events = [ | ||
url1, false, false, | ||
url2, true, false, | ||
url3, true, false, | ||
url2, true, true, | ||
url1, false, true, | ||
url2, true, true, | ||
url3, true, false, | ||
]; | ||
|
||
var iframe = document.createElement("iframe"); | ||
iframe.mozbrowser = "true"; | ||
iframe.src = url1; | ||
|
||
var actions = [ | ||
function() {iframe.src = url2}, | ||
function() {iframe.src = url3}, | ||
function() {iframe.goBack()}, | ||
function() {iframe.goBack()}, | ||
function() {iframe.goForward()}, | ||
function() {iframe.goForward()}, | ||
]; | ||
|
||
var action_idx = 0; | ||
|
||
iframe.addEventListener("mozbrowserlocationchange", e => { | ||
received_events.push(e.detail.uri); | ||
received_events.push(e.detail.canGoBack); | ||
received_events.push(e.detail.canGoForward); | ||
|
||
if (action_idx < actions.length) { | ||
actions[action_idx++](); | ||
} else { | ||
assert_array_equals(received_events, expected_events); | ||
t.done(); | ||
} | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
|
||
}); | ||
|
||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters