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