OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 void NavigateAndCheckPopupShown(const GURL& url, | 174 void NavigateAndCheckPopupShown(const GURL& url, |
175 WhatToExpect what_to_expect) { | 175 WhatToExpect what_to_expect) { |
176 content::WindowedNotificationObserver observer( | 176 content::WindowedNotificationObserver observer( |
177 chrome::NOTIFICATION_TAB_ADDED, | 177 chrome::NOTIFICATION_TAB_ADDED, |
178 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
179 ui_test_utils::NavigateToURL(browser(), url); | 179 ui_test_utils::NavigateToURL(browser(), url); |
180 observer.Wait(); | 180 observer.Wait(); |
181 | 181 |
182 if (what_to_expect == ExpectPopup) { | 182 if (what_to_expect == ExpectPopup) { |
183 ASSERT_EQ(2u, | 183 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); |
184 chrome::GetBrowserCount(browser()->profile(), | |
185 browser()->host_desktop_type())); | |
186 } else { | 184 } else { |
187 ASSERT_EQ(1u, | 185 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
188 chrome::GetBrowserCount(browser()->profile(), | |
189 browser()->host_desktop_type())); | |
190 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 186 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
191 | 187 |
192 // Check that we always create foreground tabs. | 188 // Check that we always create foreground tabs. |
193 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | 189 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
194 } | 190 } |
195 | 191 |
196 ASSERT_EQ(0, GetBlockedContentsCount()); | 192 ASSERT_EQ(0, GetBlockedContentsCount()); |
197 } | 193 } |
198 | 194 |
199 // Navigates to the test indicated by |test_name| using |browser| which is | 195 // Navigates to the test indicated by |test_name| using |browser| which is |
(...skipping 10 matching lines...) Expand all Loading... |
210 WhatToExpect what_to_expect, | 206 WhatToExpect what_to_expect, |
211 ShouldCheckTitle check_title) { | 207 ShouldCheckTitle check_title) { |
212 GURL url(embedded_test_server()->GetURL(test_name)); | 208 GURL url(embedded_test_server()->GetURL(test_name)); |
213 | 209 |
214 CountRenderViewHosts counter; | 210 CountRenderViewHosts counter; |
215 | 211 |
216 ui_test_utils::NavigateToURL(browser, url); | 212 ui_test_utils::NavigateToURL(browser, url); |
217 | 213 |
218 // Since the popup blocker blocked the window.open, there should be only one | 214 // Since the popup blocker blocked the window.open, there should be only one |
219 // tab. | 215 // tab. |
220 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile(), | 216 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
221 browser->host_desktop_type())); | |
222 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 217 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
223 WebContents* web_contents = | 218 WebContents* web_contents = |
224 browser->tab_strip_model()->GetActiveWebContents(); | 219 browser->tab_strip_model()->GetActiveWebContents(); |
225 EXPECT_EQ(url, web_contents->GetURL()); | 220 EXPECT_EQ(url, web_contents->GetURL()); |
226 | 221 |
227 // And no new RVH created. | 222 // And no new RVH created. |
228 EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); | 223 EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); |
229 | 224 |
230 content::WindowedNotificationObserver observer( | 225 content::WindowedNotificationObserver observer( |
231 chrome::NOTIFICATION_TAB_ADDED, | 226 chrome::NOTIFICATION_TAB_ADDED, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 545 |
551 GURL url( | 546 GURL url( |
552 embedded_test_server()->GetURL("/popup_blocker/popup-on-unload.html")); | 547 embedded_test_server()->GetURL("/popup_blocker/popup-on-unload.html")); |
553 ui_test_utils::NavigateToURL(browser(), url); | 548 ui_test_utils::NavigateToURL(browser(), url); |
554 | 549 |
555 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 550 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
556 | 551 |
557 tab->GetController().GoBack(); | 552 tab->GetController().GoBack(); |
558 content::WaitForLoadStop(tab); | 553 content::WaitForLoadStop(tab); |
559 | 554 |
560 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 555 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
561 browser()->host_desktop_type())); | |
562 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 556 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
563 | 557 |
564 // The popup from the unload event handler should not show up for about:blank. | 558 // The popup from the unload event handler should not show up for about:blank. |
565 ASSERT_EQ(0, GetBlockedContentsCount()); | 559 ASSERT_EQ(0, GetBlockedContentsCount()); |
566 } | 560 } |
567 | 561 |
568 // Verify that app modal prompts can't be used to create pop unders. | 562 // Verify that app modal prompts can't be used to create pop unders. |
569 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { | 563 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) { |
570 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 564 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
571 GURL url( | 565 GURL url( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::OS_LEFT), | 665 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::OS_LEFT), |
672 modifiers); | 666 modifiers); |
673 #else | 667 #else |
674 InjectRawKeyEvent( | 668 InjectRawKeyEvent( |
675 tab, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL, | 669 tab, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL, |
676 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), | 670 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), |
677 modifiers); | 671 modifiers); |
678 #endif | 672 #endif |
679 wait_for_new_tab.Wait(); | 673 wait_for_new_tab.Wait(); |
680 | 674 |
681 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 675 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
682 browser()->host_desktop_type())); | |
683 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 676 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
684 // Check that we create the background tab. | 677 // Check that we create the background tab. |
685 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 678 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
686 } | 679 } |
687 | 680 |
688 // Tests that the tapping gesture with cntl/cmd key on a link open the | 681 // Tests that the tapping gesture with cntl/cmd key on a link open the |
689 // backgournd tab. | 682 // backgournd tab. |
690 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, TapGestureWithCtrlKey) { | 683 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, TapGestureWithCtrlKey) { |
691 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 684 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
692 | 685 |
693 GURL url(embedded_test_server()->GetURL( | 686 GURL url(embedded_test_server()->GetURL( |
694 "/popup_blocker/popup-simulated-click-on-anchor2.html")); | 687 "/popup_blocker/popup-simulated-click-on-anchor2.html")); |
695 ui_test_utils::NavigateToURL(browser(), url); | 688 ui_test_utils::NavigateToURL(browser(), url); |
696 | 689 |
697 content::WindowedNotificationObserver wait_for_new_tab( | 690 content::WindowedNotificationObserver wait_for_new_tab( |
698 chrome::NOTIFICATION_TAB_ADDED, | 691 chrome::NOTIFICATION_TAB_ADDED, |
699 content::NotificationService::AllSources()); | 692 content::NotificationService::AllSources()); |
700 | 693 |
701 #if defined(OS_MACOSX) | 694 #if defined(OS_MACOSX) |
702 unsigned modifiers = blink::WebInputEvent::MetaKey; | 695 unsigned modifiers = blink::WebInputEvent::MetaKey; |
703 #else | 696 #else |
704 unsigned modifiers = blink::WebInputEvent::ControlKey; | 697 unsigned modifiers = blink::WebInputEvent::ControlKey; |
705 #endif | 698 #endif |
706 content::SimulateTapWithModifiersAt(tab, modifiers, gfx::Point(350, 250)); | 699 content::SimulateTapWithModifiersAt(tab, modifiers, gfx::Point(350, 250)); |
707 | 700 |
708 wait_for_new_tab.Wait(); | 701 wait_for_new_tab.Wait(); |
709 | 702 |
710 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 703 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
711 browser()->host_desktop_type())); | |
712 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 704 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
713 // Check that we create the background tab. | 705 // Check that we create the background tab. |
714 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 706 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
715 } | 707 } |
716 | 708 |
717 } // namespace | 709 } // namespace |
OLD | NEW |