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/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "content/browser/download/download_manager_impl.h" | 7 #include "content/browser/download/download_manager_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 base::Bind(&URLRequestFailedJob::AddUrlHandler)); | 40 base::Bind(&URLRequestFailedJob::AddUrlHandler)); |
41 } | 41 } |
42 | 42 |
43 virtual void OnDownloadCreated( | 43 virtual void OnDownloadCreated( |
44 DownloadManager* manager, | 44 DownloadManager* manager, |
45 DownloadItem* item) OVERRIDE { | 45 DownloadItem* item) OVERRIDE { |
46 if (!got_downloads_) | 46 if (!got_downloads_) |
47 got_downloads_ = !!manager->InProgressCount(); | 47 got_downloads_ = !!manager->InProgressCount(); |
48 } | 48 } |
49 | 49 |
50 RenderViewHost* render_view_host() { | |
51 return shell()->web_contents()->GetRenderViewHost(); | |
52 } | |
53 | |
54 GURL GetMockURL(const std::string& file) { | 50 GURL GetMockURL(const std::string& file) { |
55 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file)); | 51 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file)); |
56 } | 52 } |
57 | 53 |
58 void CheckTitleTest(const GURL& url, | 54 void CheckTitleTest(const GURL& url, |
59 const std::string& expected_title) { | 55 const std::string& expected_title) { |
60 string16 expected_title16(ASCIIToUTF16(expected_title)); | 56 string16 expected_title16(ASCIIToUTF16(expected_title)); |
61 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 57 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
62 NavigateToURL(shell(), url); | 58 NavigateToURL(shell(), url); |
63 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 59 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
64 } | 60 } |
65 | 61 |
66 bool GetPopupTitle(const GURL& url, string16* title) { | 62 bool GetPopupTitle(const GURL& url, string16* title) { |
67 NavigateToURL(shell(), url); | 63 NavigateToURL(shell(), url); |
68 | 64 |
69 ShellAddedObserver new_shell_observer; | 65 ShellAddedObserver new_shell_observer; |
70 | 66 |
71 // Create dynamic popup. | 67 // Create dynamic popup. |
72 if (!ExecuteJavaScript(render_view_host(), "", "OpenPopup();")) | 68 if (!ExecuteScript(shell()->web_contents(), "OpenPopup();")) |
73 return false; | 69 return false; |
74 | 70 |
75 Shell* new_shell = new_shell_observer.GetShell(); | 71 Shell* new_shell = new_shell_observer.GetShell(); |
76 *title = new_shell->web_contents()->GetTitle(); | 72 *title = new_shell->web_contents()->GetTitle(); |
77 return true; | 73 return true; |
78 } | 74 } |
79 | 75 |
80 std::string GetCookies(const GURL& url) { | 76 std::string GetCookies(const GURL& url) { |
81 return content::GetCookies( | 77 return content::GetCookies( |
82 shell()->web_contents()->GetBrowserContext(), url); | 78 shell()->web_contents()->GetBrowserContext(), url); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 154 } |
159 | 155 |
160 // Test for bug #1091358. | 156 // Test for bug #1091358. |
161 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { | 157 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { |
162 ASSERT_TRUE(test_server()->Start()); | 158 ASSERT_TRUE(test_server()->Start()); |
163 NavigateToURL( | 159 NavigateToURL( |
164 shell(), test_server()->GetURL("files/sync_xmlhttprequest.html")); | 160 shell(), test_server()->GetURL("files/sync_xmlhttprequest.html")); |
165 | 161 |
166 // Let's check the XMLHttpRequest ran successfully. | 162 // Let's check the XMLHttpRequest ran successfully. |
167 bool success = false; | 163 bool success = false; |
168 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 164 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
169 shell()->web_contents()->GetRenderViewHost(), | 165 shell()->web_contents(), |
170 "", | |
171 "window.domAutomationController.send(DidSyncRequestSucceed());", | 166 "window.domAutomationController.send(DidSyncRequestSucceed());", |
172 &success)); | 167 &success)); |
173 EXPECT_TRUE(success); | 168 EXPECT_TRUE(success); |
174 } | 169 } |
175 | 170 |
176 // If this flakes, use http://crbug.com/62776. | 171 // If this flakes, use http://crbug.com/62776. |
177 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 172 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
178 SyncXMLHttpRequest_Disallowed) { | 173 SyncXMLHttpRequest_Disallowed) { |
179 ASSERT_TRUE(test_server()->Start()); | 174 ASSERT_TRUE(test_server()->Start()); |
180 NavigateToURL( | 175 NavigateToURL( |
181 shell(), | 176 shell(), |
182 test_server()->GetURL("files/sync_xmlhttprequest_disallowed.html")); | 177 test_server()->GetURL("files/sync_xmlhttprequest_disallowed.html")); |
183 | 178 |
184 // Let's check the XMLHttpRequest ran successfully. | 179 // Let's check the XMLHttpRequest ran successfully. |
185 bool success = false; | 180 bool success = false; |
186 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 181 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
187 shell()->web_contents()->GetRenderViewHost(), | 182 shell()->web_contents(), |
188 "", | |
189 "window.domAutomationController.send(DidSucceed());", | 183 "window.domAutomationController.send(DidSucceed());", |
190 &success)); | 184 &success)); |
191 EXPECT_TRUE(success); | 185 EXPECT_TRUE(success); |
192 } | 186 } |
193 | 187 |
194 // Test for bug #1159553 -- A synchronous xhr (whose content-type is | 188 // Test for bug #1159553 -- A synchronous xhr (whose content-type is |
195 // downloadable) would trigger download and hang the renderer process, | 189 // downloadable) would trigger download and hang the renderer process, |
196 // if executed while navigating to a new page. | 190 // if executed while navigating to a new page. |
197 // If this flakes, use http://crbug.com/56264. | 191 // If this flakes, use http://crbug.com/56264. |
198 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 192 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // pages of which the error page is one. Instead, use automation to kick | 333 // pages of which the error page is one. Instead, use automation to kick |
340 // off the navigation, and wait to see that the tab loads. | 334 // off the navigation, and wait to see that the tab loads. |
341 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); | 335 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); |
342 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 336 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
343 | 337 |
344 bool success; | 338 bool success; |
345 GURL test_url(test_server()->GetURL("files/title2.html")); | 339 GURL test_url(test_server()->GetURL("files/title2.html")); |
346 std::string redirect_script = "window.location='" + | 340 std::string redirect_script = "window.location='" + |
347 test_url.possibly_invalid_spec() + "';" + | 341 test_url.possibly_invalid_spec() + "';" + |
348 "window.domAutomationController.send(true);"; | 342 "window.domAutomationController.send(true);"; |
349 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 343 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
350 shell()->web_contents()->GetRenderViewHost(), | 344 shell()->web_contents(), |
351 "", | |
352 redirect_script, | 345 redirect_script, |
353 &success)); | 346 &success)); |
354 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 347 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
355 } | 348 } |
356 | 349 |
357 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 350 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
358 CrossSiteNavigationErrorPage2) { | 351 CrossSiteNavigationErrorPage2) { |
359 ASSERT_TRUE(test_server()->Start()); | 352 ASSERT_TRUE(test_server()->Start()); |
360 | 353 |
361 GURL url(test_server()->GetURL("files/title2.html")); | 354 GURL url(test_server()->GetURL("files/title2.html")); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 CrossSiteFailedRequest) { | 391 CrossSiteFailedRequest) { |
399 // Visit another URL first to trigger a cross-site navigation. | 392 // Visit another URL first to trigger a cross-site navigation. |
400 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); | 393 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); |
401 | 394 |
402 // Visit a URL that fails without calling ResourceDispatcherHost::Read. | 395 // Visit a URL that fails without calling ResourceDispatcherHost::Read. |
403 GURL broken_url("chrome://theme"); | 396 GURL broken_url("chrome://theme"); |
404 NavigateToURL(shell(), broken_url); | 397 NavigateToURL(shell(), broken_url); |
405 } | 398 } |
406 | 399 |
407 } // namespace content | 400 } // namespace content |
OLD | NEW |