Don't compile save_password_infobar_delegate.cc everywhere but Mac and Android
[chromium-blink-merge.git] / chrome / common / cloud_print / cloud_print_helpers_unittest.cc
blob41b8f982c1a2ec6da459e6e24b18262f2cb64595
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.
5 #include "chrome/common/cloud_print/cloud_print_helpers.h"
7 #include "base/md5.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/sys_info.h"
10 #include "chrome/common/channel_info.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
14 namespace cloud_print {
16 namespace {
18 void CheckURLs(const GURL& server_base_url) {
19 std::string expected_url_base = server_base_url.spec();
20 if (expected_url_base[expected_url_base.length() - 1] != '/')
21 expected_url_base += "/";
23 EXPECT_EQ(base::StringPrintf("%ssearch", expected_url_base.c_str()),
24 GetUrlForSearch(server_base_url).spec());
26 EXPECT_EQ(base::StringPrintf("%ssubmit", expected_url_base.c_str()),
27 GetUrlForSubmit(server_base_url).spec());
29 EXPECT_EQ(base::StringPrintf("%slist?proxy=demoproxy",
30 expected_url_base.c_str()),
31 GetUrlForPrinterList(
32 server_base_url, std::string("demoproxy")).spec());
34 EXPECT_EQ(base::StringPrintf("%sregister", expected_url_base.c_str()),
35 GetUrlForPrinterRegistration(server_base_url).spec());
37 EXPECT_EQ(base::StringPrintf("%supdate?printerid=printeridfoo",
38 expected_url_base.c_str()),
39 GetUrlForPrinterUpdate(server_base_url, "printeridfoo").spec());
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());
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());
51 EXPECT_EQ(base::StringPrintf("%sdeletejob?jobid=myprinter",
52 expected_url_base.c_str()),
53 GetUrlForJobDelete(server_base_url, "myprinter").spec());
55 EXPECT_EQ(base::StringPrintf(
56 "%scontrol?jobid=myprinter&status=s1&connector_code=0",
57 expected_url_base.c_str()),
58 GetUrlForJobStatusUpdate(
59 server_base_url, "myprinter", "s1", 0).spec());
61 EXPECT_EQ(base::StringPrintf("%smessage?code=testmsg",
62 expected_url_base.c_str()),
63 GetUrlForUserMessage(server_base_url, "testmsg").spec());
65 EXPECT_EQ(base::StringPrintf(
66 "%screaterobot?oauth_client_id=democlientid&proxy=demoproxy",
67 expected_url_base.c_str()),
68 GetUrlForGetAuthCode(
69 server_base_url, "democlientid", "demoproxy").spec());
72 } // namespace
74 TEST(CloudPrintHelpersTest, GetURLs) {
75 CheckURLs(GURL("https://www.google.com/cloudprint"));
76 CheckURLs(GURL("https://www.google.com/cloudprint/"));
77 CheckURLs(GURL("http://www.myprinterserver.com"));
78 CheckURLs(GURL("http://www.myprinterserver.com/"));
81 TEST(CloudPrintHelpersTest, GetHashOfPrinterTags) {
82 PrinterTags printer_tags;
83 printer_tags["tag1"] = std::string("value1");
84 printer_tags["tag2"] = std::string("value2");
86 std::string expected_list_string = base::StringPrintf(
87 "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2",
88 chrome::GetVersionString().c_str(),
89 base::SysInfo::OperatingSystemName().c_str(),
90 base::SysInfo::OperatingSystemVersion().c_str());
91 EXPECT_EQ(base::MD5String(expected_list_string),
92 GetHashOfPrinterTags(printer_tags));
95 TEST(CloudPrintHelpersTest, GetPostDataForPrinterTags) {
96 PrinterTags printer_tags;
97 printer_tags["tag1"] = std::string("value1");
98 printer_tags["tag2"] = std::string("value2");
100 std::string expected = base::StringPrintf(
101 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
102 "\r\n\r\n__test__chrome_version=%s\r\n"
103 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
104 "\r\n\r\n__test__system_name=%s\r\n"
105 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
106 "\r\n\r\n__test__system_version=%s\r\n"
107 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
108 "\r\n\r\n__test__tag1=value1\r\n"
109 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
110 "\r\n\r\n__test__tag2=value2\r\n"
111 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
112 "\r\n\r\n__test__tagshash=%s\r\n",
113 chrome::GetVersionString().c_str(),
114 base::SysInfo::OperatingSystemName().c_str(),
115 base::SysInfo::OperatingSystemVersion().c_str(),
116 GetHashOfPrinterTags(printer_tags).c_str());
118 EXPECT_EQ(expected, GetPostDataForPrinterTags(
119 printer_tags,
120 std::string("test_mime_boundary"),
121 std::string("__test__"),
122 std::string("__test__tagshash")));
125 TEST(CloudPrintHelpersTest, GetCloudPrintAuthHeader) {
126 std::string test_auth("testauth");
127 EXPECT_EQ("Authorization: OAuth testauth",
128 GetCloudPrintAuthHeader(test_auth));
131 } // namespace cloud_print