| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "chrome/browser/local_discovery/privet_http_impl.h" | 7 #include "chrome/browser/local_discovery/privet_http_impl.h" |
| 8 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/url_request/test_url_fetcher_factory.h" | 10 #include "net/url_request/test_url_fetcher_factory.h" |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 819 |
| 820 EXPECT_TRUE(SuccessfulResponseToURL( | 820 EXPECT_TRUE(SuccessfulResponseToURL( |
| 821 GURL("http://10.0.0.8:6006/privet/capabilities"), | 821 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 822 kSampleCapabilitiesResponse)); | 822 kSampleCapabilitiesResponse)); |
| 823 | 823 |
| 824 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 824 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 825 | 825 |
| 826 // TODO(noamsml): Is encoding spaces as pluses standard? | 826 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 827 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 827 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 828 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 828 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 829 "user=sample%40gmail.com&jobname=Sample+job+name"), | 829 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 830 "job_name=Sample+job+name"), |
| 830 "Sample print data", | 831 "Sample print data", |
| 831 kSampleLocalPrintResponse)); | 832 kSampleLocalPrintResponse)); |
| 832 }; | 833 }; |
| 833 | 834 |
| 834 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { | 835 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { |
| 835 local_print_operation_->SetUsername("sample@gmail.com"); | 836 local_print_operation_->SetUsername("sample@gmail.com"); |
| 836 local_print_operation_->SetJobname("Sample job name"); | 837 local_print_operation_->SetJobname("Sample job name"); |
| 837 local_print_operation_->SetData( | 838 local_print_operation_->SetData( |
| 838 RefCountedBytesFromString("Sample print data")); | 839 RefCountedBytesFromString("Sample print data")); |
| 839 local_print_operation_->Start(); | 840 local_print_operation_->Start(); |
| 840 | 841 |
| 841 EXPECT_TRUE(SuccessfulResponseToURL( | 842 EXPECT_TRUE(SuccessfulResponseToURL( |
| 842 GURL("http://10.0.0.8:6006/privet/info"), | 843 GURL("http://10.0.0.8:6006/privet/info"), |
| 843 kSampleInfoResponse)); | 844 kSampleInfoResponse)); |
| 844 | 845 |
| 845 EXPECT_TRUE(SuccessfulResponseToURL( | 846 EXPECT_TRUE(SuccessfulResponseToURL( |
| 846 GURL("http://10.0.0.8:6006/privet/capabilities"), | 847 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 847 kSampleCapabilitiesResponseWithAnyMimetype)); | 848 kSampleCapabilitiesResponseWithAnyMimetype)); |
| 848 | 849 |
| 849 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 850 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 850 | 851 |
| 851 // TODO(noamsml): Is encoding spaces as pluses standard? | 852 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 852 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 853 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 853 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 854 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 854 "user=sample%40gmail.com&jobname=Sample+job+name"), | 855 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 856 "job_name=Sample+job+name"), |
| 855 "Sample print data", | 857 "Sample print data", |
| 856 kSampleLocalPrintResponse)); | 858 kSampleLocalPrintResponse)); |
| 857 }; | 859 }; |
| 858 | 860 |
| 859 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { | 861 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { |
| 860 local_print_operation_->SetUsername("sample@gmail.com"); | 862 local_print_operation_->SetUsername("sample@gmail.com"); |
| 861 local_print_operation_->SetJobname("Sample job name"); | 863 local_print_operation_->SetJobname("Sample job name"); |
| 862 local_print_operation_->SetData( | 864 local_print_operation_->SetData( |
| 863 RefCountedBytesFromString("path/to/")); | 865 RefCountedBytesFromString("path/to/")); |
| 864 local_print_operation_->Start(); | 866 local_print_operation_->Start(); |
| 865 | 867 |
| 866 EXPECT_TRUE(SuccessfulResponseToURL( | 868 EXPECT_TRUE(SuccessfulResponseToURL( |
| 867 GURL("http://10.0.0.8:6006/privet/info"), | 869 GURL("http://10.0.0.8:6006/privet/info"), |
| 868 kSampleInfoResponse)); | 870 kSampleInfoResponse)); |
| 869 | 871 |
| 870 EXPECT_TRUE(SuccessfulResponseToURL( | 872 EXPECT_TRUE(SuccessfulResponseToURL( |
| 871 GURL("http://10.0.0.8:6006/privet/capabilities"), | 873 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 872 kSampleCapabilitiesResponsePWGOnly)); | 874 kSampleCapabilitiesResponsePWGOnly)); |
| 873 | 875 |
| 874 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 876 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 875 | 877 |
| 876 // TODO(noamsml): Is encoding spaces as pluses standard? | 878 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 877 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 879 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 878 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 880 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 879 "user=sample%40gmail.com&jobname=Sample+job+name"), | 881 "client_name=Chrome&user_name=sample%40gmail.com" |
| 882 "&job_name=Sample+job+name"), |
| 880 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 883 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
| 881 kSampleLocalPrintResponse)); | 884 kSampleLocalPrintResponse)); |
| 882 }; | 885 }; |
| 883 | 886 |
| 884 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { | 887 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { |
| 885 local_print_operation_->SetUsername("sample@gmail.com"); | 888 local_print_operation_->SetUsername("sample@gmail.com"); |
| 886 local_print_operation_->SetJobname("Sample job name"); | 889 local_print_operation_->SetJobname("Sample job name"); |
| 887 local_print_operation_->SetTicket("Sample print ticket"); | 890 local_print_operation_->SetTicket("Sample print ticket"); |
| 888 local_print_operation_->SetData( | 891 local_print_operation_->SetData( |
| 889 RefCountedBytesFromString("Sample print data")); | 892 RefCountedBytesFromString("Sample print data")); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 900 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 903 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 901 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 904 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 902 "Sample print ticket", | 905 "Sample print ticket", |
| 903 kSampleCreatejobResponse)); | 906 kSampleCreatejobResponse)); |
| 904 | 907 |
| 905 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 908 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 906 | 909 |
| 907 // TODO(noamsml): Is encoding spaces as pluses standard? | 910 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 908 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 911 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 909 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 912 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 910 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), | 913 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 914 "job_name=Sample+job+name&job_id=1234"), |
| 911 "Sample print data", | 915 "Sample print data", |
| 912 kSampleLocalPrintResponse)); | 916 kSampleLocalPrintResponse)); |
| 913 }; | 917 }; |
| 914 | 918 |
| 915 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { | 919 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { |
| 916 local_print_operation_->SetUsername("sample@gmail.com"); | 920 local_print_operation_->SetUsername("sample@gmail.com"); |
| 917 local_print_operation_->SetJobname("Sample job name"); | 921 local_print_operation_->SetJobname("Sample job name"); |
| 918 local_print_operation_->SetTicket("Sample print ticket"); | 922 local_print_operation_->SetTicket("Sample print ticket"); |
| 919 local_print_operation_->SetData( | 923 local_print_operation_->SetData( |
| 920 RefCountedBytesFromString("sample/path/")); | 924 RefCountedBytesFromString("sample/path/")); |
| 921 local_print_operation_->Start(); | 925 local_print_operation_->Start(); |
| 922 | 926 |
| 923 EXPECT_TRUE(SuccessfulResponseToURL( | 927 EXPECT_TRUE(SuccessfulResponseToURL( |
| 924 GURL("http://10.0.0.8:6006/privet/info"), | 928 GURL("http://10.0.0.8:6006/privet/info"), |
| 925 kSampleInfoResponseWithCreatejob)); | 929 kSampleInfoResponseWithCreatejob)); |
| 926 | 930 |
| 927 EXPECT_TRUE(SuccessfulResponseToURL( | 931 EXPECT_TRUE(SuccessfulResponseToURL( |
| 928 GURL("http://10.0.0.8:6006/privet/capabilities"), | 932 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 929 kSampleCapabilitiesResponse)); | 933 kSampleCapabilitiesResponse)); |
| 930 | 934 |
| 931 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 935 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 932 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 936 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 933 "Sample print ticket", | 937 "Sample print ticket", |
| 934 kSampleCreatejobResponse)); | 938 kSampleCreatejobResponse)); |
| 935 | 939 |
| 936 // TODO(noamsml): Is encoding spaces as pluses standard? | 940 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 937 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 941 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 938 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 942 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 939 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), | 943 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 944 "job_name=Sample+job+name&job_id=1234"), |
| 940 "sample/path/", | 945 "sample/path/", |
| 941 kSampleInvalidDocumentTypeResponse)); | 946 kSampleInvalidDocumentTypeResponse)); |
| 942 | 947 |
| 943 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 948 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 944 | 949 |
| 945 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 950 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 946 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 951 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 947 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), | 952 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 953 "job_name=Sample+job+name&job_id=1234"), |
| 948 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), | 954 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), |
| 949 kSampleLocalPrintResponse)); | 955 kSampleLocalPrintResponse)); |
| 950 }; | 956 }; |
| 951 | 957 |
| 952 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { | 958 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { |
| 953 local_print_operation_->SetUsername("sample@gmail.com"); | 959 local_print_operation_->SetUsername("sample@gmail.com"); |
| 954 local_print_operation_->SetJobname("Sample job name"); | 960 local_print_operation_->SetJobname("Sample job name"); |
| 955 local_print_operation_->SetTicket("Sample print ticket"); | 961 local_print_operation_->SetTicket("Sample print ticket"); |
| 956 local_print_operation_->SetData( | 962 local_print_operation_->SetData( |
| 957 RefCountedBytesFromString("Sample print data")); | 963 RefCountedBytesFromString("Sample print data")); |
| 958 local_print_operation_->Start(); | 964 local_print_operation_->Start(); |
| 959 | 965 |
| 960 EXPECT_TRUE(SuccessfulResponseToURL( | 966 EXPECT_TRUE(SuccessfulResponseToURL( |
| 961 GURL("http://10.0.0.8:6006/privet/info"), | 967 GURL("http://10.0.0.8:6006/privet/info"), |
| 962 kSampleInfoResponseWithCreatejob)); | 968 kSampleInfoResponseWithCreatejob)); |
| 963 | 969 |
| 964 EXPECT_TRUE(SuccessfulResponseToURL( | 970 EXPECT_TRUE(SuccessfulResponseToURL( |
| 965 GURL("http://10.0.0.8:6006/privet/capabilities"), | 971 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 966 kSampleCapabilitiesResponse)); | 972 kSampleCapabilitiesResponse)); |
| 967 | 973 |
| 968 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 974 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 969 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 975 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 970 "Sample print ticket", | 976 "Sample print ticket", |
| 971 kSampleCreatejobResponse)); | 977 kSampleCreatejobResponse)); |
| 972 | 978 |
| 973 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 979 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 974 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 980 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 975 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), | 981 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 982 "job_name=Sample+job+name&job_id=1234"), |
| 976 "Sample print data", | 983 "Sample print data", |
| 977 kSampleErrorResponsePrinterBusy)); | 984 kSampleErrorResponsePrinterBusy)); |
| 978 | 985 |
| 979 RunFor(base::TimeDelta::FromSeconds(3)); | 986 RunFor(base::TimeDelta::FromSeconds(3)); |
| 980 | 987 |
| 981 EXPECT_TRUE(SuccessfulResponseToURL( | 988 EXPECT_TRUE(SuccessfulResponseToURL( |
| 982 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 989 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 983 kSampleCreatejobResponse)); | 990 kSampleCreatejobResponse)); |
| 984 }; | 991 }; |
| 985 | 992 |
| 986 | 993 |
| 987 } // namespace | 994 } // namespace |
| 988 | 995 |
| 989 } // namespace local_discovery | 996 } // namespace local_discovery |
| OLD | NEW |