Skip to content

Commit

Permalink
fido: make AuthenticatorTestBase set the MOCK_TIME TaskEnvironment trait
Browse files Browse the repository at this point in the history
This allows us to get rid of base::Timer injection into
AuthenticatorCommon, which tests used to wait for requests to time out.

Also get remove a number of superfluous RunUntilIdle() calls, and of
calls to OverrideLastCommittedOrigin() where SimulateNavigation() would
suffice.

Change-Id: I8cb4980d51efe43f59d828cde5f34ce67d38d928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299630
Auto-Submit: Martin Kreichgauer <martinkr@google.com>
Reviewed-by: Jared Saul <jsaul@google.com>
Reviewed-by: Adam Langley <agl@chromium.org>
Commit-Queue: Martin Kreichgauer <martinkr@google.com>
Cr-Commit-Position: refs/heads/master@{#788885}
  • Loading branch information
kreichgauer authored and Commit Bot committed Jul 16, 2020
1 parent a025272 commit f55cd37
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <string>
#include <utility>

#include "base/timer/timer.h"
#include "content/browser/webauth/authenticator_common.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
Expand All @@ -18,20 +17,12 @@ namespace content {

InternalAuthenticatorImpl::InternalAuthenticatorImpl(
RenderFrameHost* render_frame_host)
: InternalAuthenticatorImpl(render_frame_host,
std::make_unique<AuthenticatorCommon>(
render_frame_host,
std::make_unique<base::OneShotTimer>())) {}

InternalAuthenticatorImpl::InternalAuthenticatorImpl(
RenderFrameHost* render_frame_host,
std::unique_ptr<AuthenticatorCommon> authenticator_common)
: WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)),
render_frame_host_(render_frame_host),
effective_origin_(render_frame_host->GetLastCommittedOrigin()),
authenticator_common_(std::move(authenticator_common)) {
authenticator_common_(
std::make_unique<AuthenticatorCommon>(render_frame_host)) {
DCHECK(render_frame_host_);
DCHECK(authenticator_common_);
// Disabling WebAuthn modal dialogs to avoid conflict with Autofill's own
// modal dialogs. Since WebAuthn is designed for websites, rather than browser
// components, the UI can be confusing for users in the case for Autofill.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ class InternalAuthenticatorImpl : public autofill::InternalAuthenticator,
private:
friend class InternalAuthenticatorImplTest;

// By being able to set AuthenticatorCommon, this constructor permits setting
// the connector and timer for testing. Using this constructor will also empty
// out the protocol set, since no device discovery will take place during
// tests.
InternalAuthenticatorImpl(
RenderFrameHost* render_frame_host,
std::unique_ptr<AuthenticatorCommon> authenticator_common);

AuthenticatorCommon* get_authenticator_common_for_testing() {
return authenticator_common_.get();
}
Expand Down
8 changes: 2 additions & 6 deletions content/browser/webauth/authenticator_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,11 @@ base::flat_set<device::FidoTransportProtocol> GetAvailableTransports(

} // namespace

AuthenticatorCommon::AuthenticatorCommon(
RenderFrameHost* render_frame_host,
std::unique_ptr<base::OneShotTimer> timer)
AuthenticatorCommon::AuthenticatorCommon(RenderFrameHost* render_frame_host)
: render_frame_host_(render_frame_host),
security_checker_(static_cast<RenderFrameHostImpl*>(render_frame_host)
->GetWebAuthRequestSecurityChecker()),
timer_(std::move(timer)) {
->GetWebAuthRequestSecurityChecker()) {
DCHECK(render_frame_host_);
DCHECK(timer_);
// Disable the back-forward cache for any document that makes WebAuthn
// requests. Pages using privacy-sensitive APIs are generally exempt from
// back-forward cache for now as a precaution.
Expand Down
8 changes: 4 additions & 4 deletions content/browser/webauth/authenticator_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/containers/span.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/timer/timer.h"
#include "content/common/content_export.h"
#include "content/public/browser/authenticator_request_client_delegate.h"
#include "content/public/browser/web_contents_observer.h"
Expand Down Expand Up @@ -67,9 +68,7 @@ CONTENT_EXPORT extern const char kGetType[];
// Common code for any WebAuthn Authenticator interfaces.
class CONTENT_EXPORT AuthenticatorCommon {
public:
// Permits setting timer for testing.
AuthenticatorCommon(RenderFrameHost* render_frame_host,
std::unique_ptr<base::OneShotTimer>);
explicit AuthenticatorCommon(RenderFrameHost* render_frame_host);
virtual ~AuthenticatorCommon();

// This is not-quite an implementation of blink::mojom::Authenticator. The
Expand Down Expand Up @@ -183,7 +182,8 @@ class CONTENT_EXPORT AuthenticatorCommon {
url::Origin caller_origin_;
std::string relying_party_id_;
scoped_refptr<WebAuthRequestSecurityChecker> security_checker_;
std::unique_ptr<base::OneShotTimer> timer_;
std::unique_ptr<base::OneShotTimer> timer_ =
std::make_unique<base::OneShotTimer>();
base::Optional<device::AuthenticatorSelectionCriteria>
authenticator_selection_criteria_;
base::Optional<std::string> app_id_;
Expand Down
7 changes: 3 additions & 4 deletions content/browser/webauth/authenticator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
namespace content {

AuthenticatorImpl::AuthenticatorImpl(RenderFrameHost* render_frame_host)
: AuthenticatorImpl(render_frame_host,
std::make_unique<AuthenticatorCommon>(
render_frame_host,
std::make_unique<base::OneShotTimer>())) {}
: AuthenticatorImpl(
render_frame_host,
std::make_unique<AuthenticatorCommon>(render_frame_host)) {}

AuthenticatorImpl::AuthenticatorImpl(
RenderFrameHost* render_frame_host,
Expand Down
5 changes: 2 additions & 3 deletions content/browser/webauth/authenticator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class CONTENT_EXPORT AuthenticatorImpl : public blink::mojom::Authenticator,
public:
explicit AuthenticatorImpl(RenderFrameHost* render_frame_host);

// By being able to set AuthenticatorCommon, this constructor permits setting
// the timer for testing. Using this constructor will also empty out the
// protocol set, since no device discovery will take place during tests.
// Constructs an AuthenticatorImpl with an injected AuthenticatorCommon for
// testing.
AuthenticatorImpl(RenderFrameHost* render_frame_host,
std::unique_ptr<AuthenticatorCommon> authenticator_common);
~AuthenticatorImpl() override;
Expand Down

0 comments on commit f55cd37

Please sign in to comment.