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 "chrome/service/cloud_print/cloud_print_service_helpers.h" | 5 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
6 | 6 |
7 #include "base/md5.h" | 7 #include "base/md5.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/channel_info.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace cloud_print { | 13 namespace cloud_print { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 void CheckJobStatusURLs(const GURL& server_base_url) { | 17 void CheckJobStatusURLs(const GURL& server_base_url) { |
18 std::string expected_url_base = server_base_url.spec(); | 18 std::string expected_url_base = server_base_url.spec(); |
19 if (expected_url_base[expected_url_base.length() - 1] != '/') | 19 if (expected_url_base[expected_url_base.length() - 1] != '/') |
20 expected_url_base += "/"; | 20 expected_url_base += "/"; |
(...skipping 25 matching lines...) Expand all Loading... |
46 CheckJobStatusURLs(GURL("https://www.google.com/cloudprint/")); | 46 CheckJobStatusURLs(GURL("https://www.google.com/cloudprint/")); |
47 CheckJobStatusURLs(GURL("http://www.myprinterserver.com")); | 47 CheckJobStatusURLs(GURL("http://www.myprinterserver.com")); |
48 CheckJobStatusURLs(GURL("http://www.myprinterserver.com/")); | 48 CheckJobStatusURLs(GURL("http://www.myprinterserver.com/")); |
49 } | 49 } |
50 | 50 |
51 TEST(CloudPrintServiceHelpersTest, GetHashOfPrinterInfo) { | 51 TEST(CloudPrintServiceHelpersTest, GetHashOfPrinterInfo) { |
52 printing::PrinterBasicInfo printer_info; | 52 printing::PrinterBasicInfo printer_info; |
53 printer_info.options["tag1"] = std::string("value1"); | 53 printer_info.options["tag1"] = std::string("value1"); |
54 printer_info.options["tag2"] = std::string("value2"); | 54 printer_info.options["tag2"] = std::string("value2"); |
55 | 55 |
56 chrome::VersionInfo version_info; | |
57 std::string expected_list_string = base::StringPrintf( | 56 std::string expected_list_string = base::StringPrintf( |
58 "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2", | 57 "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2", |
59 version_info.CreateVersionString().c_str(), | 58 chrome::GetVersionString().c_str(), |
60 base::SysInfo::OperatingSystemName().c_str(), | 59 base::SysInfo::OperatingSystemName().c_str(), |
61 base::SysInfo::OperatingSystemVersion().c_str()); | 60 base::SysInfo::OperatingSystemVersion().c_str()); |
62 EXPECT_EQ(base::MD5String(expected_list_string), | 61 EXPECT_EQ(base::MD5String(expected_list_string), |
63 GetHashOfPrinterInfo(printer_info)); | 62 GetHashOfPrinterInfo(printer_info)); |
64 } | 63 } |
65 | 64 |
66 TEST(CloudPrintServiceHelpersTest, GetPostDataForPrinterInfo) { | 65 TEST(CloudPrintServiceHelpersTest, GetPostDataForPrinterInfo) { |
67 printing::PrinterBasicInfo printer_info; | 66 printing::PrinterBasicInfo printer_info; |
68 printer_info.options["tag1"] = std::string("value1"); | 67 printer_info.options["tag1"] = std::string("value1"); |
69 printer_info.options["tag2"] = std::string("value2"); | 68 printer_info.options["tag2"] = std::string("value2"); |
70 | 69 |
71 chrome::VersionInfo version_info; | |
72 std::string expected = base::StringPrintf( | 70 std::string expected = base::StringPrintf( |
73 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 71 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
74 "\r\n\r\n__cp__chrome_version=%s\r\n" | 72 "\r\n\r\n__cp__chrome_version=%s\r\n" |
75 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 73 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
76 "\r\n\r\n__cp__system_name=%s\r\n" | 74 "\r\n\r\n__cp__system_name=%s\r\n" |
77 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 75 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
78 "\r\n\r\n__cp__system_version=%s\r\n" | 76 "\r\n\r\n__cp__system_version=%s\r\n" |
79 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 77 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
80 "\r\n\r\n__cp__tag1=value1\r\n" | 78 "\r\n\r\n__cp__tag1=value1\r\n" |
81 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 79 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
82 "\r\n\r\n__cp__tag2=value2\r\n" | 80 "\r\n\r\n__cp__tag2=value2\r\n" |
83 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | 81 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" |
84 "\r\n\r\n__cp__tagshash=%s\r\n", | 82 "\r\n\r\n__cp__tagshash=%s\r\n", |
85 version_info.CreateVersionString().c_str(), | 83 chrome::GetVersionString().c_str(), |
86 base::SysInfo::OperatingSystemName().c_str(), | 84 base::SysInfo::OperatingSystemName().c_str(), |
87 base::SysInfo::OperatingSystemVersion().c_str(), | 85 base::SysInfo::OperatingSystemVersion().c_str(), |
88 GetHashOfPrinterInfo(printer_info).c_str()); | 86 GetHashOfPrinterInfo(printer_info).c_str()); |
89 | 87 |
90 EXPECT_EQ(expected, GetPostDataForPrinterInfo( | 88 EXPECT_EQ(expected, GetPostDataForPrinterInfo( |
91 printer_info, std::string("test_mime_boundary"))); | 89 printer_info, std::string("test_mime_boundary"))); |
92 } | 90 } |
93 | 91 |
94 TEST(CloudPrintServiceHelpersTest, IsDryRunJob) { | 92 TEST(CloudPrintServiceHelpersTest, IsDryRunJob) { |
95 std::vector<std::string> tags_not_dry_run; | 93 std::vector<std::string> tags_not_dry_run; |
96 tags_not_dry_run.push_back("tag_1"); | 94 tags_not_dry_run.push_back("tag_1"); |
97 EXPECT_FALSE(IsDryRunJob(tags_not_dry_run)); | 95 EXPECT_FALSE(IsDryRunJob(tags_not_dry_run)); |
98 | 96 |
99 std::vector<std::string> tags_dry_run; | 97 std::vector<std::string> tags_dry_run; |
100 tags_dry_run.push_back("__cp__dry_run"); | 98 tags_dry_run.push_back("__cp__dry_run"); |
101 EXPECT_TRUE(IsDryRunJob(tags_dry_run)); | 99 EXPECT_TRUE(IsDryRunJob(tags_dry_run)); |
102 } | 100 } |
103 | 101 |
104 } // namespace cloud_print | 102 } // namespace cloud_print |
105 | 103 |
OLD | NEW |