Index: content/renderer/render_frame_impl_browsertest.cc |
diff --git a/content/renderer/render_frame_impl_browsertest.cc b/content/renderer/render_frame_impl_browsertest.cc |
index eb36fb2ac00531ddee47f43c47a1d3857eb2f237..dfc8d8ab87fd2c2e5da0e5001195a4f6e39590e8 100644 |
--- a/content/renderer/render_frame_impl_browsertest.cc |
+++ b/content/renderer/render_frame_impl_browsertest.cc |
@@ -104,6 +104,14 @@ class RenderFrameImplTest : public RenderViewTest { |
return frame_->render_widget_.get(); |
} |
+#if defined(OS_ANDROID) |
+ void ReceiveOverlayRoutingToken(const base::UnguessableToken& token) { |
+ overlay_routing_token_ = token; |
+ } |
+ |
+ base::Optional<base::UnguessableToken> overlay_routing_token_; |
+#endif |
+ |
private: |
RenderFrameImpl* frame_; |
FakeCompositorDependencies compositor_deps_; |
@@ -370,4 +378,52 @@ TEST_F(RenderFrameImplTest, NoCrashWhenDeletingFrameDuringFind) { |
frame()->OnMessageReceived(delete_message); |
} |
+#if defined(OS_ANDROID) |
+// Verify that RFI defers token requests if the token hasn't arrived yet. |
+TEST_F(RenderFrameImplTest, TestOverlayRoutingTokenSendsLater) { |
+ ASSERT_FALSE(overlay_routing_token_.has_value()); |
+ |
+ frame()->RequestOverlayRoutingToken( |
+ base::Bind(&RenderFrameImplTest::ReceiveOverlayRoutingToken, |
+ base::Unretained(this))); |
+ ASSERT_FALSE(overlay_routing_token_.has_value()); |
+ |
+ // The host should receive a request for it sent to the frame. |
+ const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( |
+ FrameHostMsg_RequestOverlayRoutingToken::ID); |
+ EXPECT_TRUE(msg); |
+ |
+ // Send a token. |
+ base::UnguessableToken token = base::UnguessableToken::Create(); |
+ FrameMsg_SetOverlayRoutingToken token_message(0, token); |
+ frame()->OnMessageReceived(token_message); |
+ |
+ ProcessPendingMessages(); |
+ ASSERT_TRUE(overlay_routing_token_.has_value()); |
+ ASSERT_EQ(overlay_routing_token_.value(), token); |
+} |
+ |
+// Verify that RFI sends tokens if they're already available. |
+TEST_F(RenderFrameImplTest, TestOverlayRoutingTokenSendsNow) { |
+ ASSERT_FALSE(overlay_routing_token_.has_value()); |
+ base::UnguessableToken token = base::UnguessableToken::Create(); |
+ FrameMsg_SetOverlayRoutingToken token_message(0, token); |
+ frame()->OnMessageReceived(token_message); |
+ |
+ // The frame now has a token. We don't care if it sends the token before |
+ // returning or posts a message. |
+ ProcessPendingMessages(); |
+ frame()->RequestOverlayRoutingToken( |
+ base::Bind(&RenderFrameImplTest::ReceiveOverlayRoutingToken, |
+ base::Unretained(this))); |
+ ASSERT_TRUE(overlay_routing_token_.has_value()); |
+ ASSERT_EQ(overlay_routing_token_.value(), token); |
+ |
+ // Since the token already arrived, a request for it shouldn't be sent. |
+ const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( |
+ FrameHostMsg_RequestOverlayRoutingToken::ID); |
+ EXPECT_FALSE(msg); |
+} |
+#endif |
+ |
} // namespace |