Commit 3d067089 authored by landell's avatar landell Committed by Commit bot

Fix URLRequest pepper unit test

This patch creates new URLLoaderResource objects for each request
since those objects can't be reused.

Calling Open() on an instance of URLLoaderResource requires that mode_
is set to MODE_WAITING_TO_OPEN. After Open() has been called mode_
will never reach that state again.

BUG=None

Review URL: https://codereview.chromium.org/582623002

Cr-Commit-Position: refs/heads/master@{#296155}
parent 02a50d7b
...@@ -40,8 +40,7 @@ TestURLRequest::TestURLRequest(TestingInstance* instance) ...@@ -40,8 +40,7 @@ TestURLRequest::TestURLRequest(TestingInstance* instance)
ppb_url_loader_interface_(NULL), ppb_url_loader_interface_(NULL),
ppb_url_response_interface_(NULL), ppb_url_response_interface_(NULL),
ppb_core_interface_(NULL), ppb_core_interface_(NULL),
ppb_var_interface_(NULL), ppb_var_interface_(NULL) {
url_loader_(kInvalidResource) {
} }
bool TestURLRequest::Init() { bool TestURLRequest::Init() {
...@@ -65,10 +64,6 @@ bool TestURLRequest::Init() { ...@@ -65,10 +64,6 @@ bool TestURLRequest::Init() {
instance_->AppendError("PPB_Var interface not available"); instance_->AppendError("PPB_Var interface not available");
if (!ppb_url_loader_interface_) { if (!ppb_url_loader_interface_) {
instance_->AppendError("PPB_URLLoader interface not available"); instance_->AppendError("PPB_URLLoader interface not available");
} else {
url_loader_ = ppb_url_loader_interface_->Create(instance_->pp_instance());
if (url_loader_ == kInvalidResource)
instance_->AppendError("Failed to create URLLoader");
} }
return EnsureRunningOverHTTP(); return EnsureRunningOverHTTP();
} }
...@@ -106,7 +101,14 @@ std::string TestURLRequest::TestCreateAndIsURLRequestInfo() { ...@@ -106,7 +101,14 @@ std::string TestURLRequest::TestCreateAndIsURLRequestInfo() {
ppb_url_request_interface_->IsURLRequestInfo(kInvalidResource)); ppb_url_request_interface_->IsURLRequestInfo(kInvalidResource));
ASSERT_NE(PP_TRUE, ASSERT_NE(PP_TRUE,
ppb_url_request_interface_->IsURLRequestInfo(kNotAResource)); ppb_url_request_interface_->IsURLRequestInfo(kNotAResource));
ASSERT_NE(PP_TRUE, ppb_url_request_interface_->IsURLRequestInfo(url_loader_));
PP_Resource url_loader =
ppb_url_loader_interface_->Create(instance_->pp_instance());
ASSERT_NE(kInvalidResource, url_loader);
ASSERT_NE(PP_TRUE, ppb_url_request_interface_->IsURLRequestInfo(url_loader));
ppb_url_loader_interface_->Close(url_loader);
ppb_core_interface_->ReleaseResource(url_loader);
// IsURLRequestInfo: Current URLRequestInfo resource -> true. // IsURLRequestInfo: Current URLRequestInfo resource -> true.
std::string error; std::string error;
...@@ -289,15 +291,20 @@ std::string TestURLRequest::TestSetProperty() { ...@@ -289,15 +291,20 @@ std::string TestURLRequest::TestSetProperty() {
std::string TestURLRequest::LoadAndCompareBody( std::string TestURLRequest::LoadAndCompareBody(
PP_Resource url_request, const std::string& expected_body) { PP_Resource url_request, const std::string& expected_body) {
TestCompletionCallback callback(instance_->pp_instance(), PP_REQUIRED); TestCompletionCallback callback(instance_->pp_instance(), PP_REQUIRED);
PP_Resource url_loader =
ppb_url_loader_interface_->Create(instance_->pp_instance());
ASSERT_NE(kInvalidResource, url_loader);
callback.WaitForResult(ppb_url_loader_interface_->Open( callback.WaitForResult(ppb_url_loader_interface_->Open(
url_loader_, url_request, url_loader, url_request,
callback.GetCallback().pp_completion_callback())); callback.GetCallback().pp_completion_callback()));
CHECK_CALLBACK_BEHAVIOR(callback); CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result()); ASSERT_EQ(PP_OK, callback.result());
std::string error; std::string error;
PP_Resource url_response = PP_Resource url_response =
ppb_url_loader_interface_->GetResponseInfo(url_loader_); ppb_url_loader_interface_->GetResponseInfo(url_loader);
if (url_response == kInvalidResource) { if (url_response == kInvalidResource) {
error = "PPB_URLLoader::GetResponseInfo() returned invalid resource"; error = "PPB_URLLoader::GetResponseInfo() returned invalid resource";
} else { } else {
...@@ -311,7 +318,7 @@ std::string TestURLRequest::LoadAndCompareBody( ...@@ -311,7 +318,7 @@ std::string TestURLRequest::LoadAndCompareBody(
const size_t kBufferSize = 32; const size_t kBufferSize = 32;
char buf[kBufferSize]; char buf[kBufferSize];
callback.WaitForResult(ppb_url_loader_interface_->ReadResponseBody( callback.WaitForResult(ppb_url_loader_interface_->ReadResponseBody(
url_loader_, buf, kBufferSize, url_loader, buf, kBufferSize,
callback.GetCallback().pp_completion_callback())); callback.GetCallback().pp_completion_callback()));
if (callback.failed()) if (callback.failed())
error.assign(callback.errors()); error.assign(callback.errors());
...@@ -327,7 +334,8 @@ std::string TestURLRequest::LoadAndCompareBody( ...@@ -327,7 +334,8 @@ std::string TestURLRequest::LoadAndCompareBody(
} }
ppb_core_interface_->ReleaseResource(url_response); ppb_core_interface_->ReleaseResource(url_response);
ppb_url_loader_interface_->Close(url_loader_); ppb_url_loader_interface_->Close(url_loader);
ppb_core_interface_->ReleaseResource(url_loader);
return error; return error;
} }
......
...@@ -21,7 +21,6 @@ class FileRef; ...@@ -21,7 +21,6 @@ class FileRef;
class TestURLRequest : public TestCase { class TestURLRequest : public TestCase {
public: public:
explicit TestURLRequest(TestingInstance* instance); explicit TestURLRequest(TestingInstance* instance);
~TestURLRequest() { ppb_core_interface_->ReleaseResource(url_loader_); }
// TestCase implementation. // TestCase implementation.
virtual bool Init(); virtual bool Init();
...@@ -44,8 +43,6 @@ class TestURLRequest : public TestCase { ...@@ -44,8 +43,6 @@ class TestURLRequest : public TestCase {
const PPB_URLResponseInfo* ppb_url_response_interface_; const PPB_URLResponseInfo* ppb_url_response_interface_;
const PPB_Core* ppb_core_interface_; const PPB_Core* ppb_core_interface_;
const PPB_Var* ppb_var_interface_; const PPB_Var* ppb_var_interface_;
PP_Resource url_loader_;
}; };
#endif // PAPPI_TESTS_TEST_URL_REQUEST_H_ #endif // PAPPI_TESTS_TEST_URL_REQUEST_H_
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