0
Files
src/content/shell/browser/web_test/web_test_download_manager_delegate.h
Antonio Gomes 3640ddbaf2 Convert FrameHostMsg_DownloadUrl to blink.mojom.LocalFrameHost interface
In order to do this, a couple of remarkable changes took place:

- The body of RenderFrameImpl::DownloadURL() and SaveImageFromDataUR()
have been moved down to blink::LocalFrame.
Note that there were other RenderFrameImpl methods that used to call
RenderFrameImpl::DownloadURL() - namely RenderFrameImpl::BeginNavigation.
In order to keep this code chain unchanged, WebLocalFrame interface
got a DownloadURL() method added, so that it can forward calls to
LocalFrame::DownloadURL() from there.

- content/renderer/render_frame_impl_browsertest.cc:
RenderFrameImplTest got its ctor extended similarly to RenderViewImplTest's
(in render_view_browsertest.cc). Now it is possible to inject a custom
blink::mojom::LocalFrameHost instance, and catch DownloadURL() mojo call.

- web_test_download_manager_delegate.cc:
In order to run web_tests that trigger download, we could
try to intercept LocalFrameHost for web_tests. Instead, the CL
lets the browser/ to handle it.
The flow is content requests a download. Mojo calls take place.
RFHI::DownloadURL gets called and then DownloadManagerImpl.
Particularly, for every download that gets started by the renderer,
DownloadManagerDelegate::CheckDownloadAllowed is called.
This CL added an extra parameter to this method, in order
to idenfity that the download was trigger by the renderer (ie the
web_test in case), and then replied to the renderer accordingly.
See WebTestDownloadManagerDelegate::CheckDownloadAllowed() for details.

- DownloadURL() plumbing methods were removed from
WebFrameTestClient, WebFrameTestProxy, WebLocalFrameClient,
EmptyLocalFrameClient, LocalFrameClientImpl, LocalFrameClient,
ChromeClient.

- t_p/blink/public/mojom/frame/frame.mojom: In the normal case - see
LocalFrame::DownloadURL() - all members of the
blink.mojom.DownloadURLParams struct are filled properly.
However, there is another call site - see LocalFrame::SaveImageAt -
where only |data_url_blob| struct member is filled, leaving all others
"null". |url| is nullable so it is fine, but all others cause crashes
on unittests if they are not mark as "nullable" accordingly.

- web_frame_test.cc:
It implements a BlobRegister instance that intercepts the creation
of blink::mojom::Blob, or use FakeBlob instead.
Given that the content of the Blob is known, and made of bytes only,
it reads off the contents from DataElements.
The test also implements a custom blink::mojom::LocalFrameHost instance,
so it intercepts mojo calls to DownloadURL() and act accordingly.

BUG=1041083

Change-Id: I279bdc142624a0efb6be31535d505e9f6cabe5f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028708
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: Min Qin <qinmin@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#743042}
2020-02-20 10:45:20 +00:00

45 lines
1.5 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_DOWNLOAD_MANAGER_DELEGATE_H_
#define CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_DOWNLOAD_MANAGER_DELEGATE_H_
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
namespace download {
class DownloadItem;
}
namespace content {
class WebTestDownloadManagerDelegate : public ShellDownloadManagerDelegate {
public:
WebTestDownloadManagerDelegate();
~WebTestDownloadManagerDelegate() override;
// ShellDownloadManagerDelegate implementation.
bool ShouldOpenDownload(download::DownloadItem* item,
DownloadOpenDelayedCallback callback) override;
void CheckDownloadAllowed(
const content::WebContents::Getter& web_contents_getter,
const GURL& url,
const std::string& request_method,
base::Optional<url::Origin> request_initiator,
bool from_download_cross_origin_redirect,
bool content_initiated,
content::CheckDownloadAllowedCallback check_download_allowed_cb) override;
private:
DISALLOW_COPY_AND_ASSIGN(WebTestDownloadManagerDelegate);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_DOWNLOAD_MANAGER_DELEGATE_H_