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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/download/download_manager_impl.h" | 8 #include "content/browser/download/download_manager_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 got_downloads_ = !!manager->InProgressCount(); | 52 got_downloads_ = !!manager->InProgressCount(); |
53 } | 53 } |
54 | 54 |
55 GURL GetMockURL(const std::string& file) { | 55 GURL GetMockURL(const std::string& file) { |
56 return URLRequestMockHTTPJob::GetMockUrl( | 56 return URLRequestMockHTTPJob::GetMockUrl( |
57 base::FilePath().AppendASCII(file)); | 57 base::FilePath().AppendASCII(file)); |
58 } | 58 } |
59 | 59 |
60 void CheckTitleTest(const GURL& url, | 60 void CheckTitleTest(const GURL& url, |
61 const std::string& expected_title) { | 61 const std::string& expected_title) { |
62 string16 expected_title16(ASCIIToUTF16(expected_title)); | 62 base::string16 expected_title16(ASCIIToUTF16(expected_title)); |
63 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 63 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
64 NavigateToURL(shell(), url); | 64 NavigateToURL(shell(), url); |
65 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 65 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
66 } | 66 } |
67 | 67 |
68 bool GetPopupTitle(const GURL& url, string16* title) { | 68 bool GetPopupTitle(const GURL& url, base::string16* title) { |
69 NavigateToURL(shell(), url); | 69 NavigateToURL(shell(), url); |
70 | 70 |
71 ShellAddedObserver new_shell_observer; | 71 ShellAddedObserver new_shell_observer; |
72 | 72 |
73 // Create dynamic popup. | 73 // Create dynamic popup. |
74 if (!ExecuteScript(shell()->web_contents(), "OpenPopup();")) | 74 if (!ExecuteScript(shell()->web_contents(), "OpenPopup();")) |
75 return false; | 75 return false; |
76 | 76 |
77 Shell* new_shell = new_shell_observer.GetShell(); | 77 Shell* new_shell = new_shell_observer.GetShell(); |
78 *title = new_shell->web_contents()->GetTitle(); | 78 *title = new_shell->web_contents()->GetTitle(); |
(...skipping 10 matching lines...) Expand all Loading... |
89 private: | 89 private: |
90 bool got_downloads_; | 90 bool got_downloads_; |
91 }; | 91 }; |
92 | 92 |
93 // Test title for content created by javascript window.open(). | 93 // Test title for content created by javascript window.open(). |
94 // See http://crbug.com/5988 | 94 // See http://crbug.com/5988 |
95 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle1) { | 95 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle1) { |
96 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 96 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
97 | 97 |
98 GURL url(embedded_test_server()->GetURL("/dynamic1.html")); | 98 GURL url(embedded_test_server()->GetURL("/dynamic1.html")); |
99 string16 title; | 99 base::string16 title; |
100 ASSERT_TRUE(GetPopupTitle(url, &title)); | 100 ASSERT_TRUE(GetPopupTitle(url, &title)); |
101 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Popup Title"), true)) | 101 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Popup Title"), true)) |
102 << "Actual title: " << title; | 102 << "Actual title: " << title; |
103 } | 103 } |
104 | 104 |
105 // Test title for content created by javascript window.open(). | 105 // Test title for content created by javascript window.open(). |
106 // See http://crbug.com/5988 | 106 // See http://crbug.com/5988 |
107 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle2) { | 107 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle2) { |
108 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 108 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
109 | 109 |
110 GURL url(embedded_test_server()->GetURL("/dynamic2.html")); | 110 GURL url(embedded_test_server()->GetURL("/dynamic2.html")); |
111 string16 title; | 111 base::string16 title; |
112 ASSERT_TRUE(GetPopupTitle(url, &title)); | 112 ASSERT_TRUE(GetPopupTitle(url, &title)); |
113 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Dynamic Title"), true)) | 113 EXPECT_TRUE(StartsWith(title, ASCIIToUTF16("My Dynamic Title"), true)) |
114 << "Actual title: " << title; | 114 << "Actual title: " << title; |
115 } | 115 } |
116 | 116 |
117 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 117 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
118 SniffHTMLWithNoContentType) { | 118 SniffHTMLWithNoContentType) { |
119 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), | 119 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), |
120 "Content Sniffer Test 0"); | 120 "Content Sniffer Test 0"); |
121 } | 121 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 357 |
358 // Check that renderer-initiated navigations still work. In a previous bug, | 358 // Check that renderer-initiated navigations still work. In a previous bug, |
359 // the ResourceDispatcherHost would think that such navigations were | 359 // the ResourceDispatcherHost would think that such navigations were |
360 // cross-site, because we didn't clean up from the previous request. Since | 360 // cross-site, because we didn't clean up from the previous request. Since |
361 // WebContentsImpl was in the NORMAL state, it would ignore the attempt to run | 361 // WebContentsImpl was in the NORMAL state, it would ignore the attempt to run |
362 // the onunload handler, and the navigation would fail. We can't test by | 362 // the onunload handler, and the navigation would fail. We can't test by |
363 // redirecting to javascript:window.location='someURL', since javascript: | 363 // redirecting to javascript:window.location='someURL', since javascript: |
364 // URLs are prohibited by policy from interacting with sensitive chrome | 364 // URLs are prohibited by policy from interacting with sensitive chrome |
365 // pages of which the error page is one. Instead, use automation to kick | 365 // pages of which the error page is one. Instead, use automation to kick |
366 // off the navigation, and wait to see that the tab loads. | 366 // off the navigation, and wait to see that the tab loads. |
367 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); | 367 base::string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); |
368 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 368 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
369 | 369 |
370 bool success; | 370 bool success; |
371 GURL test_url(embedded_test_server()->GetURL("/title2.html")); | 371 GURL test_url(embedded_test_server()->GetURL("/title2.html")); |
372 std::string redirect_script = "window.location='" + | 372 std::string redirect_script = "window.location='" + |
373 test_url.possibly_invalid_spec() + "';" + | 373 test_url.possibly_invalid_spec() + "';" + |
374 "window.domAutomationController.send(true);"; | 374 "window.domAutomationController.send(true);"; |
375 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 375 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
376 shell()->web_contents(), | 376 shell()->web_contents(), |
377 redirect_script, | 377 redirect_script, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 "http://localhost:%d/set_cookie.html", embedded_test_server()->port())); | 458 "http://localhost:%d/set_cookie.html", embedded_test_server()->port())); |
459 GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url)); | 459 GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url)); |
460 | 460 |
461 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 461 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
462 ShellNetworkDelegate::SetAcceptAllCookies(false); | 462 ShellNetworkDelegate::SetAcceptAllCookies(false); |
463 | 463 |
464 CheckTitleTest(url, "cookie set"); | 464 CheckTitleTest(url, "cookie set"); |
465 } | 465 } |
466 | 466 |
467 } // namespace content | 467 } // namespace content |
OLD | NEW |