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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
10 #include "content/browser/web_contents/interstitial_page_impl.h" | 10 #include "content/browser/web_contents/interstitial_page_impl.h" |
11 #include "content/browser/web_contents/navigation_entry_impl.h" | 11 #include "content/browser/web_contents/navigation_entry_impl.h" |
12 #include "content/browser/web_contents/test_web_contents.h" | 12 #include "content/browser/web_contents/test_web_contents.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/public/browser/interstitial_page_delegate.h" | 14 #include "content/public/browser/interstitial_page_delegate.h" |
15 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
20 #include "content/public/browser/web_contents_observer.h" | |
20 #include "content/public/browser/web_ui_controller.h" | 21 #include "content/public/browser/web_ui_controller.h" |
21 #include "content/public/browser/web_ui_controller_factory.h" | 22 #include "content/public/browser/web_ui_controller_factory.h" |
22 #include "content/public/common/bindings_policy.h" | 23 #include "content/public/common/bindings_policy.h" |
23 #include "content/public/common/content_constants.h" | 24 #include "content/public/common/content_constants.h" |
24 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
25 #include "content/public/test/mock_render_process_host.h" | 26 #include "content/public/test/mock_render_process_host.h" |
26 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
28 #include "content/test/test_content_browser_client.h" | 29 #include "content/test/test_content_browser_client.h" |
29 #include "content/test/test_content_client.h" | 30 #include "content/test/test_content_client.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 private: | 286 private: |
286 WebContentsImplTestContentClient client_; | 287 WebContentsImplTestContentClient client_; |
287 WebContentsImplTestBrowserClient browser_client_; | 288 WebContentsImplTestBrowserClient browser_client_; |
288 ContentClient* old_client_; | 289 ContentClient* old_client_; |
289 ContentBrowserClient* old_browser_client_; | 290 ContentBrowserClient* old_browser_client_; |
290 TestBrowserThread ui_thread_; | 291 TestBrowserThread ui_thread_; |
291 TestBrowserThread file_user_blocking_thread_; | 292 TestBrowserThread file_user_blocking_thread_; |
292 TestBrowserThread io_thread_; | 293 TestBrowserThread io_thread_; |
293 }; | 294 }; |
294 | 295 |
296 class TestWebContentsObserver : public WebContentsObserver { | |
297 public: | |
298 TestWebContentsObserver(WebContents* contents) | |
299 : WebContentsObserver(contents) { | |
300 } | |
301 virtual ~TestWebContentsObserver() {} | |
302 | |
303 virtual void DidFinishLoad(int64 frame_id, | |
304 const GURL& validated_url, | |
305 bool is_main_frame, | |
306 RenderViewHost* render_view_host) OVERRIDE { | |
307 last_url_ = validated_url; | |
308 } | |
309 virtual void DidFailLoad(int64 frame_id, | |
310 const GURL& validated_url, | |
311 bool is_main_frame, | |
312 int error_code, | |
313 const string16& error_description, | |
314 RenderViewHost* render_view_host) OVERRIDE { | |
315 last_url_ = validated_url; | |
316 } | |
317 | |
318 const GURL& last_url() const { return last_url_; } | |
319 | |
320 private: | |
321 GURL last_url_; | |
322 | |
323 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); | |
324 }; | |
325 | |
295 } // namespace | 326 } // namespace |
296 | 327 |
297 // Test to make sure that title updates get stripped of whitespace. | 328 // Test to make sure that title updates get stripped of whitespace. |
298 TEST_F(WebContentsImplTest, UpdateTitle) { | 329 TEST_F(WebContentsImplTest, UpdateTitle) { |
299 NavigationControllerImpl& cont = | 330 NavigationControllerImpl& cont = |
300 static_cast<NavigationControllerImpl&>(controller()); | 331 static_cast<NavigationControllerImpl&>(controller()); |
301 ViewHostMsg_FrameNavigate_Params params; | 332 ViewHostMsg_FrameNavigate_Params params; |
302 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), | 333 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), |
303 PAGE_TRANSITION_TYPED); | 334 PAGE_TRANSITION_TYPED); |
304 | 335 |
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1942 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1973 EXPECT_TRUE(other_controller.GetTransientEntry()); |
1943 | 1974 |
1944 // And the interstitial should be showing. | 1975 // And the interstitial should be showing. |
1945 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | 1976 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); |
1946 | 1977 |
1947 // And the interstitial should do a reload on don't proceed. | 1978 // And the interstitial should do a reload on don't proceed. |
1948 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( | 1979 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( |
1949 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); | 1980 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); |
1950 } | 1981 } |
1951 | 1982 |
1983 // Regression test for http://crbug.com/168611 - the URLs passed by the | |
1984 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered. | |
1985 TEST_F(WebContentsImplTest, FilterURLs) { | |
1986 TestWebContentsObserver observer(contents()); | |
1987 | |
1988 // A navigation to about:whatever should always look like a navigation to | |
Charlie Reis
2013/01/07 20:58:46
I got a bit confused by this comment, since you're
jochen (gone - plz use gerrit)
2013/01/07 21:11:59
Clarified the comment
| |
1989 // about:blank | |
1990 GURL url_normalized("about:blank"); | |
1991 GURL url_from_ipc("about:whatever"); | |
1992 contents()->NavigateAndCommit(url_normalized); | |
1993 | |
1994 // Check that an IPC with about:whatever is correctly normalized. | |
1995 contents()->TestDidFinishLoad(1, url_from_ipc, true); | |
1996 | |
1997 EXPECT_EQ(url_normalized, observer.last_url()); | |
1998 | |
1999 // Create and navigate another WebContents. | |
2000 scoped_ptr<TestWebContents> other_contents( | |
2001 static_cast<TestWebContents*>(CreateTestWebContents())); | |
2002 TestWebContentsObserver other_observer(other_contents.get()); | |
2003 other_contents->NavigateAndCommit(url_normalized); | |
2004 | |
2005 // Check that an IPC with about:whatever is correctly normalized. | |
2006 other_contents->TestDidFailLoadWithError( | |
2007 1, url_from_ipc, true, 1, string16()); | |
2008 EXPECT_EQ(url_normalized, other_observer.last_url()); | |
2009 } | |
2010 | |
2011 | |
1952 } // namespace content | 2012 } // namespace content |
OLD | NEW |