OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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. | |
4 // | |
5 // A test application for the RLZ library. | |
6 // | |
7 // These tests should not be executed on the build server: | |
8 // - They assert for the failed cases. | |
9 // - They modify machine state (registry). | |
10 // | |
11 // These tests require write access to HKLM and HKCU. | |
12 // | |
13 // The "GGLA" brand is used to test the normal code flow of the code, and the | |
14 // "TEST" brand is used to test the supplementary brand code code flow. | |
15 | |
16 #include "base/logging.h" | |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "testing/gmock/include/gmock/gmock.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 #include "rlz/lib/rlz_lib.h" | |
22 #include "rlz/test/rlz_test_helpers.h" | |
23 | |
24 #if defined(OS_WIN) | |
25 #include <Windows.h> | |
26 #include "rlz/win/lib/machine_deal.h" | |
27 #endif | |
28 | |
29 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | |
30 #include "base/mac/scoped_nsautorelease_pool.h" | |
31 #include "base/threading/thread.h" | |
32 #include "net/url_request/url_request_test_util.h" | |
33 #endif | |
34 | |
35 | |
36 class MachineDealCodeHelper | |
37 #if defined(OS_WIN) | |
38 : public rlz_lib::MachineDealCode | |
39 #endif | |
40 { | |
41 public: | |
42 static bool Clear() { | |
43 #if defined(OS_WIN) | |
44 return rlz_lib::MachineDealCode::Clear(); | |
45 #else | |
46 return true; | |
47 #endif | |
48 } | |
49 | |
50 private: | |
51 MachineDealCodeHelper() {} | |
52 ~MachineDealCodeHelper() {} | |
53 }; | |
54 | |
55 class RlzLibTest : public RlzLibTestBase { | |
56 }; | |
57 | |
58 TEST_F(RlzLibTest, RecordProductEvent) { | |
59 char cgi_50[50]; | |
60 | |
61 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
62 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
63 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
64 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
65 cgi_50, 50)); | |
66 EXPECT_STREQ("events=I7S", cgi_50); | |
67 | |
68 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
69 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
70 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
71 cgi_50, 50)); | |
72 EXPECT_STREQ("events=I7S,W1I", cgi_50); | |
73 | |
74 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
75 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
76 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
77 cgi_50, 50)); | |
78 EXPECT_STREQ("events=I7S,W1I", cgi_50); | |
79 } | |
80 | |
81 TEST_F(RlzLibTest, ClearProductEvent) { | |
82 char cgi_50[50]; | |
83 | |
84 // Clear 1 of 1 events. | |
85 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
86 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
87 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
88 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
89 cgi_50, 50)); | |
90 EXPECT_STREQ("events=I7S", cgi_50); | |
91 EXPECT_TRUE(rlz_lib::ClearProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
92 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
93 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
94 cgi_50, 50)); | |
95 EXPECT_STREQ("", cgi_50); | |
96 | |
97 // Clear 1 of 2 events. | |
98 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
99 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
100 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
101 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
102 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
103 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
104 cgi_50, 50)); | |
105 EXPECT_STREQ("events=I7S,W1I", cgi_50); | |
106 EXPECT_TRUE(rlz_lib::ClearProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
107 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
108 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
109 cgi_50, 50)); | |
110 EXPECT_STREQ("events=W1I", cgi_50); | |
111 | |
112 // Clear a non-recorded event. | |
113 EXPECT_TRUE(rlz_lib::ClearProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
114 rlz_lib::IETB_SEARCH_BOX, rlz_lib::FIRST_SEARCH)); | |
115 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
116 cgi_50, 50)); | |
117 EXPECT_STREQ("events=W1I", cgi_50); | |
118 } | |
119 | |
120 | |
121 TEST_F(RlzLibTest, GetProductEventsAsCgi) { | |
122 char cgi_50[50]; | |
123 char cgi_1[1]; | |
124 | |
125 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
126 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
127 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
128 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
129 cgi_50, 50)); | |
130 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
131 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
132 | |
133 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
134 cgi_1, 1)); | |
135 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
136 cgi_50, 50)); | |
137 EXPECT_STREQ("events=I7S,W1I", cgi_50); | |
138 } | |
139 | |
140 TEST_F(RlzLibTest, ClearAllAllProductEvents) { | |
141 char cgi_50[50]; | |
142 | |
143 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
144 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
145 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
146 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
147 cgi_50, 50)); | |
148 EXPECT_STREQ("events=I7S", cgi_50); | |
149 | |
150 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
151 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
152 cgi_50, 50)); | |
153 EXPECT_STREQ("", cgi_50); | |
154 } | |
155 | |
156 TEST_F(RlzLibTest, SetAccessPointRlz) { | |
157 char rlz_50[50]; | |
158 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "")); | |
159 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50)); | |
160 EXPECT_STREQ("", rlz_50); | |
161 | |
162 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "IeTbRlz")); | |
163 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50)); | |
164 EXPECT_STREQ("IeTbRlz", rlz_50); | |
165 } | |
166 | |
167 TEST_F(RlzLibTest, GetAccessPointRlz) { | |
168 char rlz_1[1]; | |
169 char rlz_50[50]; | |
170 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "")); | |
171 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_1, 1)); | |
172 EXPECT_STREQ("", rlz_1); | |
173 | |
174 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "IeTbRlz")); | |
175 EXPECT_FALSE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_1, 1)); | |
176 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50)); | |
177 EXPECT_STREQ("IeTbRlz", rlz_50); | |
178 } | |
179 | |
180 TEST_F(RlzLibTest, GetPingParams) { | |
181 MachineDealCodeHelper::Clear(); | |
182 | |
183 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | |
184 "TbRlzValue")); | |
185 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IE_HOME_PAGE, "")); | |
186 | |
187 char cgi[2048]; | |
188 rlz_lib::AccessPoint points[] = | |
189 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, | |
190 rlz_lib::NO_ACCESS_POINT}; | |
191 | |
192 EXPECT_TRUE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points, | |
193 cgi, 2048)); | |
194 EXPECT_STREQ("rep=2&rlz=T4:TbRlzValue", cgi); | |
195 | |
196 #if defined(OS_WIN) | |
197 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value")); | |
198 #define DCC_PARAM "&dcc=dcc_value" | |
199 #else | |
200 #define DCC_PARAM "" | |
201 #endif | |
202 | |
203 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "")); | |
204 EXPECT_TRUE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points, | |
205 cgi, 2048)); | |
206 EXPECT_STREQ("rep=2&rlz=T4:" DCC_PARAM, cgi); | |
207 | |
208 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | |
209 "TbRlzValue")); | |
210 EXPECT_FALSE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points, | |
211 cgi, 23 + strlen(DCC_PARAM))); | |
212 EXPECT_STREQ("", cgi); | |
213 EXPECT_TRUE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points, | |
214 cgi, 24 + strlen(DCC_PARAM))); | |
215 EXPECT_STREQ("rep=2&rlz=T4:TbRlzValue" DCC_PARAM, cgi); | |
216 | |
217 EXPECT_TRUE(GetAccessPointRlz(rlz_lib::IE_HOME_PAGE, cgi, 2048)); | |
218 points[2] = rlz_lib::IE_HOME_PAGE; | |
219 EXPECT_TRUE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points, | |
220 cgi, 2048)); | |
221 EXPECT_STREQ("rep=2&rlz=T4:TbRlzValue" DCC_PARAM, cgi); | |
222 } | |
223 | |
224 TEST_F(RlzLibTest, IsPingResponseValid) { | |
225 const char* kBadPingResponses[] = { | |
226 // No checksum. | |
227 "version: 3.0.914.7250\r\n" | |
228 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
229 "launch-action: custom-action\r\n" | |
230 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
231 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
232 "rlz: 1R1_____en__252\r\n" | |
233 "rlzXX: 1R1_____en__250\r\n", | |
234 | |
235 // Invalid checksum. | |
236 "version: 3.0.914.7250\r\n" | |
237 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
238 "launch-action: custom-action\r\n" | |
239 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
240 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
241 "rlz: 1R1_____en__252\r\n" | |
242 "rlzXX: 1R1_____en__250\r\n" | |
243 "rlzT4 1T4_____en__251\r\n" | |
244 "rlzT4: 1T4_____en__252\r\n" | |
245 "rlz\r\n" | |
246 "crc32: B12CC79A", | |
247 | |
248 // Misplaced checksum. | |
249 "version: 3.0.914.7250\r\n" | |
250 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
251 "launch-action: custom-action\r\n" | |
252 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
253 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
254 "rlz: 1R1_____en__252\r\n" | |
255 "rlzXX: 1R1_____en__250\r\n" | |
256 "crc32: B12CC79C\r\n" | |
257 "rlzT4 1T4_____en__251\r\n" | |
258 "rlzT4: 1T4_____en__252\r\n" | |
259 "rlz\r\n", | |
260 | |
261 NULL | |
262 }; | |
263 | |
264 const char* kGoodPingResponses[] = { | |
265 "version: 3.0.914.7250\r\n" | |
266 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
267 "launch-action: custom-action\r\n" | |
268 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
269 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
270 "rlz: 1R1_____en__252\r\n" | |
271 "rlzXX: 1R1_____en__250\r\n" | |
272 "rlzT4 1T4_____en__251\r\n" | |
273 "rlzT4: 1T4_____en__252\r\n" | |
274 "rlz\r\n" | |
275 "crc32: D6FD55A3", | |
276 | |
277 "version: 3.0.914.7250\r\n" | |
278 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
279 "launch-action: custom-action\r\n" | |
280 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
281 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
282 "rlz: 1R1_____en__252\r\n" | |
283 "rlzXX: 1R1_____en__250\r\n" | |
284 "rlzT4 1T4_____en__251\r\n" | |
285 "rlzT4: 1T4_____en__252\r\n" | |
286 "rlz\r\n" | |
287 "crc32: D6FD55A3\r\n" | |
288 "extradata: not checksummed", | |
289 | |
290 NULL | |
291 }; | |
292 | |
293 for (int i = 0; kBadPingResponses[i]; i++) | |
294 EXPECT_FALSE(rlz_lib::IsPingResponseValid(kBadPingResponses[i], NULL)); | |
295 | |
296 for (int i = 0; kGoodPingResponses[i]; i++) | |
297 EXPECT_TRUE(rlz_lib::IsPingResponseValid(kGoodPingResponses[i], NULL)); | |
298 } | |
299 | |
300 TEST_F(RlzLibTest, ParsePingResponse) { | |
301 const char* kPingResponse = | |
302 "version: 3.0.914.7250\r\n" | |
303 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
304 "launch-action: custom-action\r\n" | |
305 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
306 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
307 "rlz: 1R1_____en__252\r\n" // Invalid RLZ - no access point. | |
308 "rlzXX: 1R1_____en__250\r\n" // Invalid RLZ - bad access point. | |
309 "rlzT4 1T4_____en__251\r\n" // Invalid RLZ - missing colon. | |
310 "rlzT4: 1T4_____en__252\r\n" // GoodRLZ. | |
311 "events: I7S,W1I\r\n" // Clear all events. | |
312 "rlz\r\n" | |
313 "dcc: dcc_value\r\n" | |
314 "crc32: F9070F81"; | |
315 | |
316 #if defined(OS_WIN) | |
317 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value2")); | |
318 #endif | |
319 | |
320 // Record some product events to check that they get cleared. | |
321 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
322 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
323 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
324 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
325 | |
326 EXPECT_TRUE(rlz_lib::SetAccessPointRlz( | |
327 rlz_lib::IETB_SEARCH_BOX, "TbRlzValue")); | |
328 | |
329 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
330 kPingResponse)); | |
331 | |
332 #if defined(OS_WIN) | |
333 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value")); | |
334 #endif | |
335 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
336 kPingResponse)); | |
337 | |
338 char value[50]; | |
339 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, value, 50)); | |
340 EXPECT_STREQ("1T4_____en__252", value); | |
341 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
342 value, 50)); | |
343 EXPECT_STREQ("", value); | |
344 | |
345 const char* kPingResponse2 = | |
346 "rlzT4: 1T4_____de__253 \r\n" // Good with extra spaces. | |
347 "crc32: 321334F5\r\n"; | |
348 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
349 kPingResponse2)); | |
350 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, value, 50)); | |
351 EXPECT_STREQ("1T4_____de__253", value); | |
352 | |
353 const char* kPingResponse3 = | |
354 "crc32: 0\r\n"; // Good RLZ - empty response. | |
355 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
356 kPingResponse3)); | |
357 EXPECT_STREQ("1T4_____de__253", value); | |
358 } | |
359 | |
360 // Test whether a stateful event will only be sent in financial pings once. | |
361 TEST_F(RlzLibTest, ParsePingResponseWithStatefulEvents) { | |
362 const char* kPingResponse = | |
363 "version: 3.0.914.7250\r\n" | |
364 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
365 "launch-action: custom-action\r\n" | |
366 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
367 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
368 "rlzT4: 1T4_____en__252\r\n" // GoodRLZ. | |
369 "events: I7S,W1I\r\n" // Clear all events. | |
370 "stateful-events: W1I\r\n" // W1I as an stateful event. | |
371 "rlz\r\n" | |
372 "dcc: dcc_value\r\n" | |
373 "crc32: 55191759"; | |
374 | |
375 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
376 | |
377 // Record some product events to check that they get cleared. | |
378 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
379 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
380 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
381 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
382 | |
383 EXPECT_TRUE(rlz_lib::SetAccessPointRlz( | |
384 rlz_lib::IETB_SEARCH_BOX, "TbRlzValue")); | |
385 | |
386 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
387 kPingResponse)); | |
388 | |
389 // Check all the events sent earlier are cleared. | |
390 char value[50]; | |
391 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
392 value, 50)); | |
393 EXPECT_STREQ("", value); | |
394 | |
395 // Record both events (one is stateless and the other is stateful) again. | |
396 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
397 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
398 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
399 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
400 | |
401 // Check the stateful event won't be sent again while the stateless one will. | |
402 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
403 value, 50)); | |
404 EXPECT_STREQ("events=I7S", value); | |
405 | |
406 // Test that stateful events are cleared by ClearAllProductEvents(). After | |
407 // calling it, trying to record a stateful again should result in it being | |
408 // recorded again. | |
409 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
410 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
411 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
412 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
413 value, 50)); | |
414 EXPECT_STREQ("events=W1I", value); | |
415 } | |
416 | |
417 TEST_F(RlzLibTest, SendFinancialPing) { | |
418 // We don't really check a value or result in this test. All this does is | |
419 // attempt to ping the financial server, which you can verify in Fiddler. | |
420 // TODO: Make this a measurable test. | |
421 | |
422 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | |
423 #if defined(OS_MACOSX) | |
424 base::mac::ScopedNSAutoreleasePool pool; | |
425 #endif | |
426 | |
427 base::Thread::Options options; | |
428 options.message_loop_type = MessageLoop::TYPE_IO; | |
429 | |
430 base::Thread io_thread("rlz_unittest_io_thread"); | |
431 ASSERT_TRUE(io_thread.StartWithOptions(options)); | |
432 | |
433 scoped_refptr<TestURLRequestContextGetter> context = | |
434 new TestURLRequestContextGetter( | |
435 io_thread.message_loop()->message_loop_proxy()); | |
436 rlz_lib::SetURLRequestContext(context.get()); | |
437 | |
438 class URLRequestRAII { | |
439 public: | |
440 URLRequestRAII(net::URLRequestContextGetter* context) { | |
441 rlz_lib::SetURLRequestContext(context); | |
442 } | |
443 ~URLRequestRAII() { | |
444 rlz_lib::SetURLRequestContext(NULL); | |
445 } | |
446 }; | |
447 | |
448 URLRequestRAII set_context(context.get()); | |
449 #endif | |
450 | |
451 MachineDealCodeHelper::Clear(); | |
452 #if defined(OS_WIN) | |
453 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value")); | |
454 #endif | |
455 | |
456 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | |
457 "TbRlzValue")); | |
458 | |
459 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
460 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
461 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
462 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
463 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
464 | |
465 rlz_lib::AccessPoint points[] = | |
466 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, | |
467 rlz_lib::NO_ACCESS_POINT}; | |
468 | |
469 std::string request; | |
470 rlz_lib::SendFinancialPing(rlz_lib::TOOLBAR_NOTIFIER, points, | |
471 "swg", "GGLA", "SwgProductId1234", "en-UK", false, | |
472 /*skip_time_check=*/true); | |
473 } | |
474 | |
475 TEST_F(RlzLibTest, ClearProductState) { | |
476 MachineDealCodeHelper::Clear(); | |
477 | |
478 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | |
479 "TbRlzValue")); | |
480 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, | |
481 "GdbRlzValue")); | |
482 | |
483 rlz_lib::AccessPoint points[] = | |
484 { rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT }; | |
485 | |
486 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
487 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
488 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
489 rlz_lib::IETB_SEARCH_BOX, rlz_lib::INSTALL)); | |
490 | |
491 rlz_lib::AccessPoint points2[] = | |
492 { rlz_lib::IETB_SEARCH_BOX, | |
493 rlz_lib::GD_DESKBAND, | |
494 rlz_lib::NO_ACCESS_POINT }; | |
495 | |
496 char cgi[2048]; | |
497 EXPECT_TRUE(rlz_lib::GetPingParams(rlz_lib::TOOLBAR_NOTIFIER, points2, | |
498 cgi, 2048)); | |
499 EXPECT_STREQ("rep=2&rlz=T4:TbRlzValue,D1:GdbRlzValue", cgi); | |
500 | |
501 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
502 cgi, 2048)); | |
503 std::string events(cgi); | |
504 EXPECT_LT(0u, events.find("I7S")); | |
505 EXPECT_LT(0u, events.find("T4I")); | |
506 EXPECT_LT(0u, events.find("T4R")); | |
507 | |
508 rlz_lib::ClearProductState(rlz_lib::TOOLBAR_NOTIFIER, points); | |
509 | |
510 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | |
511 cgi, 2048)); | |
512 EXPECT_STREQ("", cgi); | |
513 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::GD_DESKBAND, | |
514 cgi, 2048)); | |
515 EXPECT_STREQ("GdbRlzValue", cgi); | |
516 | |
517 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
518 cgi, 2048)); | |
519 EXPECT_STREQ("", cgi); | |
520 } | |
521 | |
522 #if defined(OS_WIN) | |
523 template<class T> | |
524 class typed_buffer_ptr { | |
525 scoped_array<char> buffer_; | |
526 | |
527 public: | |
528 typed_buffer_ptr() { | |
529 } | |
530 | |
531 explicit typed_buffer_ptr(size_t size) : buffer_(new char[size]) { | |
532 } | |
533 | |
534 void reset(size_t size) { | |
535 buffer_.reset(new char[size]); | |
536 } | |
537 | |
538 operator T*() { | |
539 return reinterpret_cast<T*>(buffer_.get()); | |
540 } | |
541 }; | |
542 | |
543 namespace rlz_lib { | |
544 bool HasAccess(PSID sid, ACCESS_MASK access_mask, ACL* dacl); | |
545 } | |
546 | |
547 bool EmptyAcl(ACL* acl) { | |
548 ACL_SIZE_INFORMATION info; | |
549 bool ret = GetAclInformation(acl, &info, sizeof(info), AclSizeInformation); | |
550 EXPECT_TRUE(ret); | |
551 | |
552 for (DWORD i = 0; i < info.AceCount && ret; ++i) { | |
553 ret = DeleteAce(acl, 0); | |
554 EXPECT_TRUE(ret); | |
555 } | |
556 | |
557 return ret; | |
558 } | |
559 | |
560 TEST_F(RlzLibTest, HasAccess) { | |
561 // Create a SID that represents ALL USERS. | |
562 DWORD users_sid_size = SECURITY_MAX_SID_SIZE; | |
563 typed_buffer_ptr<SID> users_sid(users_sid_size); | |
564 CreateWellKnownSid(WinBuiltinUsersSid, NULL, users_sid, &users_sid_size); | |
565 | |
566 // RLZ always asks for KEY_ALL_ACCESS access to the key. This is what we | |
567 // test here. | |
568 | |
569 // No ACL mean no access. | |
570 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, NULL)); | |
571 | |
572 // Create an ACL for these tests. | |
573 const DWORD kMaxAclSize = 1024; | |
574 typed_buffer_ptr<ACL> dacl(kMaxAclSize); | |
575 InitializeAcl(dacl, kMaxAclSize, ACL_REVISION); | |
576 | |
577 // Empty DACL mean no access. | |
578 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
579 | |
580 // ACE without all needed privileges should mean no access. | |
581 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_READ, users_sid)); | |
582 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
583 | |
584 // ACE without all needed privileges should mean no access. | |
585 EXPECT_TRUE(EmptyAcl(dacl)); | |
586 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_WRITE, users_sid)); | |
587 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
588 | |
589 // A deny ACE before an allow ACE should not give access. | |
590 EXPECT_TRUE(EmptyAcl(dacl)); | |
591 EXPECT_TRUE(AddAccessDeniedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
592 users_sid)); | |
593 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
594 users_sid)); | |
595 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
596 | |
597 // A deny ACE before an allow ACE should not give access. | |
598 EXPECT_TRUE(EmptyAcl(dacl)); | |
599 EXPECT_TRUE(AddAccessDeniedAce(dacl, ACL_REVISION, KEY_READ, users_sid)); | |
600 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
601 users_sid)); | |
602 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
603 | |
604 | |
605 // An allow ACE without all required bits should not give access. | |
606 EXPECT_TRUE(EmptyAcl(dacl)); | |
607 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_WRITE, users_sid)); | |
608 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
609 | |
610 // An allow ACE with all required bits should give access. | |
611 EXPECT_TRUE(EmptyAcl(dacl)); | |
612 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
613 users_sid)); | |
614 EXPECT_TRUE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
615 | |
616 // A deny ACE after an allow ACE should not give access. | |
617 EXPECT_TRUE(EmptyAcl(dacl)); | |
618 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
619 users_sid)); | |
620 EXPECT_TRUE(AddAccessDeniedAce(dacl, ACL_REVISION, KEY_READ, users_sid)); | |
621 EXPECT_TRUE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
622 | |
623 // An inherit-only allow ACE should not give access. | |
624 EXPECT_TRUE(EmptyAcl(dacl)); | |
625 EXPECT_TRUE(AddAccessAllowedAceEx(dacl, ACL_REVISION, INHERIT_ONLY_ACE, | |
626 KEY_ALL_ACCESS, users_sid)); | |
627 EXPECT_FALSE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
628 | |
629 // An inherit-only deny ACE should not apply. | |
630 EXPECT_TRUE(EmptyAcl(dacl)); | |
631 EXPECT_TRUE(AddAccessDeniedAceEx(dacl, ACL_REVISION, INHERIT_ONLY_ACE, | |
632 KEY_ALL_ACCESS, users_sid)); | |
633 EXPECT_TRUE(AddAccessAllowedAce(dacl, ACL_REVISION, KEY_ALL_ACCESS, | |
634 users_sid)); | |
635 EXPECT_TRUE(rlz_lib::HasAccess(users_sid, KEY_ALL_ACCESS, dacl)); | |
636 } | |
637 #endif | |
638 | |
639 TEST_F(RlzLibTest, BrandingRecordProductEvent) { | |
640 // Don't run these tests if a supplementary brand is already in place. That | |
641 // way we can control the branding. | |
642 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
643 return; | |
644 | |
645 char cgi_50[50]; | |
646 | |
647 // Record different events for the same product with diffrent branding, and | |
648 // make sure that the information remains separate. | |
649 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
650 { | |
651 rlz_lib::SupplementaryBranding branding("TEST"); | |
652 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
653 } | |
654 | |
655 // Test that recording events with the default brand and a supplementary | |
656 // brand don't overwrite each other. | |
657 | |
658 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
659 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
660 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
661 cgi_50, 50)); | |
662 EXPECT_STREQ("events=I7S", cgi_50); | |
663 | |
664 { | |
665 rlz_lib::SupplementaryBranding branding("TEST"); | |
666 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
667 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); | |
668 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
669 cgi_50, 50)); | |
670 EXPECT_STREQ("events=I7I", cgi_50); | |
671 } | |
672 | |
673 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
674 cgi_50, 50)); | |
675 EXPECT_STREQ("events=I7S", cgi_50); | |
676 } | |
677 | |
678 TEST_F(RlzLibTest, BrandingSetAccessPointRlz) { | |
679 // Don't run these tests if a supplementary brand is already in place. That | |
680 // way we can control the branding. | |
681 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
682 return; | |
683 | |
684 char rlz_50[50]; | |
685 | |
686 // Test that setting RLZ strings with the default brand and a supplementary | |
687 // brand don't overwrite each other. | |
688 | |
689 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "IeTbRlz")); | |
690 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50)); | |
691 EXPECT_STREQ("IeTbRlz", rlz_50); | |
692 | |
693 { | |
694 rlz_lib::SupplementaryBranding branding("TEST"); | |
695 | |
696 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, "SuppRlz"))
; | |
697 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, | |
698 50)); | |
699 EXPECT_STREQ("SuppRlz", rlz_50); | |
700 } | |
701 | |
702 EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50)); | |
703 EXPECT_STREQ("IeTbRlz", rlz_50); | |
704 | |
705 } | |
706 | |
707 TEST_F(RlzLibTest, BrandingWithStatefulEvents) { | |
708 // Don't run these tests if a supplementary brand is already in place. That | |
709 // way we can control the branding. | |
710 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
711 return; | |
712 | |
713 const char* kPingResponse = | |
714 "version: 3.0.914.7250\r\n" | |
715 "url: http://www.corp.google.com/~av/45/opt/SearchWithGoogleUpdate.exe\r\n" | |
716 "launch-action: custom-action\r\n" | |
717 "launch-target: SearchWithGoogleUpdate.exe\r\n" | |
718 "signature: c08a3f4438e1442c4fe5678ee147cf6c5516e5d62bb64e\r\n" | |
719 "rlzT4: 1T4_____en__252\r\n" // GoodRLZ. | |
720 "events: I7S,W1I\r\n" // Clear all events. | |
721 "stateful-events: W1I\r\n" // W1I as an stateful event. | |
722 "rlz\r\n" | |
723 "dcc: dcc_value\r\n" | |
724 "crc32: 55191759"; | |
725 | |
726 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
727 { | |
728 rlz_lib::SupplementaryBranding branding("TEST"); | |
729 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | |
730 } | |
731 | |
732 // Record some product events for the default and supplementary brand. | |
733 // Check that they get cleared only for the default brand. | |
734 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
735 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
736 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
737 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
738 | |
739 { | |
740 rlz_lib::SupplementaryBranding branding("TEST"); | |
741 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
742 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
743 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
744 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
745 } | |
746 | |
747 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
748 kPingResponse)); | |
749 | |
750 // Check all the events sent earlier are cleared only for default brand. | |
751 char value[50]; | |
752 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
753 value, 50)); | |
754 EXPECT_STREQ("", value); | |
755 | |
756 { | |
757 rlz_lib::SupplementaryBranding branding("TEST"); | |
758 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
759 value, 50)); | |
760 EXPECT_STREQ("events=I7S,W1I", value); | |
761 } | |
762 | |
763 // Record both events (one is stateless and the other is stateful) again. | |
764 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
765 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
766 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
767 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | |
768 | |
769 // Check the stateful event won't be sent again while the stateless one will. | |
770 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
771 value, 50)); | |
772 EXPECT_STREQ("events=I7S", value); | |
773 | |
774 { | |
775 rlz_lib::SupplementaryBranding branding("TEST"); | |
776 EXPECT_TRUE(rlz_lib::ParsePingResponse(rlz_lib::TOOLBAR_NOTIFIER, | |
777 kPingResponse)); | |
778 | |
779 EXPECT_FALSE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
780 value, 50)); | |
781 EXPECT_STREQ("", value); | |
782 } | |
783 | |
784 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | |
785 value, 50)); | |
786 EXPECT_STREQ("events=I7S", value); | |
787 } | |
788 | |
789 #if defined(OS_MACOSX) | |
790 class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState { | |
791 protected: | |
792 virtual void SetUp() OVERRIDE; | |
793 }; | |
794 | |
795 void ReadonlyRlzDirectoryTest::SetUp() { | |
796 RlzLibTestNoMachineState::SetUp(); | |
797 // Make the rlz directory non-writeable. | |
798 chmod(temp_dir_.path().value().c_str(), 0500); | |
799 } | |
800 | |
801 TEST_F(ReadonlyRlzDirectoryTest, WriteFails) { | |
802 // The rlz test runner runs every test twice: Once normally, and once with | |
803 // a SupplementaryBranding on the stack. In the latter case, the rlz lock | |
804 // has already been acquired before the rlz directory got changed to | |
805 // read-only, which makes this test pointless. So run it only in the first | |
806 // pass. | |
807 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
808 return; | |
809 | |
810 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
811 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | |
812 } | |
813 | |
814 // Regression test for http://crbug.com/121255 | |
815 TEST_F(ReadonlyRlzDirectoryTest, SupplementaryBrandingDoesNotCrash) { | |
816 // See the comment at the top of WriteFails. | |
817 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
818 return; | |
819 | |
820 rlz_lib::SupplementaryBranding branding("TEST"); | |
821 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
822 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); | |
823 } | |
824 #endif | |
OLD | NEW |