rlz_tracker_unittest.cc 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. #include "components/rlz/rlz_tracker.h"
  5. #include <memory>
  6. #include "base/memory/ptr_util.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/strings/utf_string_conversions.h"
  10. #include "base/test/task_environment.h"
  11. #include "base/threading/thread_task_runner_handle.h"
  12. #include "base/time/time.h"
  13. #include "build/build_config.h"
  14. #include "build/chromeos_buildflags.h"
  15. #include "components/rlz/rlz_tracker_delegate.h"
  16. #include "net/url_request/url_request_test_util.h"
  17. #include "rlz/test/rlz_test_helpers.h"
  18. #include "services/network/public/cpp/shared_url_loader_factory.h"
  19. #include "testing/gtest/include/gtest/gtest.h"
  20. #if BUILDFLAG(IS_IOS)
  21. #include "ui/base/device_form_factor.h"
  22. #endif
  23. #if BUILDFLAG(IS_CHROMEOS_ASH)
  24. #include "chromeos/system/fake_statistics_provider.h"
  25. #endif
  26. using testing::AssertionResult;
  27. using testing::AssertionSuccess;
  28. using testing::AssertionFailure;
  29. namespace rlz {
  30. namespace {
  31. class TestRLZTrackerDelegate : public RLZTrackerDelegate {
  32. public:
  33. TestRLZTrackerDelegate()
  34. : request_context_getter_(new net::TestURLRequestContextGetter(
  35. base::ThreadTaskRunnerHandle::Get())) {}
  36. TestRLZTrackerDelegate(const TestRLZTrackerDelegate&) = delete;
  37. TestRLZTrackerDelegate& operator=(const TestRLZTrackerDelegate&) = delete;
  38. void set_brand(const char* brand) { brand_override_ = brand; }
  39. void set_reactivation_brand(const char* reactivation_brand) {
  40. // TODO(thakis): Reactivation doesn't exist on Mac yet.
  41. reactivation_brand_override_ = reactivation_brand;
  42. }
  43. void SimulateOmniboxUsage() {
  44. if (!on_omnibox_search_callback_.is_null())
  45. std::move(on_omnibox_search_callback_).Run();
  46. }
  47. void SimulateHomepageUsage() {
  48. if (!on_homepage_search_callback_.is_null())
  49. std::move(on_homepage_search_callback_).Run();
  50. }
  51. // RLZTrackerDelegate implementation.
  52. void Cleanup() override {
  53. on_omnibox_search_callback_.Reset();
  54. on_homepage_search_callback_.Reset();
  55. }
  56. bool IsOnUIThread() override { return true; }
  57. scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory()
  58. override {
  59. NOTIMPLEMENTED() << "If this is called, it needs an implementation.";
  60. return nullptr;
  61. }
  62. bool GetBrand(std::string* brand) override {
  63. *brand = brand_override_;
  64. return true;
  65. }
  66. bool IsBrandOrganic(const std::string& brand) override {
  67. return brand.empty() || brand == "GGLS" || brand == "GGRS";
  68. }
  69. bool GetReactivationBrand(std::string* brand) override {
  70. *brand = reactivation_brand_override_;
  71. return true;
  72. }
  73. bool ShouldEnableZeroDelayForTesting() override { return true; }
  74. bool GetLanguage(std::u16string* language) override { return true; }
  75. bool GetReferral(std::u16string* referral) override { return true; }
  76. bool ClearReferral() override { return true; }
  77. void SetOmniboxSearchCallback(base::OnceClosure callback) override {
  78. DCHECK(!callback.is_null());
  79. on_omnibox_search_callback_ = std::move(callback);
  80. }
  81. void SetHomepageSearchCallback(base::OnceClosure callback) override {
  82. DCHECK(!callback.is_null());
  83. on_homepage_search_callback_ = std::move(callback);
  84. }
  85. // A speculative fix for https://crbug.com/907379.
  86. bool ShouldUpdateExistingAccessPointRlz() override { return false; }
  87. private:
  88. scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
  89. std::string brand_override_;
  90. std::string reactivation_brand_override_;
  91. base::OnceClosure on_omnibox_search_callback_;
  92. base::OnceClosure on_homepage_search_callback_;
  93. };
  94. // Dummy RLZ string for the access points.
  95. const char kOmniboxRlzString[] = "test_omnibox";
  96. const char kNewOmniboxRlzString[] = "new_omnibox";
  97. #if !BUILDFLAG(IS_IOS)
  98. const char kHomepageRlzString[] = "test_homepage";
  99. const char kNewHomepageRlzString[] = "new_homepage";
  100. const char kAppListRlzString[] = "test_applist";
  101. const char kNewAppListRlzString[] = "new_applist";
  102. #endif // !BUILDFLAG(IS_IOS)
  103. // Some helper macros to test it a string contains/does not contain a substring.
  104. AssertionResult CmpHelperSTRC(const char* str_expression,
  105. const char* substr_expression,
  106. const char* str,
  107. const char* substr) {
  108. if (nullptr != strstr(str, substr)) {
  109. return AssertionSuccess();
  110. }
  111. return AssertionFailure() << "Expected: (" << substr_expression << ") in ("
  112. << str_expression << "), actual: '"
  113. << substr << "' not in '" << str << "'";
  114. }
  115. AssertionResult CmpHelperSTRNC(const char* str_expression,
  116. const char* substr_expression,
  117. const char* str,
  118. const char* substr) {
  119. if (nullptr == strstr(str, substr)) {
  120. return AssertionSuccess();
  121. }
  122. return AssertionFailure() << "Expected: (" << substr_expression
  123. << ") not in (" << str_expression << "), actual: '"
  124. << substr << "' in '" << str << "'";
  125. }
  126. #define EXPECT_STR_CONTAINS(str, substr) \
  127. EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
  128. #define EXPECT_STR_NOT_CONTAIN(str, substr) \
  129. EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
  130. } // namespace
  131. // Test class for RLZ tracker. Makes some member functions public and
  132. // overrides others to make it easier to test.
  133. class TestRLZTracker : public RLZTracker {
  134. public:
  135. using RLZTracker::InitRlzDelayed;
  136. using RLZTracker::DelayedInit;
  137. TestRLZTracker() : assume_not_ui_thread_(true) { set_tracker(this); }
  138. TestRLZTracker(const TestRLZTracker&) = delete;
  139. TestRLZTracker& operator=(const TestRLZTracker&) = delete;
  140. ~TestRLZTracker() override { set_tracker(nullptr); }
  141. bool was_ping_sent_for_brand(const std::string& brand) const {
  142. return pinged_brands_.count(brand) > 0;
  143. }
  144. void set_assume_not_ui_thread(bool assume_not_ui_thread) {
  145. assume_not_ui_thread_ = assume_not_ui_thread;
  146. }
  147. private:
  148. void ScheduleDelayedInit(base::TimeDelta delay) override {
  149. // If the delay is 0, invoke the delayed init now. Otherwise,
  150. // don't schedule anything, it will be manually called during tests.
  151. if (delay.is_zero())
  152. DelayedInit();
  153. }
  154. void ScheduleFinancialPing() override { PingNowImpl(); }
  155. bool ScheduleRecordProductEvent(rlz_lib::Product product,
  156. rlz_lib::AccessPoint point,
  157. rlz_lib::Event event_id) override {
  158. return !assume_not_ui_thread_;
  159. }
  160. bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) override {
  161. return !assume_not_ui_thread_;
  162. }
  163. bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) override {
  164. return !assume_not_ui_thread_;
  165. }
  166. #if BUILDFLAG(IS_CHROMEOS_ASH)
  167. bool ScheduleClearRlzState() override { return !assume_not_ui_thread_; }
  168. #endif
  169. bool SendFinancialPing(const std::string& brand,
  170. const std::u16string& lang,
  171. const std::u16string& referral) override {
  172. // Don't ping the server during tests, just pretend as if we did.
  173. EXPECT_FALSE(brand.empty());
  174. pinged_brands_.insert(brand);
  175. // Set new access points RLZ string, like the actual server ping would have
  176. // done.
  177. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(),
  178. kNewOmniboxRlzString);
  179. #if !BUILDFLAG(IS_IOS)
  180. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(),
  181. kNewHomepageRlzString);
  182. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(),
  183. kNewAppListRlzString);
  184. #endif // !BUILDFLAG(IS_IOS)
  185. return true;
  186. }
  187. std::set<std::string> pinged_brands_;
  188. bool assume_not_ui_thread_;
  189. };
  190. class RlzLibTest : public testing::Test {
  191. protected:
  192. void SetUp() override;
  193. void TearDown() override;
  194. void SetMainBrand(const char* brand);
  195. void SetReactivationBrand(const char* brand);
  196. void SimulateOmniboxUsage();
  197. void SimulateHomepageUsage();
  198. void SimulateAppListUsage();
  199. void InvokeDelayedInit();
  200. void ExpectEventRecorded(const char* event_name, bool expected);
  201. void ExpectRlzPingSent(bool expected);
  202. void ExpectReactivationRlzPingSent(bool expected);
  203. base::test::TaskEnvironment task_environment_;
  204. raw_ptr<TestRLZTrackerDelegate> delegate_;
  205. std::unique_ptr<TestRLZTracker> tracker_;
  206. RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
  207. #if BUILDFLAG(IS_CHROMEOS_ASH)
  208. std::unique_ptr<chromeos::system::FakeStatisticsProvider>
  209. statistics_provider_;
  210. #endif
  211. };
  212. void RlzLibTest::SetUp() {
  213. testing::Test::SetUp();
  214. m_rlz_test_helper_.SetUp();
  215. delegate_ = new TestRLZTrackerDelegate;
  216. tracker_ = std::make_unique<TestRLZTracker>();
  217. RLZTracker::SetRlzDelegate(base::WrapUnique(delegate_.get()));
  218. // Make sure a non-organic brand code is set in the registry or the RLZTracker
  219. // is pretty much a no-op.
  220. SetMainBrand("TEST");
  221. SetReactivationBrand("");
  222. #if BUILDFLAG(IS_CHROMEOS_ASH)
  223. statistics_provider_ =
  224. std::make_unique<chromeos::system::FakeStatisticsProvider>();
  225. chromeos::system::StatisticsProvider::SetTestProvider(
  226. statistics_provider_.get());
  227. statistics_provider_->SetMachineStatistic(
  228. chromeos::system::kShouldSendRlzPingKey,
  229. chromeos::system::kShouldSendRlzPingValueTrue);
  230. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  231. }
  232. void RlzLibTest::TearDown() {
  233. delegate_ = nullptr;
  234. tracker_.reset();
  235. testing::Test::TearDown();
  236. m_rlz_test_helper_.TearDown();
  237. #if BUILDFLAG(IS_CHROMEOS_ASH)
  238. chromeos::system::StatisticsProvider::SetTestProvider(nullptr);
  239. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  240. }
  241. void RlzLibTest::SetMainBrand(const char* brand) {
  242. delegate_->set_brand(brand);
  243. }
  244. void RlzLibTest::SetReactivationBrand(const char* brand) {
  245. delegate_->set_reactivation_brand(brand);
  246. }
  247. void RlzLibTest::SimulateOmniboxUsage() {
  248. delegate_->SimulateOmniboxUsage();
  249. }
  250. void RlzLibTest::SimulateHomepageUsage() {
  251. delegate_->SimulateHomepageUsage();
  252. }
  253. void RlzLibTest::SimulateAppListUsage() {
  254. #if !BUILDFLAG(IS_IOS)
  255. RLZTracker::RecordAppListSearch();
  256. #endif // !BUILDFLAG(IS_IOS)
  257. }
  258. void RlzLibTest::InvokeDelayedInit() {
  259. tracker_->DelayedInit();
  260. }
  261. void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
  262. char cgi[rlz_lib::kMaxCgiLength];
  263. GetProductEventsAsCgi(rlz_lib::CHROME, cgi, std::size(cgi));
  264. if (expected) {
  265. EXPECT_STR_CONTAINS(cgi, event_name);
  266. } else {
  267. EXPECT_STR_NOT_CONTAIN(cgi, event_name);
  268. }
  269. }
  270. void RlzLibTest::ExpectRlzPingSent(bool expected) {
  271. std::string brand;
  272. delegate_->GetBrand(&brand);
  273. EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand));
  274. }
  275. void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
  276. std::string brand;
  277. delegate_->GetReactivationBrand(&brand);
  278. EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand));
  279. }
  280. // The events that affect the different RLZ scenarios are the following:
  281. //
  282. // A: the user starts chrome for the first time
  283. // B: the user stops chrome
  284. // C: the user start a subsequent time
  285. // D: the user stops chrome again
  286. // I: the RLZTracker::DelayedInit() method is invoked
  287. // X: the user performs a search using the omnibox
  288. // Y: the user performs a search using the home page
  289. // Z: the user performs a search using the app list
  290. //
  291. // The events A to D happen in chronological order, but the other events
  292. // may happen at any point between A-B or C-D, in no particular order.
  293. //
  294. // The visible results of the scenarios on Win are:
  295. //
  296. // C1I event is recorded
  297. // C2I event is recorded
  298. // C7I event is recorded
  299. // C1F event is recorded
  300. // C2F event is recorded
  301. // C7F event is recorded
  302. // C1S event is recorded
  303. // C2S event is recorded
  304. // C7S event is recorded
  305. // RLZ ping sent
  306. //
  307. // On Mac, C5 / C6 / C8 are sent instead of C1 / C2 / C7.
  308. // On ChromeOS, CA / CB / CC are sent, respectively.
  309. //
  310. // On iOS, only the omnibox events are recorded, and the value send depends
  311. // on the device form factor (phone or tablet).
  312. //
  313. // Variations on the above scenarios:
  314. //
  315. // - if the delay specified to InitRlzDelayed() is negative, then the RLZ
  316. // ping should be sent out at the time of event X and not wait for I
  317. //
  318. // Also want to test that pre-warming the RLZ string cache works correctly.
  319. #if BUILDFLAG(IS_WIN)
  320. const char kOmniboxInstall[] = "C1I";
  321. const char kOmniboxSetToGoogle[] = "C1S";
  322. const char kOmniboxFirstSearch[] = "C1F";
  323. const char kHomepageInstall[] = "C2I";
  324. const char kHomepageSetToGoogle[] = "C2S";
  325. const char kHomepageFirstSearch[] = "C2F";
  326. const char kAppListInstall[] = "C7I";
  327. const char kAppListSetToGoogle[] = "C7S";
  328. const char kAppListFirstSearch[] = "C7F";
  329. #elif BUILDFLAG(IS_IOS)
  330. const char kOmniboxInstallPhone[] = "CDI";
  331. const char kOmniboxSetToGooglePhone[] = "CDS";
  332. const char kOmniboxFirstSearchPhone[] = "CDF";
  333. const char kOmniboxInstallTablet[] = "C9I";
  334. const char kOmniboxSetToGoogleTablet[] = "C9S";
  335. const char kOmniboxFirstSearchTablet[] = "C9F";
  336. #elif BUILDFLAG(IS_MAC)
  337. const char kOmniboxInstall[] = "C5I";
  338. const char kOmniboxSetToGoogle[] = "C5S";
  339. const char kOmniboxFirstSearch[] = "C5F";
  340. const char kHomepageInstall[] = "C6I";
  341. const char kHomepageSetToGoogle[] = "C6S";
  342. const char kHomepageFirstSearch[] = "C6F";
  343. const char kAppListInstall[] = "C8I";
  344. const char kAppListSetToGoogle[] = "C8S";
  345. const char kAppListFirstSearch[] = "C8F";
  346. #elif BUILDFLAG(IS_CHROMEOS_ASH)
  347. const char kOmniboxInstall[] = "CAI";
  348. const char kOmniboxSetToGoogle[] = "CAS";
  349. const char kOmniboxFirstSearch[] = "CAF";
  350. const char kHomepageInstall[] = "CBI";
  351. const char kHomepageSetToGoogle[] = "CBS";
  352. const char kHomepageFirstSearch[] = "CBF";
  353. const char kAppListInstall[] = "CCI";
  354. const char kAppListSetToGoogle[] = "CCS";
  355. const char kAppListFirstSearch[] = "CCF";
  356. #endif
  357. const char* OmniboxInstall() {
  358. #if BUILDFLAG(IS_IOS)
  359. return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
  360. ? kOmniboxInstallTablet
  361. : kOmniboxInstallPhone;
  362. #else
  363. return kOmniboxInstall;
  364. #endif
  365. }
  366. const char* OmniboxSetToGoogle() {
  367. #if BUILDFLAG(IS_IOS)
  368. return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
  369. ? kOmniboxSetToGoogleTablet
  370. : kOmniboxSetToGooglePhone;
  371. #else
  372. return kOmniboxSetToGoogle;
  373. #endif
  374. }
  375. const char* OmniboxFirstSearch() {
  376. #if BUILDFLAG(IS_IOS)
  377. return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
  378. ? kOmniboxFirstSearchTablet
  379. : kOmniboxFirstSearchPhone;
  380. #else
  381. return kOmniboxFirstSearch;
  382. #endif
  383. }
  384. const base::TimeDelta kDelay = base::Milliseconds(20);
  385. TEST_F(RlzLibTest, RecordProductEvent) {
  386. RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
  387. rlz_lib::FIRST_SEARCH);
  388. ExpectEventRecorded(OmniboxFirstSearch(), true);
  389. }
  390. TEST_F(RlzLibTest, QuickStopAfterStart) {
  391. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, true);
  392. // Omnibox events.
  393. ExpectEventRecorded(OmniboxInstall(), false);
  394. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  395. ExpectEventRecorded(OmniboxFirstSearch(), false);
  396. #if !BUILDFLAG(IS_IOS)
  397. // Home page events.
  398. ExpectEventRecorded(kHomepageInstall, false);
  399. ExpectEventRecorded(kHomepageSetToGoogle, false);
  400. ExpectEventRecorded(kHomepageFirstSearch, false);
  401. // App list events.
  402. ExpectEventRecorded(kAppListInstall, false);
  403. ExpectEventRecorded(kAppListSetToGoogle, false);
  404. ExpectEventRecorded(kAppListFirstSearch, false);
  405. #endif // !BUILDFLAG(IS_IOS)
  406. ExpectRlzPingSent(false);
  407. }
  408. TEST_F(RlzLibTest, DelayedInitOnly) {
  409. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  410. InvokeDelayedInit();
  411. // Omnibox events.
  412. ExpectEventRecorded(OmniboxInstall(), true);
  413. ExpectEventRecorded(OmniboxSetToGoogle(), true);
  414. ExpectEventRecorded(OmniboxFirstSearch(), false);
  415. #if !BUILDFLAG(IS_IOS)
  416. // Home page events.
  417. ExpectEventRecorded(kHomepageInstall, true);
  418. ExpectEventRecorded(kHomepageSetToGoogle, true);
  419. ExpectEventRecorded(kHomepageFirstSearch, false);
  420. // App list events.
  421. ExpectEventRecorded(kAppListInstall, true);
  422. ExpectEventRecorded(kAppListSetToGoogle, true);
  423. ExpectEventRecorded(kAppListFirstSearch, false);
  424. #endif // !BUILDFLAG(IS_IOS)
  425. ExpectRlzPingSent(true);
  426. }
  427. TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) {
  428. TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, true);
  429. InvokeDelayedInit();
  430. // Omnibox events.
  431. ExpectEventRecorded(OmniboxInstall(), true);
  432. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  433. ExpectEventRecorded(OmniboxFirstSearch(), false);
  434. #if !BUILDFLAG(IS_IOS)
  435. // Home page events.
  436. ExpectEventRecorded(kHomepageInstall, true);
  437. ExpectEventRecorded(kHomepageSetToGoogle, true);
  438. ExpectEventRecorded(kHomepageFirstSearch, true);
  439. // App list events.
  440. ExpectEventRecorded(kAppListInstall, true);
  441. ExpectEventRecorded(kAppListSetToGoogle, false);
  442. ExpectEventRecorded(kAppListFirstSearch, false);
  443. #endif // !BUILDFLAG(IS_IOS)
  444. ExpectRlzPingSent(true);
  445. }
  446. TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
  447. TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, false);
  448. InvokeDelayedInit();
  449. // Omnibox events.
  450. ExpectEventRecorded(OmniboxInstall(), true);
  451. ExpectEventRecorded(OmniboxSetToGoogle(), true);
  452. ExpectEventRecorded(OmniboxFirstSearch(), false);
  453. #if !BUILDFLAG(IS_IOS)
  454. // Home page events.
  455. ExpectEventRecorded(kHomepageInstall, true);
  456. ExpectEventRecorded(kHomepageSetToGoogle, true);
  457. ExpectEventRecorded(kHomepageFirstSearch, false);
  458. // App list events.
  459. ExpectEventRecorded(kAppListInstall, true);
  460. ExpectEventRecorded(kAppListSetToGoogle, true);
  461. ExpectEventRecorded(kAppListFirstSearch, false);
  462. #endif // !BUILDFLAG(IS_IOS)
  463. ExpectRlzPingSent(true);
  464. }
  465. TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) {
  466. TestRLZTracker::InitRlzDelayed(false, false, kDelay, false, false, true);
  467. InvokeDelayedInit();
  468. // Omnibox events.
  469. ExpectEventRecorded(OmniboxInstall(), true);
  470. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  471. ExpectEventRecorded(OmniboxFirstSearch(), false);
  472. #if !BUILDFLAG(IS_IOS)
  473. // Home page events.
  474. ExpectEventRecorded(kHomepageInstall, true);
  475. ExpectEventRecorded(kHomepageSetToGoogle, true);
  476. ExpectEventRecorded(kHomepageFirstSearch, true);
  477. // App list events.
  478. ExpectEventRecorded(kAppListInstall, true);
  479. ExpectEventRecorded(kAppListSetToGoogle, false);
  480. ExpectEventRecorded(kAppListFirstSearch, false);
  481. #endif // !BUILDFLAG(IS_IOS)
  482. ExpectRlzPingSent(true);
  483. }
  484. TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
  485. // Set some dummy RLZ strings to simulate that we already ran before and
  486. // performed a successful ping to the RLZ server.
  487. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
  488. #if !BUILDFLAG(IS_IOS)
  489. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
  490. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
  491. #endif // !BUILDFLAG(IS_IOS)
  492. TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, true);
  493. InvokeDelayedInit();
  494. // Omnibox events.
  495. ExpectEventRecorded(OmniboxInstall(), true);
  496. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  497. ExpectEventRecorded(OmniboxFirstSearch(), false);
  498. #if !BUILDFLAG(IS_IOS)
  499. // Home page events.
  500. ExpectEventRecorded(kHomepageInstall, true);
  501. ExpectEventRecorded(kHomepageSetToGoogle, false);
  502. ExpectEventRecorded(kHomepageFirstSearch, true);
  503. // App list events.
  504. ExpectEventRecorded(kAppListInstall, true);
  505. ExpectEventRecorded(kAppListSetToGoogle, false);
  506. ExpectEventRecorded(kAppListFirstSearch, false);
  507. #endif // !BUILDFLAG(IS_IOS)
  508. ExpectRlzPingSent(true);
  509. }
  510. TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) {
  511. TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, false);
  512. InvokeDelayedInit();
  513. // Omnibox events.
  514. ExpectEventRecorded(OmniboxInstall(), true);
  515. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  516. ExpectEventRecorded(OmniboxFirstSearch(), false);
  517. #if !BUILDFLAG(IS_IOS)
  518. // Home page events.
  519. ExpectEventRecorded(kHomepageInstall, true);
  520. ExpectEventRecorded(kHomepageSetToGoogle, false);
  521. ExpectEventRecorded(kHomepageFirstSearch, false);
  522. // App list events.
  523. ExpectEventRecorded(kAppListInstall, true);
  524. ExpectEventRecorded(kAppListSetToGoogle, false);
  525. ExpectEventRecorded(kAppListFirstSearch, false);
  526. #endif // !BUILDFLAG(IS_IOS)
  527. ExpectRlzPingSent(true);
  528. }
  529. TEST_F(RlzLibTest, OmniboxUsageOnly) {
  530. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  531. SimulateOmniboxUsage();
  532. // Omnibox events.
  533. ExpectEventRecorded(OmniboxInstall(), false);
  534. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  535. ExpectEventRecorded(OmniboxFirstSearch(), true);
  536. #if !BUILDFLAG(IS_IOS)
  537. // Home page events.
  538. ExpectEventRecorded(kHomepageInstall, false);
  539. ExpectEventRecorded(kHomepageSetToGoogle, false);
  540. ExpectEventRecorded(kHomepageFirstSearch, false);
  541. // App list events.
  542. ExpectEventRecorded(kAppListInstall, false);
  543. ExpectEventRecorded(kAppListSetToGoogle, false);
  544. ExpectEventRecorded(kAppListFirstSearch, false);
  545. #endif // !BUILDFLAG(IS_IOS)
  546. ExpectRlzPingSent(false);
  547. }
  548. TEST_F(RlzLibTest, HomepageUsageOnly) {
  549. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  550. SimulateHomepageUsage();
  551. // Omnibox events.
  552. ExpectEventRecorded(OmniboxInstall(), false);
  553. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  554. ExpectEventRecorded(OmniboxFirstSearch(), false);
  555. #if !BUILDFLAG(IS_IOS)
  556. // Home page events.
  557. ExpectEventRecorded(kHomepageInstall, false);
  558. ExpectEventRecorded(kHomepageSetToGoogle, false);
  559. ExpectEventRecorded(kHomepageFirstSearch, true);
  560. // App list events.
  561. ExpectEventRecorded(kAppListInstall, false);
  562. ExpectEventRecorded(kAppListSetToGoogle, false);
  563. ExpectEventRecorded(kAppListFirstSearch, false);
  564. #endif // !BUILDFLAG(IS_IOS)
  565. ExpectRlzPingSent(false);
  566. }
  567. TEST_F(RlzLibTest, AppListUsageOnly) {
  568. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  569. SimulateAppListUsage();
  570. // Omnibox events.
  571. ExpectEventRecorded(OmniboxInstall(), false);
  572. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  573. ExpectEventRecorded(OmniboxFirstSearch(), false);
  574. #if !BUILDFLAG(IS_IOS)
  575. // Home page events.
  576. ExpectEventRecorded(kHomepageInstall, false);
  577. ExpectEventRecorded(kHomepageSetToGoogle, false);
  578. ExpectEventRecorded(kHomepageFirstSearch, false);
  579. // App list events.
  580. ExpectEventRecorded(kAppListInstall, false);
  581. ExpectEventRecorded(kAppListSetToGoogle, false);
  582. ExpectEventRecorded(kAppListFirstSearch, true);
  583. #endif // !BUILDFLAG(IS_IOS)
  584. ExpectRlzPingSent(false);
  585. }
  586. TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
  587. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  588. SimulateOmniboxUsage();
  589. SimulateHomepageUsage();
  590. SimulateAppListUsage();
  591. InvokeDelayedInit();
  592. // Omnibox events.
  593. ExpectEventRecorded(OmniboxInstall(), true);
  594. ExpectEventRecorded(OmniboxSetToGoogle(), true);
  595. ExpectEventRecorded(OmniboxFirstSearch(), true);
  596. #if !BUILDFLAG(IS_IOS)
  597. // Home page events.
  598. ExpectEventRecorded(kHomepageInstall, true);
  599. ExpectEventRecorded(kHomepageSetToGoogle, true);
  600. ExpectEventRecorded(kHomepageFirstSearch, true);
  601. // App list events.
  602. ExpectEventRecorded(kAppListInstall, true);
  603. ExpectEventRecorded(kAppListSetToGoogle, true);
  604. ExpectEventRecorded(kAppListFirstSearch, true);
  605. #endif // !BUILDFLAG(IS_IOS)
  606. ExpectRlzPingSent(true);
  607. }
  608. TEST_F(RlzLibTest, UsageAfterDelayedInit) {
  609. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  610. InvokeDelayedInit();
  611. SimulateOmniboxUsage();
  612. SimulateHomepageUsage();
  613. SimulateAppListUsage();
  614. // Omnibox events.
  615. ExpectEventRecorded(OmniboxInstall(), true);
  616. ExpectEventRecorded(OmniboxSetToGoogle(), true);
  617. ExpectEventRecorded(OmniboxFirstSearch(), true);
  618. #if !BUILDFLAG(IS_IOS)
  619. // Home page events.
  620. ExpectEventRecorded(kHomepageInstall, true);
  621. ExpectEventRecorded(kHomepageSetToGoogle, true);
  622. ExpectEventRecorded(kHomepageFirstSearch, true);
  623. // App list events.
  624. ExpectEventRecorded(kAppListInstall, true);
  625. ExpectEventRecorded(kAppListSetToGoogle, true);
  626. ExpectEventRecorded(kAppListFirstSearch, true);
  627. #endif // !BUILDFLAG(IS_IOS)
  628. ExpectRlzPingSent(true);
  629. }
  630. TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenSendPingImmediately) {
  631. TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
  632. SimulateOmniboxUsage();
  633. // Omnibox events.
  634. ExpectEventRecorded(OmniboxInstall(), true);
  635. ExpectEventRecorded(OmniboxSetToGoogle(), true);
  636. ExpectEventRecorded(OmniboxFirstSearch(), true);
  637. #if !BUILDFLAG(IS_IOS)
  638. // Home page events.
  639. ExpectEventRecorded(kHomepageInstall, true);
  640. ExpectEventRecorded(kHomepageSetToGoogle, true);
  641. ExpectEventRecorded(kHomepageFirstSearch, false);
  642. // App list events.
  643. ExpectEventRecorded(kAppListInstall, true);
  644. ExpectEventRecorded(kAppListSetToGoogle, true);
  645. ExpectEventRecorded(kAppListFirstSearch, false);
  646. #endif // !BUILDFLAG(IS_IOS)
  647. ExpectRlzPingSent(true);
  648. }
  649. TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenSendPingImmediately) {
  650. TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
  651. SimulateHomepageUsage();
  652. // Omnibox events.
  653. ExpectEventRecorded(OmniboxInstall(), false);
  654. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  655. ExpectEventRecorded(OmniboxFirstSearch(), false);
  656. #if !BUILDFLAG(IS_IOS)
  657. // Home page events.
  658. ExpectEventRecorded(kHomepageInstall, false);
  659. ExpectEventRecorded(kHomepageSetToGoogle, false);
  660. ExpectEventRecorded(kHomepageFirstSearch, true);
  661. // App list events.
  662. ExpectEventRecorded(kAppListInstall, false);
  663. ExpectEventRecorded(kAppListSetToGoogle, false);
  664. ExpectEventRecorded(kAppListFirstSearch, false);
  665. #endif // !BUILDFLAG(IS_IOS)
  666. ExpectRlzPingSent(false);
  667. }
  668. TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenSendPingImmediately) {
  669. TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, true);
  670. SimulateHomepageUsage();
  671. // Omnibox events.
  672. ExpectEventRecorded(OmniboxInstall(), false);
  673. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  674. ExpectEventRecorded(OmniboxFirstSearch(), false);
  675. #if !BUILDFLAG(IS_IOS)
  676. // Home page events.
  677. ExpectEventRecorded(kHomepageInstall, false);
  678. ExpectEventRecorded(kHomepageSetToGoogle, false);
  679. ExpectEventRecorded(kHomepageFirstSearch, true);
  680. // App list events.
  681. ExpectEventRecorded(kAppListInstall, false);
  682. ExpectEventRecorded(kAppListSetToGoogle, false);
  683. ExpectEventRecorded(kAppListFirstSearch, false);
  684. #endif // !BUILDFLAG(IS_IOS)
  685. ExpectRlzPingSent(false);
  686. }
  687. TEST_F(RlzLibTest, AppListUsageDoesNotSendPingWhenSendPingImmediately) {
  688. TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, false);
  689. SimulateAppListUsage();
  690. // Omnibox events.
  691. ExpectEventRecorded(OmniboxInstall(), false);
  692. ExpectEventRecorded(OmniboxSetToGoogle(), false);
  693. ExpectEventRecorded(OmniboxFirstSearch(), false);
  694. #if !BUILDFLAG(IS_IOS)
  695. // Home page events.
  696. ExpectEventRecorded(kHomepageInstall, false);
  697. ExpectEventRecorded(kHomepageSetToGoogle, false);
  698. ExpectEventRecorded(kHomepageFirstSearch, false);
  699. // App list events.
  700. ExpectEventRecorded(kAppListInstall, false);
  701. ExpectEventRecorded(kAppListSetToGoogle, false);
  702. ExpectEventRecorded(kAppListFirstSearch, true);
  703. #endif // !BUILDFLAG(IS_IOS)
  704. ExpectRlzPingSent(false);
  705. }
  706. TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) {
  707. // Set dummy RLZ string.
  708. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
  709. std::u16string rlz;
  710. tracker_->set_assume_not_ui_thread(true);
  711. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  712. EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  713. }
  714. TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) {
  715. // Set dummy RLZ string.
  716. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
  717. std::u16string rlz;
  718. tracker_->set_assume_not_ui_thread(false);
  719. EXPECT_FALSE(
  720. RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  721. }
  722. TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
  723. // Set dummy RLZ string.
  724. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
  725. std::u16string rlz;
  726. tracker_->set_assume_not_ui_thread(false);
  727. EXPECT_FALSE(
  728. RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  729. tracker_->set_assume_not_ui_thread(true);
  730. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  731. EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  732. tracker_->set_assume_not_ui_thread(false);
  733. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  734. EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  735. }
  736. #if !BUILDFLAG(IS_CHROMEOS_ASH)
  737. // By design, on Chrome OS the RLZ string can only be set once. Once set,
  738. // pings cannot change int.
  739. TEST_F(RlzLibTest, PingUpdatesRlzCache) {
  740. // Set dummy RLZ string.
  741. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
  742. #if !BUILDFLAG(IS_IOS)
  743. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
  744. rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
  745. #endif // !BUILDFLAG(IS_IOS)
  746. std::u16string rlz;
  747. // Prime the cache.
  748. tracker_->set_assume_not_ui_thread(true);
  749. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  750. EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  751. #if !BUILDFLAG(IS_IOS)
  752. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
  753. RLZTracker::ChromeHomePage(), &rlz));
  754. EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
  755. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
  756. EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
  757. #endif // !BUILDFLAG(IS_IOS)
  758. // Make sure cache is valid.
  759. tracker_->set_assume_not_ui_thread(false);
  760. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  761. EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  762. #if !BUILDFLAG(IS_IOS)
  763. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
  764. RLZTracker::ChromeHomePage(), &rlz));
  765. EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
  766. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
  767. EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
  768. #endif // !BUILDFLAG(IS_IOS)
  769. // Perform ping.
  770. tracker_->set_assume_not_ui_thread(true);
  771. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  772. InvokeDelayedInit();
  773. ExpectRlzPingSent(true);
  774. // Make sure cache is now updated.
  775. tracker_->set_assume_not_ui_thread(false);
  776. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
  777. EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
  778. #if !BUILDFLAG(IS_IOS)
  779. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
  780. RLZTracker::ChromeHomePage(), &rlz));
  781. EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
  782. EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
  783. EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
  784. #endif // !BUILDFLAG(IS_IOS)
  785. }
  786. #endif // !BUILDFLAG(IS_CHROMEOS_ASH)
  787. // TODO(thakis): Reactivation doesn't exist on Mac yet.
  788. TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
  789. SetReactivationBrand("REAC");
  790. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  791. InvokeDelayedInit();
  792. ExpectRlzPingSent(true);
  793. ExpectReactivationRlzPingSent(true);
  794. }
  795. TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) {
  796. SetMainBrand("GGLS");
  797. SetReactivationBrand("REAC");
  798. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  799. InvokeDelayedInit();
  800. ExpectRlzPingSent(false);
  801. ExpectReactivationRlzPingSent(true);
  802. }
  803. TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) {
  804. SetMainBrand("TEST");
  805. SetReactivationBrand("GGLS");
  806. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  807. InvokeDelayedInit();
  808. ExpectRlzPingSent(true);
  809. ExpectReactivationRlzPingSent(false);
  810. }
  811. TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
  812. SetMainBrand("GGLS");
  813. SetReactivationBrand("GGRS");
  814. TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
  815. InvokeDelayedInit();
  816. ExpectRlzPingSent(false);
  817. ExpectReactivationRlzPingSent(false);
  818. }
  819. #if BUILDFLAG(IS_CHROMEOS_ASH)
  820. TEST_F(RlzLibTest, ClearRlzState) {
  821. RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
  822. rlz_lib::FIRST_SEARCH);
  823. ExpectEventRecorded(OmniboxFirstSearch(), true);
  824. RLZTracker::ClearRlzState();
  825. ExpectEventRecorded(OmniboxFirstSearch(), false);
  826. }
  827. TEST_F(RlzLibTest, DoNotRecordEventUnlessShouldSendRlzPingKeyIsTrue) {
  828. // Verify the event is recorded when |kShouldSendRlzPingKey| is true.
  829. std::string should_send_rlz_ping_value;
  830. ASSERT_TRUE(statistics_provider_->GetMachineStatistic(
  831. chromeos::system::kShouldSendRlzPingKey, &should_send_rlz_ping_value));
  832. ASSERT_EQ(should_send_rlz_ping_value,
  833. chromeos::system::kShouldSendRlzPingValueTrue);
  834. RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
  835. rlz_lib::FIRST_SEARCH);
  836. ExpectEventRecorded(OmniboxFirstSearch(), true);
  837. // Verify the event is not recorded when |kShouldSendRlzPingKey| is false.
  838. RLZTracker::ClearRlzState();
  839. ExpectEventRecorded(OmniboxFirstSearch(), false);
  840. statistics_provider_->SetMachineStatistic(
  841. chromeos::system::kShouldSendRlzPingKey,
  842. chromeos::system::kShouldSendRlzPingValueFalse);
  843. ASSERT_TRUE(statistics_provider_->GetMachineStatistic(
  844. chromeos::system::kShouldSendRlzPingKey, &should_send_rlz_ping_value));
  845. ASSERT_EQ(should_send_rlz_ping_value,
  846. chromeos::system::kShouldSendRlzPingValueFalse);
  847. RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
  848. rlz_lib::FIRST_SEARCH);
  849. ExpectEventRecorded(OmniboxFirstSearch(), false);
  850. // Verify the event is not recorded when |kShouldSendRlzPingKey| does not
  851. // exist.
  852. statistics_provider_->ClearMachineStatistic(
  853. chromeos::system::kShouldSendRlzPingKey);
  854. ASSERT_FALSE(statistics_provider_->GetMachineStatistic(
  855. chromeos::system::kShouldSendRlzPingKey, &should_send_rlz_ping_value));
  856. RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
  857. rlz_lib::FIRST_SEARCH);
  858. ExpectEventRecorded(OmniboxFirstSearch(), false);
  859. }
  860. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  861. } // namespace rlz