Index: chrome/common/cloud_print/cloud_print_helpers_unittest.cc |
diff --git a/chrome/common/cloud_print/cloud_print_helpers_unittest.cc b/chrome/common/cloud_print/cloud_print_helpers_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..547ab02ea38daf3afa9d2fb9ffdbfaa7b36c70a3 |
--- /dev/null |
+++ b/chrome/common/cloud_print/cloud_print_helpers_unittest.cc |
@@ -0,0 +1,56 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/common/cloud_print/cloud_print_helpers.h" |
+ |
+#include "base/stringprintf.h" |
+#include "base/values.h" |
+#include "chrome/common/cloud_print/test_cloud_print_utils.h" |
+#include "googleurl/src/gurl.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+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.
|
+ |
+namespace { |
+ |
+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.
|
+ GURL url = GetUrlForPrinterRegistration(server_base_url); |
+ std::string expected_url_base = server_base_url.spec(); |
+ if (expected_url_base[expected_url_base.length() - 1] != '/') |
+ expected_url_base += "/"; |
+ std::string expected_url = base::StringPrintf( |
+ "%sregister", expected_url_base.c_str()); |
+ EXPECT_EQ(expected_url, url.spec()); |
+ |
+ url = GetUrlForPrinterUpdate(server_base_url, "printeridfoo"); |
+ expected_url = base::StringPrintf("%supdate?printerid=printeridfoo", |
+ expected_url_base.c_str()); |
+ EXPECT_EQ(expected_url, url.spec()); |
+ |
+ url = GetUrlForPrinterDelete(server_base_url, "printeridbar", "deleted"); |
+ expected_url = base::StringPrintf( |
+ "%sdelete?printerid=printeridbar&reason=deleted", |
+ expected_url_base.c_str()); |
+ EXPECT_EQ(expected_url, url.spec()); |
+ |
+ url = GetUrlForPrinterList(server_base_url, "demoproxy"); |
+ expected_url = base::StringPrintf("%slist?proxy=demoproxy", |
+ expected_url_base.c_str()); |
+ EXPECT_EQ(expected_url, url.spec()); |
+ |
+ url = GetUrlForJobFetch(server_base_url, "myprinter", "nogoodreason"); |
+ expected_url = base::StringPrintf( |
+ "%sfetch?printerid=myprinter&deb=nogoodreason", |
+ expected_url_base.c_str()); |
+ EXPECT_EQ(expected_url, url.spec()); |
+} |
msw
2012/11/17 00:22:30
Add cases for the other helpers: GetUrlForJobDelet
Chen Yu
2012/11/26 12:07:06
Done.
|
+ |
+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.
|
+ CheckURLs(GURL("https://www.google.com/cloudprint")); |
+ CheckURLs(GURL("https://www.google.com/cloudprint/")); |
+ CheckURLs(GURL("http://www.myprinterserver.com")); |
+ CheckURLs(GURL("http://www.myprinterserver.com/")); |
+} |
+ |
+} // namespace |