| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/previews/previews_infobar_delegate.h" | 5 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 const char kTestUrl[] = "http://www.test.com/"; | 49 const char kTestUrl[] = "http://www.test.com/"; |
| 50 | 50 |
| 51 // Key of the UMA Previews.InfoBarAction.LoFi histogram. | 51 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
| 52 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 52 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
| 53 | 53 |
| 54 // Key of the UMA Previews.InfoBarAction.Offline histogram. | 54 // Key of the UMA Previews.InfoBarAction.Offline histogram. |
| 55 const char kUMAPreviewsInfoBarActionOffline[] = | 55 const char kUMAPreviewsInfoBarActionOffline[] = |
| 56 "Previews.InfoBarAction.Offline"; | 56 "Previews.InfoBarAction.Offline"; |
| 57 | 57 |
| 58 // Key of the UMA Previews.InfoBarAction.ClientLoFi histogram. |
| 59 const char kUMAPreviewsInfoBarActionClientLoFi[] = |
| 60 "Previews.InfoBarAction.ClientLoFi"; |
| 61 |
| 58 // Key of the UMA Previews.InfoBarAction.LitePage histogram. | 62 // Key of the UMA Previews.InfoBarAction.LitePage histogram. |
| 59 const char kUMAPreviewsInfoBarActionLitePage[] = | 63 const char kUMAPreviewsInfoBarActionLitePage[] = |
| 60 "Previews.InfoBarAction.LitePage"; | 64 "Previews.InfoBarAction.LitePage"; |
| 61 | 65 |
| 62 class TestPreviewsWebContentsObserver | 66 class TestPreviewsWebContentsObserver |
| 63 : public content::WebContentsObserver, | 67 : public content::WebContentsObserver, |
| 64 public content::WebContentsUserData<TestPreviewsWebContentsObserver> { | 68 public content::WebContentsUserData<TestPreviewsWebContentsObserver> { |
| 65 public: | 69 public: |
| 66 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) | 70 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) |
| 67 : content::WebContentsObserver(web_contents), | 71 : content::WebContentsObserver(web_contents), |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 521 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 518 ->pingback_client() | 522 ->pingback_client() |
| 519 ->OptOutsSizeForTesting()); | 523 ->OptOutsSizeForTesting()); |
| 520 | 524 |
| 521 drp_test_context_->RunUntilIdle(); | 525 drp_test_context_->RunUntilIdle(); |
| 522 | 526 |
| 523 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 527 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 524 ->pingback_client() | 528 ->pingback_client() |
| 525 ->OptOutsSizeForTesting()); | 529 ->OptOutsSizeForTesting()); |
| 526 } | 530 } |
| 531 |
| 532 TEST_F(PreviewsInfoBarDelegateUnitTest, ClientSideLoFiTest) { |
| 533 base::HistogramTester tester; |
| 534 |
| 535 NavigateAndCommit(GURL(kTestUrl)); |
| 536 |
| 537 ConfirmInfoBarDelegate* infobar = CreateInfoBar( |
| 538 PreviewsInfoBarDelegate::CLIENT_LOFI, true /* is_data_saver_user */); |
| 539 |
| 540 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionClientLoFi, |
| 541 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 542 |
| 543 // Check the strings. |
| 544 ASSERT_TRUE(infobar); |
| 545 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
| 546 infobar->GetMessageText()); |
| 547 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 548 infobar->GetLinkText()); |
| 549 #if defined(OS_ANDROID) |
| 550 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 551 #else |
| 552 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 553 #endif |
| 554 |
| 555 // Simulate clicking the infobar link. |
| 556 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| 557 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 558 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 559 |
| 560 tester.ExpectBucketCount( |
| 561 kUMAPreviewsInfoBarActionClientLoFi, |
| 562 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
| 563 |
| 564 auto* data_reduction_proxy_settings = |
| 565 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 566 web_contents()->GetBrowserContext()); |
| 567 |
| 568 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 569 ->pingback_client() |
| 570 ->OptOutsSizeForTesting()); |
| 571 } |
| OLD | NEW |