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

Side by Side Diff: chrome/browser/rlz/rlz_unittest.cc

Issue 7736001: Adding unit tests to RLZ code. Refactoring RLZ code to make it more testable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Uploading any merged files after sync, no new changes Created 9 years, 4 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
« chrome/browser/rlz/rlz.h ('K') | « chrome/browser/rlz/rlz.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/rlz/rlz.h" 5 #include "chrome/browser/rlz/rlz.h"
6 6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/stringprintf.h"
7 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/test/test_reg_util_win.h"
11 #include "base/utf_string_conversions.h"
8 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "chrome/browser/autocomplete/autocomplete.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/env_vars.h"
17 #include "chrome/installer/util/browser_distribution.h"
18 #include "chrome/installer/util/google_update_constants.h"
19 #include "chrome/test/base/testing_browser_process_test.h"
20 #include "content/browser/tab_contents/navigation_entry.h"
21 #include "content/common/notification_details.h"
22 #include "content/common/notification_source.h"
9 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
10 24
11 using base::win::RegKey; 25 using base::win::RegKey;
26 using registry_util::RegistryOverrideManager;
27 using testing::AssertionResult;
28 using testing::AssertionSuccess;
29 using testing::AssertionFailure;
12 30
13 namespace { 31 namespace {
14 32
15 // Gets rid of registry leftovers from testing. Returns false if there 33 // Registry path to overridden hive.
16 // is nothing to clean. 34 const wchar_t kRlzTempHkcu[] = L"rlz_hkcu";
17 bool CleanValue(const wchar_t* key_name, const wchar_t* value) { 35 const wchar_t kRlzTempHklm[] = L"rlz_hklm";
18 RegKey key; 36
19 if (key.Open(HKEY_CURRENT_USER, key_name, KEY_READ | KEY_WRITE) != 37 // Dummy RLZ string for the access points.
20 ERROR_SUCCESS) 38 const char kOmniboxRlzString[] = "test_omnibox";
21 return false; 39 const char kHomepageRlzString[] = "test_homepage";
22 EXPECT_EQ(ERROR_SUCCESS, key.DeleteValue(value)); 40
23 return true; 41 // Some helper macros to test it a string contains/does not contain a substring.
24 } 42
25 43 AssertionResult CmpHelperSTRC(const char* str_expression,
26 // The chrome events RLZ key lives here. 44 const char* substr_expression,
27 const wchar_t kKeyName[] = L"Software\\Google\\Common\\Rlz\\Events\\C"; 45 const char* str,
46 const char* substr) {
47 if (NULL != strstr(str, substr)) {
48 return AssertionSuccess();
49 }
50
51 return AssertionFailure() << "Expected: (" << substr_expression << ") in ("
52 << str_expression << "), actual: '"
53 << substr << "' not in '" << str << "'";
54 }
55
56 AssertionResult CmpHelperSTRNC(const char* str_expression,
57 const char* substr_expression,
58 const char* str,
59 const char* substr) {
60 if (NULL == strstr(str, substr)) {
61 return AssertionSuccess();
62 }
63
64 return AssertionFailure() << "Expected: (" << substr_expression
65 << ") not in (" << str_expression << "), actual: '"
66 << substr << "' in '" << str << "'";
67 }
68
69 #define EXPECT_STR_CONTAINS(str, substr) \
70 EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
71
72 #define EXPECT_STR_NOT_CONTAIN(str, substr) \
73 EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 remove lines 33 to 73, this is overkill and only u
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 I think you meant 41-73. Actually, I disagree. I
cpu_(ooo_6.6-7.5) 2011/08/29 19:43:04 basically on the only place where is called if (N
28 74
29 } // namespace 75 } // namespace
30 76
31 TEST(RlzLibTest, RecordProductEvent) { 77 // Test class for RLZ tracker. Makes some member functions public and
32 DWORD recorded_value = 0; 78 // overrides others to make it easier to test.
33 EXPECT_TRUE(RLZTracker::RecordProductEvent(rlz_lib::CHROME, 79 class TestRLZTracker : public RLZTracker {
34 rlz_lib::CHROME_OMNIBOX, rlz_lib::FIRST_SEARCH)); 80 public:
35 const wchar_t kEvent1[] = L"C1F"; 81 using RLZTracker::DelayedInit;
36 RegKey key1; 82 using RLZTracker::Observe;
37 EXPECT_EQ(ERROR_SUCCESS, key1.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); 83 using RLZTracker::RLZ_PAGETRANSITION_HOME_PAGE;
38 EXPECT_EQ(ERROR_SUCCESS, key1.ReadValueDW(kEvent1, &recorded_value)); 84
39 EXPECT_EQ(1, recorded_value); 85 TestRLZTracker() : pingnow_called_(false), assume_io_thread_(false) {
40 EXPECT_TRUE(CleanValue(kKeyName, kEvent1)); 86 set_tracker(this);
41 87 }
42 EXPECT_TRUE(RLZTracker::RecordProductEvent(rlz_lib::CHROME, 88
43 rlz_lib::CHROME_HOME_PAGE, rlz_lib::SET_TO_GOOGLE)); 89 virtual ~TestRLZTracker() {
44 const wchar_t kEvent2[] = L"C2S"; 90 set_tracker(NULL);
45 RegKey key2; 91 }
46 EXPECT_EQ(ERROR_SUCCESS, key2.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); 92
47 DWORD value = 0; 93 bool pingnow_called() {
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 const function
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 Done.
48 EXPECT_EQ(ERROR_SUCCESS, key2.ReadValueDW(kEvent2, &recorded_value)); 94 return pingnow_called_;
49 EXPECT_EQ(1, recorded_value); 95 }
50 EXPECT_TRUE(CleanValue(kKeyName, kEvent2)); 96
51 } 97 bool assume_io_thread() {
98 return assume_io_thread_;
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 const function
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 Done.
99 }
100
101 void set_assume_io_thread(bool assume_io_thread) {
102 assume_io_thread_ = assume_io_thread;
103 }
104
105 private:
106 virtual void ScheduleDelayedInit(int delay) OVERRIDE {
107 // If the delay is 0, invoke the delayed init now. Otherwise,
108 // don't schedule anything, it will be manually called during tests.
109 if (delay == 0)
110 DelayedInit();
111 }
112
113 virtual void ScheduleFinancialPing() OVERRIDE {
114 PingNow(this);
115 }
116
117 virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) OVERRIDE {
118 return !assume_io_thread_;
119 }
120
121 virtual bool SendFinancialPing(const std::wstring& brand,
122 const std::wstring& lang,
123 const std::wstring& referral,
124 bool exclude_id) OVERRIDE {
125 // Don't ping the server during tests.
126 pingnow_called_ = true;
127 return true;
128 }
129
130 bool pingnow_called_;
131 bool assume_io_thread_;
132
133 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
134 };
135
136 class RlzLibTest : public TestingBrowserProcessTest {
137 virtual void SetUp() OVERRIDE;
138 virtual void TearDown() OVERRIDE;
139
140 protected:
141 RlzLibTest();
142 ~RlzLibTest();
143
144 void SimulateOmniboxUsage();
145 void SimulateHomepageUsage();
146 void InvokeDelayedInit();
147
148 void ExpectEventRecorded(const char* event_name, bool expected);
149 void ExpectRlzPingSent(bool expected);
150
151 TestRLZTracker tracker_;
152 RegistryOverrideManager override_manager_;
153 wchar_t env_var_[64];
154 };
155
156 RlzLibTest::RlzLibTest() {
157 }
158
159 RlzLibTest::~RlzLibTest() {
160 }
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 remove lines 156 - 160
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 Done.
161
162 void RlzLibTest::SetUp() {
163 TestingBrowserProcessTest::SetUp();
164
165 // Make sure HEADLESS environment variable is not set.
166 env_var_[0] = 0;
167 DWORD size = ::GetEnvironmentVariableW(
168 ASCIIToWide(env_vars::kHeadless).c_str(), env_var_, arraysize(env_var_));
169 if (size == 0)
170 ASSERT_EQ(ERROR_ENVVAR_NOT_FOUND, ::GetLastError());
171 ASSERT_LT(size, arraysize(env_var_));
172
173 ::SetEnvironmentVariable(ASCIIToWide(env_vars::kHeadless).c_str(), NULL);
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 why?
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 See rlz.cc, line 213. It seems like headless may
cpu_(ooo_6.6-7.5) 2011/08/29 19:43:04 Hmmm... better ask Pawel. Sounds fishy to me.
174
175 // Before overriding HKLM for the tests, we need to set it up correctly
176 // so that the rlz_lib calls work. This needs to be done before we do the
177 // override.
178
179 std::wstring temp_hklm_path = base::StringPrintf(
180 L"%ls\\%ls",
181 RegistryOverrideManager::kTempTestKeyPath,
182 kRlzTempHklm);
183
184 base::win::RegKey hklm;
185 ASSERT_EQ(ERROR_SUCCESS, hklm.Create(HKEY_CURRENT_USER,
186 temp_hklm_path.c_str(),
187 KEY_READ));
188
189 std::wstring temp_hkcu_path = base::StringPrintf(
190 L"%ls\\%ls",
191 RegistryOverrideManager::kTempTestKeyPath,
192 kRlzTempHkcu);
193
194 base::win::RegKey hkcu;
195 ASSERT_EQ(ERROR_SUCCESS, hkcu.Create(HKEY_CURRENT_USER,
196 temp_hkcu_path.c_str(),
197 KEY_READ));
198
199 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu);
200
201 // Its important to override HKLM before HKCU because of the registry
202 // initialization performed above.
203 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, kRlzTempHklm);
204 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, kRlzTempHkcu);
205
206 // Make sure a non-organic brand code is set in the registry or the RLZTracker
207 // is pretty much a no-op.
208 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
209 std::wstring reg_path = dist->GetStateKey();
210 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE);
211 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(google_update::kRegRLZBrandField,
212 L"TEST"));
213 }
214
215 void RlzLibTest::TearDown() {
216 TestingBrowserProcessTest::TearDown();
217
cpu_(ooo_6.6-7.5) 2011/08/26 21:37:51 so we don't delete the registry keys?
Roger Tawa OOO till Jul 10th 2011/08/27 02:00:06 No need, done by the dtor of RegistryOverrideManag
218 if (env_var_[0] != 0)
219 ::SetEnvironmentVariable(ASCIIToWide(env_vars::kHeadless).c_str(),
220 env_var_);
221 }
222
223 void RlzLibTest::SimulateOmniboxUsage() {
224 tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
225 NotificationService::AllSources(),
226 Details<AutocompleteLog>(NULL));
227 }
228
229 void RlzLibTest::SimulateHomepageUsage() {
230 NavigationEntry entry(NULL, 0, GURL(), GURL(), string16(),
231 TestRLZTracker::RLZ_PAGETRANSITION_HOME_PAGE);
232 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
233 NotificationService::AllSources(),
234 Details<NavigationEntry>(&entry));
235 }
236
237 void RlzLibTest::InvokeDelayedInit() {
238 tracker_.DelayedInit();
239 }
240
241 void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
242 char cgi[rlz_lib::kMaxCgiLength];
243 GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi));
244 if (expected) {
245 EXPECT_STR_CONTAINS(cgi, event_name);
246 } else {
247 EXPECT_STR_NOT_CONTAIN(cgi, event_name);
248 }
249 }
250
251 void RlzLibTest::ExpectRlzPingSent(bool expected) {
252 EXPECT_EQ(expected, tracker_.pingnow_called());
253 }
254
255 TEST_F(RlzLibTest, RecordProductEvent) {
256 RLZTracker::RecordProductEvent(rlz_lib::CHROME, rlz_lib::CHROME_OMNIBOX,
257 rlz_lib::FIRST_SEARCH);
258
259 ExpectEventRecorded("C1F", true);
260 }
261
262 // The events that affect the different RLZ scenarios are the following:
263 //
264 // A: the user starts chrome for the first time
265 // B: the user stops chrome
266 // C: the user start a subsequent time
267 // D: the user stops chrome again
268 // I: the RLZTracker::DelayedInit() method is invoked
269 // X: the user performs a search using the omnibox
270 // Y: the user performs a search using the home page
271 //
272 // The events A to D happen in chronological order, but the other events
273 // may happen at any point between A-B or C-D, in no particular order.
274 //
275 // The visible results of the scenarios are:
276 //
277 // C1I event is recorded
278 // C2I event is recorded
279 // C1F event is recorded
280 // C2F event is recorded
281 // C1S event is recorded
282 // C2S event is recorded
283 // RLZ ping sent
284 //
285 // Variations on the above scenarios:
286 //
287 // - if the delay specified to InitRlzDelayed() is negative, then the RLZ
288 // ping should be sent out at the time of event X and not wait for I
289 //
290 // Also want to test that pre-warming the RLZ string cache works correctly.
291
292 TEST_F(RlzLibTest, QuickStopAfterStart) {
293 RLZTracker::InitRlzDelayed(true, 20, true, true);
294
295 // Omnibox events.
296 ExpectEventRecorded("C1I", false);
297 ExpectEventRecorded("C1S", false);
298 ExpectEventRecorded("C1F", false);
299
300 // Home page events.
301 ExpectEventRecorded("C2I", false);
302 ExpectEventRecorded("C2S", false);
303 ExpectEventRecorded("C2F", false);
304
305 ExpectRlzPingSent(false);
306 }
307
308 TEST_F(RlzLibTest, DelayedInitOnly) {
309 RLZTracker::InitRlzDelayed(true, 20, true, true);
310 InvokeDelayedInit();
311
312 // Omnibox events.
313 ExpectEventRecorded("C1I", true);
314 ExpectEventRecorded("C1S", true);
315 ExpectEventRecorded("C1F", false);
316
317 // Home page events.
318 ExpectEventRecorded("C2I", true);
319 ExpectEventRecorded("C2S", true);
320 ExpectEventRecorded("C2F", false);
321
322 ExpectRlzPingSent(true);
323 }
324
325 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
326 RLZTracker::InitRlzDelayed(false, 20, true, true);
327 InvokeDelayedInit();
328
329 // Omnibox events.
330 ExpectEventRecorded("C1I", true);
331 ExpectEventRecorded("C1S", true);
332 ExpectEventRecorded("C1F", false);
333
334 // Home page events.
335 ExpectEventRecorded("C2I", true);
336 ExpectEventRecorded("C2S", true);
337 ExpectEventRecorded("C2F", false);
338
339 ExpectRlzPingSent(true);
340 }
341
342 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
343 // Set some dummy RLZ strings to simulate that we already ran before and
344 // performed a successful ping to the RLZ server.
345 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString);
346 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, kHomepageRlzString);
347
348 RLZTracker::InitRlzDelayed(false, 20, true, true);
349 InvokeDelayedInit();
350
351 // Omnibox events.
352 ExpectEventRecorded("C1I", true);
353 ExpectEventRecorded("C1S", false);
354 ExpectEventRecorded("C1F", false);
355
356 // Home page events.
357 ExpectEventRecorded("C2I", true);
358 ExpectEventRecorded("C2S", false);
359 ExpectEventRecorded("C2F", false);
360
361 ExpectRlzPingSent(true);
362 }
363
364 TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepage) {
365 RLZTracker::InitRlzDelayed(true, 20, false, false);
366 InvokeDelayedInit();
367
368 // Omnibox events.
369 ExpectEventRecorded("C1I", true);
370 ExpectEventRecorded("C1S", false);
371 ExpectEventRecorded("C1F", false);
372
373 // Home page events.
374 ExpectEventRecorded("C2I", true);
375 ExpectEventRecorded("C2S", false);
376 ExpectEventRecorded("C2F", false);
377
378 ExpectRlzPingSent(true);
379 }
380
381 TEST_F(RlzLibTest, OmniboxUsageOnly) {
382 RLZTracker::InitRlzDelayed(true, 20, true, true);
383 SimulateOmniboxUsage();
384
385 // Omnibox events.
386 ExpectEventRecorded("C1I", false);
387 ExpectEventRecorded("C1S", false);
388 ExpectEventRecorded("C1F", true);
389
390 // Home page events.
391 ExpectEventRecorded("C2I", false);
392 ExpectEventRecorded("C2S", false);
393 ExpectEventRecorded("C2F", false);
394
395 ExpectRlzPingSent(false);
396 }
397
398 TEST_F(RlzLibTest, HomepageUsageOnly) {
399 RLZTracker::InitRlzDelayed(true, 20, true, true);
400 SimulateHomepageUsage();
401
402 // Omnibox events.
403 ExpectEventRecorded("C1I", false);
404 ExpectEventRecorded("C1S", false);
405 ExpectEventRecorded("C1F", false);
406
407 // Home page events.
408 ExpectEventRecorded("C2I", false);
409 ExpectEventRecorded("C2S", false);
410 ExpectEventRecorded("C2F", true);
411
412 ExpectRlzPingSent(false);
413 }
414
415 TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
416 RLZTracker::InitRlzDelayed(true, 20, true, true);
417 SimulateOmniboxUsage();
418 SimulateHomepageUsage();
419 InvokeDelayedInit();
420
421 // Omnibox events.
422 ExpectEventRecorded("C1I", true);
423 ExpectEventRecorded("C1S", true);
424 ExpectEventRecorded("C1F", true);
425
426 // Home page events.
427 ExpectEventRecorded("C2I", true);
428 ExpectEventRecorded("C2S", true);
429 ExpectEventRecorded("C2F", true);
430
431 ExpectRlzPingSent(true);
432 }
433
434 TEST_F(RlzLibTest, OmniboxUsageAfterDelayedInit) {
435 RLZTracker::InitRlzDelayed(true, 20, true, true);
436 InvokeDelayedInit();
437 SimulateOmniboxUsage();
438 SimulateHomepageUsage();
439
440 // Omnibox events.
441 ExpectEventRecorded("C1I", true);
442 ExpectEventRecorded("C1S", true);
443 ExpectEventRecorded("C1F", true);
444
445 // Home page events.
446 ExpectEventRecorded("C2I", true);
447 ExpectEventRecorded("C2S", true);
448 ExpectEventRecorded("C2F", true);
449
450 ExpectRlzPingSent(true);
451 }
452
453 TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenDelayNegative) {
454 RLZTracker::InitRlzDelayed(true, -20, true, true);
455 SimulateOmniboxUsage();
456
457 // Omnibox events.
458 ExpectEventRecorded("C1I", true);
459 ExpectEventRecorded("C1S", true);
460 ExpectEventRecorded("C1F", true);
461
462 // Home page events.
463 ExpectEventRecorded("C2I", true);
464 ExpectEventRecorded("C2S", true);
465 ExpectEventRecorded("C2F", false);
466
467 ExpectRlzPingSent(true);
468 }
469
470 TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenDelayNegative) {
471 RLZTracker::InitRlzDelayed(true, -20, true, true);
472 SimulateHomepageUsage();
473
474 // Omnibox events.
475 ExpectEventRecorded("C1I", false);
476 ExpectEventRecorded("C1S", false);
477 ExpectEventRecorded("C1F", false);
478
479 // Home page events.
480 ExpectEventRecorded("C2I", false);
481 ExpectEventRecorded("C2S", false);
482 ExpectEventRecorded("C2F", true);
483
484 ExpectRlzPingSent(false);
485 }
486
487 TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) {
488 // Set dummy RLZ string.
489 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString);
490
491 std::wstring rlz;
492
493 tracker_.set_assume_io_thread(true);
494 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
495 EXPECT_STREQ(kOmniboxRlzString, WideToUTF8(rlz).c_str());
496 }
497
498 TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) {
499 // Set dummy RLZ string.
500 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString);
501
502 std::wstring rlz;
503
504 tracker_.set_assume_io_thread(false);
505 EXPECT_FALSE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
506 }
507
508 TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
509 // Set dummy RLZ string.
510 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString);
511
512 std::wstring rlz;
513
514 tracker_.set_assume_io_thread(false);
515 EXPECT_FALSE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
516
517 tracker_.set_assume_io_thread(true);
518 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
519 EXPECT_STREQ(kOmniboxRlzString, WideToUTF8(rlz).c_str());
520
521 tracker_.set_assume_io_thread(false);
522 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
523 EXPECT_STREQ(kOmniboxRlzString, WideToUTF8(rlz).c_str());
524 }
525
526 TEST_F(RlzLibTest, PingInvalidatesRlzCache) {
527 // Set dummy RLZ string.
528 rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString);
529
530 std::wstring rlz;
531
532 // Prime the cache.
533 tracker_.set_assume_io_thread(true);
534 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
535 EXPECT_STREQ(kOmniboxRlzString, WideToUTF8(rlz).c_str());
536
537 // Make sure cache is valid.
538 tracker_.set_assume_io_thread(false);
539 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
540 EXPECT_STREQ(kOmniboxRlzString, WideToUTF8(rlz).c_str());
541
542 // Perform ping.
543 RLZTracker::InitRlzDelayed(true, 20, true, true);
544 InvokeDelayedInit();
545 ExpectRlzPingSent(true);
546
547 // Make sure cache is now invalid.
548 EXPECT_FALSE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz));
549 }
550
551 TEST_F(RlzLibTest, ObserveHandlesBadArgs) {
552 NavigationEntry entry(NULL, 0, GURL(), GURL(), string16(),
553 PageTransition::LINK);
554 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
555 NotificationService::AllSources(),
556 Details<NavigationEntry>(NULL));
557 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
558 NotificationService::AllSources(),
559 Details<NavigationEntry>(&entry));
560 }
OLDNEW
« chrome/browser/rlz/rlz.h ('K') | « chrome/browser/rlz/rlz.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698