Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / common / cloud_print / cloud_print_helpers_unittest.cc
blob662ee5847f4a513adc7b5e8a131e8f94b3ddd008
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/chrome_version_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 chrome::VersionInfo version_info;
87 std::string expected_list_string = base::StringPrintf(
88 "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2",
89 version_info.CreateVersionString().c_str(),
90 base::SysInfo::OperatingSystemName().c_str(),
91 base::SysInfo::OperatingSystemVersion().c_str());
92 EXPECT_EQ(base::MD5String(expected_list_string),
93 GetHashOfPrinterTags(printer_tags));
96 TEST(CloudPrintHelpersTest, GetPostDataForPrinterTags) {
97 PrinterTags printer_tags;
98 printer_tags["tag1"] = std::string("value1");
99 printer_tags["tag2"] = std::string("value2");
101 chrome::VersionInfo version_info;
102 std::string expected = base::StringPrintf(
103 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
104 "\r\n\r\n__test__chrome_version=%s\r\n"
105 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
106 "\r\n\r\n__test__system_name=%s\r\n"
107 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
108 "\r\n\r\n__test__system_version=%s\r\n"
109 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
110 "\r\n\r\n__test__tag1=value1\r\n"
111 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
112 "\r\n\r\n__test__tag2=value2\r\n"
113 "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
114 "\r\n\r\n__test__tagshash=%s\r\n",
115 version_info.CreateVersionString().c_str(),
116 base::SysInfo::OperatingSystemName().c_str(),
117 base::SysInfo::OperatingSystemVersion().c_str(),
118 GetHashOfPrinterTags(printer_tags).c_str());
120 EXPECT_EQ(expected, GetPostDataForPrinterTags(
121 printer_tags,
122 std::string("test_mime_boundary"),
123 std::string("__test__"),
124 std::string("__test__tagshash")));
127 TEST(CloudPrintHelpersTest, GetCloudPrintAuthHeader) {
128 std::string test_auth("testauth");
129 EXPECT_EQ("Authorization: OAuth testauth",
130 GetCloudPrintAuthHeader(test_auth));
133 } // namespace cloud_print