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

Side by Side Diff: goopdate/update_request_utils_unittest.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/update_request_utils.cc ('k') | goopdate/update_response_utils.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 2010 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/common/const_group_policy.h"
18 #include "omaha/common/update_response.h"
19 #include "omaha/goopdate/app_manager.h"
20 #include "omaha/goopdate/app_unittest_base.h"
21 #include "omaha/goopdate/update_request_utils.h"
22 #include "omaha/testing/unit_test.h"
23
24 using ::testing::Return;
25
26 namespace omaha {
27
28 namespace update_request_utils {
29
30 namespace {
31
32 #define USER_UPDATE_KEY _T("HKCU\\Software\\") SHORT_COMPANY_NAME _T("\\") PRODU CT_NAME _T("\\")
33 #define APP_ID1 _T("{DDE97E2B-A82C-4790-A630-FCA02F64E8BE}");
34 const TCHAR* const kAppId1 = APP_ID1
35 const TCHAR* const kAppId1ClientsKeyPathUser =
36 USER_UPDATE_KEY _T("Clients\\") APP_ID1;
37 const TCHAR* const kAppId1ClientStateKeyPathUser =
38 USER_UPDATE_KEY _T("ClientState\\") APP_ID1;
39 const TCHAR* const kInstallPolicyApp1 = _T("Install") APP_ID1;
40 const TCHAR* const kUpdatePolicyApp1 = _T("Update") APP_ID1;
41 const TCHAR* const kAppDidRunValueName = _T("dr");
42
43 void SetPolicy(const CString& policy, DWORD value) {
44 EXPECT_SUCCEEDED(RegKey::SetValue(kRegKeyGoopdateGroupPolicy,
45 policy,
46 value));
47 }
48
49 } // namespace
50
51 class UpdateRequestUtilsTest : public AppTestBaseWithRegistryOverride {
52 protected:
53 UpdateRequestUtilsTest()
54 : AppTestBaseWithRegistryOverride(false, // is_machine
55 true), // use_strict_mock
56 app_(NULL) {}
57
58 virtual void SetUp() {
59 AppTestBaseWithRegistryOverride::SetUp();
60
61 update_request_.reset(xml::UpdateRequest::Create(is_machine_,
62 _T("unittest"),
63 _T("unittest"),
64 CString()));
65
66 EXPECT_SUCCEEDED(
67 app_bundle_->createApp(CComBSTR(kAppId1), &app_));
68 ASSERT_TRUE(app_);
69 }
70
71 App* app_;
72 scoped_ptr<xml::UpdateRequest> update_request_;
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(UpdateRequestUtilsTest);
76 };
77
78 // TODO(omaha): write tests.
79
80 // For now, this test is just checking !update_check.is_valid. Add more checks.
81 TEST_F(UpdateRequestUtilsTest, BuildRequest_Ping) {
82 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_TRUE));
83
84 PingEventPtr ping_event(
85 new PingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
86 PingEvent::EVENT_RESULT_ERROR, E_FAIL, 0));
87 app_->AddPingEvent(ping_event);
88
89 BuildRequest(app_, false, update_request_.get());
90
91 const xml::request::Request& request = update_request_->request();
92 ASSERT_EQ(1, request.apps.size());
93
94 const xml::request::App& app = request.apps[0];
95 const xml::request::UpdateCheck& update_check = app.update_check;
96 EXPECT_FALSE(update_check.is_valid);
97 }
98
99 TEST_F(UpdateRequestUtilsTest, BuildRequest_Ping_NoEvents) {
100 BuildRequest(app_, false, update_request_.get());
101
102 const xml::request::Request& request = update_request_->request();
103 ASSERT_EQ(0, request.apps.size());
104 }
105
106 TEST_F(UpdateRequestUtilsTest, BuildRequest_Ping_EulaNotAccepted) {
107 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_FALSE));
108
109 PingEventPtr ping_event(
110 new PingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
111 PingEvent::EVENT_RESULT_ERROR, E_FAIL, 0));
112 app_->AddPingEvent(ping_event);
113
114 BuildRequest(app_, false, update_request_.get());
115
116 const xml::request::Request& request = update_request_->request();
117 ASSERT_EQ(0, request.apps.size());
118 }
119
120 // For now, this test is just checking is_update_disabled. Add more checks.
121 TEST_F(UpdateRequestUtilsTest, BuildRequest_UpdateCheck) {
122 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_TRUE));
123
124 BuildRequest(app_, true, update_request_.get());
125
126 const xml::request::Request& request = update_request_->request();
127 ASSERT_EQ(1, request.apps.size());
128
129 const xml::request::App& app = request.apps[0];
130 const xml::request::UpdateCheck& update_check = app.update_check;
131 EXPECT_TRUE(update_check.is_valid);
132 EXPECT_FALSE(update_check.is_update_disabled);
133 }
134
135 TEST_F(UpdateRequestUtilsTest,
136 BuildRequest_UpdateCheck_GroupPolicy_InstallDisabled) {
137 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_TRUE));
138
139 SetPolicy(kInstallPolicyApp1, kPolicyDisabled);
140
141 BuildRequest(app_, true, update_request_.get());
142
143 const xml::request::Request& request = update_request_->request();
144 ASSERT_EQ(1, request.apps.size());
145
146 const xml::request::App& app = request.apps[0];
147 const xml::request::UpdateCheck& update_check = app.update_check;
148 EXPECT_TRUE(update_check.is_valid);
149 EXPECT_TRUE(update_check.is_update_disabled);
150 }
151
152 TEST_F(UpdateRequestUtilsTest,
153 BuildRequest_DoNotPickUpDidRunValueWhenNotDoingUpdateCheck) {
154 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_TRUE));
155 PingEventPtr ping_event(
156 new PingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
157 PingEvent::EVENT_RESULT_ERROR, E_FAIL, 0));
158 app_->AddPingEvent(ping_event);
159
160 RegKey key;
161 ASSERT_SUCCEEDED(key.Create(kAppId1ClientStateKeyPathUser));
162 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, _T("1")));
163 __mutexScope(app_->model()->lock());
164 AppManager::Instance()->ReadAppPersistentData(app_);
165
166 BuildRequest(app_, false, update_request_.get());
167
168 const xml::request::Request& request = update_request_->request();
169 ASSERT_EQ(1, request.apps.size());
170
171 const xml::request::Ping& ping = request.apps[0].ping;
172 EXPECT_EQ(ACTIVE_UNKNOWN, ping.active);
173 EXPECT_EQ(0, ping.days_since_last_active_ping);
174 EXPECT_EQ(0, ping.days_since_last_roll_call);
175 }
176
177 TEST_F(UpdateRequestUtilsTest,
178 BuildRequest_UpdateCheckShouldSendDidRunValue) {
179 EXPECT_SUCCEEDED(app_->put_isEulaAccepted(VARIANT_TRUE));
180 PingEventPtr ping_event(
181 new PingEvent(PingEvent::EVENT_INSTALL_COMPLETE,
182 PingEvent::EVENT_RESULT_ERROR, E_FAIL, 0));
183 app_->AddPingEvent(ping_event);
184
185 RegKey key;
186 ASSERT_SUCCEEDED(key.Create(kAppId1ClientStateKeyPathUser));
187 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, _T("1")));
188 __mutexScope(app_->model()->lock());
189 AppManager::Instance()->ReadAppPersistentData(app_);
190
191 BuildRequest(app_, true, update_request_.get());
192
193 const xml::request::Request& request = update_request_->request();
194 ASSERT_EQ(1, request.apps.size());
195
196 const xml::request::Ping& ping = request.apps[0].ping;
197 EXPECT_EQ(ACTIVE_RUN, ping.active);
198 EXPECT_EQ(-1, ping.days_since_last_active_ping);
199 EXPECT_EQ(-1, ping.days_since_last_roll_call);
200 }
201
202 } // namespace update_request_utils
203
204 } // namespace omaha
OLDNEW
« no previous file with comments | « goopdate/update_request_utils.cc ('k') | goopdate/update_response_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698