Commit 19719e9b authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

Remove testing binder on tear down in some Blink unit tests.

Follow-up to commits 4ba0b61c ("Convert ShareService client to use
BrowserInterfaceBroker"), 1dec3c1c ("Convert WakeLockService client to use
BrowserInterfaceBroker") and e676be1f ("Convert PermissionService client
to use BrowserInterfaceBroker").

Essentially, the BrowserInterfaceBroker conversion introduced flakiness to
some unit tests, and this CL fixes the ones I have noticed. The flakiness is
caused by the fact that we after the first test case we end up trying to
rebind an already bound object, which often leads to DCHECKs and other
crashes.

Follow what is done in commits 567040bd ("[mojo] Convert
CredentialManagerProxy to use BrowserInterfaceBroker") and
b5630d76 ("Convert NFC client to use BrowserInterfaceBroker") and explicitly
remove the test binders between test cases.

Bug: 936482, 1010116
Change-Id: If31d8f3dfb95c69651265a6e8cdcebdfb3816728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835360
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#702183}
parent a747b441
...@@ -257,6 +257,16 @@ WakeLockTestingContext::WakeLockTestingContext( ...@@ -257,6 +257,16 @@ WakeLockTestingContext::WakeLockTestingContext(
WTF::Unretained(&permission_service_))); WTF::Unretained(&permission_service_)));
} }
WakeLockTestingContext::~WakeLockTestingContext() {
// Remove the testing binder to avoid crashes between tests caused by
// our mocks rebinding an already-bound Binding.
// See https://crbug.com/1010116 for more information.
GetDocument()->GetBrowserInterfaceBroker().SetBinderForTesting(
mojom::blink::WakeLockService::Name_, {});
GetDocument()->GetBrowserInterfaceBroker().SetBinderForTesting(
mojom::blink::PermissionService::Name_, {});
}
Document* WakeLockTestingContext::GetDocument() { Document* WakeLockTestingContext::GetDocument() {
return &testing_scope_.GetDocument(); return &testing_scope_.GetDocument();
} }
......
...@@ -150,6 +150,7 @@ class WakeLockTestingContext final { ...@@ -150,6 +150,7 @@ class WakeLockTestingContext final {
public: public:
WakeLockTestingContext(MockWakeLockService* mock_wake_lock_service); WakeLockTestingContext(MockWakeLockService* mock_wake_lock_service);
~WakeLockTestingContext();
Document* GetDocument(); Document* GetDocument();
LocalFrame* Frame(); LocalFrame* Frame();
......
...@@ -118,6 +118,14 @@ class NavigatorShareTest : public testing::Test { ...@@ -118,6 +118,14 @@ class NavigatorShareTest : public testing::Test {
WTF::Unretained(&mock_share_service_))); WTF::Unretained(&mock_share_service_)));
} }
void TearDown() override {
// Remove the testing binder to avoid crashes between tests caused by
// MockShareService rebinding an already-bound Binding.
// See https://crbug.com/1010116 for more information.
GetFrame().GetBrowserInterfaceBroker().SetBinderForTesting(
ShareService::Name_, {});
}
public: public:
MockShareService mock_share_service_; MockShareService mock_share_service_;
......
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