OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/common/cloud_print/cloud_print_helpers.h" | |
6 | |
7 #include <vector> | |
msw
2012/11/29 19:57:36
nit: vector appears to be unused here, but i may b
Chen Yu
2012/11/30 17:35:46
Done.
| |
8 | |
9 #include "base/md5.h" | |
10 #include "base/stringprintf.h" | |
11 #include "base/sys_info.h" | |
12 #include "chrome/common/chrome_version_info.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace cloud_print { | |
17 | |
18 void CheckURLs(const GURL& server_base_url) { | |
msw
2012/11/29 19:57:36
optional nit: keep CheckURLs and the tests within
Chen Yu
2012/11/30 17:35:46
Done.
| |
19 std::string expected_url_base = server_base_url.spec(); | |
20 if (expected_url_base[expected_url_base.length() - 1] != '/') | |
21 expected_url_base += "/"; | |
22 | |
23 EXPECT_EQ(base::StringPrintf("%ssearch", expected_url_base.c_str()), | |
24 GetUrlForSearch(server_base_url).spec()); | |
25 | |
26 EXPECT_EQ(base::StringPrintf("%ssubmit", expected_url_base.c_str()), | |
27 GetUrlForSubmit(server_base_url).spec()); | |
28 | |
29 EXPECT_EQ(base::StringPrintf("%slist?proxy=demoproxy", | |
30 expected_url_base.c_str()), | |
31 GetUrlForPrinterList( | |
32 server_base_url, std::string("demoproxy")).spec()); | |
33 | |
34 EXPECT_EQ(base::StringPrintf("%sregister", expected_url_base.c_str()), | |
35 GetUrlForPrinterRegistration(server_base_url).spec()); | |
36 | |
37 EXPECT_EQ(base::StringPrintf("%supdate?printerid=printeridfoo", | |
38 expected_url_base.c_str()), | |
39 GetUrlForPrinterUpdate(server_base_url, "printeridfoo").spec()); | |
40 | |
41 EXPECT_EQ(base::StringPrintf("%sdelete?printerid=printeridbar&reason=deleted", | |
42 expected_url_base.c_str()), | |
43 GetUrlForPrinterDelete( | |
44 server_base_url, "printeridbar", "deleted").spec()); | |
45 | |
46 EXPECT_EQ(base::StringPrintf("%sfetch?printerid=myprinter&deb=nogoodreason", | |
47 expected_url_base.c_str()), | |
48 GetUrlForJobFetch( | |
49 server_base_url, "myprinter", "nogoodreason").spec()); | |
50 | |
51 EXPECT_EQ(base::StringPrintf("%sdeletejob?jobid=myprinter", | |
52 expected_url_base.c_str()), | |
53 GetUrlForJobDelete(server_base_url, "myprinter").spec()); | |
54 | |
55 EXPECT_EQ(base::StringPrintf("%scontrol?jobid=myprinter&status=s1", | |
56 expected_url_base.c_str()), | |
57 GetUrlForJobStatusUpdate( | |
58 server_base_url, "myprinter", "s1").spec()); | |
59 | |
60 EXPECT_EQ(base::StringPrintf("%smessage?code=testmsg", | |
61 expected_url_base.c_str()), | |
62 GetUrlForUserMessage(server_base_url, "testmsg").spec()); | |
63 | |
64 EXPECT_EQ(base::StringPrintf( | |
65 "%screaterobot?oauth_client_id=democlientid&proxy=demoproxy", | |
66 expected_url_base.c_str()), | |
67 GetUrlForGetAuthCode( | |
68 server_base_url, "democlientid", "demoproxy").spec()); | |
69 } | |
70 | |
71 TEST(CloudPrintHelpersTest, GetURLs) { | |
72 CheckURLs(GURL("https://www.google.com/cloudprint")); | |
73 CheckURLs(GURL("https://www.google.com/cloudprint/")); | |
74 CheckURLs(GURL("http://www.myprinterserver.com")); | |
75 CheckURLs(GURL("http://www.myprinterserver.com/")); | |
76 } | |
77 | |
78 TEST(CloudPrintHelpersTest, GetHashOfPrinterTags) { | |
79 PrinterTags printer_tags; | |
80 printer_tags["tag1"] = std::string("value1"); | |
81 printer_tags["tag2"] = std::string("value2"); | |
82 | |
83 chrome::VersionInfo version_info; | |
84 std::string expected_list_string = StringPrintf( | |
85 "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2", | |
86 version_info.CreateVersionString().c_str(), | |
87 base::SysInfo::OperatingSystemName().c_str(), | |
88 base::SysInfo::OperatingSystemVersion().c_str()); | |
89 EXPECT_EQ(base::MD5String(expected_list_string), | |
90 GetHashOfPrinterTags(printer_tags)); | |
91 } | |
92 | |
93 TEST(CloudPrintHelpersTest, GetPostDataForPrinterTags) { | |
94 PrinterTags printer_tags; | |
95 printer_tags["tag1"] = std::string("value1"); | |
96 printer_tags["tag2"] = std::string("value2"); | |
97 | |
98 chrome::VersionInfo version_info; | |
99 std::string expected = base::StringPrintf( | |
100 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
101 "\r\n\r\n__test__chrome_version=%s\r\n" | |
102 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
103 "\r\n\r\n__test__system_name=%s\r\n" | |
104 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
105 "\r\n\r\n__test__system_version=%s\r\n" | |
106 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
107 "\r\n\r\n__test__tag1=value1\r\n" | |
108 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
109 "\r\n\r\n__test__tag2=value2\r\n" | |
110 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\"" | |
111 "\r\n\r\n__test__tagshash=%s\r\n", | |
112 version_info.CreateVersionString().c_str(), | |
113 base::SysInfo::OperatingSystemName().c_str(), | |
114 base::SysInfo::OperatingSystemVersion().c_str(), | |
115 GetHashOfPrinterTags(printer_tags).c_str()); | |
116 | |
117 EXPECT_EQ(expected, GetPostDataForPrinterTags( | |
118 printer_tags, | |
119 std::string("test_mime_boundary"), | |
120 std::string("__test__"), | |
121 std::string("__test__tagshash"))); | |
122 } | |
123 | |
124 TEST(CloudPrintHelpersTest, GetCloudPrintAuthHeader) { | |
125 std::string test_auth("testauth"); | |
126 EXPECT_EQ("Authorization: OAuth testauth", | |
127 GetCloudPrintAuthHeader(test_auth)); | |
128 } | |
129 | |
130 } // namespace cloud_print | |
OLD | NEW |