| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" | 15 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
| 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 19 #include "components/autofill/core/browser/autofill_metrics.h" | 19 #include "components/autofill/core/browser/autofill_metrics.h" |
| 20 #include "components/autofill/core/browser/credit_card.h" | 20 #include "components/autofill/core/browser/credit_card.h" |
| 21 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_handle.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using base::Bucket; | 25 using base::Bucket; |
| 26 using testing::ElementsAre; | 26 using testing::ElementsAre; |
| 27 | 27 |
| 28 namespace autofill { | 28 namespace autofill { |
| 29 | 29 |
| 30 class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl { | 30 class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl { |
| 31 public: | 31 public: |
| 32 static void CreateForTesting(content::WebContents* web_contents) { | 32 static void CreateForTesting(content::WebContents* web_contents) { |
| 33 web_contents->SetUserData( | 33 web_contents->SetUserData( |
| 34 UserDataKey(), new TestSaveCardBubbleControllerImpl(web_contents)); | 34 UserDataKey(), new TestSaveCardBubbleControllerImpl(web_contents)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 explicit TestSaveCardBubbleControllerImpl(content::WebContents* web_contents) | 37 explicit TestSaveCardBubbleControllerImpl(content::WebContents* web_contents) |
| 38 : SaveCardBubbleControllerImpl(web_contents) {} | 38 : SaveCardBubbleControllerImpl(web_contents) {} |
| 39 | 39 |
| 40 void set_elapsed(base::TimeDelta elapsed) { elapsed_ = elapsed; } | 40 void set_elapsed(base::TimeDelta elapsed) { elapsed_ = elapsed; } |
| 41 | 41 |
| 42 using SaveCardBubbleControllerImpl::DidNavigateMainFrame; | 42 void SimulateNavigation() { |
| 43 content::RenderFrameHost* rfh = web_contents()->GetMainFrame(); |
| 44 std::unique_ptr<content::NavigationHandle> navigation_handle = |
| 45 content::NavigationHandle::CreateNavigationHandleForTesting( |
| 46 GURL(), rfh, true); |
| 47 // Destructor calls DidFinishNavigation. |
| 48 } |
| 43 | 49 |
| 44 protected: | 50 protected: |
| 45 base::TimeDelta Elapsed() const override { return elapsed_; } | 51 base::TimeDelta Elapsed() const override { return elapsed_; } |
| 46 | 52 |
| 47 private: | 53 private: |
| 48 base::TimeDelta elapsed_; | 54 base::TimeDelta elapsed_; |
| 49 }; | 55 }; |
| 50 | 56 |
| 51 class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest { | 57 class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest { |
| 52 public: | 58 public: |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1); | 238 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1); |
| 233 } | 239 } |
| 234 | 240 |
| 235 TEST_F(SaveCardBubbleControllerImplTest, | 241 TEST_F(SaveCardBubbleControllerImplTest, |
| 236 Metrics_Local_FirstShow_NavigateWhileShowing) { | 242 Metrics_Local_FirstShow_NavigateWhileShowing) { |
| 237 ShowLocalBubble(); | 243 ShowLocalBubble(); |
| 238 | 244 |
| 239 base::HistogramTester histogram_tester; | 245 base::HistogramTester histogram_tester; |
| 240 // Fake-navigate after bubble has been visible for a long time. | 246 // Fake-navigate after bubble has been visible for a long time. |
| 241 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); | 247 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); |
| 242 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 248 |
| 243 content::FrameNavigateParams()); | 249 controller()->SimulateNavigation(); |
| 244 | 250 |
| 245 histogram_tester.ExpectUniqueSample( | 251 histogram_tester.ExpectUniqueSample( |
| 246 "Autofill.SaveCreditCardPrompt.Local.FirstShow", | 252 "Autofill.SaveCreditCardPrompt.Local.FirstShow", |
| 247 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, 1); | 253 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, 1); |
| 248 } | 254 } |
| 249 | 255 |
| 250 TEST_F(SaveCardBubbleControllerImplTest, | 256 TEST_F(SaveCardBubbleControllerImplTest, |
| 251 Metrics_Local_Reshows_NavigateWhileShowing) { | 257 Metrics_Local_Reshows_NavigateWhileShowing) { |
| 252 ShowLocalBubble(); | 258 ShowLocalBubble(); |
| 253 CloseAndReshowBubble(); | 259 CloseAndReshowBubble(); |
| 254 | 260 |
| 255 base::HistogramTester histogram_tester; | 261 base::HistogramTester histogram_tester; |
| 256 // Fake-navigate after bubble has been visible for a long time. | 262 // Fake-navigate after bubble has been visible for a long time. |
| 257 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); | 263 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); |
| 258 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 264 controller()->SimulateNavigation(); |
| 259 content::FrameNavigateParams()); | |
| 260 | 265 |
| 261 histogram_tester.ExpectUniqueSample( | 266 histogram_tester.ExpectUniqueSample( |
| 262 "Autofill.SaveCreditCardPrompt.Local.Reshows", | 267 "Autofill.SaveCreditCardPrompt.Local.Reshows", |
| 263 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, 1); | 268 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, 1); |
| 264 } | 269 } |
| 265 | 270 |
| 266 TEST_F(SaveCardBubbleControllerImplTest, | 271 TEST_F(SaveCardBubbleControllerImplTest, |
| 267 Metrics_Local_FirstShow_NavigateWhileHidden) { | 272 Metrics_Local_FirstShow_NavigateWhileHidden) { |
| 268 ShowLocalBubble(); | 273 ShowLocalBubble(); |
| 269 | 274 |
| 270 base::HistogramTester histogram_tester; | 275 base::HistogramTester histogram_tester; |
| 271 controller()->OnBubbleClosed(); | 276 controller()->OnBubbleClosed(); |
| 272 // Fake-navigate after bubble has been visible for a long time. | 277 // Fake-navigate after bubble has been visible for a long time. |
| 273 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); | 278 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); |
| 274 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 279 controller()->SimulateNavigation(); |
| 275 content::FrameNavigateParams()); | |
| 276 | 280 |
| 277 histogram_tester.ExpectUniqueSample( | 281 histogram_tester.ExpectUniqueSample( |
| 278 "Autofill.SaveCreditCardPrompt.Local.FirstShow", | 282 "Autofill.SaveCreditCardPrompt.Local.FirstShow", |
| 279 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1); | 283 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1); |
| 280 } | 284 } |
| 281 | 285 |
| 282 TEST_F(SaveCardBubbleControllerImplTest, | 286 TEST_F(SaveCardBubbleControllerImplTest, |
| 283 Metrics_Local_Reshows_NavigateWhileHidden) { | 287 Metrics_Local_Reshows_NavigateWhileHidden) { |
| 284 ShowLocalBubble(); | 288 ShowLocalBubble(); |
| 285 CloseAndReshowBubble(); | 289 CloseAndReshowBubble(); |
| 286 | 290 |
| 287 base::HistogramTester histogram_tester; | 291 base::HistogramTester histogram_tester; |
| 288 controller()->OnBubbleClosed(); | 292 controller()->OnBubbleClosed(); |
| 289 // Fake-navigate after bubble has been visible for a long time. | 293 // Fake-navigate after bubble has been visible for a long time. |
| 290 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); | 294 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); |
| 291 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 295 controller()->SimulateNavigation(); |
| 292 content::FrameNavigateParams()); | |
| 293 | 296 |
| 294 histogram_tester.ExpectUniqueSample( | 297 histogram_tester.ExpectUniqueSample( |
| 295 "Autofill.SaveCreditCardPrompt.Local.Reshows", | 298 "Autofill.SaveCreditCardPrompt.Local.Reshows", |
| 296 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1); | 299 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1); |
| 297 } | 300 } |
| 298 | 301 |
| 299 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_LearnMore) { | 302 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_LearnMore) { |
| 300 ShowUploadBubble(); | 303 ShowUploadBubble(); |
| 301 | 304 |
| 302 base::HistogramTester histogram_tester; | 305 base::HistogramTester histogram_tester; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_THAT( | 367 EXPECT_THAT( |
| 365 histogram_tester.GetAllSamples( | 368 histogram_tester.GetAllSamples( |
| 366 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), | 369 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), |
| 367 ElementsAre( | 370 ElementsAre( |
| 368 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), | 371 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 369 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, | 372 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, |
| 370 1))); | 373 1))); |
| 371 } | 374 } |
| 372 | 375 |
| 373 } // namespace autofill | 376 } // namespace autofill |
| OLD | NEW |