| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
| 7 #include "chrome/browser/download/download_prefs.h" | 7 #include "chrome/browser/download/download_prefs.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/safe_browsing/download_protection_service.h" | 9 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // html element with ID specified by |element_id|, and waits for | 177 // html element with ID specified by |element_id|, and waits for |
| 178 // |number_of_navigations| to complete. | 178 // |number_of_navigations| to complete. |
| 179 void ClickTestLink(const char* element_id, | 179 void ClickTestLink(const char* element_id, |
| 180 int number_of_navigations, | 180 int number_of_navigations, |
| 181 const GURL& page_url) { | 181 const GURL& page_url) { |
| 182 TabStripModel* tab_strip = browser()->tab_strip_model(); | 182 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 183 content::WebContents* current_web_contents = | 183 content::WebContents* current_web_contents = |
| 184 tab_strip->GetActiveWebContents(); | 184 tab_strip->GetActiveWebContents(); |
| 185 ASSERT_TRUE(content::WaitForLoadStop(current_web_contents)); | 185 ASSERT_TRUE(content::WaitForLoadStop(current_web_contents)); |
| 186 content::TestNavigationObserver navigation_observer( | 186 content::TestNavigationObserver navigation_observer( |
| 187 current_web_contents, | 187 current_web_contents, number_of_navigations, |
| 188 number_of_navigations); | 188 content::MessageLoopRunner::QuitMode::DEFERRED); |
| 189 navigation_observer.StartWatchingNewWebContents(); | 189 navigation_observer.StartWatchingNewWebContents(); |
| 190 // Execute test. | 190 // Execute test. |
| 191 std::string script = base::StringPrintf("clickLink('%s');", element_id); | 191 std::string script = base::StringPrintf("clickLink('%s');", element_id); |
| 192 ASSERT_TRUE(content::ExecuteScript(current_web_contents, script)); | 192 ASSERT_TRUE(content::ExecuteScript(current_web_contents, script)); |
| 193 // Wait for navigations on current tab and new tab (if any) to finish. | 193 // Wait for navigations on current tab and new tab (if any) to finish. |
| 194 navigation_observer.Wait(); | 194 navigation_observer.Wait(); |
| 195 navigation_observer.StopWatchingNewWebContents(); | 195 navigation_observer.StopWatchingNewWebContents(); |
| 196 | 196 |
| 197 // Since this test uses javascript to mimic clicking on a link (no actual | 197 // Since this test uses javascript to mimic clicking on a link (no actual |
| 198 // user gesture), and DidGetUserInteraction() does not respond to | 198 // user gesture), and DidGetUserInteraction() does not respond to |
| (...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 yesterday, embedded_test_server()->host_port_pair().host())); | 1761 yesterday, embedded_test_server()->host_port_pair().host())); |
| 1762 ASSERT_EQ(1U, ip_map->at(test_server_host).size()); | 1762 ASSERT_EQ(1U, ip_map->at(test_server_host).size()); |
| 1763 ClickTestLink("direct_download", 1, initial_url); | 1763 ClickTestLink("direct_download", 1, initial_url); |
| 1764 EXPECT_EQ(1U, ip_map->at(test_server_host).size()); | 1764 EXPECT_EQ(1U, ip_map->at(test_server_host).size()); |
| 1765 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), | 1765 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), |
| 1766 ip_map->at(test_server_host).back().ip); | 1766 ip_map->at(test_server_host).back().ip); |
| 1767 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp); | 1767 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp); |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 } // namespace safe_browsing | 1770 } // namespace safe_browsing |
| OLD | NEW |