Index: ios/chrome/browser/web/blocked_popup_tab_helper_unittest.mm |
diff --git a/ios/chrome/browser/web/blocked_popup_tab_helper_unittest.mm b/ios/chrome/browser/web/blocked_popup_tab_helper_unittest.mm |
index e56dd1525b1d4344c5f1ef0958c07c60a1401a85..2e9050c663637f7808fff55a71ef8699a9417b44 100644 |
--- a/ios/chrome/browser/web/blocked_popup_tab_helper_unittest.mm |
+++ b/ios/chrome/browser/web/blocked_popup_tab_helper_unittest.mm |
@@ -6,6 +6,7 @@ |
#include "base/memory/ptr_util.h" |
#include "components/content_settings/core/browser/host_content_settings_map.h" |
+#include "components/infobars/core/confirm_infobar_delegate.h" |
#include "components/infobars/core/infobar.h" |
#include "components/infobars/core/infobar_manager.h" |
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
@@ -39,6 +40,10 @@ class BlockedPopupTabHelperTest : public ChromeWebTest { |
BlockedPopupTabHelper* GetBlockedPopupTabHelper() { |
return BlockedPopupTabHelper::FromWebState(&web_state_); |
} |
+ // Returns InfoBarManager attached to |web_state_|. |
+ infobars::InfoBarManager* GetInfobarManager() { |
+ return InfoBarManagerImpl::FromWebState(&web_state_); |
+ } |
web::TestWebState web_state_; |
}; |
@@ -71,6 +76,33 @@ TEST_F(BlockedPopupTabHelperTest, ShouldBlockPopup) { |
EXPECT_FALSE(GetBlockedPopupTabHelper()->ShouldBlockPopup(source_url2)); |
} |
+// Tests that allowing blocked popup calls |show_popup_handler| and allows |
+// future popups for the source url. |
+TEST_F(BlockedPopupTabHelperTest, AllowBlockedPopup) { |
+ const GURL source_url("https://source-url"); |
+ ASSERT_TRUE(GetBlockedPopupTabHelper()->ShouldBlockPopup(source_url)); |
+ |
+ // Block popup. |
+ const GURL target_url("https://target-url"); |
+ web::Referrer referrer(source_url, web::ReferrerPolicyDefault); |
+ __block bool show_popup_handler_was_called = false; |
+ web::BlockedPopupInfo popup_info(target_url, referrer, nil, ^{ |
+ show_popup_handler_was_called = true; |
+ }); |
+ GetBlockedPopupTabHelper()->HandlePopup(popup_info); |
+ |
+ // Allow blocked popup. |
+ ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); |
+ infobars::InfoBar* infobar = GetInfobarManager()->infobar_at(0); |
+ auto delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); |
+ ASSERT_TRUE(delegate); |
+ delegate->Accept(); |
+ |
+ // Verify that handler was called and popups are allowed for |test_url|. |
+ EXPECT_TRUE(show_popup_handler_was_called); |
+ EXPECT_FALSE(GetBlockedPopupTabHelper()->ShouldBlockPopup(source_url)); |
+} |
+ |
// Tests that an infobar is added to the infobar manager when |
// BlockedPopupTabHelper::HandlePopup() is called. |
TEST_F(BlockedPopupTabHelperTest, ShowAndDismissInfoBar) { |
@@ -78,19 +110,17 @@ TEST_F(BlockedPopupTabHelperTest, ShowAndDismissInfoBar) { |
web::BlockedPopupInfo popup_info(test_url, web::Referrer(), nil, nil); |
// Check that there are no infobars showing and no registered observers. |
- infobars::InfoBarManager* infobar_manager = |
- InfoBarManagerImpl::FromWebState(&web_state_); |
- EXPECT_EQ(0U, infobar_manager->infobar_count()); |
+ EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); |
EXPECT_FALSE(IsObservingSources()); |
// Call |HandlePopup| to show an infobar. |
GetBlockedPopupTabHelper()->HandlePopup(popup_info); |
- ASSERT_EQ(1U, infobar_manager->infobar_count()); |
+ ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); |
EXPECT_TRUE(IsObservingSources()); |
// Dismiss the infobar and check that the tab helper no longer has any |
// registered observers. |
- infobar_manager->infobar_at(0)->RemoveSelf(); |
- EXPECT_EQ(0U, infobar_manager->infobar_count()); |
+ GetInfobarManager()->infobar_at(0)->RemoveSelf(); |
+ EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); |
EXPECT_FALSE(IsObservingSources()); |
} |