blob: 344980ec01f92827ed1bfc6c4800f7e366d37a1d [file] [log] [blame]
[email protected]902a8a012013-05-04 05:04:161// 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]46acbf12013-06-10 18:43:427#include "base/strings/stringprintf.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:038#include "base/system/sys_info.h"
[email protected]902a8a012013-05-04 05:04:169#include "chrome/browser/extensions/webstore_installer.h"
sorin39eab2f2015-01-06 01:09:0810#include "chrome/browser/update_client/chrome_update_query_params_delegate.h"
[email protected]fdd28372014-08-21 02:27:2611#include "components/crx_file/id_util.h"
sorin39eab2f2015-01-06 01:09:0812#include "components/update_client/update_query_params.h"
[email protected]084e35482013-09-25 02:46:1913#include "net/base/escape.h"
[email protected]902a8a012013-05-04 05:04:1614#include "testing/gtest/include/gtest/gtest.h"
15
16using base::StringPrintf;
sorin39eab2f2015-01-06 01:09:0817using update_client::UpdateQueryParams;
[email protected]902a8a012013-05-04 05:04:1618
19namespace extensions {
20
21// Returns true if |target| is found in |source|.
22bool Contains(const std::string& source, const std::string& target) {
23 return source.find(target) != std::string::npos;
24}
25
26TEST(WebstoreInstallerTest, PlatformParams) {
[email protected]fdd28372014-08-21 02:27:2627 std::string id = crx_file::id_util::GenerateId("some random string");
[email protected]084e35482013-09-25 02:46:1928 std::string source = "inline";
Benjamin Ackermanc4fb02302018-10-03 19:55:4129 GURL url = WebstoreInstaller::GetWebstoreInstallURL(
30 id, WebstoreInstaller::INSTALL_SOURCE_INLINE);
[email protected]902a8a012013-05-04 05:04:1631 std::string query = url.query();
[email protected]ec4a6782014-02-14 20:00:0432 EXPECT_TRUE(
sorin39eab2f2015-01-06 01:09:0833 Contains(query, StringPrintf("os=%s", UpdateQueryParams::GetOS())));
[email protected]ec4a6782014-02-14 20:00:0434 EXPECT_TRUE(
sorin39eab2f2015-01-06 01:09:0835 Contains(query, StringPrintf("arch=%s", UpdateQueryParams::GetArch())));
[email protected]ec4a6782014-02-14 20:00:0436 EXPECT_TRUE(Contains(
Minh X. Nguyend9cbbaa8c2017-12-20 21:03:3137 query,
38 StringPrintf("os_arch=%s",
39 base::SysInfo().OperatingSystemArchitecture().c_str())));
40 EXPECT_TRUE(Contains(
sorin39eab2f2015-01-06 01:09:0841 query, StringPrintf("nacl_arch=%s", UpdateQueryParams::GetNaclArch())));
[email protected]ec4a6782014-02-14 20:00:0442 EXPECT_TRUE(
43 Contains(query,
44 net::EscapeQueryParamValue(
45 StringPrintf("installsource=%s", source.c_str()), true)));
[email protected]8f4b69e2014-06-26 00:01:3146 EXPECT_TRUE(Contains(
47 query,
sorin39eab2f2015-01-06 01:09:0848 StringPrintf("lang=%s", ChromeUpdateQueryParamsDelegate::GetLang())));
[email protected]902a8a012013-05-04 05:04:1649}
50
51} // namespace extensions