OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
msw
2012/11/09 23:18:17
ditto for unit tests, move it to common instead of
| |
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 "chrome/service/cloud_print/cloud_print_helpers.h" | 5 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
6 | 6 |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 void CheckURLs(const GURL& server_base_url) { | 12 void CheckURLs(const GURL& server_base_url) { |
13 GURL url = CloudPrintHelpers::GetUrlForPrinterRegistration(server_base_url); | |
14 std::string expected_url_base = server_base_url.spec(); | |
15 if (expected_url_base[expected_url_base.length() - 1] != '/') { | |
16 expected_url_base += "/"; | |
17 } | |
18 std::string expected_url = base::StringPrintf("%sregister", | |
19 expected_url_base.c_str()); | |
20 EXPECT_EQ(expected_url, url.spec()); | |
21 | |
22 url = CloudPrintHelpers::GetUrlForPrinterUpdate(server_base_url, | |
23 "printeridfoo"); | |
24 expected_url = base::StringPrintf("%supdate?printerid=printeridfoo", | |
25 expected_url_base.c_str()); | |
26 EXPECT_EQ(expected_url, url.spec()); | |
27 | |
28 url = CloudPrintHelpers::GetUrlForPrinterDelete(server_base_url, | |
29 "printeridbar", "deleted"); | |
30 expected_url = base::StringPrintf( | |
31 "%sdelete?printerid=printeridbar&reason=deleted", | |
32 expected_url_base.c_str()); | |
33 EXPECT_EQ(expected_url, url.spec()); | |
34 | |
35 url = CloudPrintHelpers::GetUrlForPrinterList(server_base_url, "demoproxy"); | |
36 expected_url = base::StringPrintf("%slist?proxy=demoproxy", | |
37 expected_url_base.c_str()); | |
38 EXPECT_EQ(expected_url, url.spec()); | |
39 | |
40 url = CloudPrintHelpers::GetUrlForJobFetch(server_base_url, | |
41 "myprinter", | |
42 "nogoodreason"); | |
43 expected_url = base::StringPrintf( | |
44 "%sfetch?printerid=myprinter&deb=nogoodreason", | |
45 expected_url_base.c_str()); | |
46 EXPECT_EQ(expected_url, url.spec()); | |
47 | |
48 url = CloudPrintHelpers::GetUrlForJobStatusUpdate( | |
49 server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_IN_PROGRESS); | |
50 expected_url = base::StringPrintf( | |
51 "%scontrol?jobid=12345678&status=IN_PROGRESS", expected_url_base.c_str()); | |
52 EXPECT_EQ(expected_url, url.spec()); | |
53 | |
54 url = CloudPrintHelpers::GetUrlForJobStatusUpdate( | |
55 server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_ERROR); | |
56 expected_url = base::StringPrintf("%scontrol?jobid=12345678&status=ERROR", | |
57 expected_url_base.c_str()); | |
58 EXPECT_EQ(expected_url, url.spec()); | |
59 | |
60 url = CloudPrintHelpers::GetUrlForJobStatusUpdate( | |
61 server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_COMPLETED); | |
62 expected_url = base::StringPrintf("%scontrol?jobid=12345678&status=DONE", | |
63 expected_url_base.c_str()); | |
64 EXPECT_EQ(expected_url, url.spec()); | |
65 | |
66 cloud_print::PrintJobDetails details; | 13 cloud_print::PrintJobDetails details; |
67 details.status = cloud_print::PRINT_JOB_STATUS_IN_PROGRESS; | 14 details.status = cloud_print::PRINT_JOB_STATUS_IN_PROGRESS; |
68 details.platform_status_flags = 2; | 15 details.platform_status_flags = 2; |
69 details.status_message = "Out of Paper"; | 16 details.status_message = "Out of Paper"; |
70 details.total_pages = 345; | 17 details.total_pages = 345; |
71 details.pages_printed = 47; | 18 details.pages_printed = 47; |
72 url = CloudPrintHelpers::GetUrlForJobStatusUpdate(server_base_url, | 19 GURL url = CloudPrintHelpers::GetUrlForJobStatusUpdate( |
73 "87654321", details); | 20 server_base_url, "87654321", details); |
74 expected_url = base::StringPrintf( | 21 std::string expected_url = base::StringPrintf( |
75 "%scontrol?jobid=87654321&status=IN_PROGRESS&code=2" | 22 "%scontrol?jobid=87654321&status=IN_PROGRESS&code=2" |
76 "&message=Out%%20of%%20Paper&numpages=345&pagesprinted=47", | 23 "&message=Out%%20of%%20Paper&numpages=345&pagesprinted=47", |
77 expected_url_base.c_str()); | 24 expected_url_base.c_str()); |
78 EXPECT_EQ(expected_url, url.spec()); | 25 EXPECT_EQ(expected_url, url.spec()); |
79 | |
80 url = CloudPrintHelpers::GetUrlForUserMessage(server_base_url, | |
81 "blahmessageid"); | |
82 expected_url = base::StringPrintf("%smessage?code=blahmessageid", | |
83 expected_url_base.c_str()); | |
84 EXPECT_EQ(expected_url, url.spec()); | |
85 | |
86 url = CloudPrintHelpers::GetUrlForGetAuthCode( | |
87 server_base_url, | |
88 "fooclientid.apps.googleusercontent.com", | |
89 "test_proxy"); | |
90 expected_url = base::StringPrintf( | |
91 "%screaterobot?oauth_client_id=fooclientid.apps.googleusercontent.com&" | |
92 "proxy=test_proxy", expected_url_base.c_str()); | |
93 EXPECT_EQ(expected_url, url.spec()); | |
94 } | 26 } |
95 | 27 |
96 } // namespace | 28 } // namespace |
97 | 29 |
98 TEST(CloudPrintHelpersTest, URLGetters) { | 30 TEST(CloudPrintHelpersTest, URLGetters) { |
99 CheckURLs(GURL("https://www.google.com/cloudprint")); | 31 CheckURLs(GURL("https://www.google.com/cloudprint")); |
100 CheckURLs(GURL("https://www.google.com/cloudprint/")); | 32 CheckURLs(GURL("https://www.google.com/cloudprint/")); |
101 CheckURLs(GURL("http://www.myprinterserver.com")); | 33 CheckURLs(GURL("http://www.myprinterserver.com")); |
102 CheckURLs(GURL("http://www.myprinterserver.com/")); | 34 CheckURLs(GURL("http://www.myprinterserver.com/")); |
103 } | 35 } |
104 | 36 |
OLD | NEW |