15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/stringprintf.h"
6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/omaha_query_params/omaha_query_params.h"
7116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/omaha_query_params/omaha_query_params_delegate.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::StringPrintf;
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace omaha_query_params {
13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace {
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool Contains(const std::string& source, const std::string& target) {
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return source.find(target) != std::string::npos;
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
20116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass TestOmahaQueryParamsDelegate : public OmahaQueryParamsDelegate {
21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual std::string GetExtraParams() OVERRIDE { return "&cat=dog"; }
22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch};
23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}  // namespace
25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
26116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid TestParams(OmahaQueryParams::ProdId prod_id, bool extra_params) {
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string params = OmahaQueryParams::Get(prod_id);
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This doesn't so much test what the values are (since that would be an
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // almost exact duplication of code with omaha_query_params.cc, and wouldn't
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // really test anything) as it is a verification that all the params are
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // present in the generated string.
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Contains(params, StringPrintf("os=%s", OmahaQueryParams::GetOS())));
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Contains(params, StringPrintf("arch=%s", OmahaQueryParams::GetArch())));
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(Contains(
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      params,
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      StringPrintf("prod=%s", OmahaQueryParams::GetProdIdString(prod_id))));
40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (extra_params)
41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    EXPECT_TRUE(Contains(params, "cat=dog"));
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
44116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST(OmahaQueryParamsTest, GetParams) {
45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  TestParams(OmahaQueryParams::CRX, false);
46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  TestParams(OmahaQueryParams::CHROME, false);
47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  TestOmahaQueryParamsDelegate delegate;
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  OmahaQueryParams::SetDelegate(&delegate);
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  TestParams(OmahaQueryParams::CRX, true);
52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  TestParams(OmahaQueryParams::CHROME, true);
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}  // namespace omaha_query_params
56