Skip to content

Commit

Permalink
blink: PopState and NavigateEvent init + ship hasUAVisualTransition
Browse files Browse the repository at this point in the history
This change implements the following:

- Fix PopStateEvent and NavigateEvent initializers to take
  hasUAVisualTransition. See spec change at
  whatwg/html#9628.

- Ship hasUAVisualTransition. See approved I2S at:
  https://groups.google.com/a/chromium.org/g/blink-dev/c/OTGqhEZ7aug/m/tDfjCG4KAQAJ

R=vmpstr@chromium.org

Fixed: 1470029
Change-Id: I2385cd87df8d823e40d6de88efcc348de168370c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4811335
Auto-Submit: Khushal Sagar <khushalsagar@chromium.org>
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Commit-Queue: Khushal Sagar <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187983}
  • Loading branch information
khushalsagar authored and Chromium LUCI CQ committed Aug 24, 2023
1 parent bfdf883 commit daad5dc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion third_party/blink/renderer/core/events/pop_state_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ PopStateEvent* PopStateEvent::Create(
PopStateEvent::PopStateEvent(ScriptState* script_state,
const AtomicString& type,
const PopStateEventInit* initializer)
: Event(type, initializer) {
: Event(type, initializer),
has_ua_visual_transition_(initializer->hasUAVisualTransition()) {
v8::Isolate* isolate = script_state->GetIsolate();
if (initializer->hasState()) {
state_.Set(isolate, initializer->state().V8Value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

dictionary PopStateEventInit : EventInit {
any state = null;
boolean hasUAVisualTransition = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ NavigateEvent::NavigateEvent(ExecutionContext* context,
info_(init->hasInfo()
? init->info()
: ScriptValue(context->GetIsolate(),
v8::Undefined(context->GetIsolate()))) {
v8::Undefined(context->GetIsolate()))),
has_ua_visual_transition_(init->hasUAVisualTransition()) {
CHECK(IsA<LocalDOMWindow>(context));
CHECK(!controller_ || controller_->signal() == signal_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dictionary NavigateEventInit : EventInit {
FormData? formData = null;
DOMString? downloadRequest = null;
any info;
boolean hasUAVisualTransition = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@
},
{
name: "HasUAVisualTransition",
status: "test",
status: "stable",
base_feature: "none",
},
// HighlightAPI's custom highlights use HighlightInheritance's behavior even
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@
assert_equals(popStateEvent.state, null, "the PopStateEvent.state");
}, "Initial value of PopStateEvent.state must be null");

test(function () {
var popStateEvent = new PopStateEvent("popstate");
assert_false(popStateEvent.hasUAVisualTransition, "the PopStateEvent.hasUAVisualTransition");
}, "Initial value of PopStateEvent.hasUAVisualTransition must be false");

test(function () {
var state = history.state;
var data;
var hasUAVisualTransition = false;
window.addEventListener('popstate', function (e) {
data = e.state;
hasUAVisualTransition = e.hasUAVisualTransition;
});
window.dispatchEvent(new PopStateEvent('popstate', {
'state': {testdata:true}
'state': {testdata:true},
'hasUAVisualTransition': true
}));
assert_true(data.testdata,'state data was corrupted');
assert_equals(history.state, state, "history.state was NOT set by dispatching the event");
assert_true(hasUAVisualTransition, 'hasUAVisualTransition not set correctly');
}, 'Dispatching a synthetic PopStateEvent');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
const formData = new FormData();
const signal = (new AbortController()).signal;
const downloadRequest = "abc";
const hasUAVisualTransition = true;

const event = new NavigateEvent("navigate", {
navigationType: "replace",
Expand All @@ -59,7 +60,8 @@
signal,
formData,
downloadRequest,
info
info,
hasUAVisualTransition
});

assert_equals(event.navigationType, "replace");
Expand All @@ -71,6 +73,7 @@
assert_equals(event.formData, formData);
assert_equals(event.downloadRequest, downloadRequest);
assert_equals(event.info, info);
assert_equals(event.hasUAVisualTransition, hasUAVisualTransition);
});
history.pushState(2, null, "#2");
}, "all properties are reflected back");
Expand All @@ -93,4 +96,16 @@
});
history.pushState(3, null, "#3");
}, "defaults are as expected");

async_test(t => {
navigation.onnavigate = t.step_func_done(e => {
const event = new NavigateEvent("navigate", {
destination: e.destination,
signal: (new AbortController()).signal
});

assert_false(event.hasUAVisualTransition);
});
history.pushState(3, null, "#3");
}, "hasUAVisualTransition is default false");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5555,6 +5555,7 @@ interface NavigateEvent : Event
getter destination
getter downloadRequest
getter formData
getter hasUAVisualTransition
getter hashChange
getter info
getter navigationType
Expand Down Expand Up @@ -6323,6 +6324,7 @@ interface PointerEvent : MouseEvent
method getPredictedEvents
interface PopStateEvent : Event
attribute @@toStringTag
getter hasUAVisualTransition
getter state
method constructor
interface Presentation
Expand Down

0 comments on commit daad5dc

Please sign in to comment.