Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7239)

Unified Diff: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc

Issue 20924002: Try to restore window.opener when opening blocked popups (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
diff --git a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
index 525c4d1a320e63f37762d724b1e52ec4ae8411f6..114bb992825e318f61b62a1d2935fbf6d82b1d20 100644
--- a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
+++ b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
@@ -228,6 +228,63 @@ class BetterPopupBlockerBrowserTest : public PopupBlockerBrowserTest {
InProcessBrowserTest::SetUpCommandLine(command_line);
}
+ // Navigates to the test indicated by |test_name| which is expected to try to
+ // open a popup. Verifies that the popup was blocked and then opens the
+ // blocked popup. Once the popup stopped loading, verifies that the title of
+ // the page is "PASS".
+ //
+ // If |expect_new_browser| is true, the popup is expected to open a new
+ // window, or a background tab if it is false.
+ void RunCheckTest(const base::FilePath& test_name, bool expect_new_browser) {
+ GURL url(ui_test_utils::GetTestUrl(base::FilePath(kTestDir), test_name));
+
+ CountRenderViewHosts counter;
+
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Since the popup blocker blocked the window.open, there should be only one
+ // tab.
+ EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
+ browser()->host_desktop_type()));
+ EXPECT_EQ(1, browser()->tab_strip_model()->count());
+ WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_EQ(url, web_contents->GetURL());
+
+ // And no new RVH created.
+ EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount());
+
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+ ui_test_utils::BrowserAddedObserver browser_observer;
+
+ // Launch the blocked popup.
+ PopupBlockerTabHelper* popup_blocker_helper =
+ PopupBlockerTabHelper::FromWebContents(web_contents);
+ EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount());
+ std::map<int32, GURL> blocked_requests =
+ popup_blocker_helper->GetBlockedPopupRequests();
+ std::map<int32, GURL>::const_iterator iter = blocked_requests.begin();
+ popup_blocker_helper->ShowBlockedPopup(iter->first);
+
+ observer.Wait();
+ Browser* new_browser;
+ if (expect_new_browser) {
+ new_browser = browser_observer.WaitForSingleNewBrowser();
+ web_contents = new_browser->tab_strip_model()->GetActiveWebContents();
+ } else {
+ new_browser = browser();
+ EXPECT_EQ(2, browser()->tab_strip_model()->count());
+ web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
+ }
+
+ // Check that the check passed.
+ base::string16 expected_title(base::ASCIIToUTF16("PASS"));
+ content::TitleWatcher title_watcher(web_contents, expected_title);
+ EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(BetterPopupBlockerBrowserTest);
};
@@ -369,91 +426,26 @@ IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeatures) {
}
IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, CorrectReferrer) {
- GURL url(ui_test_utils::GetTestUrl(
- base::FilePath(kTestDir),
- base::FilePath(FILE_PATH_LITERAL("popup-referrer.html"))));
-
- CountRenderViewHosts counter;
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- // If the popup blocker blocked the blank post, there should be only one tab.
- EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
- browser()->host_desktop_type()));
- EXPECT_EQ(1, browser()->tab_strip_model()->count());
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- EXPECT_EQ(url, web_contents->GetURL());
-
- // And no new RVH created.
- EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount());
-
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_TAB_ADDED,
- content::NotificationService::AllSources());
- ui_test_utils::BrowserAddedObserver browser_observer;
-
- // Launch the blocked popup.
- PopupBlockerTabHelper* popup_blocker_helper =
- PopupBlockerTabHelper::FromWebContents(web_contents);
- EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount());
- std::map<int32, GURL> blocked_requests =
- popup_blocker_helper->GetBlockedPopupRequests();
- std::map<int32, GURL>::const_iterator iter = blocked_requests.begin();
- popup_blocker_helper->ShowBlockedPopup(iter->first);
-
- observer.Wait();
- Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
-
- // Check that the referrer was correctly set.
- web_contents = new_browser->tab_strip_model()->GetActiveWebContents();
- base::string16 expected_title(base::ASCIIToUTF16("PASS"));
- content::TitleWatcher title_watcher(web_contents, expected_title);
- EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
+ RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-referrer.html")), true);
}
IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeaturesBarProps) {
- GURL url(ui_test_utils::GetTestUrl(
- base::FilePath(kTestDir),
- base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html"))));
-
- CountRenderViewHosts counter;
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- // If the popup blocker blocked the blank post, there should be only one tab.
- EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
- browser()->host_desktop_type()));
- EXPECT_EQ(1, browser()->tab_strip_model()->count());
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- EXPECT_EQ(url, web_contents->GetURL());
-
- // And no new RVH created.
- EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount());
-
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_TAB_ADDED,
- content::NotificationService::AllSources());
- ui_test_utils::BrowserAddedObserver browser_observer;
+ RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html")),
+ true);
+}
- // Launch the blocked popup.
- PopupBlockerTabHelper* popup_blocker_helper =
- PopupBlockerTabHelper::FromWebContents(web_contents);
- EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount());
- std::map<int32, GURL> blocked_requests =
- popup_blocker_helper->GetBlockedPopupRequests();
- std::map<int32, GURL>::const_iterator iter = blocked_requests.begin();
- popup_blocker_helper->ShowBlockedPopup(iter->first);
+IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, SessionStorage) {
+ RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-sessionstorage.html")),
+ true);
+}
- observer.Wait();
- Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
+IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, Opener) {
+ RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-opener.html")), true);
+}
- // Check that the referrer was correctly set.
- web_contents = new_browser->tab_strip_model()->GetActiveWebContents();
- base::string16 expected_title(base::ASCIIToUTF16("PASS"));
- content::TitleWatcher title_watcher(web_contents, expected_title);
- EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
+IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, OpenerSuppressed) {
+ RunCheckTest(
+ base::FilePath(FILE_PATH_LITERAL("popup-openersuppressed.html")), false);
}
} // namespace
« no previous file with comments | « no previous file | chrome/browser/ui/blocked_content/popup_blocker_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698