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

Side by Side Diff: ppapi/tests/test_url_loader.cc

Issue 9381010: Convert resources to take an instance key instead of an Instance*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: USELESS PATCH TITLE Created 8 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.cc ('k') | ppapi/tests/test_url_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_url_loader.h" 5 #include "ppapi/tests/test_url_loader.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <string> 9 #include <string>
10 10
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 PASS(); 164 PASS();
165 } 165 }
166 166
167 std::string TestURLLoader::LoadAndCompareBody( 167 std::string TestURLLoader::LoadAndCompareBody(
168 const pp::URLRequestInfo& request, 168 const pp::URLRequestInfo& request,
169 const std::string& expected_body) { 169 const std::string& expected_body) {
170 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 170 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
171 171
172 pp::URLLoader loader(*instance_); 172 pp::URLLoader loader(instance_);
173 int32_t rv = loader.Open(request, callback); 173 int32_t rv = loader.Open(request, callback);
174 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 174 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
175 return ReportError("URLLoader::Open force_async", rv); 175 return ReportError("URLLoader::Open force_async", rv);
176 if (rv == PP_OK_COMPLETIONPENDING) 176 if (rv == PP_OK_COMPLETIONPENDING)
177 rv = callback.WaitForResult(); 177 rv = callback.WaitForResult();
178 if (rv != PP_OK) 178 if (rv != PP_OK)
179 return ReportError("URLLoader::Open", rv); 179 return ReportError("URLLoader::Open", rv);
180 180
181 pp::URLResponseInfo response_info(loader.GetResponseInfo()); 181 pp::URLResponseInfo response_info(loader.GetResponseInfo());
182 if (response_info.is_null()) 182 if (response_info.is_null())
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 245
246 return rv; 246 return rv;
247 } 247 }
248 248
249 std::string TestURLLoader::GetReachableAbsoluteURL( 249 std::string TestURLLoader::GetReachableAbsoluteURL(
250 const std::string& file_name) { 250 const std::string& file_name) {
251 // Get the absolute page URL and replace the test case file name 251 // Get the absolute page URL and replace the test case file name
252 // with the given one. 252 // with the given one.
253 pp::Var document_url( 253 pp::Var document_url(
254 pp::Var::PassRef(), 254 pp::PASS_REF,
255 testing_interface_->GetDocumentURL(instance_->pp_instance(), 255 testing_interface_->GetDocumentURL(instance_->pp_instance(),
256 NULL)); 256 NULL));
257 std::string url(document_url.AsString()); 257 std::string url(document_url.AsString());
258 std::string old_name("test_case.html"); 258 std::string old_name("test_case.html");
259 size_t index = url.find(old_name); 259 size_t index = url.find(old_name);
260 ASSERT_NE(index, std::string::npos); 260 ASSERT_NE(index, std::string::npos);
261 url.replace(index, old_name.length(), file_name); 261 url.replace(index, old_name.length(), file_name);
262 return url; 262 return url;
263 } 263 }
264 264
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 int32_t TestURLLoader::OpenUntrusted(const pp::URLRequestInfo& request) { 299 int32_t TestURLLoader::OpenUntrusted(const pp::URLRequestInfo& request) {
300 return Open(request, false); 300 return Open(request, false);
301 } 301 }
302 302
303 int32_t TestURLLoader::OpenTrusted(const pp::URLRequestInfo& request) { 303 int32_t TestURLLoader::OpenTrusted(const pp::URLRequestInfo& request) {
304 return Open(request, true); 304 return Open(request, true);
305 } 305 }
306 306
307 int32_t TestURLLoader::Open(const pp::URLRequestInfo& request, 307 int32_t TestURLLoader::Open(const pp::URLRequestInfo& request,
308 bool trusted) { 308 bool trusted) {
309 pp::URLLoader loader(*instance_); 309 pp::URLLoader loader(instance_);
310 if (trusted) 310 if (trusted)
311 url_loader_trusted_interface_->GrantUniversalAccess(loader.pp_resource()); 311 url_loader_trusted_interface_->GrantUniversalAccess(loader.pp_resource());
312 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 312 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
313 int32_t rv = loader.Open(request, callback); 313 int32_t rv = loader.Open(request, callback);
314 314
315 if (rv == PP_OK_COMPLETIONPENDING) 315 if (rv == PP_OK_COMPLETIONPENDING)
316 rv = callback.WaitForResult(); 316 rv = callback.WaitForResult();
317 else if (force_async_) 317 else if (force_async_)
318 ReportError("URLLoader::Open force_async", rv); 318 ReportError("URLLoader::Open force_async", rv);
319 319
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 PASS(); 432 PASS();
433 } 433 }
434 434
435 std::string TestURLLoader::TestStreamToFile() { 435 std::string TestURLLoader::TestStreamToFile() {
436 pp::URLRequestInfo request(instance_); 436 pp::URLRequestInfo request(instance_);
437 request.SetURL("test_url_loader_data/hello.txt"); 437 request.SetURL("test_url_loader_data/hello.txt");
438 request.SetStreamToFile(true); 438 request.SetStreamToFile(true);
439 439
440 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 440 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
441 441
442 pp::URLLoader loader(*instance_); 442 pp::URLLoader loader(instance_);
443 int32_t rv = loader.Open(request, callback); 443 int32_t rv = loader.Open(request, callback);
444 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 444 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
445 return ReportError("URLLoader::Open force_async", rv); 445 return ReportError("URLLoader::Open force_async", rv);
446 if (rv == PP_OK_COMPLETIONPENDING) 446 if (rv == PP_OK_COMPLETIONPENDING)
447 rv = callback.WaitForResult(); 447 rv = callback.WaitForResult();
448 if (rv != PP_OK) 448 if (rv != PP_OK)
449 return ReportError("URLLoader::Open", rv); 449 return ReportError("URLLoader::Open", rv);
450 450
451 pp::URLResponseInfo response_info(loader.GetResponseInfo()); 451 pp::URLResponseInfo response_info(loader.GetResponseInfo());
452 if (response_info.is_null()) 452 if (response_info.is_null())
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // This prefix causes the test server to return a 301 redirect. 721 // This prefix causes the test server to return a 301 redirect.
722 std::string redirect_prefix("/server-redirect?"); 722 std::string redirect_prefix("/server-redirect?");
723 // We need an absolute path for the redirect to actually work. 723 // We need an absolute path for the redirect to actually work.
724 std::string redirect_url = 724 std::string redirect_url =
725 GetReachableAbsoluteURL("test_url_loader_data/hello.txt"); 725 GetReachableAbsoluteURL("test_url_loader_data/hello.txt");
726 request.SetURL(redirect_prefix.append(redirect_url)); 726 request.SetURL(redirect_prefix.append(redirect_url));
727 request.SetFollowRedirects(false); 727 request.SetFollowRedirects(false);
728 728
729 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 729 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
730 730
731 pp::URLLoader loader(*instance_); 731 pp::URLLoader loader(instance_);
732 int32_t rv = loader.Open(request, callback); 732 int32_t rv = loader.Open(request, callback);
733 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 733 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
734 return ReportError("URLLoader::Open force_async", rv); 734 return ReportError("URLLoader::Open force_async", rv);
735 if (rv == PP_OK_COMPLETIONPENDING) 735 if (rv == PP_OK_COMPLETIONPENDING)
736 rv = callback.WaitForResult(); 736 rv = callback.WaitForResult();
737 if (rv != PP_OK) 737 if (rv != PP_OK)
738 return ReportError("URLLoader::Open", rv); 738 return ReportError("URLLoader::Open", rv);
739 739
740 // Checks that the response indicates a redirect, and that the URL 740 // Checks that the response indicates a redirect, and that the URL
741 // is correct. 741 // is correct.
(...skipping 28 matching lines...) Expand all
770 std::string TestURLLoader::TestAbortCalls() { 770 std::string TestURLLoader::TestAbortCalls() {
771 pp::URLRequestInfo request(instance_); 771 pp::URLRequestInfo request(instance_);
772 request.SetURL("test_url_loader_data/hello.txt"); 772 request.SetURL("test_url_loader_data/hello.txt");
773 773
774 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 774 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
775 int32_t rv; 775 int32_t rv;
776 776
777 // Abort |Open()|. 777 // Abort |Open()|.
778 { 778 {
779 callback.reset_run_count(); 779 callback.reset_run_count();
780 rv = pp::URLLoader(*instance_).Open(request, callback); 780 rv = pp::URLLoader(instance_).Open(request, callback);
781 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 781 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
782 return ReportError("URLLoader::Open force_async", rv); 782 return ReportError("URLLoader::Open force_async", rv);
783 if (callback.run_count() > 0) 783 if (callback.run_count() > 0)
784 return "URLLoader::Open ran callback synchronously."; 784 return "URLLoader::Open ran callback synchronously.";
785 if (rv == PP_OK_COMPLETIONPENDING) { 785 if (rv == PP_OK_COMPLETIONPENDING) {
786 rv = callback.WaitForResult(); 786 rv = callback.WaitForResult();
787 if (rv != PP_ERROR_ABORTED) 787 if (rv != PP_ERROR_ABORTED)
788 return "URLLoader::Open not aborted."; 788 return "URLLoader::Open not aborted.";
789 } else if (rv != PP_OK) { 789 } else if (rv != PP_OK) {
790 return ReportError("URLLoader::Open", rv); 790 return ReportError("URLLoader::Open", rv);
791 } 791 }
792 } 792 }
793 793
794 // Abort |ReadResponseBody()|. 794 // Abort |ReadResponseBody()|.
795 { 795 {
796 char buf[2] = { 0 }; 796 char buf[2] = { 0 };
797 { 797 {
798 pp::URLLoader loader(*instance_); 798 pp::URLLoader loader(instance_);
799 rv = loader.Open(request, callback); 799 rv = loader.Open(request, callback);
800 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 800 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
801 return ReportError("URLLoader::Open force_async", rv); 801 return ReportError("URLLoader::Open force_async", rv);
802 if (rv == PP_OK_COMPLETIONPENDING) 802 if (rv == PP_OK_COMPLETIONPENDING)
803 rv = callback.WaitForResult(); 803 rv = callback.WaitForResult();
804 if (rv != PP_OK) 804 if (rv != PP_OK)
805 return ReportError("URLLoader::Open", rv); 805 return ReportError("URLLoader::Open", rv);
806 806
807 callback.reset_run_count(); 807 callback.reset_run_count();
808 rv = loader.ReadResponseBody(buf, sizeof(buf), callback); 808 rv = loader.ReadResponseBody(buf, sizeof(buf), callback);
(...skipping 20 matching lines...) Expand all
829 829
830 PASS(); 830 PASS();
831 } 831 }
832 832
833 std::string TestURLLoader::TestUntendedLoad() { 833 std::string TestURLLoader::TestUntendedLoad() {
834 pp::URLRequestInfo request(instance_); 834 pp::URLRequestInfo request(instance_);
835 request.SetURL("test_url_loader_data/hello.txt"); 835 request.SetURL("test_url_loader_data/hello.txt");
836 request.SetRecordDownloadProgress(true); 836 request.SetRecordDownloadProgress(true);
837 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 837 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
838 838
839 pp::URLLoader loader(*instance_); 839 pp::URLLoader loader(instance_);
840 int32_t rv = loader.Open(request, callback); 840 int32_t rv = loader.Open(request, callback);
841 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 841 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
842 return ReportError("URLLoader::Open force_async", rv); 842 return ReportError("URLLoader::Open force_async", rv);
843 if (rv == PP_OK_COMPLETIONPENDING) 843 if (rv == PP_OK_COMPLETIONPENDING)
844 rv = callback.WaitForResult(); 844 rv = callback.WaitForResult();
845 if (rv != PP_OK) 845 if (rv != PP_OK)
846 return ReportError("URLLoader::Open", rv); 846 return ReportError("URLLoader::Open", rv);
847 847
848 // We received the response callback. Yield until the network code has called 848 // We received the response callback. Yield until the network code has called
849 // the loader's didReceiveData and didFinishLoading methods before we give it 849 // the loader's didReceiveData and didFinishLoading methods before we give it
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 if (rv != PP_ERROR_FAILED) { 899 if (rv != PP_ERROR_FAILED) {
900 return ReportError("The lower buffer value was higher than the upper but " 900 return ReportError("The lower buffer value was higher than the upper but "
901 "the URLLoader did not fail.", rv); 901 "the URLLoader did not fail.", rv);
902 } 902 }
903 903
904 PASS(); 904 PASS();
905 } 905 }
906 906
907 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close 907 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close
908 // (including abort tests if applicable). 908 // (including abort tests if applicable).
OLDNEW
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.cc ('k') | ppapi/tests/test_url_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698