Chromium Code Reviews| 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 "base/stringprintf.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/common/cloud_print/test_cloud_print_utils.h" | |
| 10 #include "googleurl/src/gurl.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 using namespace cloud_print; | |
|
msw
2012/11/17 00:22:30
nit: Put everything here in the cloud_print namesp
Chen Yu
2012/11/26 12:07:06
Done.
| |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 void CheckURLs(const GURL& server_base_url) { | |
|
msw
2012/11/17 00:22:30
nit: Test calling helpers in the order they are de
Chen Yu
2012/11/26 12:07:06
Done.
| |
| 18 GURL url = GetUrlForPrinterRegistration(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 += "/"; | |
| 22 std::string expected_url = base::StringPrintf( | |
| 23 "%sregister", expected_url_base.c_str()); | |
| 24 EXPECT_EQ(expected_url, url.spec()); | |
| 25 | |
| 26 url = GetUrlForPrinterUpdate(server_base_url, "printeridfoo"); | |
| 27 expected_url = base::StringPrintf("%supdate?printerid=printeridfoo", | |
| 28 expected_url_base.c_str()); | |
| 29 EXPECT_EQ(expected_url, url.spec()); | |
| 30 | |
| 31 url = GetUrlForPrinterDelete(server_base_url, "printeridbar", "deleted"); | |
| 32 expected_url = base::StringPrintf( | |
| 33 "%sdelete?printerid=printeridbar&reason=deleted", | |
| 34 expected_url_base.c_str()); | |
| 35 EXPECT_EQ(expected_url, url.spec()); | |
| 36 | |
| 37 url = GetUrlForPrinterList(server_base_url, "demoproxy"); | |
| 38 expected_url = base::StringPrintf("%slist?proxy=demoproxy", | |
| 39 expected_url_base.c_str()); | |
| 40 EXPECT_EQ(expected_url, url.spec()); | |
| 41 | |
| 42 url = GetUrlForJobFetch(server_base_url, "myprinter", "nogoodreason"); | |
| 43 expected_url = base::StringPrintf( | |
| 44 "%sfetch?printerid=myprinter&deb=nogoodreason", | |
| 45 expected_url_base.c_str()); | |
| 46 EXPECT_EQ(expected_url, url.spec()); | |
| 47 } | |
|
msw
2012/11/17 00:22:30
Add cases for the other helpers: GetUrlForJobDelet
Chen Yu
2012/11/26 12:07:06
Done.
| |
| 48 | |
| 49 TEST(CloudPrintHelpersTest, GetURLs) { | |
|
msw
2012/11/17 00:22:30
For bonus points, add more tests for other helper
Chen Yu
2012/11/26 12:07:06
Done.
| |
| 50 CheckURLs(GURL("https://www.google.com/cloudprint")); | |
| 51 CheckURLs(GURL("https://www.google.com/cloudprint/")); | |
| 52 CheckURLs(GURL("http://www.myprinterserver.com")); | |
| 53 CheckURLs(GURL("http://www.myprinterserver.com/")); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| OLD | NEW |