Commit ee3f412f authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

Fuchsia: Fix PostMessage message buffering, add & fix FrameImpl tests.

* Fixes issue with an on-receive callback not being unbound, causing
  the incoming message buffer to be drained immediately.
* Add browser tests to verify buffering behavior.
* Add browser tests to verify proper origin enforcement for
  Frame::PostMessage.
* Make the AsyncValueReceiver interface a bit nicer to use.
* Minor cleanups for other FrameImpl browser tests.

Bug: 893236
Change-Id: I521e9316ccf9195133a940be670556a882cb1044
Reviewed-on: https://chromium-review.googlesource.com/c/1351777
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612812}
parent d260cfb5
This diff is collapsed.
......@@ -112,7 +112,7 @@ MessagePortImpl::MessagePortImpl(mojo::ScopedMessagePipeHandle mojo_port)
connector_->set_connection_error_handler(
base::BindOnce(&MessagePortImpl::OnDisconnected, base::Unretained(this)));
binding_.set_error_handler([this](zx_status_t status) {
if (status != ZX_OK)
if (status != ZX_OK && status != ZX_ERR_PEER_CLOSED)
ZX_DLOG(INFO, status) << "Disconnected";
OnDisconnected();
......@@ -135,6 +135,7 @@ void MessagePortImpl::PostMessage(chromium::web::WebMessage message,
return;
}
CHECK(connector_->Accept(&mojo_message));
callback(true);
}
void MessagePortImpl::ReceiveMessage(ReceiveMessageCallback callback) {
......@@ -148,7 +149,8 @@ void MessagePortImpl::MaybeDeliverToClient() {
if (!pending_client_read_cb_ || message_queue_.empty())
return;
std::move(pending_client_read_cb_)(std::move(message_queue_.front()));
base::ResetAndReturn(&pending_client_read_cb_)(
std::move(message_queue_.front()));
message_queue_.pop_front();
}
......
......@@ -5,6 +5,7 @@
#ifndef WEBRUNNER_BROWSER_TEST_COMMON_H_
#define WEBRUNNER_BROWSER_TEST_COMMON_H_
#include "base/optional.h"
#include "content/public/browser/web_contents_observer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h"
......@@ -45,6 +46,46 @@ class MockNavigationObserver : public chromium::web::NavigationEventObserver,
DISALLOW_COPY_AND_ASSIGN(MockNavigationObserver);
};
// Stores an asynchronously generated value for later retrieval, optionally
// invoking a callback on value receipt for controlling test flow.
//
// The value can be read by using the dereference (*) or arrow (->) operators.
// Values must first be received before they can be accessed. Dereferencing a
// value before it is set will produce a CHECK violation.
template <typename T>
class Promise {
public:
explicit Promise(base::RepeatingClosure on_capture = base::DoNothing())
: on_capture_(std::move(on_capture)) {}
~Promise() = default;
// Returns a fit::function<> which will receive and store a value T.
fit::function<void(T)> GetReceiveCallback() {
return [this](T value) {
captured_ = std::move(value);
on_capture_.Run();
};
}
bool has_value() const { return captured_.has_value(); };
T& operator*() {
CHECK(captured_.has_value());
return *captured_;
}
T* operator->() {
CHECK(captured_.has_value());
return &*captured_;
}
private:
base::Optional<T> captured_;
base::RepeatingClosure on_capture_;
DISALLOW_COPY_AND_ASSIGN(Promise<T>);
};
} // namespace webrunner
#endif // WEBRUNNER_BROWSER_TEST_COMMON_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment