Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1611)

Unified Diff: remoting/host/token_validator_factory_impl_unittest.cc

Issue 2542843006: ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases. (Closed)
Patch Set: Fix merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/token_validator_base.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/token_validator_factory_impl_unittest.cc
diff --git a/remoting/host/token_validator_factory_impl_unittest.cc b/remoting/host/token_validator_factory_impl_unittest.cc
index a0e4d1d788f8b4ef239bc866490160426ef30338..0a530e3fd82f22be65d9a483e1d09c291ebb6761 100644
--- a/remoting/host/token_validator_factory_impl_unittest.cc
+++ b/remoting/host/token_validator_factory_impl_unittest.cc
@@ -13,7 +13,9 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/values.h"
+#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
+#include "net/test/url_request/url_request_failed_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_status.h"
@@ -44,6 +46,9 @@ class FakeProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
: headers_(headers),
response_(response) {
}
+
+ ~FakeProtocolHandler() override {}
+
net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override {
@@ -56,6 +61,29 @@ class FakeProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
std::string response_;
};
+// Creates URLRequestJobs that fail at the specified phase.
+class FakeFailingProtocolHandler
+ : public net::URLRequestJobFactory::ProtocolHandler {
+ public:
+ FakeFailingProtocolHandler(
+ net::URLRequestFailedJob::FailurePhase failure_phase,
+ net::Error net_error)
+ : failure_phase_(failure_phase), net_error_(net_error) {}
+
+ ~FakeFailingProtocolHandler() override {}
+
+ net::URLRequestJob* MaybeCreateJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const override {
+ return new net::URLRequestFailedJob(request, network_delegate,
+ failure_phase_, net_error_);
+ }
+
+ private:
+ const net::URLRequestFailedJob::FailurePhase failure_phase_;
+ const net::Error net_error_;
+};
+
class SetResponseURLRequestContext: public net::TestURLRequestContext {
public:
void SetResponse(const std::string& headers, const std::string& response) {
@@ -65,6 +93,16 @@ class SetResponseURLRequestContext: public net::TestURLRequestContext {
"https", base::MakeUnique<FakeProtocolHandler>(headers, response));
context_storage_.set_job_factory(std::move(factory));
}
+
+ void SetErrorResponse(net::URLRequestFailedJob::FailurePhase failure_phase,
+ net::Error net_error) {
+ std::unique_ptr<net::URLRequestJobFactoryImpl> factory =
+ base::MakeUnique<net::URLRequestJobFactoryImpl>();
+ factory->SetProtocolHandler(
+ "https",
+ base::MakeUnique<FakeFailingProtocolHandler>(failure_phase, net_error));
+ context_storage_.set_job_factory(std::move(factory));
+ }
};
} // namespace
@@ -131,6 +169,14 @@ class TokenValidatorFactoryImplTest : public testing::Test {
context->SetResponse(headers, response);
}
+ void SetErrorResponse(net::URLRequestFailedJob::FailurePhase failure_phase,
+ net::Error net_error) {
+ SetResponseURLRequestContext* context =
+ static_cast<SetResponseURLRequestContext*>(
+ request_context_getter_->GetURLRequestContext());
+ context->SetErrorResponse(failure_phase, net_error);
+ }
+
base::MessageLoop message_loop_;
scoped_refptr<RsaKeyPair> key_pair_;
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
@@ -189,4 +235,43 @@ TEST_F(TokenValidatorFactoryImplTest, DeleteOnFailure) {
base::RunLoop().Run();
}
+TEST_F(TokenValidatorFactoryImplTest, DeleteOnStartError) {
+ token_validator_ =
+ token_validator_factory_->CreateTokenValidator(kLocalJid, kRemoteJid);
+
+ SetErrorResponse(net::URLRequestFailedJob::START, net::ERR_FAILED);
+
+ token_validator_->ValidateThirdPartyToken(
+ kToken,
+ base::Bind(&TokenValidatorFactoryImplTest::DeleteOnFailureCallback,
+ base::Unretained(this)));
+ base::RunLoop().Run();
+}
+
+TEST_F(TokenValidatorFactoryImplTest, DeleteOnSyncReadError) {
+ token_validator_ =
+ token_validator_factory_->CreateTokenValidator(kLocalJid, kRemoteJid);
+
+ SetErrorResponse(net::URLRequestFailedJob::READ_SYNC, net::ERR_FAILED);
+
+ token_validator_->ValidateThirdPartyToken(
+ kToken,
+ base::Bind(&TokenValidatorFactoryImplTest::DeleteOnFailureCallback,
+ base::Unretained(this)));
+ base::RunLoop().Run();
+}
+
+TEST_F(TokenValidatorFactoryImplTest, DeleteOnAsyncReadError) {
+ token_validator_ =
+ token_validator_factory_->CreateTokenValidator(kLocalJid, kRemoteJid);
+
+ SetErrorResponse(net::URLRequestFailedJob::READ_ASYNC, net::ERR_FAILED);
+
+ token_validator_->ValidateThirdPartyToken(
+ kToken,
+ base::Bind(&TokenValidatorFactoryImplTest::DeleteOnFailureCallback,
+ base::Unretained(this)));
+ base::RunLoop().Run();
+}
+
} // namespace remoting
« no previous file with comments | « remoting/host/token_validator_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698