quick_pair_metrics_logger_unittest.cc 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. // Copyright 2021 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 "ash/quick_pair/keyed_service/quick_pair_metrics_logger.h"
  5. #include <memory>
  6. #include "ash/constants/ash_pref_names.h"
  7. #include "ash/quick_pair/common/account_key_failure.h"
  8. #include "ash/quick_pair/common/constants.h"
  9. #include "ash/quick_pair/common/device.h"
  10. #include "ash/quick_pair/common/fast_pair/fast_pair_metrics.h"
  11. #include "ash/quick_pair/common/logging.h"
  12. #include "ash/quick_pair/common/mock_quick_pair_browser_delegate.h"
  13. #include "ash/quick_pair/common/pair_failure.h"
  14. #include "ash/quick_pair/common/protocol.h"
  15. #include "ash/quick_pair/pairing/fake_retroactive_pairing_detector.h"
  16. #include "ash/quick_pair/pairing/mock_pairer_broker.h"
  17. #include "ash/quick_pair/pairing/pairer_broker.h"
  18. #include "ash/quick_pair/pairing/retroactive_pairing_detector.h"
  19. #include "ash/quick_pair/scanning/mock_scanner_broker.h"
  20. #include "ash/quick_pair/scanning/scanner_broker.h"
  21. #include "ash/quick_pair/ui/mock_ui_broker.h"
  22. #include "ash/quick_pair/ui/ui_broker.h"
  23. #include "base/memory/scoped_refptr.h"
  24. #include "base/run_loop.h"
  25. #include "base/test/metrics/histogram_tester.h"
  26. #include "base/test/task_environment.h"
  27. #include "base/time/time.h"
  28. #include "components/prefs/pref_registry.h"
  29. #include "components/prefs/pref_registry_simple.h"
  30. #include "components/prefs/testing_pref_service.h"
  31. #include "device/bluetooth/bluetooth_adapter_factory.h"
  32. #include "device/bluetooth/test/mock_bluetooth_adapter.h"
  33. #include "device/bluetooth/test/mock_bluetooth_device.h"
  34. #include "testing/gtest/include/gtest/gtest.h"
  35. #include "third_party/abseil-cpp/absl/types/optional.h"
  36. namespace {
  37. constexpr char kTestMetadataId[] = "test_metadata_id";
  38. constexpr char kTestAddress[] = "test_address";
  39. constexpr char kFastPairEngagementFlowMetricInitial[] =
  40. "Bluetooth.ChromeOS.FastPair.EngagementFunnel.Steps.InitialPairingProtocol";
  41. constexpr char kFastPairEngagementFlowMetricSubsequent[] =
  42. "Bluetooth.ChromeOS.FastPair.EngagementFunnel.Steps."
  43. "SubsequentPairingProtocol";
  44. const char kFastPairRetroactiveEngagementFlowMetric[] =
  45. "Bluetooth.ChromeOS.FastPair.RetroactiveEngagementFunnel.Steps";
  46. constexpr char kFastPairPairTimeMetricInitial[] =
  47. "Bluetooth.ChromeOS.FastPair.TotalUxPairTime.InitialPairingProtocol2";
  48. constexpr char kFastPairPairTimeMetricSubsequent[] =
  49. "Bluetooth.ChromeOS.FastPair.TotalUxPairTime.SubsequentPairingProtocol2";
  50. const char kPairingMethodMetric[] = "Bluetooth.ChromeOS.FastPair.PairingMethod";
  51. const char kRetroactivePairingResultMetric[] =
  52. "Bluetooth.ChromeOS.FastPair.RetroactivePairing.Result";
  53. const char kFastPairPairFailureMetricInitial[] =
  54. "Bluetooth.ChromeOS.FastPair.PairFailure.InitialPairingProtocol";
  55. const char kFastPairPairFailureMetricSubsequent[] =
  56. "Bluetooth.ChromeOS.FastPair.PairFailure.SubsequentPairingProtocol";
  57. const char kFastPairPairFailureMetricRetroactive[] =
  58. "Bluetooth.ChromeOS.FastPair.PairFailure.RetroactivePairingProtocol";
  59. const char kFastPairPairResultMetricInitial[] =
  60. "Bluetooth.ChromeOS.FastPair.Pairing.Result.InitialPairingProtocol";
  61. const char kFastPairPairResultMetricSubsequent[] =
  62. "Bluetooth.ChromeOS.FastPair.Pairing.Result.SubsequentPairingProtocol";
  63. const char kFastPairPairResultMetricRetroactive[] =
  64. "Bluetooth.ChromeOS.FastPair.Pairing.Result.RetroactivePairingProtocol";
  65. const char kFastPairAccountKeyWriteResultMetricInitial[] =
  66. "Bluetooth.ChromeOS.FastPair.AccountKey.Write.Result."
  67. "InitialPairingProtocol";
  68. const char kFastPairAccountKeyWriteResultMetricRetroactive[] =
  69. "Bluetooth.ChromeOS.FastPair.AccountKey.Write.Result."
  70. "RetroactivePairingProtocol";
  71. const char kFastPairAccountKeyWriteFailureMetricInitial[] =
  72. "Bluetooth.ChromeOS.FastPair.AccountKey.Failure.InitialPairingProtocol";
  73. const char kFastPairAccountKeyWriteFailureMetricRetroactive[] =
  74. "Bluetooth.ChromeOS.FastPair.AccountKey.Failure.RetroactivePairingProtocol";
  75. constexpr char kTestDeviceAddress[] = "11:12:13:14:15:16";
  76. constexpr char kTestBleDeviceName[] = "Test Device Name";
  77. constexpr char kValidModelId[] = "718c17";
  78. std::unique_ptr<testing::NiceMock<device::MockBluetoothDevice>>
  79. CreateTestBluetoothDevice(std::string address) {
  80. return std::make_unique<testing::NiceMock<device::MockBluetoothDevice>>(
  81. /*adapter=*/nullptr, /*bluetooth_class=*/0, kTestBleDeviceName, address,
  82. /*paired=*/true, /*connected=*/false);
  83. }
  84. class FakeMetricBluetoothAdapter
  85. : public testing::NiceMock<device::MockBluetoothAdapter> {
  86. public:
  87. device::BluetoothDevice* GetDevice(const std::string& address) override {
  88. for (const auto& it : mock_devices_) {
  89. if (it->GetAddress() == address)
  90. return it.get();
  91. }
  92. return nullptr;
  93. }
  94. void NotifyDevicePairedChanged(device::BluetoothDevice* device,
  95. bool new_paired_status) {
  96. device::BluetoothAdapter::NotifyDevicePairedChanged(device,
  97. new_paired_status);
  98. }
  99. bool IsPresent() const override { return true; }
  100. device::BluetoothAdapter::LowEnergyScanSessionHardwareOffloadingStatus
  101. GetLowEnergyScanSessionHardwareOffloadingStatus() override {
  102. return device::BluetoothAdapter::
  103. LowEnergyScanSessionHardwareOffloadingStatus::kSupported;
  104. }
  105. private:
  106. ~FakeMetricBluetoothAdapter() = default;
  107. };
  108. } // namespace
  109. namespace ash {
  110. namespace quick_pair {
  111. class QuickPairMetricsLoggerTest : public testing::Test {
  112. public:
  113. void SetUp() override {
  114. adapter_ = base::MakeRefCounted<FakeMetricBluetoothAdapter>();
  115. device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_);
  116. scanner_broker_ = std::make_unique<MockScannerBroker>();
  117. mock_scanner_broker_ =
  118. static_cast<MockScannerBroker*>(scanner_broker_.get());
  119. retroactive_pairing_detector_ =
  120. std::make_unique<FakeRetroactivePairingDetector>();
  121. fake_retroactive_pairing_detector_ =
  122. static_cast<FakeRetroactivePairingDetector*>(
  123. retroactive_pairing_detector_.get());
  124. pairer_broker_ = std::make_unique<MockPairerBroker>();
  125. mock_pairer_broker_ = static_cast<MockPairerBroker*>(pairer_broker_.get());
  126. ui_broker_ = std::make_unique<MockUIBroker>();
  127. mock_ui_broker_ = static_cast<MockUIBroker*>(ui_broker_.get());
  128. initial_device_ = base::MakeRefCounted<Device>(
  129. kTestMetadataId, kTestAddress, Protocol::kFastPairInitial);
  130. subsequent_device_ = base::MakeRefCounted<Device>(
  131. kTestMetadataId, kTestAddress, Protocol::kFastPairSubsequent);
  132. retroactive_device_ = base::MakeRefCounted<Device>(
  133. kTestMetadataId, kTestAddress, Protocol::kFastPairRetroactive);
  134. browser_delegate_ = std::make_unique<MockQuickPairBrowserDelegate>();
  135. ON_CALL(*browser_delegate_, GetActivePrefService())
  136. .WillByDefault(testing::Return(&pref_service_));
  137. pref_service_.registry()->RegisterBooleanPref(ash::prefs::kFastPairEnabled,
  138. /*default_value=*/true);
  139. metrics_logger_ = std::make_unique<QuickPairMetricsLogger>(
  140. scanner_broker_.get(), pairer_broker_.get(), ui_broker_.get(),
  141. retroactive_pairing_detector_.get());
  142. }
  143. void SimulateDiscoveryUiShown(Protocol protocol) {
  144. switch (protocol) {
  145. case Protocol::kFastPairInitial:
  146. mock_scanner_broker_->NotifyDeviceFound(initial_device_);
  147. break;
  148. case Protocol::kFastPairSubsequent:
  149. mock_scanner_broker_->NotifyDeviceFound(subsequent_device_);
  150. break;
  151. case Protocol::kFastPairRetroactive:
  152. break;
  153. }
  154. }
  155. void SimulateDiscoveryUiDismissed(Protocol protocol) {
  156. switch (protocol) {
  157. case Protocol::kFastPairInitial:
  158. mock_ui_broker_->NotifyDiscoveryAction(initial_device_,
  159. DiscoveryAction::kDismissed);
  160. break;
  161. case Protocol::kFastPairSubsequent:
  162. mock_ui_broker_->NotifyDiscoveryAction(subsequent_device_,
  163. DiscoveryAction::kDismissed);
  164. break;
  165. case Protocol::kFastPairRetroactive:
  166. break;
  167. }
  168. }
  169. void SimulateDiscoveryUiDismissedByUser(Protocol protocol) {
  170. switch (protocol) {
  171. case Protocol::kFastPairInitial:
  172. mock_ui_broker_->NotifyDiscoveryAction(
  173. initial_device_, DiscoveryAction::kDismissedByUser);
  174. break;
  175. case Protocol::kFastPairSubsequent:
  176. mock_ui_broker_->NotifyDiscoveryAction(
  177. subsequent_device_, DiscoveryAction::kDismissedByUser);
  178. break;
  179. case Protocol::kFastPairRetroactive:
  180. break;
  181. }
  182. }
  183. void SimulateDiscoveryUiLearnMorePressed(Protocol protocol) {
  184. switch (protocol) {
  185. case Protocol::kFastPairInitial:
  186. mock_ui_broker_->NotifyDiscoveryAction(initial_device_,
  187. DiscoveryAction::kLearnMore);
  188. break;
  189. case Protocol::kFastPairSubsequent:
  190. mock_ui_broker_->NotifyDiscoveryAction(subsequent_device_,
  191. DiscoveryAction::kLearnMore);
  192. break;
  193. case Protocol::kFastPairRetroactive:
  194. break;
  195. }
  196. }
  197. void SimulateDiscoveryUiConnectPressed(Protocol protocol) {
  198. switch (protocol) {
  199. case Protocol::kFastPairInitial:
  200. mock_ui_broker_->NotifyDiscoveryAction(initial_device_,
  201. DiscoveryAction::kPairToDevice);
  202. break;
  203. case Protocol::kFastPairSubsequent:
  204. mock_ui_broker_->NotifyDiscoveryAction(subsequent_device_,
  205. DiscoveryAction::kPairToDevice);
  206. break;
  207. case Protocol::kFastPairRetroactive:
  208. break;
  209. }
  210. }
  211. void SimulatePairingFailed(Protocol protocol) {
  212. switch (protocol) {
  213. case Protocol::kFastPairInitial:
  214. mock_pairer_broker_->NotifyPairFailure(
  215. initial_device_,
  216. PairFailure::kKeyBasedPairingCharacteristicDiscovery);
  217. break;
  218. case Protocol::kFastPairSubsequent:
  219. mock_pairer_broker_->NotifyPairFailure(
  220. subsequent_device_,
  221. PairFailure::kKeyBasedPairingCharacteristicDiscovery);
  222. break;
  223. case Protocol::kFastPairRetroactive:
  224. mock_pairer_broker_->NotifyPairFailure(
  225. retroactive_device_,
  226. PairFailure::kKeyBasedPairingCharacteristicDiscovery);
  227. break;
  228. }
  229. }
  230. void SimulatePairingSucceeded(Protocol protocol) {
  231. switch (protocol) {
  232. case Protocol::kFastPairInitial:
  233. initial_device_->set_classic_address(kTestAddress);
  234. mock_pairer_broker_->NotifyDevicePaired(initial_device_);
  235. break;
  236. case Protocol::kFastPairSubsequent:
  237. subsequent_device_->set_classic_address(kTestAddress);
  238. mock_pairer_broker_->NotifyDevicePaired(subsequent_device_);
  239. break;
  240. case Protocol::kFastPairRetroactive:
  241. retroactive_device_->set_classic_address(kTestAddress);
  242. mock_pairer_broker_->NotifyDevicePaired(retroactive_device_);
  243. break;
  244. }
  245. }
  246. void SimulateErrorUiDismissedByUser(Protocol protocol) {
  247. switch (protocol) {
  248. case Protocol::kFastPairInitial:
  249. mock_ui_broker_->NotifyPairingFailedAction(
  250. initial_device_, PairingFailedAction::kDismissedByUser);
  251. break;
  252. case Protocol::kFastPairSubsequent:
  253. mock_ui_broker_->NotifyPairingFailedAction(
  254. subsequent_device_, PairingFailedAction::kDismissedByUser);
  255. break;
  256. case Protocol::kFastPairRetroactive:
  257. break;
  258. }
  259. }
  260. void SimulateErrorUiDismissed(Protocol protocol) {
  261. switch (protocol) {
  262. case Protocol::kFastPairInitial:
  263. mock_ui_broker_->NotifyPairingFailedAction(
  264. initial_device_, PairingFailedAction::kDismissed);
  265. break;
  266. case Protocol::kFastPairSubsequent:
  267. mock_ui_broker_->NotifyPairingFailedAction(
  268. subsequent_device_, PairingFailedAction::kDismissed);
  269. break;
  270. case Protocol::kFastPairRetroactive:
  271. break;
  272. }
  273. }
  274. void SimulateErrorUiSettingsPressed(Protocol protocol) {
  275. switch (protocol) {
  276. case Protocol::kFastPairInitial:
  277. mock_ui_broker_->NotifyPairingFailedAction(
  278. initial_device_, PairingFailedAction::kNavigateToSettings);
  279. break;
  280. case Protocol::kFastPairSubsequent:
  281. mock_ui_broker_->NotifyPairingFailedAction(
  282. subsequent_device_, PairingFailedAction::kNavigateToSettings);
  283. break;
  284. case Protocol::kFastPairRetroactive:
  285. break;
  286. }
  287. }
  288. void SimulateAssociateAccountUiShown() {
  289. fake_retroactive_pairing_detector_->NotifyRetroactivePairFound(
  290. retroactive_device_);
  291. }
  292. void SimulateAssociateAccountUiDismissed() {
  293. mock_ui_broker_->NotifyAssociateAccountAction(
  294. retroactive_device_, AssociateAccountAction::kDismissed);
  295. }
  296. void SimulateAssociateAccountUiDismissedByUser() {
  297. mock_ui_broker_->NotifyAssociateAccountAction(
  298. retroactive_device_, AssociateAccountAction::kDismissedByUser);
  299. }
  300. void SimulateAssociateAccountUiSavePressed() {
  301. mock_ui_broker_->NotifyAssociateAccountAction(
  302. retroactive_device_, AssociateAccountAction::kAssoicateAccount);
  303. }
  304. void SimulateAssociateAccountUiLearnMorePressed() {
  305. mock_ui_broker_->NotifyAssociateAccountAction(
  306. retroactive_device_, AssociateAccountAction::kLearnMore);
  307. }
  308. void SimulateAccountKeyWritten(Protocol protocol) {
  309. switch (protocol) {
  310. case Protocol::kFastPairInitial:
  311. mock_pairer_broker_->NotifyAccountKeyWrite(initial_device_,
  312. absl::nullopt);
  313. break;
  314. case Protocol::kFastPairSubsequent:
  315. break;
  316. case Protocol::kFastPairRetroactive:
  317. mock_pairer_broker_->NotifyAccountKeyWrite(retroactive_device_,
  318. absl::nullopt);
  319. break;
  320. }
  321. }
  322. void SimulateAccountKeyFailure(Protocol protocol) {
  323. switch (protocol) {
  324. case Protocol::kFastPairInitial:
  325. mock_pairer_broker_->NotifyAccountKeyWrite(
  326. initial_device_, AccountKeyFailure::kAccountKeyCharacteristicWrite);
  327. break;
  328. case Protocol::kFastPairSubsequent:
  329. break;
  330. case Protocol::kFastPairRetroactive:
  331. mock_pairer_broker_->NotifyAccountKeyWrite(
  332. retroactive_device_,
  333. AccountKeyFailure::kAccountKeyCharacteristicWrite);
  334. break;
  335. }
  336. }
  337. void PairFastPairDeviceWithFastPair(std::string address) {
  338. auto fp_device = base::MakeRefCounted<Device>(kValidModelId, address,
  339. Protocol::kFastPairInitial);
  340. fp_device->set_classic_address(address);
  341. mock_pairer_broker_->NotifyDevicePaired(fp_device);
  342. }
  343. void PairFastPairDeviceWithClassicBluetooth(bool new_paired_status,
  344. std::string classic_address) {
  345. std::unique_ptr<testing::NiceMock<device::MockBluetoothDevice>>
  346. bluetooth_device = CreateTestBluetoothDevice(classic_address);
  347. bluetooth_device->AddUUID(ash::quick_pair::kFastPairBluetoothUuid);
  348. auto* bt_device_ptr = bluetooth_device.get();
  349. adapter_->AddMockDevice(std::move(bluetooth_device));
  350. adapter_->NotifyDevicePairedChanged(bt_device_ptr, new_paired_status);
  351. }
  352. base::HistogramTester& histogram_tester() { return histogram_tester_; }
  353. protected:
  354. base::HistogramTester histogram_tester_;
  355. base::test::SingleThreadTaskEnvironment task_environment_;
  356. scoped_refptr<FakeMetricBluetoothAdapter> adapter_;
  357. scoped_refptr<Device> initial_device_;
  358. scoped_refptr<Device> subsequent_device_;
  359. scoped_refptr<Device> retroactive_device_;
  360. std::unique_ptr<MockQuickPairBrowserDelegate> browser_delegate_;
  361. TestingPrefServiceSimple pref_service_;
  362. MockScannerBroker* mock_scanner_broker_ = nullptr;
  363. MockPairerBroker* mock_pairer_broker_ = nullptr;
  364. MockUIBroker* mock_ui_broker_ = nullptr;
  365. FakeRetroactivePairingDetector* fake_retroactive_pairing_detector_ = nullptr;
  366. std::unique_ptr<ScannerBroker> scanner_broker_;
  367. std::unique_ptr<RetroactivePairingDetector> retroactive_pairing_detector_;
  368. std::unique_ptr<PairerBroker> pairer_broker_;
  369. std::unique_ptr<UIBroker> ui_broker_;
  370. std::unique_ptr<QuickPairMetricsLogger> metrics_logger_;
  371. };
  372. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiShown_Initial) {
  373. SimulateDiscoveryUiShown(Protocol::kFastPairInitial);
  374. base::RunLoop().RunUntilIdle();
  375. EXPECT_EQ(histogram_tester().GetBucketCount(
  376. kFastPairEngagementFlowMetricInitial,
  377. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  378. 1);
  379. EXPECT_EQ(histogram_tester().GetBucketCount(
  380. kFastPairEngagementFlowMetricInitial,
  381. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  382. 0);
  383. EXPECT_EQ(histogram_tester().GetBucketCount(
  384. kFastPairEngagementFlowMetricInitial,
  385. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  386. 0);
  387. EXPECT_EQ(histogram_tester().GetBucketCount(
  388. kFastPairEngagementFlowMetricInitial,
  389. FastPairEngagementFlowEvent::kPairingFailed),
  390. 0);
  391. EXPECT_EQ(histogram_tester().GetBucketCount(
  392. kFastPairEngagementFlowMetricInitial,
  393. FastPairEngagementFlowEvent::kPairingSucceeded),
  394. 0);
  395. EXPECT_EQ(histogram_tester().GetBucketCount(
  396. kFastPairEngagementFlowMetricInitial,
  397. FastPairEngagementFlowEvent::kErrorUiDismissed),
  398. 0);
  399. EXPECT_EQ(histogram_tester().GetBucketCount(
  400. kFastPairEngagementFlowMetricInitial,
  401. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  402. 0);
  403. EXPECT_EQ(histogram_tester().GetBucketCount(
  404. kFastPairEngagementFlowMetricInitial,
  405. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  406. 0);
  407. EXPECT_EQ(histogram_tester().GetBucketCount(
  408. kFastPairEngagementFlowMetricInitial,
  409. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  410. 0);
  411. }
  412. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiShown_Subsequent) {
  413. SimulateDiscoveryUiShown(Protocol::kFastPairSubsequent);
  414. base::RunLoop().RunUntilIdle();
  415. EXPECT_EQ(histogram_tester().GetBucketCount(
  416. kFastPairEngagementFlowMetricSubsequent,
  417. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  418. 1);
  419. EXPECT_EQ(histogram_tester().GetBucketCount(
  420. kFastPairEngagementFlowMetricSubsequent,
  421. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  422. 0);
  423. EXPECT_EQ(histogram_tester().GetBucketCount(
  424. kFastPairEngagementFlowMetricSubsequent,
  425. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  426. 0);
  427. EXPECT_EQ(histogram_tester().GetBucketCount(
  428. kFastPairEngagementFlowMetricSubsequent,
  429. FastPairEngagementFlowEvent::kPairingFailed),
  430. 0);
  431. EXPECT_EQ(histogram_tester().GetBucketCount(
  432. kFastPairEngagementFlowMetricSubsequent,
  433. FastPairEngagementFlowEvent::kPairingSucceeded),
  434. 0);
  435. EXPECT_EQ(histogram_tester().GetBucketCount(
  436. kFastPairEngagementFlowMetricSubsequent,
  437. FastPairEngagementFlowEvent::kErrorUiDismissed),
  438. 0);
  439. EXPECT_EQ(histogram_tester().GetBucketCount(
  440. kFastPairEngagementFlowMetricSubsequent,
  441. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  442. 0);
  443. EXPECT_EQ(histogram_tester().GetBucketCount(
  444. kFastPairEngagementFlowMetricSubsequent,
  445. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  446. 0);
  447. EXPECT_EQ(histogram_tester().GetBucketCount(
  448. kFastPairEngagementFlowMetricSubsequent,
  449. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  450. 0);
  451. }
  452. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiDismissed_Initial) {
  453. SimulateDiscoveryUiDismissed(Protocol::kFastPairInitial);
  454. base::RunLoop().RunUntilIdle();
  455. EXPECT_EQ(histogram_tester().GetBucketCount(
  456. kFastPairEngagementFlowMetricInitial,
  457. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  458. 0);
  459. EXPECT_EQ(histogram_tester().GetBucketCount(
  460. kFastPairEngagementFlowMetricInitial,
  461. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  462. 1);
  463. EXPECT_EQ(histogram_tester().GetBucketCount(
  464. kFastPairEngagementFlowMetricInitial,
  465. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  466. 0);
  467. EXPECT_EQ(histogram_tester().GetBucketCount(
  468. kFastPairEngagementFlowMetricInitial,
  469. FastPairEngagementFlowEvent::kPairingFailed),
  470. 0);
  471. EXPECT_EQ(histogram_tester().GetBucketCount(
  472. kFastPairEngagementFlowMetricInitial,
  473. FastPairEngagementFlowEvent::kPairingSucceeded),
  474. 0);
  475. EXPECT_EQ(histogram_tester().GetBucketCount(
  476. kFastPairEngagementFlowMetricInitial,
  477. FastPairEngagementFlowEvent::kErrorUiDismissed),
  478. 0);
  479. EXPECT_EQ(histogram_tester().GetBucketCount(
  480. kFastPairEngagementFlowMetricInitial,
  481. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  482. 0);
  483. EXPECT_EQ(histogram_tester().GetBucketCount(
  484. kFastPairEngagementFlowMetricInitial,
  485. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  486. 0);
  487. EXPECT_EQ(histogram_tester().GetBucketCount(
  488. kFastPairEngagementFlowMetricInitial,
  489. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  490. 0);
  491. }
  492. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiDismissedByUser_Initial) {
  493. SimulateDiscoveryUiDismissedByUser(Protocol::kFastPairInitial);
  494. base::RunLoop().RunUntilIdle();
  495. EXPECT_EQ(histogram_tester().GetBucketCount(
  496. kFastPairEngagementFlowMetricInitial,
  497. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  498. 0);
  499. EXPECT_EQ(histogram_tester().GetBucketCount(
  500. kFastPairEngagementFlowMetricInitial,
  501. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  502. 0);
  503. EXPECT_EQ(histogram_tester().GetBucketCount(
  504. kFastPairEngagementFlowMetricInitial,
  505. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  506. 0);
  507. EXPECT_EQ(histogram_tester().GetBucketCount(
  508. kFastPairEngagementFlowMetricInitial,
  509. FastPairEngagementFlowEvent::kPairingFailed),
  510. 0);
  511. EXPECT_EQ(histogram_tester().GetBucketCount(
  512. kFastPairEngagementFlowMetricInitial,
  513. FastPairEngagementFlowEvent::kPairingSucceeded),
  514. 0);
  515. EXPECT_EQ(histogram_tester().GetBucketCount(
  516. kFastPairEngagementFlowMetricInitial,
  517. FastPairEngagementFlowEvent::kErrorUiDismissed),
  518. 0);
  519. EXPECT_EQ(histogram_tester().GetBucketCount(
  520. kFastPairEngagementFlowMetricInitial,
  521. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  522. 0);
  523. EXPECT_EQ(histogram_tester().GetBucketCount(
  524. kFastPairEngagementFlowMetricInitial,
  525. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  526. 0);
  527. EXPECT_EQ(histogram_tester().GetBucketCount(
  528. kFastPairEngagementFlowMetricInitial,
  529. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  530. 1);
  531. }
  532. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiDismissed_Subsequent) {
  533. SimulateDiscoveryUiDismissed(Protocol::kFastPairSubsequent);
  534. base::RunLoop().RunUntilIdle();
  535. EXPECT_EQ(histogram_tester().GetBucketCount(
  536. kFastPairEngagementFlowMetricSubsequent,
  537. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  538. 0);
  539. EXPECT_EQ(histogram_tester().GetBucketCount(
  540. kFastPairEngagementFlowMetricSubsequent,
  541. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  542. 1);
  543. EXPECT_EQ(histogram_tester().GetBucketCount(
  544. kFastPairEngagementFlowMetricSubsequent,
  545. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  546. 0);
  547. EXPECT_EQ(histogram_tester().GetBucketCount(
  548. kFastPairEngagementFlowMetricSubsequent,
  549. FastPairEngagementFlowEvent::kPairingFailed),
  550. 0);
  551. EXPECT_EQ(histogram_tester().GetBucketCount(
  552. kFastPairEngagementFlowMetricSubsequent,
  553. FastPairEngagementFlowEvent::kPairingSucceeded),
  554. 0);
  555. EXPECT_EQ(histogram_tester().GetBucketCount(
  556. kFastPairEngagementFlowMetricSubsequent,
  557. FastPairEngagementFlowEvent::kErrorUiDismissed),
  558. 0);
  559. EXPECT_EQ(histogram_tester().GetBucketCount(
  560. kFastPairEngagementFlowMetricSubsequent,
  561. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  562. 0);
  563. EXPECT_EQ(histogram_tester().GetBucketCount(
  564. kFastPairEngagementFlowMetricSubsequent,
  565. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  566. 0);
  567. EXPECT_EQ(histogram_tester().GetBucketCount(
  568. kFastPairEngagementFlowMetricSubsequent,
  569. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  570. 0);
  571. }
  572. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiDismissedByUser_Subsequent) {
  573. SimulateDiscoveryUiDismissedByUser(Protocol::kFastPairSubsequent);
  574. base::RunLoop().RunUntilIdle();
  575. EXPECT_EQ(histogram_tester().GetBucketCount(
  576. kFastPairEngagementFlowMetricSubsequent,
  577. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  578. 0);
  579. EXPECT_EQ(histogram_tester().GetBucketCount(
  580. kFastPairEngagementFlowMetricSubsequent,
  581. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  582. 0);
  583. EXPECT_EQ(histogram_tester().GetBucketCount(
  584. kFastPairEngagementFlowMetricSubsequent,
  585. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  586. 0);
  587. EXPECT_EQ(histogram_tester().GetBucketCount(
  588. kFastPairEngagementFlowMetricSubsequent,
  589. FastPairEngagementFlowEvent::kPairingFailed),
  590. 0);
  591. EXPECT_EQ(histogram_tester().GetBucketCount(
  592. kFastPairEngagementFlowMetricSubsequent,
  593. FastPairEngagementFlowEvent::kPairingSucceeded),
  594. 0);
  595. EXPECT_EQ(histogram_tester().GetBucketCount(
  596. kFastPairEngagementFlowMetricSubsequent,
  597. FastPairEngagementFlowEvent::kErrorUiDismissed),
  598. 0);
  599. EXPECT_EQ(histogram_tester().GetBucketCount(
  600. kFastPairEngagementFlowMetricSubsequent,
  601. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  602. 0);
  603. EXPECT_EQ(histogram_tester().GetBucketCount(
  604. kFastPairEngagementFlowMetricSubsequent,
  605. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  606. 0);
  607. EXPECT_EQ(histogram_tester().GetBucketCount(
  608. kFastPairEngagementFlowMetricSubsequent,
  609. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  610. 1);
  611. }
  612. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiConnectPressed_Initial) {
  613. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairInitial);
  614. base::RunLoop().RunUntilIdle();
  615. EXPECT_EQ(histogram_tester().GetBucketCount(
  616. kFastPairEngagementFlowMetricInitial,
  617. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  618. 0);
  619. EXPECT_EQ(histogram_tester().GetBucketCount(
  620. kFastPairEngagementFlowMetricInitial,
  621. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  622. 0);
  623. EXPECT_EQ(histogram_tester().GetBucketCount(
  624. kFastPairEngagementFlowMetricInitial,
  625. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  626. 1);
  627. EXPECT_EQ(histogram_tester().GetBucketCount(
  628. kFastPairEngagementFlowMetricInitial,
  629. FastPairEngagementFlowEvent::kPairingFailed),
  630. 0);
  631. EXPECT_EQ(histogram_tester().GetBucketCount(
  632. kFastPairEngagementFlowMetricInitial,
  633. FastPairEngagementFlowEvent::kPairingSucceeded),
  634. 0);
  635. EXPECT_EQ(histogram_tester().GetBucketCount(
  636. kFastPairEngagementFlowMetricInitial,
  637. FastPairEngagementFlowEvent::kErrorUiDismissed),
  638. 0);
  639. EXPECT_EQ(histogram_tester().GetBucketCount(
  640. kFastPairEngagementFlowMetricInitial,
  641. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  642. 0);
  643. EXPECT_EQ(histogram_tester().GetBucketCount(
  644. kFastPairEngagementFlowMetricInitial,
  645. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  646. 0);
  647. EXPECT_EQ(histogram_tester().GetBucketCount(
  648. kFastPairEngagementFlowMetricInitial,
  649. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  650. 0);
  651. }
  652. TEST_F(QuickPairMetricsLoggerTest, LogDiscoveryUiConnectPressed_Subsequent) {
  653. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairSubsequent);
  654. base::RunLoop().RunUntilIdle();
  655. EXPECT_EQ(histogram_tester().GetBucketCount(
  656. kFastPairEngagementFlowMetricSubsequent,
  657. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  658. 0);
  659. EXPECT_EQ(histogram_tester().GetBucketCount(
  660. kFastPairEngagementFlowMetricSubsequent,
  661. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  662. 0);
  663. EXPECT_EQ(histogram_tester().GetBucketCount(
  664. kFastPairEngagementFlowMetricSubsequent,
  665. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  666. 1);
  667. EXPECT_EQ(histogram_tester().GetBucketCount(
  668. kFastPairEngagementFlowMetricSubsequent,
  669. FastPairEngagementFlowEvent::kPairingFailed),
  670. 0);
  671. EXPECT_EQ(histogram_tester().GetBucketCount(
  672. kFastPairEngagementFlowMetricSubsequent,
  673. FastPairEngagementFlowEvent::kPairingSucceeded),
  674. 0);
  675. EXPECT_EQ(histogram_tester().GetBucketCount(
  676. kFastPairEngagementFlowMetricSubsequent,
  677. FastPairEngagementFlowEvent::kErrorUiDismissed),
  678. 0);
  679. EXPECT_EQ(histogram_tester().GetBucketCount(
  680. kFastPairEngagementFlowMetricSubsequent,
  681. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  682. 0);
  683. EXPECT_EQ(histogram_tester().GetBucketCount(
  684. kFastPairEngagementFlowMetricSubsequent,
  685. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  686. 0);
  687. EXPECT_EQ(histogram_tester().GetBucketCount(
  688. kFastPairEngagementFlowMetricSubsequent,
  689. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  690. 0);
  691. }
  692. TEST_F(QuickPairMetricsLoggerTest, LogPairingFailed_Initial) {
  693. SimulatePairingFailed(Protocol::kFastPairInitial);
  694. base::RunLoop().RunUntilIdle();
  695. EXPECT_EQ(histogram_tester().GetBucketCount(
  696. kFastPairEngagementFlowMetricInitial,
  697. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  698. 0);
  699. EXPECT_EQ(histogram_tester().GetBucketCount(
  700. kFastPairEngagementFlowMetricInitial,
  701. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  702. 0);
  703. EXPECT_EQ(histogram_tester().GetBucketCount(
  704. kFastPairEngagementFlowMetricInitial,
  705. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  706. 0);
  707. EXPECT_EQ(histogram_tester().GetBucketCount(
  708. kFastPairEngagementFlowMetricInitial,
  709. FastPairEngagementFlowEvent::kPairingFailed),
  710. 1);
  711. EXPECT_EQ(histogram_tester().GetBucketCount(
  712. kFastPairEngagementFlowMetricInitial,
  713. FastPairEngagementFlowEvent::kPairingSucceeded),
  714. 0);
  715. EXPECT_EQ(histogram_tester().GetBucketCount(
  716. kFastPairEngagementFlowMetricInitial,
  717. FastPairEngagementFlowEvent::kErrorUiDismissed),
  718. 0);
  719. EXPECT_EQ(histogram_tester().GetBucketCount(
  720. kFastPairEngagementFlowMetricInitial,
  721. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  722. 0);
  723. EXPECT_EQ(histogram_tester().GetBucketCount(
  724. kFastPairEngagementFlowMetricInitial,
  725. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  726. 0);
  727. EXPECT_EQ(histogram_tester().GetBucketCount(
  728. kFastPairEngagementFlowMetricInitial,
  729. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  730. 0);
  731. }
  732. TEST_F(QuickPairMetricsLoggerTest, LogPairingFailed_Subsequent) {
  733. SimulatePairingFailed(Protocol::kFastPairSubsequent);
  734. base::RunLoop().RunUntilIdle();
  735. EXPECT_EQ(histogram_tester().GetBucketCount(
  736. kFastPairEngagementFlowMetricSubsequent,
  737. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  738. 0);
  739. EXPECT_EQ(histogram_tester().GetBucketCount(
  740. kFastPairEngagementFlowMetricSubsequent,
  741. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  742. 0);
  743. EXPECT_EQ(histogram_tester().GetBucketCount(
  744. kFastPairEngagementFlowMetricSubsequent,
  745. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  746. 0);
  747. EXPECT_EQ(histogram_tester().GetBucketCount(
  748. kFastPairEngagementFlowMetricSubsequent,
  749. FastPairEngagementFlowEvent::kPairingFailed),
  750. 1);
  751. EXPECT_EQ(histogram_tester().GetBucketCount(
  752. kFastPairEngagementFlowMetricSubsequent,
  753. FastPairEngagementFlowEvent::kPairingSucceeded),
  754. 0);
  755. EXPECT_EQ(histogram_tester().GetBucketCount(
  756. kFastPairEngagementFlowMetricSubsequent,
  757. FastPairEngagementFlowEvent::kErrorUiDismissed),
  758. 0);
  759. EXPECT_EQ(histogram_tester().GetBucketCount(
  760. kFastPairEngagementFlowMetricSubsequent,
  761. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  762. 0);
  763. EXPECT_EQ(histogram_tester().GetBucketCount(
  764. kFastPairEngagementFlowMetricSubsequent,
  765. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  766. 0);
  767. EXPECT_EQ(histogram_tester().GetBucketCount(
  768. kFastPairEngagementFlowMetricSubsequent,
  769. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  770. 0);
  771. }
  772. TEST_F(QuickPairMetricsLoggerTest, LogPairingSucceeded_Initial) {
  773. SimulatePairingSucceeded(Protocol::kFastPairInitial);
  774. base::RunLoop().RunUntilIdle();
  775. EXPECT_EQ(histogram_tester().GetBucketCount(
  776. kFastPairEngagementFlowMetricInitial,
  777. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  778. 0);
  779. EXPECT_EQ(histogram_tester().GetBucketCount(
  780. kFastPairEngagementFlowMetricInitial,
  781. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  782. 0);
  783. EXPECT_EQ(histogram_tester().GetBucketCount(
  784. kFastPairEngagementFlowMetricInitial,
  785. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  786. 0);
  787. EXPECT_EQ(histogram_tester().GetBucketCount(
  788. kFastPairEngagementFlowMetricInitial,
  789. FastPairEngagementFlowEvent::kPairingFailed),
  790. 0);
  791. EXPECT_EQ(histogram_tester().GetBucketCount(
  792. kFastPairEngagementFlowMetricInitial,
  793. FastPairEngagementFlowEvent::kPairingSucceeded),
  794. 1);
  795. EXPECT_EQ(histogram_tester().GetBucketCount(
  796. kFastPairEngagementFlowMetricInitial,
  797. FastPairEngagementFlowEvent::kErrorUiDismissed),
  798. 0);
  799. EXPECT_EQ(histogram_tester().GetBucketCount(
  800. kFastPairEngagementFlowMetricInitial,
  801. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  802. 0);
  803. EXPECT_EQ(histogram_tester().GetBucketCount(
  804. kFastPairEngagementFlowMetricInitial,
  805. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  806. 0);
  807. EXPECT_EQ(histogram_tester().GetBucketCount(
  808. kFastPairEngagementFlowMetricInitial,
  809. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  810. 0);
  811. }
  812. TEST_F(QuickPairMetricsLoggerTest, LogPairingSucceeded_Subsequent) {
  813. SimulatePairingSucceeded(Protocol::kFastPairSubsequent);
  814. base::RunLoop().RunUntilIdle();
  815. EXPECT_EQ(histogram_tester().GetBucketCount(
  816. kFastPairEngagementFlowMetricSubsequent,
  817. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  818. 0);
  819. EXPECT_EQ(histogram_tester().GetBucketCount(
  820. kFastPairEngagementFlowMetricSubsequent,
  821. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  822. 0);
  823. EXPECT_EQ(histogram_tester().GetBucketCount(
  824. kFastPairEngagementFlowMetricSubsequent,
  825. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  826. 0);
  827. EXPECT_EQ(histogram_tester().GetBucketCount(
  828. kFastPairEngagementFlowMetricSubsequent,
  829. FastPairEngagementFlowEvent::kPairingFailed),
  830. 0);
  831. EXPECT_EQ(histogram_tester().GetBucketCount(
  832. kFastPairEngagementFlowMetricSubsequent,
  833. FastPairEngagementFlowEvent::kPairingSucceeded),
  834. 1);
  835. EXPECT_EQ(histogram_tester().GetBucketCount(
  836. kFastPairEngagementFlowMetricSubsequent,
  837. FastPairEngagementFlowEvent::kErrorUiDismissed),
  838. 0);
  839. EXPECT_EQ(histogram_tester().GetBucketCount(
  840. kFastPairEngagementFlowMetricSubsequent,
  841. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  842. 0);
  843. EXPECT_EQ(histogram_tester().GetBucketCount(
  844. kFastPairEngagementFlowMetricSubsequent,
  845. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  846. 0);
  847. EXPECT_EQ(histogram_tester().GetBucketCount(
  848. kFastPairEngagementFlowMetricSubsequent,
  849. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  850. 0);
  851. }
  852. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiDismissed_Initial) {
  853. SimulateErrorUiDismissed(Protocol::kFastPairInitial);
  854. base::RunLoop().RunUntilIdle();
  855. EXPECT_EQ(histogram_tester().GetBucketCount(
  856. kFastPairEngagementFlowMetricInitial,
  857. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  858. 0);
  859. EXPECT_EQ(histogram_tester().GetBucketCount(
  860. kFastPairEngagementFlowMetricInitial,
  861. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  862. 0);
  863. EXPECT_EQ(histogram_tester().GetBucketCount(
  864. kFastPairEngagementFlowMetricInitial,
  865. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  866. 0);
  867. EXPECT_EQ(histogram_tester().GetBucketCount(
  868. kFastPairEngagementFlowMetricInitial,
  869. FastPairEngagementFlowEvent::kPairingFailed),
  870. 0);
  871. EXPECT_EQ(histogram_tester().GetBucketCount(
  872. kFastPairEngagementFlowMetricInitial,
  873. FastPairEngagementFlowEvent::kPairingSucceeded),
  874. 0);
  875. EXPECT_EQ(histogram_tester().GetBucketCount(
  876. kFastPairEngagementFlowMetricInitial,
  877. FastPairEngagementFlowEvent::kErrorUiDismissed),
  878. 1);
  879. EXPECT_EQ(histogram_tester().GetBucketCount(
  880. kFastPairEngagementFlowMetricInitial,
  881. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  882. 0);
  883. EXPECT_EQ(histogram_tester().GetBucketCount(
  884. kFastPairEngagementFlowMetricInitial,
  885. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  886. 0);
  887. EXPECT_EQ(histogram_tester().GetBucketCount(
  888. kFastPairEngagementFlowMetricInitial,
  889. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  890. 0);
  891. }
  892. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiDismissedByUser_Initial) {
  893. SimulateErrorUiDismissedByUser(Protocol::kFastPairInitial);
  894. base::RunLoop().RunUntilIdle();
  895. EXPECT_EQ(histogram_tester().GetBucketCount(
  896. kFastPairEngagementFlowMetricInitial,
  897. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  898. 0);
  899. EXPECT_EQ(histogram_tester().GetBucketCount(
  900. kFastPairEngagementFlowMetricInitial,
  901. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  902. 0);
  903. EXPECT_EQ(histogram_tester().GetBucketCount(
  904. kFastPairEngagementFlowMetricInitial,
  905. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  906. 0);
  907. EXPECT_EQ(histogram_tester().GetBucketCount(
  908. kFastPairEngagementFlowMetricInitial,
  909. FastPairEngagementFlowEvent::kPairingFailed),
  910. 0);
  911. EXPECT_EQ(histogram_tester().GetBucketCount(
  912. kFastPairEngagementFlowMetricInitial,
  913. FastPairEngagementFlowEvent::kPairingSucceeded),
  914. 0);
  915. EXPECT_EQ(histogram_tester().GetBucketCount(
  916. kFastPairEngagementFlowMetricInitial,
  917. FastPairEngagementFlowEvent::kErrorUiDismissed),
  918. 0);
  919. EXPECT_EQ(histogram_tester().GetBucketCount(
  920. kFastPairEngagementFlowMetricInitial,
  921. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  922. 0);
  923. EXPECT_EQ(histogram_tester().GetBucketCount(
  924. kFastPairEngagementFlowMetricInitial,
  925. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  926. 1);
  927. EXPECT_EQ(histogram_tester().GetBucketCount(
  928. kFastPairEngagementFlowMetricInitial,
  929. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  930. 0);
  931. }
  932. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiDismissed_Subsequent) {
  933. SimulateErrorUiDismissed(Protocol::kFastPairSubsequent);
  934. base::RunLoop().RunUntilIdle();
  935. EXPECT_EQ(histogram_tester().GetBucketCount(
  936. kFastPairEngagementFlowMetricSubsequent,
  937. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  938. 0);
  939. EXPECT_EQ(histogram_tester().GetBucketCount(
  940. kFastPairEngagementFlowMetricSubsequent,
  941. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  942. 0);
  943. EXPECT_EQ(histogram_tester().GetBucketCount(
  944. kFastPairEngagementFlowMetricSubsequent,
  945. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  946. 0);
  947. EXPECT_EQ(histogram_tester().GetBucketCount(
  948. kFastPairEngagementFlowMetricSubsequent,
  949. FastPairEngagementFlowEvent::kPairingFailed),
  950. 0);
  951. EXPECT_EQ(histogram_tester().GetBucketCount(
  952. kFastPairEngagementFlowMetricSubsequent,
  953. FastPairEngagementFlowEvent::kPairingSucceeded),
  954. 0);
  955. EXPECT_EQ(histogram_tester().GetBucketCount(
  956. kFastPairEngagementFlowMetricSubsequent,
  957. FastPairEngagementFlowEvent::kErrorUiDismissed),
  958. 1);
  959. EXPECT_EQ(histogram_tester().GetBucketCount(
  960. kFastPairEngagementFlowMetricSubsequent,
  961. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  962. 0);
  963. EXPECT_EQ(histogram_tester().GetBucketCount(
  964. kFastPairEngagementFlowMetricSubsequent,
  965. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  966. 0);
  967. EXPECT_EQ(histogram_tester().GetBucketCount(
  968. kFastPairEngagementFlowMetricSubsequent,
  969. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  970. 0);
  971. }
  972. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiDismissedByUser_Subsequent) {
  973. SimulateErrorUiDismissedByUser(Protocol::kFastPairSubsequent);
  974. base::RunLoop().RunUntilIdle();
  975. EXPECT_EQ(histogram_tester().GetBucketCount(
  976. kFastPairEngagementFlowMetricSubsequent,
  977. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  978. 0);
  979. EXPECT_EQ(histogram_tester().GetBucketCount(
  980. kFastPairEngagementFlowMetricSubsequent,
  981. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  982. 0);
  983. EXPECT_EQ(histogram_tester().GetBucketCount(
  984. kFastPairEngagementFlowMetricSubsequent,
  985. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  986. 0);
  987. EXPECT_EQ(histogram_tester().GetBucketCount(
  988. kFastPairEngagementFlowMetricSubsequent,
  989. FastPairEngagementFlowEvent::kPairingFailed),
  990. 0);
  991. EXPECT_EQ(histogram_tester().GetBucketCount(
  992. kFastPairEngagementFlowMetricSubsequent,
  993. FastPairEngagementFlowEvent::kPairingSucceeded),
  994. 0);
  995. EXPECT_EQ(histogram_tester().GetBucketCount(
  996. kFastPairEngagementFlowMetricSubsequent,
  997. FastPairEngagementFlowEvent::kErrorUiDismissed),
  998. 0);
  999. EXPECT_EQ(histogram_tester().GetBucketCount(
  1000. kFastPairEngagementFlowMetricSubsequent,
  1001. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  1002. 0);
  1003. EXPECT_EQ(histogram_tester().GetBucketCount(
  1004. kFastPairEngagementFlowMetricSubsequent,
  1005. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  1006. 1);
  1007. EXPECT_EQ(histogram_tester().GetBucketCount(
  1008. kFastPairEngagementFlowMetricSubsequent,
  1009. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  1010. 0);
  1011. }
  1012. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiSettingsPressed_Initial) {
  1013. SimulateErrorUiSettingsPressed(Protocol::kFastPairInitial);
  1014. base::RunLoop().RunUntilIdle();
  1015. EXPECT_EQ(histogram_tester().GetBucketCount(
  1016. kFastPairEngagementFlowMetricInitial,
  1017. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  1018. 0);
  1019. EXPECT_EQ(histogram_tester().GetBucketCount(
  1020. kFastPairEngagementFlowMetricInitial,
  1021. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  1022. 0);
  1023. EXPECT_EQ(histogram_tester().GetBucketCount(
  1024. kFastPairEngagementFlowMetricInitial,
  1025. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  1026. 0);
  1027. EXPECT_EQ(histogram_tester().GetBucketCount(
  1028. kFastPairEngagementFlowMetricInitial,
  1029. FastPairEngagementFlowEvent::kPairingFailed),
  1030. 0);
  1031. EXPECT_EQ(histogram_tester().GetBucketCount(
  1032. kFastPairEngagementFlowMetricInitial,
  1033. FastPairEngagementFlowEvent::kPairingSucceeded),
  1034. 0);
  1035. EXPECT_EQ(histogram_tester().GetBucketCount(
  1036. kFastPairEngagementFlowMetricInitial,
  1037. FastPairEngagementFlowEvent::kErrorUiDismissed),
  1038. 0);
  1039. EXPECT_EQ(histogram_tester().GetBucketCount(
  1040. kFastPairEngagementFlowMetricInitial,
  1041. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  1042. 1);
  1043. EXPECT_EQ(histogram_tester().GetBucketCount(
  1044. kFastPairEngagementFlowMetricInitial,
  1045. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  1046. 0);
  1047. EXPECT_EQ(histogram_tester().GetBucketCount(
  1048. kFastPairEngagementFlowMetricInitial,
  1049. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  1050. 0);
  1051. }
  1052. TEST_F(QuickPairMetricsLoggerTest, LogErrorUiSettingsPressed_Subsequent) {
  1053. SimulateErrorUiSettingsPressed(Protocol::kFastPairSubsequent);
  1054. base::RunLoop().RunUntilIdle();
  1055. EXPECT_EQ(histogram_tester().GetBucketCount(
  1056. kFastPairEngagementFlowMetricSubsequent,
  1057. FastPairEngagementFlowEvent::kDiscoveryUiShown),
  1058. 0);
  1059. EXPECT_EQ(histogram_tester().GetBucketCount(
  1060. kFastPairEngagementFlowMetricSubsequent,
  1061. FastPairEngagementFlowEvent::kDiscoveryUiDismissed),
  1062. 0);
  1063. EXPECT_EQ(histogram_tester().GetBucketCount(
  1064. kFastPairEngagementFlowMetricSubsequent,
  1065. FastPairEngagementFlowEvent::kDiscoveryUiConnectPressed),
  1066. 0);
  1067. EXPECT_EQ(histogram_tester().GetBucketCount(
  1068. kFastPairEngagementFlowMetricSubsequent,
  1069. FastPairEngagementFlowEvent::kPairingFailed),
  1070. 0);
  1071. EXPECT_EQ(histogram_tester().GetBucketCount(
  1072. kFastPairEngagementFlowMetricSubsequent,
  1073. FastPairEngagementFlowEvent::kPairingSucceeded),
  1074. 0);
  1075. EXPECT_EQ(histogram_tester().GetBucketCount(
  1076. kFastPairEngagementFlowMetricSubsequent,
  1077. FastPairEngagementFlowEvent::kErrorUiDismissed),
  1078. 0);
  1079. EXPECT_EQ(histogram_tester().GetBucketCount(
  1080. kFastPairEngagementFlowMetricSubsequent,
  1081. FastPairEngagementFlowEvent::kErrorUiSettingsPressed),
  1082. 1);
  1083. EXPECT_EQ(histogram_tester().GetBucketCount(
  1084. kFastPairEngagementFlowMetricSubsequent,
  1085. FastPairEngagementFlowEvent::kErrorUiDismissedByUser),
  1086. 0);
  1087. EXPECT_EQ(histogram_tester().GetBucketCount(
  1088. kFastPairEngagementFlowMetricSubsequent,
  1089. FastPairEngagementFlowEvent::kDiscoveryUiDismissedByUser),
  1090. 0);
  1091. }
  1092. TEST_F(QuickPairMetricsLoggerTest, LogPairTime_Initial) {
  1093. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairInitial);
  1094. base::RunLoop().RunUntilIdle();
  1095. histogram_tester().ExpectTotalCount(kFastPairPairTimeMetricInitial, 0);
  1096. SimulatePairingSucceeded(Protocol::kFastPairInitial);
  1097. base::RunLoop().RunUntilIdle();
  1098. histogram_tester().ExpectTotalCount(kFastPairPairTimeMetricInitial, 1);
  1099. }
  1100. TEST_F(QuickPairMetricsLoggerTest, LogPairTime_Subsequent) {
  1101. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairSubsequent);
  1102. base::RunLoop().RunUntilIdle();
  1103. histogram_tester().ExpectTotalCount(kFastPairPairTimeMetricSubsequent, 0);
  1104. SimulatePairingSucceeded(Protocol::kFastPairSubsequent);
  1105. base::RunLoop().RunUntilIdle();
  1106. histogram_tester().ExpectTotalCount(kFastPairPairTimeMetricSubsequent, 1);
  1107. }
  1108. TEST_F(QuickPairMetricsLoggerTest, LogAssociateAccountShown) {
  1109. SimulateAssociateAccountUiShown();
  1110. base::RunLoop().RunUntilIdle();
  1111. EXPECT_EQ(
  1112. histogram_tester().GetBucketCount(
  1113. kFastPairRetroactiveEngagementFlowMetric,
  1114. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1115. 1);
  1116. EXPECT_EQ(
  1117. histogram_tester().GetBucketCount(
  1118. kFastPairRetroactiveEngagementFlowMetric,
  1119. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1120. 0);
  1121. EXPECT_EQ(histogram_tester().GetBucketCount(
  1122. kFastPairRetroactiveEngagementFlowMetric,
  1123. FastPairRetroactiveEngagementFlowEvent::
  1124. kAssociateAccountUiDismissedByUser),
  1125. 0);
  1126. EXPECT_EQ(
  1127. histogram_tester().GetBucketCount(
  1128. kFastPairRetroactiveEngagementFlowMetric,
  1129. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1130. 0);
  1131. EXPECT_EQ(histogram_tester().GetBucketCount(
  1132. kFastPairRetroactiveEngagementFlowMetric,
  1133. FastPairRetroactiveEngagementFlowEvent::
  1134. kAssociateAccountLearnMorePressed),
  1135. 0);
  1136. EXPECT_EQ(histogram_tester().GetBucketCount(
  1137. kFastPairRetroactiveEngagementFlowMetric,
  1138. FastPairRetroactiveEngagementFlowEvent::
  1139. kAssociateAccountSavePressedAfterLearnMorePressed),
  1140. 0);
  1141. EXPECT_EQ(histogram_tester().GetBucketCount(
  1142. kFastPairRetroactiveEngagementFlowMetric,
  1143. FastPairRetroactiveEngagementFlowEvent::
  1144. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1145. 0);
  1146. EXPECT_EQ(histogram_tester().GetBucketCount(
  1147. kFastPairRetroactiveEngagementFlowMetric,
  1148. FastPairRetroactiveEngagementFlowEvent::
  1149. kAssociateAccountDismissedAfterLearnMorePressed),
  1150. 0);
  1151. }
  1152. TEST_F(QuickPairMetricsLoggerTest, LogAssociateAccountDismissed) {
  1153. SimulateAssociateAccountUiDismissed();
  1154. base::RunLoop().RunUntilIdle();
  1155. EXPECT_EQ(
  1156. histogram_tester().GetBucketCount(
  1157. kFastPairRetroactiveEngagementFlowMetric,
  1158. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1159. 0);
  1160. EXPECT_EQ(
  1161. histogram_tester().GetBucketCount(
  1162. kFastPairRetroactiveEngagementFlowMetric,
  1163. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1164. 1);
  1165. EXPECT_EQ(histogram_tester().GetBucketCount(
  1166. kFastPairRetroactiveEngagementFlowMetric,
  1167. FastPairRetroactiveEngagementFlowEvent::
  1168. kAssociateAccountUiDismissedByUser),
  1169. 0);
  1170. EXPECT_EQ(
  1171. histogram_tester().GetBucketCount(
  1172. kFastPairRetroactiveEngagementFlowMetric,
  1173. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1174. 0);
  1175. EXPECT_EQ(histogram_tester().GetBucketCount(
  1176. kFastPairRetroactiveEngagementFlowMetric,
  1177. FastPairRetroactiveEngagementFlowEvent::
  1178. kAssociateAccountLearnMorePressed),
  1179. 0);
  1180. EXPECT_EQ(histogram_tester().GetBucketCount(
  1181. kFastPairRetroactiveEngagementFlowMetric,
  1182. FastPairRetroactiveEngagementFlowEvent::
  1183. kAssociateAccountSavePressedAfterLearnMorePressed),
  1184. 0);
  1185. EXPECT_EQ(histogram_tester().GetBucketCount(
  1186. kFastPairRetroactiveEngagementFlowMetric,
  1187. FastPairRetroactiveEngagementFlowEvent::
  1188. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1189. 0);
  1190. EXPECT_EQ(histogram_tester().GetBucketCount(
  1191. kFastPairRetroactiveEngagementFlowMetric,
  1192. FastPairRetroactiveEngagementFlowEvent::
  1193. kAssociateAccountDismissedAfterLearnMorePressed),
  1194. 0);
  1195. }
  1196. TEST_F(QuickPairMetricsLoggerTest, LogAssociateAccountDismissedByUser) {
  1197. SimulateAssociateAccountUiDismissedByUser();
  1198. base::RunLoop().RunUntilIdle();
  1199. EXPECT_EQ(
  1200. histogram_tester().GetBucketCount(
  1201. kFastPairRetroactiveEngagementFlowMetric,
  1202. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1203. 0);
  1204. EXPECT_EQ(
  1205. histogram_tester().GetBucketCount(
  1206. kFastPairRetroactiveEngagementFlowMetric,
  1207. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1208. 0);
  1209. EXPECT_EQ(histogram_tester().GetBucketCount(
  1210. kFastPairRetroactiveEngagementFlowMetric,
  1211. FastPairRetroactiveEngagementFlowEvent::
  1212. kAssociateAccountUiDismissedByUser),
  1213. 1);
  1214. EXPECT_EQ(
  1215. histogram_tester().GetBucketCount(
  1216. kFastPairRetroactiveEngagementFlowMetric,
  1217. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1218. 0);
  1219. EXPECT_EQ(histogram_tester().GetBucketCount(
  1220. kFastPairRetroactiveEngagementFlowMetric,
  1221. FastPairRetroactiveEngagementFlowEvent::
  1222. kAssociateAccountLearnMorePressed),
  1223. 0);
  1224. EXPECT_EQ(histogram_tester().GetBucketCount(
  1225. kFastPairRetroactiveEngagementFlowMetric,
  1226. FastPairRetroactiveEngagementFlowEvent::
  1227. kAssociateAccountSavePressedAfterLearnMorePressed),
  1228. 0);
  1229. EXPECT_EQ(histogram_tester().GetBucketCount(
  1230. kFastPairRetroactiveEngagementFlowMetric,
  1231. FastPairRetroactiveEngagementFlowEvent::
  1232. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1233. 0);
  1234. EXPECT_EQ(histogram_tester().GetBucketCount(
  1235. kFastPairRetroactiveEngagementFlowMetric,
  1236. FastPairRetroactiveEngagementFlowEvent::
  1237. kAssociateAccountDismissedAfterLearnMorePressed),
  1238. 0);
  1239. }
  1240. TEST_F(QuickPairMetricsLoggerTest, LogAssociateAccountSavePressed) {
  1241. SimulateAssociateAccountUiSavePressed();
  1242. base::RunLoop().RunUntilIdle();
  1243. EXPECT_EQ(
  1244. histogram_tester().GetBucketCount(
  1245. kFastPairRetroactiveEngagementFlowMetric,
  1246. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1247. 0);
  1248. EXPECT_EQ(
  1249. histogram_tester().GetBucketCount(
  1250. kFastPairRetroactiveEngagementFlowMetric,
  1251. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1252. 0);
  1253. EXPECT_EQ(histogram_tester().GetBucketCount(
  1254. kFastPairRetroactiveEngagementFlowMetric,
  1255. FastPairRetroactiveEngagementFlowEvent::
  1256. kAssociateAccountUiDismissedByUser),
  1257. 0);
  1258. EXPECT_EQ(
  1259. histogram_tester().GetBucketCount(
  1260. kFastPairRetroactiveEngagementFlowMetric,
  1261. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1262. 1);
  1263. EXPECT_EQ(histogram_tester().GetBucketCount(
  1264. kFastPairRetroactiveEngagementFlowMetric,
  1265. FastPairRetroactiveEngagementFlowEvent::
  1266. kAssociateAccountLearnMorePressed),
  1267. 0);
  1268. EXPECT_EQ(histogram_tester().GetBucketCount(
  1269. kFastPairRetroactiveEngagementFlowMetric,
  1270. FastPairRetroactiveEngagementFlowEvent::
  1271. kAssociateAccountSavePressedAfterLearnMorePressed),
  1272. 0);
  1273. EXPECT_EQ(histogram_tester().GetBucketCount(
  1274. kFastPairRetroactiveEngagementFlowMetric,
  1275. FastPairRetroactiveEngagementFlowEvent::
  1276. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1277. 0);
  1278. EXPECT_EQ(histogram_tester().GetBucketCount(
  1279. kFastPairRetroactiveEngagementFlowMetric,
  1280. FastPairRetroactiveEngagementFlowEvent::
  1281. kAssociateAccountDismissedAfterLearnMorePressed),
  1282. 0);
  1283. }
  1284. TEST_F(QuickPairMetricsLoggerTest, LogAssociateAccountLearnMorePressed) {
  1285. SimulateAssociateAccountUiLearnMorePressed();
  1286. base::RunLoop().RunUntilIdle();
  1287. EXPECT_EQ(
  1288. histogram_tester().GetBucketCount(
  1289. kFastPairRetroactiveEngagementFlowMetric,
  1290. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1291. 0);
  1292. EXPECT_EQ(
  1293. histogram_tester().GetBucketCount(
  1294. kFastPairRetroactiveEngagementFlowMetric,
  1295. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1296. 0);
  1297. EXPECT_EQ(histogram_tester().GetBucketCount(
  1298. kFastPairRetroactiveEngagementFlowMetric,
  1299. FastPairRetroactiveEngagementFlowEvent::
  1300. kAssociateAccountUiDismissedByUser),
  1301. 0);
  1302. EXPECT_EQ(
  1303. histogram_tester().GetBucketCount(
  1304. kFastPairRetroactiveEngagementFlowMetric,
  1305. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1306. 0);
  1307. EXPECT_EQ(histogram_tester().GetBucketCount(
  1308. kFastPairRetroactiveEngagementFlowMetric,
  1309. FastPairRetroactiveEngagementFlowEvent::
  1310. kAssociateAccountLearnMorePressed),
  1311. 1);
  1312. EXPECT_EQ(histogram_tester().GetBucketCount(
  1313. kFastPairRetroactiveEngagementFlowMetric,
  1314. FastPairRetroactiveEngagementFlowEvent::
  1315. kAssociateAccountSavePressedAfterLearnMorePressed),
  1316. 0);
  1317. EXPECT_EQ(histogram_tester().GetBucketCount(
  1318. kFastPairRetroactiveEngagementFlowMetric,
  1319. FastPairRetroactiveEngagementFlowEvent::
  1320. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1321. 0);
  1322. EXPECT_EQ(histogram_tester().GetBucketCount(
  1323. kFastPairRetroactiveEngagementFlowMetric,
  1324. FastPairRetroactiveEngagementFlowEvent::
  1325. kAssociateAccountDismissedAfterLearnMorePressed),
  1326. 0);
  1327. }
  1328. TEST_F(QuickPairMetricsLoggerTest,
  1329. LogAssociateAccountLearnMorePressed_SavePressed) {
  1330. SimulateAssociateAccountUiLearnMorePressed();
  1331. base::RunLoop().RunUntilIdle();
  1332. SimulateAssociateAccountUiSavePressed();
  1333. base::RunLoop().RunUntilIdle();
  1334. EXPECT_EQ(
  1335. histogram_tester().GetBucketCount(
  1336. kFastPairRetroactiveEngagementFlowMetric,
  1337. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1338. 0);
  1339. EXPECT_EQ(
  1340. histogram_tester().GetBucketCount(
  1341. kFastPairRetroactiveEngagementFlowMetric,
  1342. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1343. 0);
  1344. EXPECT_EQ(histogram_tester().GetBucketCount(
  1345. kFastPairRetroactiveEngagementFlowMetric,
  1346. FastPairRetroactiveEngagementFlowEvent::
  1347. kAssociateAccountUiDismissedByUser),
  1348. 0);
  1349. EXPECT_EQ(
  1350. histogram_tester().GetBucketCount(
  1351. kFastPairRetroactiveEngagementFlowMetric,
  1352. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1353. 0);
  1354. EXPECT_EQ(histogram_tester().GetBucketCount(
  1355. kFastPairRetroactiveEngagementFlowMetric,
  1356. FastPairRetroactiveEngagementFlowEvent::
  1357. kAssociateAccountLearnMorePressed),
  1358. 1);
  1359. EXPECT_EQ(histogram_tester().GetBucketCount(
  1360. kFastPairRetroactiveEngagementFlowMetric,
  1361. FastPairRetroactiveEngagementFlowEvent::
  1362. kAssociateAccountSavePressedAfterLearnMorePressed),
  1363. 1);
  1364. EXPECT_EQ(histogram_tester().GetBucketCount(
  1365. kFastPairRetroactiveEngagementFlowMetric,
  1366. FastPairRetroactiveEngagementFlowEvent::
  1367. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1368. 0);
  1369. EXPECT_EQ(histogram_tester().GetBucketCount(
  1370. kFastPairRetroactiveEngagementFlowMetric,
  1371. FastPairRetroactiveEngagementFlowEvent::
  1372. kAssociateAccountDismissedAfterLearnMorePressed),
  1373. 0);
  1374. }
  1375. TEST_F(QuickPairMetricsLoggerTest,
  1376. LogAssociateAccountLearnMorePressed_Dismissed) {
  1377. SimulateAssociateAccountUiLearnMorePressed();
  1378. base::RunLoop().RunUntilIdle();
  1379. SimulateAssociateAccountUiDismissed();
  1380. base::RunLoop().RunUntilIdle();
  1381. EXPECT_EQ(
  1382. histogram_tester().GetBucketCount(
  1383. kFastPairRetroactiveEngagementFlowMetric,
  1384. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1385. 0);
  1386. EXPECT_EQ(
  1387. histogram_tester().GetBucketCount(
  1388. kFastPairRetroactiveEngagementFlowMetric,
  1389. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1390. 0);
  1391. EXPECT_EQ(histogram_tester().GetBucketCount(
  1392. kFastPairRetroactiveEngagementFlowMetric,
  1393. FastPairRetroactiveEngagementFlowEvent::
  1394. kAssociateAccountUiDismissedByUser),
  1395. 0);
  1396. EXPECT_EQ(
  1397. histogram_tester().GetBucketCount(
  1398. kFastPairRetroactiveEngagementFlowMetric,
  1399. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1400. 0);
  1401. EXPECT_EQ(histogram_tester().GetBucketCount(
  1402. kFastPairRetroactiveEngagementFlowMetric,
  1403. FastPairRetroactiveEngagementFlowEvent::
  1404. kAssociateAccountLearnMorePressed),
  1405. 1);
  1406. EXPECT_EQ(histogram_tester().GetBucketCount(
  1407. kFastPairRetroactiveEngagementFlowMetric,
  1408. FastPairRetroactiveEngagementFlowEvent::
  1409. kAssociateAccountSavePressedAfterLearnMorePressed),
  1410. 0);
  1411. EXPECT_EQ(histogram_tester().GetBucketCount(
  1412. kFastPairRetroactiveEngagementFlowMetric,
  1413. FastPairRetroactiveEngagementFlowEvent::
  1414. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1415. 0);
  1416. EXPECT_EQ(histogram_tester().GetBucketCount(
  1417. kFastPairRetroactiveEngagementFlowMetric,
  1418. FastPairRetroactiveEngagementFlowEvent::
  1419. kAssociateAccountDismissedAfterLearnMorePressed),
  1420. 1);
  1421. }
  1422. TEST_F(QuickPairMetricsLoggerTest,
  1423. LogAssociateAccountLearnMorePressed_DismissedByUser) {
  1424. SimulateAssociateAccountUiLearnMorePressed();
  1425. base::RunLoop().RunUntilIdle();
  1426. SimulateAssociateAccountUiDismissedByUser();
  1427. base::RunLoop().RunUntilIdle();
  1428. EXPECT_EQ(
  1429. histogram_tester().GetBucketCount(
  1430. kFastPairRetroactiveEngagementFlowMetric,
  1431. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiShown),
  1432. 0);
  1433. EXPECT_EQ(
  1434. histogram_tester().GetBucketCount(
  1435. kFastPairRetroactiveEngagementFlowMetric,
  1436. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountUiDismissed),
  1437. 0);
  1438. EXPECT_EQ(histogram_tester().GetBucketCount(
  1439. kFastPairRetroactiveEngagementFlowMetric,
  1440. FastPairRetroactiveEngagementFlowEvent::
  1441. kAssociateAccountUiDismissedByUser),
  1442. 0);
  1443. EXPECT_EQ(
  1444. histogram_tester().GetBucketCount(
  1445. kFastPairRetroactiveEngagementFlowMetric,
  1446. FastPairRetroactiveEngagementFlowEvent::kAssociateAccountSavePressed),
  1447. 0);
  1448. EXPECT_EQ(histogram_tester().GetBucketCount(
  1449. kFastPairRetroactiveEngagementFlowMetric,
  1450. FastPairRetroactiveEngagementFlowEvent::
  1451. kAssociateAccountLearnMorePressed),
  1452. 1);
  1453. EXPECT_EQ(histogram_tester().GetBucketCount(
  1454. kFastPairRetroactiveEngagementFlowMetric,
  1455. FastPairRetroactiveEngagementFlowEvent::
  1456. kAssociateAccountSavePressedAfterLearnMorePressed),
  1457. 0);
  1458. EXPECT_EQ(histogram_tester().GetBucketCount(
  1459. kFastPairRetroactiveEngagementFlowMetric,
  1460. FastPairRetroactiveEngagementFlowEvent::
  1461. kAssociateAccountDismissedByUserAfterLearnMorePressed),
  1462. 1);
  1463. EXPECT_EQ(histogram_tester().GetBucketCount(
  1464. kFastPairRetroactiveEngagementFlowMetric,
  1465. FastPairRetroactiveEngagementFlowEvent::
  1466. kAssociateAccountDismissedAfterLearnMorePressed),
  1467. 0);
  1468. }
  1469. TEST_F(QuickPairMetricsLoggerTest, DevicedPaired_FastPair) {
  1470. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1471. PairingMethod::kFastPair),
  1472. 0);
  1473. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1474. PairingMethod::kSystemPairingUi),
  1475. 0);
  1476. PairFastPairDeviceWithFastPair(kTestDeviceAddress);
  1477. PairFastPairDeviceWithClassicBluetooth(
  1478. /*new_paired_status=*/true, kTestDeviceAddress);
  1479. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1480. PairingMethod::kFastPair),
  1481. 1);
  1482. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1483. PairingMethod::kSystemPairingUi),
  1484. 0);
  1485. }
  1486. TEST_F(QuickPairMetricsLoggerTest, DeviceUnpaired) {
  1487. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1488. PairingMethod::kFastPair),
  1489. 0);
  1490. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1491. PairingMethod::kSystemPairingUi),
  1492. 0);
  1493. PairFastPairDeviceWithClassicBluetooth(
  1494. /*new_paired_status=*/false, kTestDeviceAddress);
  1495. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1496. PairingMethod::kFastPair),
  1497. 0);
  1498. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1499. PairingMethod::kSystemPairingUi),
  1500. 0);
  1501. }
  1502. TEST_F(QuickPairMetricsLoggerTest, DevicePaired) {
  1503. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1504. PairingMethod::kFastPair),
  1505. 0);
  1506. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1507. PairingMethod::kSystemPairingUi),
  1508. 0);
  1509. PairFastPairDeviceWithClassicBluetooth(
  1510. /*new_paired_status=*/true, kTestDeviceAddress);
  1511. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1512. PairingMethod::kFastPair),
  1513. 0);
  1514. EXPECT_EQ(histogram_tester().GetBucketCount(kPairingMethodMetric,
  1515. PairingMethod::kSystemPairingUi),
  1516. 1);
  1517. }
  1518. TEST_F(QuickPairMetricsLoggerTest, WriteAccountKey_Initial) {
  1519. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1520. histogram_tester().ExpectTotalCount(
  1521. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1522. histogram_tester().ExpectTotalCount(
  1523. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1524. histogram_tester().ExpectTotalCount(
  1525. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1526. histogram_tester().ExpectTotalCount(
  1527. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1528. SimulateAccountKeyWritten(Protocol::kFastPairInitial);
  1529. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1530. histogram_tester().ExpectTotalCount(
  1531. kFastPairAccountKeyWriteResultMetricInitial, 1);
  1532. histogram_tester().ExpectTotalCount(
  1533. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1534. histogram_tester().ExpectTotalCount(
  1535. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1536. histogram_tester().ExpectTotalCount(
  1537. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1538. }
  1539. TEST_F(QuickPairMetricsLoggerTest, WriteAccountKey_Retroactive) {
  1540. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1541. histogram_tester().ExpectTotalCount(
  1542. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1543. histogram_tester().ExpectTotalCount(
  1544. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1545. histogram_tester().ExpectTotalCount(
  1546. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1547. histogram_tester().ExpectTotalCount(
  1548. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1549. SimulateAccountKeyWritten(Protocol::kFastPairRetroactive);
  1550. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 1);
  1551. histogram_tester().ExpectTotalCount(
  1552. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1553. histogram_tester().ExpectTotalCount(
  1554. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1555. histogram_tester().ExpectTotalCount(
  1556. kFastPairAccountKeyWriteResultMetricRetroactive, 1);
  1557. histogram_tester().ExpectTotalCount(
  1558. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1559. }
  1560. TEST_F(QuickPairMetricsLoggerTest, WriteAccountKeyFailure_Retroactive) {
  1561. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1562. histogram_tester().ExpectTotalCount(
  1563. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1564. histogram_tester().ExpectTotalCount(
  1565. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1566. histogram_tester().ExpectTotalCount(
  1567. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1568. histogram_tester().ExpectTotalCount(
  1569. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1570. SimulateAccountKeyFailure(Protocol::kFastPairRetroactive);
  1571. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 1);
  1572. histogram_tester().ExpectTotalCount(
  1573. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1574. histogram_tester().ExpectTotalCount(
  1575. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1576. histogram_tester().ExpectTotalCount(
  1577. kFastPairAccountKeyWriteResultMetricRetroactive, 1);
  1578. histogram_tester().ExpectTotalCount(
  1579. kFastPairAccountKeyWriteFailureMetricRetroactive, 1);
  1580. }
  1581. TEST_F(QuickPairMetricsLoggerTest, WriteAccountKeyFailure_Initial) {
  1582. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1583. histogram_tester().ExpectTotalCount(
  1584. kFastPairAccountKeyWriteResultMetricInitial, 0);
  1585. histogram_tester().ExpectTotalCount(
  1586. kFastPairAccountKeyWriteFailureMetricInitial, 0);
  1587. histogram_tester().ExpectTotalCount(
  1588. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1589. histogram_tester().ExpectTotalCount(
  1590. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1591. SimulateAccountKeyFailure(Protocol::kFastPairInitial);
  1592. histogram_tester().ExpectTotalCount(kRetroactivePairingResultMetric, 0);
  1593. histogram_tester().ExpectTotalCount(
  1594. kFastPairAccountKeyWriteResultMetricInitial, 1);
  1595. histogram_tester().ExpectTotalCount(
  1596. kFastPairAccountKeyWriteFailureMetricInitial, 1);
  1597. histogram_tester().ExpectTotalCount(
  1598. kFastPairAccountKeyWriteResultMetricRetroactive, 0);
  1599. histogram_tester().ExpectTotalCount(
  1600. kFastPairAccountKeyWriteFailureMetricRetroactive, 0);
  1601. }
  1602. TEST_F(QuickPairMetricsLoggerTest, LogPairFailure_Initial) {
  1603. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1604. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1605. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1606. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1607. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1608. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1609. SimulatePairingFailed(Protocol::kFastPairInitial);
  1610. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 1);
  1611. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1612. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1613. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 1);
  1614. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1615. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1616. }
  1617. TEST_F(QuickPairMetricsLoggerTest, LogPairSuccess_Initial) {
  1618. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1619. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1620. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1621. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1622. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1623. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1624. SimulatePairingSucceeded(Protocol::kFastPairInitial);
  1625. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1626. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1627. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1628. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 1);
  1629. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1630. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1631. }
  1632. TEST_F(QuickPairMetricsLoggerTest, LogPairFailure_Subsequent) {
  1633. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1634. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1635. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1636. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1637. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1638. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1639. SimulatePairingFailed(Protocol::kFastPairSubsequent);
  1640. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1641. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 1);
  1642. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1643. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1644. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 1);
  1645. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1646. }
  1647. TEST_F(QuickPairMetricsLoggerTest, LogPairSuccess_Subsequent) {
  1648. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1649. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1650. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1651. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1652. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1653. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1654. SimulatePairingSucceeded(Protocol::kFastPairSubsequent);
  1655. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1656. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1657. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1658. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1659. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 1);
  1660. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1661. }
  1662. TEST_F(QuickPairMetricsLoggerTest, LogPairFailure_Retroactive) {
  1663. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1664. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1665. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1666. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1667. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1668. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1669. SimulatePairingFailed(Protocol::kFastPairRetroactive);
  1670. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1671. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1672. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 1);
  1673. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1674. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1675. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 1);
  1676. }
  1677. TEST_F(QuickPairMetricsLoggerTest, LogPairSuccess_Retroactive) {
  1678. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1679. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1680. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1681. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1682. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1683. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 0);
  1684. SimulatePairingSucceeded(Protocol::kFastPairRetroactive);
  1685. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricInitial, 0);
  1686. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricSubsequent, 0);
  1687. histogram_tester().ExpectTotalCount(kFastPairPairFailureMetricRetroactive, 0);
  1688. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricInitial, 0);
  1689. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricSubsequent, 0);
  1690. histogram_tester().ExpectTotalCount(kFastPairPairResultMetricRetroactive, 1);
  1691. }
  1692. TEST_F(QuickPairMetricsLoggerTest, DiscoveryLearnMorePressed_Initial) {
  1693. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairInitial);
  1694. base::RunLoop().RunUntilIdle();
  1695. EXPECT_EQ(histogram_tester().GetBucketCount(
  1696. kFastPairEngagementFlowMetricInitial,
  1697. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1698. 1);
  1699. EXPECT_EQ(histogram_tester().GetBucketCount(
  1700. kFastPairEngagementFlowMetricInitial,
  1701. FastPairEngagementFlowEvent::
  1702. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1703. 0);
  1704. EXPECT_EQ(histogram_tester().GetBucketCount(
  1705. kFastPairEngagementFlowMetricInitial,
  1706. FastPairEngagementFlowEvent::
  1707. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1708. 0);
  1709. EXPECT_EQ(histogram_tester().GetBucketCount(
  1710. kFastPairEngagementFlowMetricInitial,
  1711. FastPairEngagementFlowEvent::
  1712. kDiscoveryUiDismissedAfterLearnMorePressed),
  1713. 0);
  1714. }
  1715. TEST_F(QuickPairMetricsLoggerTest,
  1716. LogDiscoveryUiLearnMorePressed_ConnectPressed_Initial) {
  1717. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairInitial);
  1718. base::RunLoop().RunUntilIdle();
  1719. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairInitial);
  1720. base::RunLoop().RunUntilIdle();
  1721. EXPECT_EQ(histogram_tester().GetBucketCount(
  1722. kFastPairEngagementFlowMetricInitial,
  1723. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1724. 1);
  1725. EXPECT_EQ(histogram_tester().GetBucketCount(
  1726. kFastPairEngagementFlowMetricInitial,
  1727. FastPairEngagementFlowEvent::
  1728. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1729. 1);
  1730. EXPECT_EQ(histogram_tester().GetBucketCount(
  1731. kFastPairEngagementFlowMetricInitial,
  1732. FastPairEngagementFlowEvent::
  1733. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1734. 0);
  1735. EXPECT_EQ(histogram_tester().GetBucketCount(
  1736. kFastPairEngagementFlowMetricInitial,
  1737. FastPairEngagementFlowEvent::
  1738. kDiscoveryUiDismissedAfterLearnMorePressed),
  1739. 0);
  1740. }
  1741. TEST_F(QuickPairMetricsLoggerTest,
  1742. LogDiscoveryUiLearnMorePressed_DismissedByUser_Initial) {
  1743. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairInitial);
  1744. base::RunLoop().RunUntilIdle();
  1745. SimulateDiscoveryUiDismissedByUser(Protocol::kFastPairInitial);
  1746. base::RunLoop().RunUntilIdle();
  1747. EXPECT_EQ(histogram_tester().GetBucketCount(
  1748. kFastPairEngagementFlowMetricInitial,
  1749. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1750. 1);
  1751. EXPECT_EQ(histogram_tester().GetBucketCount(
  1752. kFastPairEngagementFlowMetricInitial,
  1753. FastPairEngagementFlowEvent::
  1754. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1755. 0);
  1756. EXPECT_EQ(histogram_tester().GetBucketCount(
  1757. kFastPairEngagementFlowMetricInitial,
  1758. FastPairEngagementFlowEvent::
  1759. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1760. 1);
  1761. EXPECT_EQ(histogram_tester().GetBucketCount(
  1762. kFastPairEngagementFlowMetricInitial,
  1763. FastPairEngagementFlowEvent::
  1764. kDiscoveryUiDismissedAfterLearnMorePressed),
  1765. 0);
  1766. }
  1767. TEST_F(QuickPairMetricsLoggerTest,
  1768. LogDiscoveryUiLearnMorePressed_Dismissed_Initial) {
  1769. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairInitial);
  1770. base::RunLoop().RunUntilIdle();
  1771. SimulateDiscoveryUiDismissed(Protocol::kFastPairInitial);
  1772. base::RunLoop().RunUntilIdle();
  1773. EXPECT_EQ(histogram_tester().GetBucketCount(
  1774. kFastPairEngagementFlowMetricInitial,
  1775. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1776. 1);
  1777. EXPECT_EQ(histogram_tester().GetBucketCount(
  1778. kFastPairEngagementFlowMetricInitial,
  1779. FastPairEngagementFlowEvent::
  1780. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1781. 0);
  1782. EXPECT_EQ(histogram_tester().GetBucketCount(
  1783. kFastPairEngagementFlowMetricInitial,
  1784. FastPairEngagementFlowEvent::
  1785. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1786. 0);
  1787. EXPECT_EQ(histogram_tester().GetBucketCount(
  1788. kFastPairEngagementFlowMetricInitial,
  1789. FastPairEngagementFlowEvent::
  1790. kDiscoveryUiDismissedAfterLearnMorePressed),
  1791. 1);
  1792. }
  1793. TEST_F(QuickPairMetricsLoggerTest, DiscoveryLearnMorePressed_Subsequent) {
  1794. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairSubsequent);
  1795. base::RunLoop().RunUntilIdle();
  1796. EXPECT_EQ(histogram_tester().GetBucketCount(
  1797. kFastPairEngagementFlowMetricSubsequent,
  1798. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1799. 1);
  1800. EXPECT_EQ(histogram_tester().GetBucketCount(
  1801. kFastPairEngagementFlowMetricSubsequent,
  1802. FastPairEngagementFlowEvent::
  1803. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1804. 0);
  1805. EXPECT_EQ(histogram_tester().GetBucketCount(
  1806. kFastPairEngagementFlowMetricSubsequent,
  1807. FastPairEngagementFlowEvent::
  1808. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1809. 0);
  1810. EXPECT_EQ(histogram_tester().GetBucketCount(
  1811. kFastPairEngagementFlowMetricSubsequent,
  1812. FastPairEngagementFlowEvent::
  1813. kDiscoveryUiDismissedAfterLearnMorePressed),
  1814. 0);
  1815. }
  1816. TEST_F(QuickPairMetricsLoggerTest,
  1817. LogDiscoveryUiLearnMorePressed_ConnectPressed_Subsequent) {
  1818. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairSubsequent);
  1819. base::RunLoop().RunUntilIdle();
  1820. SimulateDiscoveryUiConnectPressed(Protocol::kFastPairSubsequent);
  1821. base::RunLoop().RunUntilIdle();
  1822. EXPECT_EQ(histogram_tester().GetBucketCount(
  1823. kFastPairEngagementFlowMetricSubsequent,
  1824. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1825. 1);
  1826. EXPECT_EQ(histogram_tester().GetBucketCount(
  1827. kFastPairEngagementFlowMetricSubsequent,
  1828. FastPairEngagementFlowEvent::
  1829. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1830. 1);
  1831. EXPECT_EQ(histogram_tester().GetBucketCount(
  1832. kFastPairEngagementFlowMetricSubsequent,
  1833. FastPairEngagementFlowEvent::
  1834. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1835. 0);
  1836. EXPECT_EQ(histogram_tester().GetBucketCount(
  1837. kFastPairEngagementFlowMetricSubsequent,
  1838. FastPairEngagementFlowEvent::
  1839. kDiscoveryUiDismissedAfterLearnMorePressed),
  1840. 0);
  1841. }
  1842. TEST_F(QuickPairMetricsLoggerTest,
  1843. LogDiscoveryUiLearnMorePressed_DismissedByUser_Subsequent) {
  1844. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairSubsequent);
  1845. base::RunLoop().RunUntilIdle();
  1846. SimulateDiscoveryUiDismissedByUser(Protocol::kFastPairSubsequent);
  1847. base::RunLoop().RunUntilIdle();
  1848. EXPECT_EQ(histogram_tester().GetBucketCount(
  1849. kFastPairEngagementFlowMetricSubsequent,
  1850. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1851. 1);
  1852. EXPECT_EQ(histogram_tester().GetBucketCount(
  1853. kFastPairEngagementFlowMetricSubsequent,
  1854. FastPairEngagementFlowEvent::
  1855. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1856. 0);
  1857. EXPECT_EQ(histogram_tester().GetBucketCount(
  1858. kFastPairEngagementFlowMetricSubsequent,
  1859. FastPairEngagementFlowEvent::
  1860. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1861. 1);
  1862. EXPECT_EQ(histogram_tester().GetBucketCount(
  1863. kFastPairEngagementFlowMetricSubsequent,
  1864. FastPairEngagementFlowEvent::
  1865. kDiscoveryUiDismissedAfterLearnMorePressed),
  1866. 0);
  1867. }
  1868. TEST_F(QuickPairMetricsLoggerTest,
  1869. LogDiscoveryUiLearnMorePressed_Dismissed_Subsequent) {
  1870. SimulateDiscoveryUiLearnMorePressed(Protocol::kFastPairSubsequent);
  1871. base::RunLoop().RunUntilIdle();
  1872. SimulateDiscoveryUiDismissed(Protocol::kFastPairSubsequent);
  1873. base::RunLoop().RunUntilIdle();
  1874. EXPECT_EQ(histogram_tester().GetBucketCount(
  1875. kFastPairEngagementFlowMetricSubsequent,
  1876. FastPairEngagementFlowEvent::kDiscoveryUiLearnMorePressed),
  1877. 1);
  1878. EXPECT_EQ(histogram_tester().GetBucketCount(
  1879. kFastPairEngagementFlowMetricSubsequent,
  1880. FastPairEngagementFlowEvent::
  1881. kDiscoveryUiConnectPressedAfterLearnMorePressed),
  1882. 0);
  1883. EXPECT_EQ(histogram_tester().GetBucketCount(
  1884. kFastPairEngagementFlowMetricSubsequent,
  1885. FastPairEngagementFlowEvent::
  1886. kDiscoveryUiDismissedByUserAfterLearnMorePressed),
  1887. 0);
  1888. EXPECT_EQ(histogram_tester().GetBucketCount(
  1889. kFastPairEngagementFlowMetricSubsequent,
  1890. FastPairEngagementFlowEvent::
  1891. kDiscoveryUiDismissedAfterLearnMorePressed),
  1892. 1);
  1893. }
  1894. } // namespace quick_pair
  1895. } // namespace ash