| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Payment Request is shown. | 44 // Payment Request is shown. |
| 45 ResetEventObserverForSequence( | 45 ResetEventObserverForSequence( |
| 46 {DialogEvent::CAN_MAKE_PAYMENT_CALLED, DialogEvent::DIALOG_OPENED}); | 46 {DialogEvent::CAN_MAKE_PAYMENT_CALLED, DialogEvent::DIALOG_OPENED}); |
| 47 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "queryShow();")); | 47 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "queryShow();")); |
| 48 WaitForObservedEvent(); | 48 WaitForObservedEvent(); |
| 49 | 49 |
| 50 // Complete the Payment Request. | 50 // Complete the Payment Request. |
| 51 PayWithCreditCardAndWait(base::ASCIIToUTF16("123")); | 51 PayWithCreditCardAndWait(base::ASCIIToUTF16("123")); |
| 52 | 52 |
| 53 // Make sure the metrics are logged correctly. | 53 // Make sure the metrics are logged correctly. |
| 54 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 55 1, 1); |
| 56 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 57 1); |
| 58 histogram_tester.ExpectUniqueSample( |
| 59 "PaymentRequest.CheckoutFunnel.PayClicked", 1, 1); |
| 60 histogram_tester.ExpectUniqueSample( |
| 61 "PaymentRequest.CheckoutFunnel.ReceivedInstrumentDetails", 1, 1); |
| 54 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Completed", | 62 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Completed", |
| 55 1, 1); | 63 1, 1); |
| 56 } | 64 } |
| 57 | 65 |
| 58 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 66 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 59 MerchantAborted_Reload) { | 67 MerchantAborted_Reload) { |
| 60 base::HistogramTester histogram_tester; | 68 base::HistogramTester histogram_tester; |
| 61 | 69 |
| 62 // Start the Payment Request. | 70 // Start the Payment Request. |
| 63 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 71 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 64 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 72 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 65 WaitForObservedEvent(); | 73 WaitForObservedEvent(); |
| 66 | 74 |
| 67 // The merchant reloads the page. | 75 // The merchant reloads the page. |
| 68 ResetEventObserver(DialogEvent::DIALOG_CLOSED); | 76 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 69 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), | 77 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), |
| 70 "(function() { location.reload(); })();")); | 78 "(function() { location.reload(); })();")); |
| 71 WaitForObservedEvent(); | 79 WaitForObservedEvent(); |
| 72 | 80 |
| 73 // Make sure the metrics are logged correctly. | 81 // Make sure the metrics are logged correctly. |
| 82 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 83 1, 1); |
| 84 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 85 1); |
| 74 histogram_tester.ExpectUniqueSample( | 86 histogram_tester.ExpectUniqueSample( |
| 75 "PaymentRequest.CheckoutFunnel.Aborted", | 87 "PaymentRequest.CheckoutFunnel.Aborted", |
| 76 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1); | 88 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1); |
| 77 } | 89 } |
| 78 | 90 |
| 79 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 91 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 80 MerchantAborted_Navigation) { | 92 MerchantAborted_Navigation) { |
| 81 base::HistogramTester histogram_tester; | 93 base::HistogramTester histogram_tester; |
| 82 | 94 |
| 83 // Start the Payment Request. | 95 // Start the Payment Request. |
| 84 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 96 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 85 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 97 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 86 WaitForObservedEvent(); | 98 WaitForObservedEvent(); |
| 87 | 99 |
| 88 // The merchant navigates away. | 100 // The merchant navigates away. |
| 89 ResetEventObserver(DialogEvent::DIALOG_CLOSED); | 101 ResetEventObserver(DialogEvent::DIALOG_CLOSED); |
| 90 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), | 102 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), |
| 91 "(function() { window.location.href = " | 103 "(function() { window.location.href = " |
| 92 "'/payment_request_email_test.html'; " | 104 "'/payment_request_email_test.html'; " |
| 93 "})();")); | 105 "})();")); |
| 94 WaitForObservedEvent(); | 106 WaitForObservedEvent(); |
| 95 | 107 |
| 96 // Make sure the metrics are logged correctly. | 108 // Make sure the metrics are logged correctly. |
| 109 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 110 1, 1); |
| 111 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 112 1); |
| 97 histogram_tester.ExpectUniqueSample( | 113 histogram_tester.ExpectUniqueSample( |
| 98 "PaymentRequest.CheckoutFunnel.Aborted", | 114 "PaymentRequest.CheckoutFunnel.Aborted", |
| 99 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1); | 115 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1); |
| 100 } | 116 } |
| 101 | 117 |
| 102 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 118 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 103 MerchantAborted_Abort) { | 119 MerchantAborted_Abort) { |
| 104 base::HistogramTester histogram_tester; | 120 base::HistogramTester histogram_tester; |
| 105 | 121 |
| 106 // Start the Payment Request. | 122 // Start the Payment Request. |
| 107 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 123 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 108 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 124 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 109 WaitForObservedEvent(); | 125 WaitForObservedEvent(); |
| 110 | 126 |
| 111 // The merchant aborts the Payment Request. | 127 // The merchant aborts the Payment Request. |
| 112 ResetEventObserverForSequence( | 128 ResetEventObserverForSequence( |
| 113 {DialogEvent::ABORT_CALLED, DialogEvent::DIALOG_CLOSED}); | 129 {DialogEvent::ABORT_CALLED, DialogEvent::DIALOG_CLOSED}); |
| 114 const std::string click_buy_button_js = | 130 const std::string click_buy_button_js = |
| 115 "(function() { document.getElementById('abort').click(); })();"; | 131 "(function() { document.getElementById('abort').click(); })();"; |
| 116 ASSERT_TRUE( | 132 ASSERT_TRUE( |
| 117 content::ExecuteScript(GetActiveWebContents(), click_buy_button_js)); | 133 content::ExecuteScript(GetActiveWebContents(), click_buy_button_js)); |
| 118 WaitForObservedEvent(); | 134 WaitForObservedEvent(); |
| 119 | 135 |
| 120 // Make sure the metrics are logged correctly. | 136 // Make sure the metrics are logged correctly. |
| 137 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 138 1, 1); |
| 139 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 140 1); |
| 121 histogram_tester.ExpectUniqueSample( | 141 histogram_tester.ExpectUniqueSample( |
| 122 "PaymentRequest.CheckoutFunnel.Aborted", | 142 "PaymentRequest.CheckoutFunnel.Aborted", |
| 123 JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT, 1); | 143 JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT, 1); |
| 124 } | 144 } |
| 125 | 145 |
| 126 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 146 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 127 UserAborted_Navigation) { | 147 UserAborted_Navigation) { |
| 128 base::HistogramTester histogram_tester; | 148 base::HistogramTester histogram_tester; |
| 129 | 149 |
| 130 // Start the Payment Request. | 150 // Start the Payment Request. |
| 131 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 151 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 132 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 152 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 133 WaitForObservedEvent(); | 153 WaitForObservedEvent(); |
| 134 | 154 |
| 135 // Navigate away. | 155 // Navigate away. |
| 136 NavigateTo("/payment_request_email_test.html"); | 156 NavigateTo("/payment_request_email_test.html"); |
| 137 | 157 |
| 138 // Make sure the metrics are logged correctly. | 158 // Make sure the metrics are logged correctly. |
| 159 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 160 1, 1); |
| 161 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 162 1); |
| 139 histogram_tester.ExpectUniqueSample( | 163 histogram_tester.ExpectUniqueSample( |
| 140 "PaymentRequest.CheckoutFunnel.Aborted", | 164 "PaymentRequest.CheckoutFunnel.Aborted", |
| 141 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1); | 165 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1); |
| 142 } | 166 } |
| 143 | 167 |
| 144 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 168 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 145 UserAborted_CancelButton) { | 169 UserAborted_CancelButton) { |
| 146 base::HistogramTester histogram_tester; | 170 base::HistogramTester histogram_tester; |
| 147 | 171 |
| 148 // Start the Payment Request. | 172 // Start the Payment Request. |
| 149 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 173 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 150 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 174 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 151 WaitForObservedEvent(); | 175 WaitForObservedEvent(); |
| 152 | 176 |
| 153 // Click on the cancel button. | 177 // Click on the cancel button. |
| 154 ClickOnCancel(); | 178 ClickOnCancel(); |
| 155 | 179 |
| 156 // Make sure the metrics are logged correctly. | 180 // Make sure the metrics are logged correctly. |
| 181 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 182 1, 1); |
| 183 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 184 1); |
| 157 histogram_tester.ExpectUniqueSample( | 185 histogram_tester.ExpectUniqueSample( |
| 158 "PaymentRequest.CheckoutFunnel.Aborted", | 186 "PaymentRequest.CheckoutFunnel.Aborted", |
| 159 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1); | 187 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1); |
| 160 } | 188 } |
| 161 | 189 |
| 162 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 190 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 163 UserAborted_TabClosed) { | 191 UserAborted_TabClosed) { |
| 164 base::HistogramTester histogram_tester; | 192 base::HistogramTester histogram_tester; |
| 165 | 193 |
| 166 // Start the Payment Request. | 194 // Start the Payment Request. |
| 167 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 195 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 168 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 196 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 169 WaitForObservedEvent(); | 197 WaitForObservedEvent(); |
| 170 | 198 |
| 171 // Close the tab containing the Payment Request. | 199 // Close the tab containing the Payment Request. |
| 172 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED}); | 200 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED}); |
| 173 chrome::CloseTab(browser()); | 201 chrome::CloseTab(browser()); |
| 174 WaitForObservedEvent(); | 202 WaitForObservedEvent(); |
| 175 | 203 |
| 176 // Make sure the metrics are logged correctly. | 204 // Make sure the metrics are logged correctly. |
| 205 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 206 1, 1); |
| 207 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 208 1); |
| 177 histogram_tester.ExpectUniqueSample( | 209 histogram_tester.ExpectUniqueSample( |
| 178 "PaymentRequest.CheckoutFunnel.Aborted", | 210 "PaymentRequest.CheckoutFunnel.Aborted", |
| 179 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1); | 211 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1); |
| 180 } | 212 } |
| 181 | 213 |
| 182 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, | 214 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, |
| 183 UserAborted_Reload) { | 215 UserAborted_Reload) { |
| 184 base::HistogramTester histogram_tester; | 216 base::HistogramTester histogram_tester; |
| 185 | 217 |
| 186 // Start the Payment Request. | 218 // Start the Payment Request. |
| 187 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 219 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 188 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); | 220 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();")); |
| 189 WaitForObservedEvent(); | 221 WaitForObservedEvent(); |
| 190 | 222 |
| 191 // Reload the page containing the Payment Request. | 223 // Reload the page containing the Payment Request. |
| 192 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED}); | 224 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED}); |
| 193 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 225 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 194 WaitForObservedEvent(); | 226 WaitForObservedEvent(); |
| 195 | 227 |
| 196 // Make sure the metrics are logged correctly. | 228 // Make sure the metrics are logged correctly. |
| 229 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Initiated", |
| 230 1, 1); |
| 231 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Shown", 1, |
| 232 1); |
| 197 histogram_tester.ExpectUniqueSample( | 233 histogram_tester.ExpectUniqueSample( |
| 198 "PaymentRequest.CheckoutFunnel.Aborted", | 234 "PaymentRequest.CheckoutFunnel.Aborted", |
| 199 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1); | 235 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1); |
| 200 } | 236 } |
| 201 | 237 |
| 202 } // namespace payments | 238 } // namespace payments |
| OLD | NEW |