From 902a8a01d32a4a992b2f8932504b7b2da8705b65 Mon Sep 17 00:00:00 2001 From: "asargent@chromium.org" Date: Sat, 4 May 2013 05:04:16 +0000 Subject: [PATCH] Add os/arch/nacl_arch to webstore install code We already had it for update checks, but need it for the initial install requests as well. BUG=235233 Review URL: https://chromiumcodereview.appspot.com/14935002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198294 0039d316-1c4b-4281-b951-d872f2087c98 --- .../updater/extension_updater_unittest.cc | 9 +--- .../extensions/updater/manifest_fetch_data.cc | 8 +--- chrome/browser/extensions/webstore_installer.cc | 52 ++++++++++++---------- chrome/browser/extensions/webstore_installer.h | 5 +++ .../extensions/webstore_installer_unittest.cc | 35 +++++++++++++++ chrome/chrome_tests_unit.gypi | 21 ++++----- chrome/common/extensions/extension_test_util.h | 3 -- .../omaha_query_params/omaha_query_params.cc | 7 +-- .../common/omaha_query_params/omaha_query_params.h | 3 +- 9 files changed, 87 insertions(+), 56 deletions(-) create mode 100644 chrome/browser/extensions/webstore_installer_unittest.cc diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc index 91d86b0e914c..30359d112ac4 100644 --- a/chrome/browser/extensions/updater/extension_updater_unittest.cc +++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc @@ -451,13 +451,8 @@ static void VerifyQueryAndExtractParameters( std::map params; ExtractParameters(query, ¶ms); -chrome::OmahaQueryParams::ProdId prod = -#if defined(GOOGLE_CHROME_BUILD) - chrome::OmahaQueryParams::CHROMECRX; -#else - chrome::OmahaQueryParams::CHROMIUMCRX; -#endif - std::string omaha_params = chrome::OmahaQueryParams::Get(prod); + std::string omaha_params = + chrome::OmahaQueryParams::Get(chrome::OmahaQueryParams::CRX); std::map expected; ExtractParameters(omaha_params, &expected); diff --git a/chrome/browser/extensions/updater/manifest_fetch_data.cc b/chrome/browser/extensions/updater/manifest_fetch_data.cc index c243f9b9183b..ea5fb0db4584 100644 --- a/chrome/browser/extensions/updater/manifest_fetch_data.cc +++ b/chrome/browser/extensions/updater/manifest_fetch_data.cc @@ -28,15 +28,9 @@ namespace extensions { ManifestFetchData::ManifestFetchData(const GURL& update_url, int request_id) : base_url_(update_url), full_url_(update_url) { -chrome::OmahaQueryParams::ProdId prod = -#if defined(GOOGLE_CHROME_BUILD) - chrome::OmahaQueryParams::CHROMECRX; -#else - chrome::OmahaQueryParams::CHROMIUMCRX; -#endif std::string query = full_url_.has_query() ? full_url_.query() + "&" : std::string(); - query += chrome::OmahaQueryParams::Get(prod); + query += chrome::OmahaQueryParams::Get(chrome::OmahaQueryParams::CRX); GURL::Replacements replacements; replacements.SetQueryStr(query); full_url_ = full_url_.ReplaceComponents(replacements); diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc index a611ed62595b..8059cf875d22 100644 --- a/chrome/browser/extensions/webstore_installer.cc +++ b/chrome/browser/extensions/webstore_installer.cc @@ -25,6 +25,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/omaha_query_params/omaha_query_params.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/download_save_info.h" @@ -44,6 +45,7 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #endif +using chrome::OmahaQueryParams; using content::BrowserContext; using content::BrowserThread; using content::DownloadItem; @@ -68,30 +70,6 @@ const char kDefaultInstallSource[] = ""; base::FilePath* g_download_directory_for_tests = NULL; -GURL GetWebstoreInstallURL( - const std::string& extension_id, const std::string& install_source) { - CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - if (cmd_line->HasSwitch(switches::kAppsGalleryDownloadURL)) { - std::string download_url = - cmd_line->GetSwitchValueASCII(switches::kAppsGalleryDownloadURL); - return GURL(base::StringPrintf(download_url.c_str(), - extension_id.c_str())); - } - std::vector params; - params.push_back("id=" + extension_id); - if (!install_source.empty()) - params.push_back("installsource=" + install_source); - params.push_back("lang=" + g_browser_process->GetApplicationLocale()); - params.push_back("uc"); - std::string url_string = extension_urls::GetWebstoreUpdateUrl().spec(); - - GURL url(url_string + "?response=redirect&x=" + - net::EscapeQueryParamValue(JoinString(params, '&'), true)); - DCHECK(url.is_valid()); - - return url; -} - // Must be executed on the FILE thread. void GetDownloadFilePath( const base::FilePath& download_directory, const std::string& id, @@ -140,6 +118,32 @@ void GetDownloadFilePath( namespace extensions { +// static +GURL WebstoreInstaller::GetWebstoreInstallURL( + const std::string& extension_id, const std::string& install_source) { + CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kAppsGalleryDownloadURL)) { + std::string download_url = + cmd_line->GetSwitchValueASCII(switches::kAppsGalleryDownloadURL); + return GURL(base::StringPrintf(download_url.c_str(), + extension_id.c_str())); + } + std::vector params; + params.push_back("id=" + extension_id); + if (!install_source.empty()) + params.push_back("installsource=" + install_source); + params.push_back("lang=" + g_browser_process->GetApplicationLocale()); + params.push_back("uc"); + std::string url_string = extension_urls::GetWebstoreUpdateUrl().spec(); + + GURL url(url_string + "?response=redirect&" + + OmahaQueryParams::Get(OmahaQueryParams::CRX) + "&x=" + + net::EscapeQueryParamValue(JoinString(params, '&'), true)); + DCHECK(url.is_valid()); + + return url; +} + void WebstoreInstaller::Delegate::OnExtensionDownloadStarted( const std::string& id, content::DownloadItem* item) { diff --git a/chrome/browser/extensions/webstore_installer.h b/chrome/browser/extensions/webstore_installer.h index 82c9ab563d95..18b972e67619 100644 --- a/chrome/browser/extensions/webstore_installer.h +++ b/chrome/browser/extensions/webstore_installer.h @@ -154,11 +154,16 @@ class WebstoreInstaller :public content::NotificationObserver, static void SetDownloadDirectoryForTests(base::FilePath* directory); private: + FRIEND_TEST_ALL_PREFIXES(WebstoreInstallerTest, PlatformParams); friend struct content::BrowserThread::DeleteOnThread< content::BrowserThread::UI>; friend class base::DeleteHelper; virtual ~WebstoreInstaller(); + // Helper to get install URL. + static GURL GetWebstoreInstallURL(const std::string& extension_id, + const std::string& install_source); + // DownloadManager::DownloadUrl callback. void OnDownloadStarted(content::DownloadItem* item, net::Error error); diff --git a/chrome/browser/extensions/webstore_installer_unittest.cc b/chrome/browser/extensions/webstore_installer_unittest.cc new file mode 100644 index 000000000000..62b1728f42c6 --- /dev/null +++ b/chrome/browser/extensions/webstore_installer_unittest.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2013 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 + +#include "base/stringprintf.h" +#include "chrome/browser/extensions/webstore_installer.h" +#include "chrome/common/omaha_query_params/omaha_query_params.h" +#include "extensions/common/id_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +using base::StringPrintf; +using chrome::OmahaQueryParams; + +namespace extensions { + +// Returns true if |target| is found in |source|. +bool Contains(const std::string& source, const std::string& target) { + return source.find(target) != std::string::npos; +} + +TEST(WebstoreInstallerTest, PlatformParams) { + std::string id = extensions::id_util::GenerateId("some random string"); + GURL url = WebstoreInstaller::GetWebstoreInstallURL(id, ""); + std::string query = url.query(); + EXPECT_TRUE(Contains(query,StringPrintf("os=%s", OmahaQueryParams::getOS()))); + EXPECT_TRUE(Contains(query,StringPrintf("arch=%s", + OmahaQueryParams::getArch()))); + EXPECT_TRUE(Contains(query,StringPrintf("nacl_arch=%s", + OmahaQueryParams::getNaclArch()))); + +} + +} // namespace extensions diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index ee8b64e02e81..25f77548f3aa 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -713,8 +713,8 @@ 'browser/extensions/api/content_settings/content_settings_store_unittest.cc', 'browser/extensions/api/content_settings/content_settings_unittest.cc', 'browser/extensions/api/cookies/cookies_unittest.cc', - 'browser/extensions/api/declarative/deduping_factory_unittest.cc', 'browser/extensions/api/declarative/declarative_rule_unittest.cc', + 'browser/extensions/api/declarative/deduping_factory_unittest.cc', 'browser/extensions/api/declarative/initializing_rules_registry_unittest.cc', 'browser/extensions/api/declarative/rules_registry_service_unittest.cc', 'browser/extensions/api/declarative/rules_registry_with_cache_unittest.cc', @@ -749,6 +749,12 @@ 'browser/extensions/api/socket/socket_api_unittest.cc', 'browser/extensions/api/socket/tcp_socket_unittest.cc', 'browser/extensions/api/socket/udp_socket_unittest.cc', + 'browser/extensions/api/storage/policy_value_store_unittest.cc', + 'browser/extensions/api/storage/settings_frontend_unittest.cc', + 'browser/extensions/api/storage/settings_quota_unittest.cc', + 'browser/extensions/api/storage/settings_sync_unittest.cc', + 'browser/extensions/api/storage/settings_test_util.cc', + 'browser/extensions/api/storage/settings_test_util.h', 'browser/extensions/api/streams_private/streams_private_manifest_unittest.cc', 'browser/extensions/api/system_info_memory/memory_info_provider_unittest.cc', 'browser/extensions/api/system_info_storage/storage_info_provider_linux_unittest.cc', @@ -792,22 +798,16 @@ 'browser/extensions/extensions_quota_service_unittest.cc', 'browser/extensions/external_policy_loader_unittest.cc', 'browser/extensions/external_provider_impl_chromeos_unittest.cc', - 'browser/extensions/menu_manager_unittest.cc', - 'browser/extensions/page_action_controller_unittest.cc', - 'browser/extensions/permissions_updater_unittest.cc', 'browser/extensions/image_loader_unittest.cc', 'browser/extensions/management_policy_unittest.cc', + 'browser/extensions/menu_manager_unittest.cc', 'browser/extensions/pack_extension_unittest.cc', + 'browser/extensions/page_action_controller_unittest.cc', + 'browser/extensions/permissions_updater_unittest.cc', 'browser/extensions/process_map_unittest.cc', 'browser/extensions/sandboxed_unpacker_unittest.cc', 'browser/extensions/script_badge_controller_unittest.cc', 'browser/extensions/script_bubble_controller_unittest.cc', - 'browser/extensions/api/storage/policy_value_store_unittest.cc', - 'browser/extensions/api/storage/settings_frontend_unittest.cc', - 'browser/extensions/api/storage/settings_quota_unittest.cc', - 'browser/extensions/api/storage/settings_sync_unittest.cc', - 'browser/extensions/api/storage/settings_test_util.cc', - 'browser/extensions/api/storage/settings_test_util.h', 'browser/extensions/shell_window_geometry_cache_unittest.cc', 'browser/extensions/token_cache/token_cache_service_unittest.cc', 'browser/extensions/standard_management_policy_provider_unittest.cc', @@ -815,6 +815,7 @@ 'browser/extensions/user_script_listener_unittest.cc', 'browser/extensions/user_script_master_unittest.cc', 'browser/extensions/webstore_inline_installer_unittest.cc', + 'browser/extensions/webstore_installer_unittest.cc', 'browser/external_protocol/external_protocol_handler_unittest.cc', 'browser/favicon/favicon_handler_unittest.cc', 'browser/file_select_helper_unittest.cc', diff --git a/chrome/common/extensions/extension_test_util.h b/chrome/common/extensions/extension_test_util.h index 278f514bee71..12e5104b6d60 100644 --- a/chrome/common/extensions/extension_test_util.h +++ b/chrome/common/extensions/extension_test_util.h @@ -16,9 +16,6 @@ class Extension; namespace extension_test_util { -// Makes a fake extension id using the given |seed|. -std::string MakeId(std::string seed); - // Return a very simple extension with id |id|. scoped_refptr CreateExtensionWithID(std::string id); diff --git a/chrome/common/omaha_query_params/omaha_query_params.cc b/chrome/common/omaha_query_params/omaha_query_params.cc index 5286be6a4992..6cd91fe2441f 100644 --- a/chrome/common/omaha_query_params/omaha_query_params.cc +++ b/chrome/common/omaha_query_params/omaha_query_params.cc @@ -54,11 +54,12 @@ const char* GetProdIdString(chrome::OmahaQueryParams::ProdId prod) { case chrome::OmahaQueryParams::CHROME: return kChrome; break; - case chrome::OmahaQueryParams::CHROMECRX: + case chrome::OmahaQueryParams::CRX: +#if defined(GOOGLE_CHROME_BUILD) return kChromeCrx; - break; - case chrome::OmahaQueryParams::CHROMIUMCRX: +#else return kChromiumCrx; +#endif break; } return kUnknown; diff --git a/chrome/common/omaha_query_params/omaha_query_params.h b/chrome/common/omaha_query_params/omaha_query_params.h index b7820c0e8317..7f74be1237ad 100644 --- a/chrome/common/omaha_query_params/omaha_query_params.h +++ b/chrome/common/omaha_query_params/omaha_query_params.h @@ -15,8 +15,7 @@ class OmahaQueryParams { public: enum ProdId { CHROME = 0, - CHROMECRX, - CHROMIUMCRX, + CRX, }; // Generates a string of URL query paramaters to be used when getting -- 2.11.4.GIT