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/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/browser/local_discovery/privet_http_impl.h" | 9 #include "chrome/browser/local_discovery/privet_http_impl.h" |
10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
14 #include "printing/pwg_raster_settings.h" | 14 #include "printing/pwg_raster_settings.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 #if defined(ENABLE_FULL_PRINTING) | 18 #if defined(ENABLE_PRINT_PREVIEW) |
19 #include "chrome/browser/local_discovery/pwg_raster_converter.h" | 19 #include "chrome/browser/local_discovery/pwg_raster_converter.h" |
20 #endif // ENABLE_FULL_PRINTING | 20 #endif // ENABLE_PRINT_PREVIEW |
21 | 21 |
22 using testing::StrictMock; | 22 using testing::StrictMock; |
23 using testing::NiceMock; | 23 using testing::NiceMock; |
24 | 24 |
25 namespace local_discovery { | 25 namespace local_discovery { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kSampleInfoResponse[] = "{" | 29 const char kSampleInfoResponse[] = "{" |
30 " \"version\": \"1.0\"," | 30 " \"version\": \"1.0\"," |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 const char kSampleCapabilitiesResponse[] = "{" | 117 const char kSampleCapabilitiesResponse[] = "{" |
118 "\"version\" : \"1.0\"," | 118 "\"version\" : \"1.0\"," |
119 "\"printer\" : {" | 119 "\"printer\" : {" |
120 " \"supported_content_type\" : [" | 120 " \"supported_content_type\" : [" |
121 " { \"content_type\" : \"application/pdf\" }," | 121 " { \"content_type\" : \"application/pdf\" }," |
122 " { \"content_type\" : \"image/pwg-raster\" }" | 122 " { \"content_type\" : \"image/pwg-raster\" }" |
123 " ]" | 123 " ]" |
124 "}" | 124 "}" |
125 "}"; | 125 "}"; |
126 | 126 |
127 #if defined(ENABLE_FULL_PRINTING) | 127 #if defined(ENABLE_PRINT_PREVIEW) |
128 const char kSampleInfoResponseWithCreatejob[] = "{" | 128 const char kSampleInfoResponseWithCreatejob[] = "{" |
129 " \"version\": \"1.0\"," | 129 " \"version\": \"1.0\"," |
130 " \"name\": \"Common printer\"," | 130 " \"name\": \"Common printer\"," |
131 " \"description\": \"Printer connected through Chrome connector\"," | 131 " \"description\": \"Printer connected through Chrome connector\"," |
132 " \"url\": \"https://www.google.com/cloudprint\"," | 132 " \"url\": \"https://www.google.com/cloudprint\"," |
133 " \"type\": [" | 133 " \"type\": [" |
134 " \"printer\"" | 134 " \"printer\"" |
135 " ]," | 135 " ]," |
136 " \"id\": \"\"," | 136 " \"id\": \"\"," |
137 " \"device_state\": \"idle\"," | 137 " \"device_state\": \"idle\"," |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 " { \"content_type\" : \"image/pwg-raster\" }" | 205 " { \"content_type\" : \"image/pwg-raster\" }" |
206 " ]" | 206 " ]" |
207 "}" | 207 "}" |
208 "}"; | 208 "}"; |
209 | 209 |
210 const char kSampleCJTDuplex[] = | 210 const char kSampleCJTDuplex[] = |
211 "{" | 211 "{" |
212 "\"version\" : \"1.0\"," | 212 "\"version\" : \"1.0\"," |
213 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" | 213 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" |
214 "}"; | 214 "}"; |
215 #endif // ENABLE_FULL_PRINTING | 215 #endif // ENABLE_PRINT_PREVIEW |
216 | 216 |
217 // Return the representation of the given JSON that would be outputted by | 217 // Return the representation of the given JSON that would be outputted by |
218 // JSONWriter. This ensures the same JSON values are represented by the same | 218 // JSONWriter. This ensures the same JSON values are represented by the same |
219 // string. | 219 // string. |
220 std::string NormalizeJson(const std::string& json) { | 220 std::string NormalizeJson(const std::string& json) { |
221 std::string result = json; | 221 std::string result = json; |
222 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); | 222 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); |
223 DCHECK(value); | 223 DCHECK(value); |
224 base::JSONWriter::Write(value.get(), &result); | 224 base::JSONWriter::Write(value.get(), &result); |
225 return result; | 225 return result; |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 GURL("http://10.0.0.8:6006/privet/info"), | 745 GURL("http://10.0.0.8:6006/privet/info"), |
746 kSampleInfoResponse)); | 746 kSampleInfoResponse)); |
747 | 747 |
748 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 748 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
749 | 749 |
750 EXPECT_TRUE(SuccessfulResponseToURL( | 750 EXPECT_TRUE(SuccessfulResponseToURL( |
751 GURL("http://10.0.0.8:6006/privet/capabilities"), | 751 GURL("http://10.0.0.8:6006/privet/capabilities"), |
752 kSampleCapabilitiesResponse)); | 752 kSampleCapabilitiesResponse)); |
753 } | 753 } |
754 | 754 |
755 #if defined(ENABLE_FULL_PRINTING) | 755 #if defined(ENABLE_PRINT_PREVIEW) |
756 // A note on PWG raster conversion: The PWG raster converter used simply | 756 // A note on PWG raster conversion: The PWG raster converter used simply |
757 // converts strings to file paths based on them by appending "test.pdf", since | 757 // converts strings to file paths based on them by appending "test.pdf", since |
758 // it's easier to test that way. Instead of using a mock, we simply check if the | 758 // it's easier to test that way. Instead of using a mock, we simply check if the |
759 // request is uploading a file that is based on this pattern. | 759 // request is uploading a file that is based on this pattern. |
760 class FakePWGRasterConverter : public PWGRasterConverter { | 760 class FakePWGRasterConverter : public PWGRasterConverter { |
761 public: | 761 public: |
762 FakePWGRasterConverter() { | 762 FakePWGRasterConverter() { |
763 } | 763 } |
764 | 764 |
765 ~FakePWGRasterConverter() override {} | 765 ~FakePWGRasterConverter() override {} |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 "job_name=Sample+job+name&job_id=1234"), | 1067 "job_name=Sample+job+name&job_id=1234"), |
1068 "Sample print data", | 1068 "Sample print data", |
1069 kSampleErrorResponsePrinterBusy)); | 1069 kSampleErrorResponsePrinterBusy)); |
1070 | 1070 |
1071 RunFor(base::TimeDelta::FromSeconds(3)); | 1071 RunFor(base::TimeDelta::FromSeconds(3)); |
1072 | 1072 |
1073 EXPECT_TRUE(SuccessfulResponseToURL( | 1073 EXPECT_TRUE(SuccessfulResponseToURL( |
1074 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 1074 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
1075 kSampleCreatejobResponse)); | 1075 kSampleCreatejobResponse)); |
1076 } | 1076 } |
1077 #endif // ENABLE_FULL_PRINTING | 1077 #endif // ENABLE_PRINT_PREVIEW |
1078 | 1078 |
1079 } // namespace | 1079 } // namespace |
1080 | 1080 |
1081 } // namespace local_discovery | 1081 } // namespace local_discovery |
OLD | NEW |