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 #import "ios/chrome/browser/web/blocked_popup_tab_helper.h" | 5 #import "ios/chrome/browser/web/blocked_popup_tab_helper.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "components/content_settings/core/browser/host_content_settings_map.h" | 8 #include "components/content_settings/core/browser/host_content_settings_map.h" |
9 #include "components/infobars/core/confirm_infobar_delegate.h" | 9 #include "components/infobars/core/confirm_infobar_delegate.h" |
10 #include "components/infobars/core/infobar.h" | 10 #include "components/infobars/core/infobar.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 web::Referrer referrer(source_url, web::ReferrerPolicyDefault); | 87 web::Referrer referrer(source_url, web::ReferrerPolicyDefault); |
88 __block bool show_popup_handler_was_called = false; | 88 __block bool show_popup_handler_was_called = false; |
89 web::BlockedPopupInfo popup_info(target_url, referrer, nil, ^{ | 89 web::BlockedPopupInfo popup_info(target_url, referrer, nil, ^{ |
90 show_popup_handler_was_called = true; | 90 show_popup_handler_was_called = true; |
91 }); | 91 }); |
92 GetBlockedPopupTabHelper()->HandlePopup(popup_info); | 92 GetBlockedPopupTabHelper()->HandlePopup(popup_info); |
93 | 93 |
94 // Allow blocked popup. | 94 // Allow blocked popup. |
95 ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); | 95 ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); |
96 infobars::InfoBar* infobar = GetInfobarManager()->infobar_at(0); | 96 infobars::InfoBar* infobar = GetInfobarManager()->infobar_at(0); |
97 auto delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); | 97 auto* delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); |
98 ASSERT_TRUE(delegate); | 98 ASSERT_TRUE(delegate); |
99 delegate->Accept(); | 99 delegate->Accept(); |
100 | 100 |
101 // Verify that handler was called and popups are allowed for |test_url|. | 101 // Verify that handler was called and popups are allowed for |test_url|. |
102 EXPECT_TRUE(show_popup_handler_was_called); | 102 EXPECT_TRUE(show_popup_handler_was_called); |
103 EXPECT_FALSE(GetBlockedPopupTabHelper()->ShouldBlockPopup(source_url)); | 103 EXPECT_FALSE(GetBlockedPopupTabHelper()->ShouldBlockPopup(source_url)); |
104 } | 104 } |
105 | 105 |
106 // Tests that an infobar is added to the infobar manager when | 106 // Tests that an infobar is added to the infobar manager when |
107 // BlockedPopupTabHelper::HandlePopup() is called. | 107 // BlockedPopupTabHelper::HandlePopup() is called. |
108 TEST_F(BlockedPopupTabHelperTest, ShowAndDismissInfoBar) { | 108 TEST_F(BlockedPopupTabHelperTest, ShowAndDismissInfoBar) { |
109 const GURL test_url("https://popups.example.com"); | 109 const GURL test_url("https://popups.example.com"); |
110 web::BlockedPopupInfo popup_info(test_url, web::Referrer(), nil, nil); | 110 web::BlockedPopupInfo popup_info(test_url, web::Referrer(), nil, nil); |
111 | 111 |
112 // Check that there are no infobars showing and no registered observers. | 112 // Check that there are no infobars showing and no registered observers. |
113 EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); | 113 EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); |
114 EXPECT_FALSE(IsObservingSources()); | 114 EXPECT_FALSE(IsObservingSources()); |
115 | 115 |
116 // Call |HandlePopup| to show an infobar. | 116 // Call |HandlePopup| to show an infobar. |
117 GetBlockedPopupTabHelper()->HandlePopup(popup_info); | 117 GetBlockedPopupTabHelper()->HandlePopup(popup_info); |
118 ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); | 118 ASSERT_EQ(1U, GetInfobarManager()->infobar_count()); |
119 EXPECT_TRUE(IsObservingSources()); | 119 EXPECT_TRUE(IsObservingSources()); |
120 | 120 |
121 // Dismiss the infobar and check that the tab helper no longer has any | 121 // Dismiss the infobar and check that the tab helper no longer has any |
122 // registered observers. | 122 // registered observers. |
123 GetInfobarManager()->infobar_at(0)->RemoveSelf(); | 123 GetInfobarManager()->infobar_at(0)->RemoveSelf(); |
124 EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); | 124 EXPECT_EQ(0U, GetInfobarManager()->infobar_count()); |
125 EXPECT_FALSE(IsObservingSources()); | 125 EXPECT_FALSE(IsObservingSources()); |
126 } | 126 } |
OLD | NEW |