[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 1 | // Copyright (c) 2013 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 <string> |
| 6 | |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 7 | #include "base/strings/stringprintf.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 8 | #include "base/system/sys_info.h" |
[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 9 | #include "chrome/browser/extensions/webstore_installer.h" |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 10 | #include "chrome/browser/update_client/chrome_update_query_params_delegate.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 11 | #include "components/crx_file/id_util.h" |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 12 | #include "components/update_client/update_query_params.h" |
[email protected] | 084e3548 | 2013-09-25 02:46:19 | [diff] [blame] | 13 | #include "net/base/escape.h" |
[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | using base::StringPrintf; |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 17 | using update_client::UpdateQueryParams; |
[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 18 | |
| 19 | namespace extensions { |
| 20 | |
| 21 | // Returns true if |target| is found in |source|. |
| 22 | bool Contains(const std::string& source, const std::string& target) { |
| 23 | return source.find(target) != std::string::npos; |
| 24 | } |
| 25 | |
| 26 | TEST(WebstoreInstallerTest, PlatformParams) { |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 27 | std::string id = crx_file::id_util::GenerateId("some random string"); |
[email protected] | 084e3548 | 2013-09-25 02:46:19 | [diff] [blame] | 28 | std::string source = "inline"; |
Benjamin Ackerman | c4fb0230 | 2018-10-03 19:55:41 | [diff] [blame] | 29 | GURL url = WebstoreInstaller::GetWebstoreInstallURL( |
| 30 | id, WebstoreInstaller::INSTALL_SOURCE_INLINE); |
[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 31 | std::string query = url.query(); |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 32 | EXPECT_TRUE( |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 33 | Contains(query, StringPrintf("os=%s", UpdateQueryParams::GetOS()))); |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 34 | EXPECT_TRUE( |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 35 | Contains(query, StringPrintf("arch=%s", UpdateQueryParams::GetArch()))); |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 36 | EXPECT_TRUE(Contains( |
Minh X. Nguyen | d9cbbaa8c | 2017-12-20 21:03:31 | [diff] [blame] | 37 | query, |
| 38 | StringPrintf("os_arch=%s", |
| 39 | base::SysInfo().OperatingSystemArchitecture().c_str()))); |
| 40 | EXPECT_TRUE(Contains( |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 41 | query, StringPrintf("nacl_arch=%s", UpdateQueryParams::GetNaclArch()))); |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 42 | EXPECT_TRUE( |
| 43 | Contains(query, |
| 44 | net::EscapeQueryParamValue( |
| 45 | StringPrintf("installsource=%s", source.c_str()), true))); |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 46 | EXPECT_TRUE(Contains( |
| 47 | query, |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 48 | StringPrintf("lang=%s", ChromeUpdateQueryParamsDelegate::GetLang()))); |
[email protected] | 902a8a01 | 2013-05-04 05:04:16 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace extensions |