Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: components/omaha_query_params/omaha_query_params_unittest.cc

Issue 333353005: Move OmahaQueryParams to a component and add a delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/omaha_query_params/omaha_query_params_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/omaha_query_params/omaha_query_params.h"
6
7 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
8 #include "chrome/common/chrome_version_info.h" 6 #include "components/omaha_query_params/omaha_query_params.h"
7 #include "components/omaha_query_params/omaha_query_params_delegate.h"
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 using base::StringPrintf; 10 using base::StringPrintf;
12 11
13 namespace chrome { 12 namespace omaha_query_params {
13
14 namespace {
14 15
15 bool Contains(const std::string& source, const std::string& target) { 16 bool Contains(const std::string& source, const std::string& target) {
16 return source.find(target) != std::string::npos; 17 return source.find(target) != std::string::npos;
17 } 18 }
18 19
19 void TestParams(OmahaQueryParams::ProdId prod_id) { 20 class TestOmahaQueryParamsDelegate : public OmahaQueryParamsDelegate {
21 virtual std::string GetExtraParams() OVERRIDE { return "&cat=dog"; }
22 };
23
24 } // namespace
25
26 void TestParams(OmahaQueryParams::ProdId prod_id, bool extra_params) {
20 std::string params = OmahaQueryParams::Get(prod_id); 27 std::string params = OmahaQueryParams::Get(prod_id);
21 28
22 // This doesn't so much test what the values are (since that would be an 29 // This doesn't so much test what the values are (since that would be an
23 // almost exact duplication of code with omaha_query_params.cc, and wouldn't 30 // almost exact duplication of code with omaha_query_params.cc, and wouldn't
24 // really test anything) as it is a verification that all the params are 31 // really test anything) as it is a verification that all the params are
25 // present in the generated string. 32 // present in the generated string.
26 EXPECT_TRUE( 33 EXPECT_TRUE(
27 Contains(params, StringPrintf("os=%s", OmahaQueryParams::GetOS()))); 34 Contains(params, StringPrintf("os=%s", OmahaQueryParams::GetOS())));
28 EXPECT_TRUE( 35 EXPECT_TRUE(
29 Contains(params, StringPrintf("arch=%s", OmahaQueryParams::GetArch()))); 36 Contains(params, StringPrintf("arch=%s", OmahaQueryParams::GetArch())));
30 EXPECT_TRUE(Contains( 37 EXPECT_TRUE(Contains(
31 params, 38 params,
32 StringPrintf("prod=%s", OmahaQueryParams::GetProdIdString(prod_id)))); 39 StringPrintf("prod=%s", OmahaQueryParams::GetProdIdString(prod_id))));
33 EXPECT_TRUE(Contains( 40 if (extra_params)
34 params, 41 EXPECT_TRUE(Contains(params, "cat=dog"));
35 StringPrintf("prodchannel=%s", OmahaQueryParams::GetChannelString())));
36 EXPECT_TRUE(Contains(
37 params,
38 StringPrintf("prodversion=%s", chrome::VersionInfo().Version().c_str())));
39 EXPECT_TRUE(Contains(
40 params,
41 StringPrintf("lang=%s", OmahaQueryParams::GetLang())));
42 } 42 }
43 43
44 TEST(OmahaQueryParams, GetOmahaQueryParams) { 44 TEST(OmahaQueryParamsTest, GetParams) {
45 TestParams(OmahaQueryParams::CRX); 45 TestParams(OmahaQueryParams::CRX, false);
46 TestParams(OmahaQueryParams::CHROME); 46 TestParams(OmahaQueryParams::CHROME, false);
47
48 TestOmahaQueryParamsDelegate delegate;
49 OmahaQueryParams::SetDelegate(&delegate);
50
51 TestParams(OmahaQueryParams::CRX, true);
52 TestParams(OmahaQueryParams::CHROME, true);
47 } 53 }
48 54
49 } // namespace chrome 55 } // namespace omaha_query_params
OLDNEW
« no previous file with comments | « components/omaha_query_params/omaha_query_params_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698