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

Side by Side Diff: goopdate/download_complete_ping_event_test.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « goopdate/download_complete_ping_event.cc ('k') | goopdate/download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/base/reg_key.h"
17 #include "omaha/base/string.h"
18 #include "omaha/common/ping.h"
19 #include "omaha/goopdate/download_complete_ping_event.h"
20 #include "omaha/testing/unit_test.h"
21
22 namespace omaha {
23
24 namespace {
25 const CString kPv = _T("1.3.23.0");
26 const CString kLang = _T("en");
27 const CString kBrandCode = _T("GOOG");
28 const CString kClientId = _T("testclientid");
29 const CString kIid = _T("{7C0B6E56-B24B-436b-A960-A6EA201E886D}");
30 } // namespace
31
32 class DownloadCompletePingEventTest : public testing::Test {
33 protected:
34 void SetUpRegistry() {
35 RegKey::DeleteKey(kRegistryHiveOverrideRoot);
36 OverrideRegistryHives(kRegistryHiveOverrideRoot);
37
38 const TCHAR* const kOmahaUserClientStatePath =
39 _T("HKCU\\Software\\") SHORT_COMPANY_NAME
40 _T("\\") PRODUCT_NAME
41 _T("\\ClientState\\") GOOPDATE_APP_ID;
42
43 EXPECT_HRESULT_SUCCEEDED(RegKey::SetValue(kOmahaUserClientStatePath,
44 kRegValueProductVersion,
45 kPv));
46 EXPECT_HRESULT_SUCCEEDED(RegKey::SetValue(kOmahaUserClientStatePath,
47 kRegValueLanguage,
48 kLang));
49 EXPECT_HRESULT_SUCCEEDED(RegKey::SetValue(kOmahaUserClientStatePath,
50 kRegValueBrandCode,
51 kBrandCode));
52 EXPECT_HRESULT_SUCCEEDED(RegKey::SetValue(kOmahaUserClientStatePath,
53 kRegValueClientId,
54 kClientId));
55 EXPECT_HRESULT_SUCCEEDED(RegKey::SetValue(kOmahaUserClientStatePath,
56 kRegValueInstallationId,
57 kIid));
58 }
59
60 virtual void CleanUpRegistry() {
61 RestoreRegistryHives();
62 RegKey::DeleteKey(kRegistryHiveOverrideRoot);
63 }
64 };
65
66 TEST_F(DownloadCompletePingEventTest, BuildDownloadCompletePing) {
67 const int error_code = 34;
68 const int extra_code1 = 3333;
69 const int download_time_ms = 15000;
70 const uint64 num_bytes_downloaded = 4000000;
71 const uint64 app_packages_total_size = 8000000;
72
73 SetUpRegistry();
74 PingEventPtr ping_event(
75 new DownloadCompletePingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
76 PingEvent::EVENT_RESULT_SUCCESS,
77 error_code,
78 extra_code1,
79 download_time_ms,
80 num_bytes_downloaded,
81 app_packages_total_size));
82
83 Ping ping(false, _T("unittest"), _T("InstallSource_Foo"));
84 std::vector<CString> apps;
85 apps.push_back(GOOPDATE_APP_ID);
86 ping.LoadAppDataFromRegistry(apps);
87 ping.BuildAppsPing(ping_event);
88 CleanUpRegistry();
89
90 CString expected_ping_request_substring;
91 expected_ping_request_substring.Format(
92 _T("<app appid=\"%s\" version=\"%s\" nextversion=\"\" lang=\"%s\" ")
93 _T("brand=\"%s\" client=\"%s\" iid=\"%s\">")
94 _T("<event eventtype=\"%d\" eventresult=\"%d\" ")
95 _T("errorcode=\"%d\" extracode1=\"%d\" ")
96 _T("download_time_ms=\"%d\" downloaded=\"%I64u\" total=\"%I64u\"/>")
97 _T("</app>"),
98 GOOPDATE_APP_ID, kPv, kLang, kBrandCode, kClientId, kIid,
99 PingEvent::EVENT_INSTALL_COMPLETE, PingEvent::EVENT_RESULT_SUCCESS,
100 error_code, extra_code1, download_time_ms, num_bytes_downloaded,
101 app_packages_total_size);
102
103 CString actual_ping_request;
104 ping.BuildRequestString(&actual_ping_request);
105 EXPECT_NE(-1, actual_ping_request.Find(expected_ping_request_substring));
106 }
107
108 TEST_F(DownloadCompletePingEventTest, BuildDownloadCompletePing_NoDownload) {
109 const int error_code = 888;
110 const int extra_code1 = 0;
111 const int download_time_ms = 15;
112 const uint64 num_bytes_downloaded = 0; // 0 indicates no actual download.
113 const uint64 app_packages_total_size = 4000000;
114
115 SetUpRegistry();
116 PingEventPtr ping_event(
117 new DownloadCompletePingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
118 PingEvent::EVENT_RESULT_SUCCESS,
119 error_code,
120 extra_code1,
121 download_time_ms,
122 num_bytes_downloaded,
123 app_packages_total_size));
124
125 Ping ping(false, _T("unittest"), _T("InstallSource_Foo"));
126 std::vector<CString> apps;
127 apps.push_back(GOOPDATE_APP_ID);
128 ping.LoadAppDataFromRegistry(apps);
129 ping.BuildAppsPing(ping_event);
130 CleanUpRegistry();
131
132 CString expected_ping_request_substring;
133 expected_ping_request_substring.Format(
134 _T("<app appid=\"%s\" version=\"%s\" nextversion=\"\" lang=\"%s\" ")
135 _T("brand=\"%s\" client=\"%s\" iid=\"%s\">")
136 _T("<event eventtype=\"%d\" eventresult=\"%d\" ")
137 _T("errorcode=\"%d\" extracode1=\"%d\"/>")
138 _T("</app>"),
139 GOOPDATE_APP_ID, kPv, kLang, kBrandCode, kClientId, kIid,
140 PingEvent::EVENT_INSTALL_COMPLETE, PingEvent::EVENT_RESULT_SUCCESS,
141 error_code, extra_code1);
142
143 CString actual_ping_request;
144 ping.BuildRequestString(&actual_ping_request);
145 EXPECT_NE(-1, actual_ping_request.Find(expected_ping_request_substring));
146 }
147
148 } // namespace omaha
OLDNEW
« no previous file with comments | « goopdate/download_complete_ping_event.cc ('k') | goopdate/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698