test: use WebContents event to test beforeunload (#23699)

This commit is contained in:
Cheng Zhao 2020-05-26 22:21:38 +09:00 committed by GitHub
parent 0dabd5e8c7
commit 08f288faf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 97 additions and 134 deletions

View file

@ -756,6 +756,8 @@ void WebContents::BeforeUnloadFired(content::WebContents* tab,
*proceed_to_fire_unload = proceed;
else
*proceed_to_fire_unload = true;
// Note that Chromium does not emit this for navigations.
Emit("before-unload-fired", proceed);
}
void WebContents::SetContentsBounds(content::WebContents* source,
@ -1546,6 +1548,9 @@ void WebContents::LoadURL(const GURL& url,
// Calling LoadURLWithParams() can trigger JS which destroys |this|.
auto weak_this = GetWeakPtr();
// Required to make beforeunload handler work.
NotifyUserActivation();
params.transition_type = ui::PAGE_TRANSITION_TYPED;
params.should_clear_history_list = true;
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
@ -2675,6 +2680,15 @@ void WebContents::GrantOriginAccess(const GURL& url) {
url::Origin::Create(url));
}
void WebContents::NotifyUserActivation() {
auto* frame = web_contents()->GetMainFrame();
if (!frame)
return;
mojo::AssociatedRemote<mojom::ElectronRenderer> renderer;
frame->GetRemoteAssociatedInterfaces()->GetInterface(&renderer);
renderer->NotifyUserActivation();
}
v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
const base::FilePath& file_path) {
gin_helper::Promise<void> promise(isolate());