| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 ui_test_utils::NavigateToURL(browser, url); | 70 ui_test_utils::NavigateToURL(browser, url); |
| 71 observer.Wait(); | 71 observer.Wait(); |
| 72 | 72 |
| 73 ASSERT_EQ(2u, chrome::GetBrowserCount(browser->profile(), | 73 ASSERT_EQ(2u, chrome::GetBrowserCount(browser->profile(), |
| 74 browser->host_desktop_type())); | 74 browser->host_desktop_type())); |
| 75 | 75 |
| 76 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); | 76 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); |
| 77 ASSERT_TRUE(blocked_contents.empty()); | 77 ASSERT_TRUE(blocked_contents.empty()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BasicTest(Browser* browser) { | 80 void BasicTest(Browser* browser, const GURL& url) { |
| 81 GURL url(GetTestURL()); | |
| 82 ui_test_utils::NavigateToURL(browser, url); | 81 ui_test_utils::NavigateToURL(browser, url); |
| 83 | 82 |
| 84 // If the popup blocker blocked the blank post, there should be only one | 83 // If the popup blocker blocked the blank post, there should be only one |
| 85 // tab in only one browser window and the URL of current tab must be equal | 84 // tab in only one browser window and the URL of current tab must be equal |
| 86 // to the original URL. | 85 // to the original URL. |
| 87 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile(), | 86 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile(), |
| 88 browser->host_desktop_type())); | 87 browser->host_desktop_type())); |
| 89 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 88 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| 90 WebContents* web_contents = | 89 WebContents* web_contents = |
| 91 browser->tab_strip_model()->GetActiveWebContents(); | 90 browser->tab_strip_model()->GetActiveWebContents(); |
| 92 EXPECT_EQ(url, web_contents->GetURL()); | 91 EXPECT_EQ(url, web_contents->GetURL()); |
| 93 | 92 |
| 94 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); | 93 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); |
| 95 ASSERT_EQ(1u, blocked_contents.size()); | 94 ASSERT_EQ(1u, blocked_contents.size()); |
| 96 | 95 |
| 97 content::WindowedNotificationObserver observer( | 96 content::WindowedNotificationObserver observer( |
| 98 chrome::NOTIFICATION_TAB_ADDED, | 97 chrome::NOTIFICATION_TAB_ADDED, |
| 99 content::NotificationService::AllSources()); | 98 content::NotificationService::AllSources()); |
| 100 | 99 |
| 101 BlockedContentTabHelper* blocked_content_tab_helper = | 100 BlockedContentTabHelper* blocked_content_tab_helper = |
| 102 BlockedContentTabHelper::FromWebContents(web_contents); | 101 BlockedContentTabHelper::FromWebContents(web_contents); |
| 103 blocked_content_tab_helper->LaunchForContents(blocked_contents[0]); | 102 blocked_content_tab_helper->LaunchForContents(blocked_contents[0]); |
| 104 | 103 |
| 105 observer.Wait(); | 104 observer.Wait(); |
| 106 } | 105 } |
| 107 }; | 106 }; |
| 108 | 107 |
| 109 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupBlockedPostBlank) { | 108 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupBlockedPostBlank) { |
| 110 BasicTest(browser()); | 109 BasicTest(browser(), GetTestURL()); |
| 111 } | 110 } |
| 112 | 111 |
| 113 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 112 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 114 PopupBlockedPostBlankIncognito) { | 113 PopupBlockedPostBlankIncognito) { |
| 115 BasicTest(CreateIncognitoBrowser()); | 114 BasicTest(CreateIncognitoBrowser(), GetTestURL()); |
| 115 } |
| 116 |
| 117 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupBlockedFakeClickOnAnchor) { |
| 118 GURL url(ui_test_utils::GetTestUrl( |
| 119 base::FilePath(kTestDir), |
| 120 base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor.html")))); |
| 121 BasicTest(browser(), url); |
| 116 } | 122 } |
| 117 | 123 |
| 118 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, MultiplePopups) { | 124 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, MultiplePopups) { |
| 119 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 125 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
| 120 kTestDir), base::FilePath(FILE_PATH_LITERAL("popup-many.html")))); | 126 kTestDir), base::FilePath(FILE_PATH_LITERAL("popup-many.html")))); |
| 121 ui_test_utils::NavigateToURL(browser(), url); | 127 ui_test_utils::NavigateToURL(browser(), url); |
| 122 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser()); | 128 std::vector<WebContents*> blocked_contents = GetBlockedContents(browser()); |
| 123 ASSERT_EQ(2u, blocked_contents.size()); | 129 ASSERT_EQ(2u, blocked_contents.size()); |
| 124 } | 130 } |
| 125 | 131 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 browser()->profile()); | 176 browser()->profile()); |
| 171 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 177 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 172 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 178 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
| 173 ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); | 179 ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); |
| 174 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); | 180 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); |
| 175 EXPECT_EQ(GURL(search_string), model->CurrentMatch().destination_url); | 181 EXPECT_EQ(GURL(search_string), model->CurrentMatch().destination_url); |
| 176 EXPECT_EQ(ASCIIToUTF16(search_string), model->CurrentMatch().contents); | 182 EXPECT_EQ(ASCIIToUTF16(search_string), model->CurrentMatch().contents); |
| 177 } | 183 } |
| 178 | 184 |
| 179 } // namespace | 185 } // namespace |
| OLD | NEW |