-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Direct Sockets: Detect when render frame is deleted
DirectSocketsServiceImpl is now a WebContentsObserver. OpenTcpSocket() and OpenUdpSocket() now fail safely if they are called after the RenderFrameHost is destroyed. Bug: 1122917 Change-Id: I4a880c9aee73271cd5895818e0da3d85e32a8e5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383531 Auto-Submit: Eric Willigers <ericwilligers@chromium.org> Commit-Queue: Glen Robertson <glenrob@chromium.org> Reviewed-by: Glen Robertson <glenrob@chromium.org> Cr-Commit-Position: refs/heads/master@{#803005}
- Loading branch information
1 parent
0eb482f
commit fe9666e
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020 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. | ||
|
||
#include <memory> | ||
|
||
#include "base/test/scoped_feature_list.h" | ||
#include "content/browser/direct_sockets/direct_sockets_service_impl.h" | ||
#include "content/public/common/content_features.h" | ||
#include "content/public/test/test_renderer_host.h" | ||
#include "net/base/net_errors.h" | ||
#include "third_party/blink/public/mojom/direct_sockets/direct_sockets.mojom.h" | ||
|
||
namespace content { | ||
|
||
class DirectSocketsUnitTest : public RenderViewHostTestHarness { | ||
public: | ||
DirectSocketsUnitTest() { | ||
feature_list_.InitAndEnableFeature(features::kDirectSockets); | ||
} | ||
~DirectSocketsUnitTest() override = default; | ||
|
||
void SetUp() override { | ||
RenderViewHostTestHarness::SetUp(); | ||
direct_sockets_service_ = | ||
std::make_unique<DirectSocketsServiceImpl>(*main_rfh()); | ||
} | ||
|
||
DirectSocketsServiceImpl& direct_sockets_service() { | ||
return *direct_sockets_service_; | ||
} | ||
|
||
net::Error EnsurePermission( | ||
const blink::mojom::DirectSocketOptions& options) { | ||
return direct_sockets_service().EnsurePermission(options); | ||
} | ||
|
||
private: | ||
base::test::ScopedFeatureList feature_list_; | ||
std::unique_ptr<DirectSocketsServiceImpl> direct_sockets_service_; | ||
}; | ||
|
||
TEST_F(DirectSocketsUnitTest, RenderFrameDeleted) { | ||
direct_sockets_service().RenderFrameDeleted(main_rfh()); | ||
|
||
blink::mojom::DirectSocketOptions options; | ||
EXPECT_EQ(EnsurePermission(options), net::ERR_CONTEXT_SHUT_DOWN); | ||
} | ||
|
||
TEST_F(DirectSocketsUnitTest, WebContentsDestroyed) { | ||
direct_sockets_service().WebContentsDestroyed(); | ||
|
||
blink::mojom::DirectSocketOptions options; | ||
EXPECT_EQ(EnsurePermission(options), net::ERR_CONTEXT_SHUT_DOWN); | ||
} | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters