Revert of Recorded additional tough_energy_cases. (patchset #1 id:1 of https://codere...
[chromium-blink-merge.git] / components / omaha_query_params / omaha_query_params_unittest.cc
blob37a97e919dd1f8c22186f4c2b696e4198dbcc0c6
1 // Copyright 2014 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.
5 #include "base/strings/stringprintf.h"
6 #include "components/omaha_query_params/omaha_query_params.h"
7 #include "components/omaha_query_params/omaha_query_params_delegate.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using base::StringPrintf;
12 namespace omaha_query_params {
14 namespace {
16 bool Contains(const std::string& source, const std::string& target) {
17 return source.find(target) != std::string::npos;
20 class TestOmahaQueryParamsDelegate : public OmahaQueryParamsDelegate {
21 virtual std::string GetExtraParams() OVERRIDE { return "&cat=dog"; }
24 } // namespace
26 void TestParams(OmahaQueryParams::ProdId prod_id, bool extra_params) {
27 std::string params = OmahaQueryParams::Get(prod_id);
29 // This doesn't so much test what the values are (since that would be an
30 // almost exact duplication of code with omaha_query_params.cc, and wouldn't
31 // really test anything) as it is a verification that all the params are
32 // present in the generated string.
33 EXPECT_TRUE(
34 Contains(params, StringPrintf("os=%s", OmahaQueryParams::GetOS())));
35 EXPECT_TRUE(
36 Contains(params, StringPrintf("arch=%s", OmahaQueryParams::GetArch())));
37 EXPECT_TRUE(Contains(
38 params,
39 StringPrintf("prod=%s", OmahaQueryParams::GetProdIdString(prod_id))));
40 if (extra_params)
41 EXPECT_TRUE(Contains(params, "cat=dog"));
44 TEST(OmahaQueryParamsTest, GetParams) {
45 TestParams(OmahaQueryParams::CRX, false);
46 TestParams(OmahaQueryParams::CHROME, false);
48 TestOmahaQueryParamsDelegate delegate;
49 OmahaQueryParams::SetDelegate(&delegate);
51 TestParams(OmahaQueryParams::CRX, true);
52 TestParams(OmahaQueryParams::CHROME, true);
55 } // namespace omaha_query_params