diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-20 22:04:48 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-20 22:04:48 +0000 |
commit | 09cff78781a7bfc6858544b0bd754300eb000bbb (patch) | |
tree | ed81b0c8d63d755ee720a1f8b9bde267b3cbd260 /components/cloud_devices | |
parent | b897d5caed9c84579564d4a6d8b864776931616a (diff) | |
download | chromium_src-09cff78781a7bfc6858544b0bd754300eb000bbb.zip chromium_src-09cff78781a7bfc6858544b0bd754300eb000bbb.tar.gz chromium_src-09cff78781a7bfc6858544b0bd754300eb000bbb.tar.bz2 |
Moved CloudPrintUrl to components/cloud_devices/cloud_devices_urls.h.
Removed unused cloud print prefs.
TBR=jochen, rogerta
Review URL: https://codereview.chromium.org/240283010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264945 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/cloud_devices')
6 files changed, 278 insertions, 0 deletions
diff --git a/components/cloud_devices/common/DEPS b/components/cloud_devices/common/DEPS new file mode 100644 index 0000000..2d23c96 --- /dev/null +++ b/components/cloud_devices/common/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+google_apis/gaia", + "+net/base", +] diff --git a/components/cloud_devices/common/cloud_devices_switches.cc b/components/cloud_devices/common/cloud_devices_switches.cc new file mode 100644 index 0000000..83667fa --- /dev/null +++ b/components/cloud_devices/common/cloud_devices_switches.cc @@ -0,0 +1,21 @@ +// Copyright 2014 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 "components/cloud_devices/common/cloud_devices_switches.h" + +namespace switches { + +// The URL of the cloud print service to use, overrides any value stored in +// preferences, and the default. Only used if the cloud print service has been +// enabled. Used for testing. +const char kCloudPrintURL[] = "cloud-print-url"; + +// The XMPP endpoint the cloud print service will use. Only used if the cloud +// print service has been enabled. Used for testing. +const char kCloudPrintXmppEndpoint[] = "cloud-print-xmpp-endpoint"; + +// The URL of the cloud devices service to use. +const char kCloudDevicesURL[] = "cloud-devices-url"; + +} // namespace switches diff --git a/components/cloud_devices/common/cloud_devices_switches.h b/components/cloud_devices/common/cloud_devices_switches.h new file mode 100644 index 0000000..2a57d73 --- /dev/null +++ b/components/cloud_devices/common/cloud_devices_switches.h @@ -0,0 +1,16 @@ +// Copyright 2014 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. + +#ifndef COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_SWITCHES_H_ +#define COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_SWITCHES_H_ + +namespace switches { + +extern const char kCloudPrintURL[]; +extern const char kCloudPrintXmppEndpoint[]; +extern const char kCloudDevicesURL[]; + +} // namespace switches + +#endif // COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_SWITCHES_H_ diff --git a/components/cloud_devices/common/cloud_devices_urls.cc b/components/cloud_devices/common/cloud_devices_urls.cc new file mode 100644 index 0000000..7645429 --- /dev/null +++ b/components/cloud_devices/common/cloud_devices_urls.cc @@ -0,0 +1,119 @@ +// Copyright 2014 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 "components/cloud_devices/common/cloud_devices_urls.h" + +#include "base/command_line.h" +#include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" +#include "components/cloud_devices/common/cloud_devices_switches.h" +#include "google_apis/gaia/gaia_urls.h" +#include "net/base/url_util.h" + +namespace cloud_devices { + +const char kCloudPrintAuthScope[] = + "https://www.googleapis.com/auth/cloudprint"; + +const char kCloudDevicesAuthScope[] = + "https://www.googleapis.com/auth/clouddevices"; + +const char kCloudPrintLearnMoreURL[] = + "https://www.google.com/support/cloudprint"; + +const char kCloudPrintTestPageURL[] = + "http://www.google.com/landing/cloudprint/enable.html?print=true"; + +namespace { + +// Url must not be matched by "urls" section of +// cloud_print_app/manifest.json. If it's matched, print driver dialog will +// open sign-in page in separate window. +const char kCloudPrintURL[] = "https://www.google.com/cloudprint"; + +const char kCloudDevicesUrl[] = "https://www.googleapis.com/clouddevices/v1"; +} + +// Returns the root service URL for the cloud print service. The default is to +// point at the Google Cloud Print service. This can be overridden by the +// command line or by the user preferences. +GURL GetCloudPrintURL() { + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + GURL cloud_print_url( + command_line->GetSwitchValueASCII(switches::kCloudPrintURL)); + if (cloud_print_url.is_empty()) + cloud_print_url = GURL(kCloudPrintURL); + return cloud_print_url; +} + +GURL GetCloudPrintRelativeURL(const std::string& relative_path) { + GURL url = GetCloudPrintURL(); + std::string path; + const char kURLPathSeparator[] = "/"; + base::TrimString(url.path(), kURLPathSeparator, &path); + std::string trimmed_path; + base::TrimString(relative_path, kURLPathSeparator, &trimmed_path); + path += kURLPathSeparator; + path += trimmed_path; + GURL::Replacements replacements; + replacements.SetPathStr(path); + return url.ReplaceComponents(replacements); +} + +GURL GetCloudPrintSigninURL() { + GURL url(GaiaUrls::GetInstance()->service_login_url()); + url = net::AppendQueryParameter(url, "service", "cloudprint"); + url = net::AppendQueryParameter(url, "sarp", "1"); + std::string continue_str = GetCloudPrintURL().spec(); + url = net::AppendQueryParameter(url, "continue", continue_str); + return url; +} + +GURL GetCloudPrintAddAccountURL() { + GURL url(GaiaUrls::GetInstance()->add_account_url()); + url = net::AppendQueryParameter(url, "service", "cloudprint"); + url = net::AppendQueryParameter(url, "sarp", "1"); + std::string continue_str = GetCloudPrintURL().spec(); + url = net::AppendQueryParameter(url, "continue", continue_str); + return url; +} + +GURL GetCloudPrintEnableURL(const std::string& proxy_id) { + GURL url = GetCloudPrintRelativeURL("enable_chrome_connector/enable.html"); + url = net::AppendQueryParameter(url, "proxy", proxy_id); + return url; +} + +GURL GetCloudPrintEnableURLWithSignin(const std::string& proxy_id) { + GURL url(GaiaUrls::GetInstance()->service_login_url()); + url = net::AppendQueryParameter(url, "service", "cloudprint"); + url = net::AppendQueryParameter(url, "sarp", "1"); + std::string continue_str = GetCloudPrintEnableURL(proxy_id).spec(); + return net::AppendQueryParameter(url, "continue", continue_str); +} + +GURL GetCloudDevicesURL() { + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + GURL cloud_print_url( + command_line->GetSwitchValueASCII(switches::kCloudDevicesURL)); + if (cloud_print_url.is_empty()) + cloud_print_url = GURL(kCloudDevicesUrl); + return cloud_print_url; +} + +GURL GetCloudDevicesRelativeURL(const std::string& relative_path) { + GURL url = GetCloudDevicesURL(); + std::string path; + const char kURLPathSeparator[] = "/"; + base::TrimString(url.path(), kURLPathSeparator, &path); + std::string trimmed_path; + base::TrimString(relative_path, kURLPathSeparator, &trimmed_path); + path += kURLPathSeparator; + path += trimmed_path; + GURL::Replacements replacements; + replacements.SetPathStr(path); + return url.ReplaceComponents(replacements); +} + +} // namespace cloud_devices diff --git a/components/cloud_devices/common/cloud_devices_urls.h b/components/cloud_devices/common/cloud_devices_urls.h new file mode 100644 index 0000000..8e03856 --- /dev/null +++ b/components/cloud_devices/common/cloud_devices_urls.h @@ -0,0 +1,31 @@ +// Copyright 2014 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. + +#ifndef COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_URLS_H_ +#define COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_URLS_H_ + +#include <string> + +#include "url/gurl.h" + +namespace cloud_devices { + +extern const char kCloudPrintAuthScope[]; +extern const char kCloudDevicesAuthScope[]; +extern const char kCloudPrintLearnMoreURL[]; +extern const char kCloudPrintTestPageURL[]; + +GURL GetCloudPrintURL(); +GURL GetCloudPrintRelativeURL(const std::string& relative_path); +GURL GetCloudPrintEnableURL(const std::string& proxy_id); +GURL GetCloudPrintEnableURLWithSignin(const std::string& proxy_id); +GURL GetCloudPrintSigninURL(); +GURL GetCloudPrintAddAccountURL(); + +GURL GetCloudDevicesURL(); +GURL GetCloudDevicesRelativeURL(const std::string& relative_path); + +} // namespace cloud_devices + +#endif // COMPONENTS_CLOUD_DEVICES_COMMON_CLOUD_DEVICES_URLS_H_ diff --git a/components/cloud_devices/common/cloud_devices_urls_unittest.cc b/components/cloud_devices/common/cloud_devices_urls_unittest.cc new file mode 100644 index 0000000..4a285c6 --- /dev/null +++ b/components/cloud_devices/common/cloud_devices_urls_unittest.cc @@ -0,0 +1,87 @@ +// Copyright 2014 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 "components/cloud_devices/common/cloud_devices_urls.h" + +#include <string> + +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using testing::HasSubstr; + +namespace cloud_devices { + +TEST(CloudPrintURLTest, GetCloudPrintURL) { + std::string service_url = GetCloudPrintURL().spec(); + EXPECT_THAT(service_url, HasSubstr("www.google.com")); + EXPECT_THAT(service_url, HasSubstr("cloudprint")); +} + +TEST(CloudPrintURLTest, GetCloudPrintRelativeURL) { + EXPECT_THAT(GetCloudPrintRelativeURL("///a/b/c///").spec(), + HasSubstr("/cloudprint/a/b/c")); + + EXPECT_THAT(GetCloudPrintRelativeURL("a/b/c").spec(), + HasSubstr("/cloudprint/a/b/c")); +} + +TEST(CloudPrintURLTest, GetCloudPrintDialogUrl) { + std::string dialog_url = + GetCloudPrintRelativeURL("client/dialog.html").spec(); + EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); + EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); + EXPECT_THAT(dialog_url, HasSubstr("/client/")); + EXPECT_THAT(dialog_url, Not(HasSubstr("cloudprint/cloudprint"))); + EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); +} + +TEST(CloudPrintURLTest, GetCloudPrintManageUrl) { + std::string manage_url = GetCloudPrintRelativeURL("manage.html").spec(); + EXPECT_THAT(manage_url, HasSubstr("www.google.com")); + EXPECT_THAT(manage_url, HasSubstr("/cloudprint/")); + EXPECT_THAT(manage_url, Not(HasSubstr("/client/"))); + EXPECT_THAT(manage_url, Not(HasSubstr("cloudprint/cloudprint"))); + EXPECT_THAT(manage_url, HasSubstr("/manage.html")); +} + +TEST(CloudPrintURLTest, GetCloudPrintEnableURL) { + std::string enable_url = GetCloudPrintEnableURL("123123").spec(); + EXPECT_THAT(enable_url, HasSubstr("proxy=123123")); + EXPECT_THAT(enable_url, HasSubstr("/enable_chrome_connector/enable.html")); + EXPECT_THAT(enable_url, HasSubstr("/cloudprint/")); +} + +TEST(CloudPrintURLTest, GetCloudPrintEnableURLWithSignin) { + std::string enable_url = GetCloudPrintEnableURLWithSignin("123123").spec(); + EXPECT_THAT(enable_url, HasSubstr("accounts.google.com")); + EXPECT_THAT(enable_url, HasSubstr("/ServiceLogin")); + EXPECT_THAT(enable_url, HasSubstr("service=cloudprint")); + EXPECT_THAT(enable_url, HasSubstr("continue=")); + EXPECT_THAT(enable_url, HasSubstr("proxy%3D123123")); + EXPECT_THAT(enable_url, HasSubstr("%2Fenable_chrome_connector%2Fenable")); + EXPECT_THAT(enable_url, HasSubstr("%2Fcloudprint%2F")); +} + +TEST(CloudPrintURLTest, GetCloudPrintSigninURL) { + std::string signin_url = GetCloudPrintSigninURL().spec(); + EXPECT_THAT(signin_url, HasSubstr("accounts.google.com")); + EXPECT_THAT(signin_url, HasSubstr("/ServiceLogin")); + EXPECT_THAT(signin_url, HasSubstr("service=cloudprint")); + EXPECT_THAT(signin_url, HasSubstr("continue=")); + EXPECT_THAT(signin_url, HasSubstr("%2Fcloudprint")); + EXPECT_THAT(signin_url, Not(HasSubstr("/cloudprint"))); +} + +TEST(CloudPrintURLTest, GetCloudPrintAddAccountURL) { + std::string add_url = GetCloudPrintAddAccountURL().spec(); + EXPECT_THAT(add_url, HasSubstr("accounts.google.com")); + EXPECT_THAT(add_url, HasSubstr("/AddSession")); + EXPECT_THAT(add_url, HasSubstr("service=cloudprint")); + EXPECT_THAT(add_url, HasSubstr("continue=")); + EXPECT_THAT(add_url, HasSubstr("%2Fcloudprint")); + EXPECT_THAT(add_url, Not(HasSubstr("/cloudprint"))); +} + +} // namespace cloud_devices |