Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 2052633002: Extend the ToRenderFrameHost magic to FrameTreeNode* and Shell* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix induced script bug. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/macros.h" 5 #include "base/macros.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // See http://crbug.com/280512. 245 // See http://crbug.com/280512.
246 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 246 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
247 ClearNonVisiblePendingOnFail) { 247 ClearNonVisiblePendingOnFail) {
248 ASSERT_TRUE(embedded_test_server()->Start()); 248 ASSERT_TRUE(embedded_test_server()->Start());
249 249
250 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 250 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
251 251
252 // Navigate to an invalid URL and make sure it doesn't leave a pending entry. 252 // Navigate to an invalid URL and make sure it doesn't leave a pending entry.
253 LoadStopNotificationObserver load_observer1( 253 LoadStopNotificationObserver load_observer1(
254 &shell()->web_contents()->GetController()); 254 &shell()->web_contents()->GetController());
255 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 255 ASSERT_TRUE(
256 "window.location.href=\"nonexistent:12121\";")); 256 ExecuteScript(shell(), "window.location.href=\"nonexistent:12121\";"));
257 load_observer1.Wait(); 257 load_observer1.Wait();
258 EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry()); 258 EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry());
259 259
260 LoadStopNotificationObserver load_observer2( 260 LoadStopNotificationObserver load_observer2(
261 &shell()->web_contents()->GetController()); 261 &shell()->web_contents()->GetController());
262 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 262 ASSERT_TRUE(ExecuteScript(shell(), "window.location.href=\"#foo\";"));
263 "window.location.href=\"#foo\";"));
264 load_observer2.Wait(); 263 load_observer2.Wait();
265 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html#foo"), 264 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html#foo"),
266 shell()->web_contents()->GetVisibleURL()); 265 shell()->web_contents()->GetVisibleURL());
267 } 266 }
268 267
269 // Crashes under ThreadSanitizer, http://crbug.com/356758. 268 // Crashes under ThreadSanitizer, http://crbug.com/356758.
270 #if defined(OS_WIN) || defined(OS_ANDROID) \ 269 #if defined(OS_WIN) || defined(OS_ANDROID) \
271 || defined(THREAD_SANITIZER) 270 || defined(THREAD_SANITIZER)
272 #define MAYBE_GetSizeForNewRenderView DISABLED_GetSizeForNewRenderView 271 #define MAYBE_GetSizeForNewRenderView DISABLED_GetSizeForNewRenderView
273 #else 272 #else
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 394 }
396 395
397 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 396 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
398 AppendingFrameInWebUIDoesNotCrash) { 397 AppendingFrameInWebUIDoesNotCrash) {
399 const GURL kWebUIUrl("chrome://tracing"); 398 const GURL kWebUIUrl("chrome://tracing");
400 const char kJSCodeForAppendingFrame[] = 399 const char kJSCodeForAppendingFrame[] =
401 "document.body.appendChild(document.createElement('iframe'));"; 400 "document.body.appendChild(document.createElement('iframe'));";
402 401
403 NavigateToURL(shell(), kWebUIUrl); 402 NavigateToURL(shell(), kWebUIUrl);
404 403
405 bool js_executed = content::ExecuteScript(shell()->web_contents(), 404 bool js_executed = content::ExecuteScript(shell(), kJSCodeForAppendingFrame);
406 kJSCodeForAppendingFrame);
407 EXPECT_TRUE(js_executed); 405 EXPECT_TRUE(js_executed);
408 } 406 }
409 407
410 // Observer class to track the creation of RenderFrameHost objects. It is used 408 // Observer class to track the creation of RenderFrameHost objects. It is used
411 // in subsequent tests. 409 // in subsequent tests.
412 class RenderFrameCreatedObserver : public WebContentsObserver { 410 class RenderFrameCreatedObserver : public WebContentsObserver {
413 public: 411 public:
414 RenderFrameCreatedObserver(Shell* shell) 412 RenderFrameCreatedObserver(Shell* shell)
415 : WebContentsObserver(shell->web_contents()), 413 : WebContentsObserver(shell->web_contents()),
416 last_rfh_(NULL) { 414 last_rfh_(NULL) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 490 }
493 491
494 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 492 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
495 RenderViewCreatedForChildWindow) { 493 RenderViewCreatedForChildWindow) {
496 ASSERT_TRUE(embedded_test_server()->Start()); 494 ASSERT_TRUE(embedded_test_server()->Start());
497 495
498 NavigateToURL(shell(), 496 NavigateToURL(shell(),
499 embedded_test_server()->GetURL("/title1.html")); 497 embedded_test_server()->GetURL("/title1.html"));
500 498
501 WebContentsAddedObserver new_web_contents_observer; 499 WebContentsAddedObserver new_web_contents_observer;
502 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 500 ASSERT_TRUE(ExecuteScript(shell(),
503 "var a = document.createElement('a');" 501 "var a = document.createElement('a');"
504 "a.href='./title2.html';" 502 "a.href='./title2.html';"
505 "a.target = '_blank';" 503 "a.target = '_blank';"
506 "document.body.appendChild(a);" 504 "document.body.appendChild(a);"
507 "a.click();")); 505 "a.click();"));
508 WebContents* new_web_contents = new_web_contents_observer.GetWebContents(); 506 WebContents* new_web_contents = new_web_contents_observer.GetWebContents();
509 WaitForLoadStop(new_web_contents); 507 WaitForLoadStop(new_web_contents);
510 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled()); 508 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled());
511 } 509 }
512 510
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 690
693 } 691 }
694 692
695 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangeDisplayMode) { 693 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangeDisplayMode) {
696 ASSERT_TRUE(embedded_test_server()->Start()); 694 ASSERT_TRUE(embedded_test_server()->Start());
697 WebDisplayModeDelegate delegate(blink::WebDisplayModeMinimalUi); 695 WebDisplayModeDelegate delegate(blink::WebDisplayModeMinimalUi);
698 shell()->web_contents()->SetDelegate(&delegate); 696 shell()->web_contents()->SetDelegate(&delegate);
699 697
700 NavigateToURL(shell(), GURL("about://blank")); 698 NavigateToURL(shell(), GURL("about://blank"));
701 699
702 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 700 ASSERT_TRUE(ExecuteScript(shell(),
703 "document.title = " 701 "document.title = "
704 " window.matchMedia('(display-mode:" 702 " window.matchMedia('(display-mode:"
705 " minimal-ui)').matches")); 703 " minimal-ui)').matches"));
706 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); 704 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle());
707 705
708 delegate.set_mode(blink::WebDisplayModeFullscreen); 706 delegate.set_mode(blink::WebDisplayModeFullscreen);
709 // Simulate widget is entering fullscreen (changing size is enough). 707 // Simulate widget is entering fullscreen (changing size is enough).
710 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); 708 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized();
711 709
712 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 710 ASSERT_TRUE(ExecuteScript(shell(),
713 "document.title = " 711 "document.title = "
714 " window.matchMedia('(display-mode:" 712 " window.matchMedia('(display-mode:"
715 " fullscreen)').matches")); 713 " fullscreen)').matches"));
716 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); 714 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle());
717 } 715 }
718 716
719 // Observer class used to verify that WebContentsObservers are notified 717 // Observer class used to verify that WebContentsObservers are notified
720 // when the page scale factor changes. 718 // when the page scale factor changes.
721 // See WebContentsImplBrowserTest.ChangePageScale. 719 // See WebContentsImplBrowserTest.ChangePageScale.
722 class MockPageScaleObserver : public WebContentsObserver { 720 class MockPageScaleObserver : public WebContentsObserver {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { 850 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
853 ASSERT_TRUE(embedded_test_server()->Start()); 851 ASSERT_TRUE(embedded_test_server()->Start());
854 852
855 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); 853 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html");
856 EXPECT_TRUE(NavigateToURL(shell(), url)); 854 EXPECT_TRUE(NavigateToURL(shell(), url));
857 855
858 { 856 {
859 ShellAddedObserver new_shell_observer; 857 ShellAddedObserver new_shell_observer;
860 858
861 // Open a new, named window. 859 // Open a new, named window.
862 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 860 EXPECT_TRUE(
863 "window.open('about:blank','new_window');")); 861 ExecuteScript(shell(), "window.open('about:blank','new_window');"));
864 862
865 Shell* new_shell = new_shell_observer.GetShell(); 863 Shell* new_shell = new_shell_observer.GetShell();
866 WaitForLoadStop(new_shell->web_contents()); 864 WaitForLoadStop(new_shell->web_contents());
867 865
868 EXPECT_EQ("new_window", 866 EXPECT_EQ("new_window",
869 static_cast<WebContentsImpl*>(new_shell->web_contents()) 867 static_cast<WebContentsImpl*>(new_shell->web_contents())
870 ->GetFrameTree()->root()->frame_name()); 868 ->GetFrameTree()->root()->frame_name());
871 869
872 bool success = false; 870 bool success = false;
873 EXPECT_TRUE(ExecuteScriptAndExtractBool( 871 EXPECT_TRUE(ExecuteScriptAndExtractBool(
874 new_shell->web_contents(), 872 new_shell,
875 "window.domAutomationController.send(window.name == 'new_window');", 873 "window.domAutomationController.send(window.name == 'new_window');",
876 &success)); 874 &success));
877 EXPECT_TRUE(success); 875 EXPECT_TRUE(success);
878 } 876 }
879 877
880 { 878 {
881 ShellAddedObserver new_shell_observer; 879 ShellAddedObserver new_shell_observer;
882 880
883 // Test clicking a target=foo link. 881 // Test clicking a target=foo link.
884 bool success = false; 882 bool success = false;
885 EXPECT_TRUE(ExecuteScriptAndExtractBool( 883 EXPECT_TRUE(ExecuteScriptAndExtractBool(
886 shell()->web_contents(), 884 shell(),
887 "window.domAutomationController.send(clickSameSiteTargetedLink());", 885 "window.domAutomationController.send(clickSameSiteTargetedLink());",
888 &success)); 886 &success));
889 EXPECT_TRUE(success); 887 EXPECT_TRUE(success);
890 888
891 Shell* new_shell = new_shell_observer.GetShell(); 889 Shell* new_shell = new_shell_observer.GetShell();
892 WaitForLoadStop(new_shell->web_contents()); 890 WaitForLoadStop(new_shell->web_contents());
893 891
894 EXPECT_EQ("foo", 892 EXPECT_EQ("foo",
895 static_cast<WebContentsImpl*>(new_shell->web_contents()) 893 static_cast<WebContentsImpl*>(new_shell->web_contents())
896 ->GetFrameTree()->root()->frame_name()); 894 ->GetFrameTree()->root()->frame_name());
(...skipping 29 matching lines...) Expand all
926 cross_site_delayer.WaitForWillStartRequest(); 924 cross_site_delayer.WaitForWillStartRequest();
927 925
928 // Click on a link in the page. This will show the BeforeUnload dialog. 926 // Click on a link in the page. This will show the BeforeUnload dialog.
929 // Ensure the dialog is not dismissed, which will cause it to still be 927 // Ensure the dialog is not dismissed, which will cause it to still be
930 // present when the cross-site navigation later commits. 928 // present when the cross-site navigation later commits.
931 // Note: the javascript function executed will not do the link click but 929 // Note: the javascript function executed will not do the link click but
932 // schedule it for afterwards. Since the BeforeUnload event is synchronous, 930 // schedule it for afterwards. Since the BeforeUnload event is synchronous,
933 // clicking on the link right away would cause the ExecuteScript to never 931 // clicking on the link right away would cause the ExecuteScript to never
934 // return. 932 // return.
935 SetShouldProceedOnBeforeUnload(shell(), false); 933 SetShouldProceedOnBeforeUnload(shell(), false);
936 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "clickLinkSoon()")); 934 EXPECT_TRUE(ExecuteScript(shell(), "clickLinkSoon()"));
937 WaitForAppModalDialog(shell()); 935 WaitForAppModalDialog(shell());
938 936
939 // Have the cross-site navigation commit. The main RenderFrameHost should 937 // Have the cross-site navigation commit. The main RenderFrameHost should
940 // still be loading after that. 938 // still be loading after that.
941 cross_site_delayer.ResumeNavigation(); 939 cross_site_delayer.ResumeNavigation();
942 cross_site_delayer.WaitForNavigationFinished(); 940 cross_site_delayer.WaitForNavigationFinished();
943 EXPECT_TRUE(shell()->web_contents()->IsLoading()); 941 EXPECT_TRUE(shell()->web_contents()->IsLoading());
944 } 942 }
945 943
946 namespace { 944 namespace {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 // Check that pre-warmed process isn't used. 1161 // Check that pre-warmed process isn't used.
1164 EXPECT_NE(renderer_id, web_contents->GetRenderProcessHost()->GetID()); 1162 EXPECT_NE(renderer_id, web_contents->GetRenderProcessHost()->GetID());
1165 EXPECT_EQ(1, web_contents->GetController().GetEntryCount()); 1163 EXPECT_EQ(1, web_contents->GetController().GetEntryCount());
1166 NavigationEntry* entry = 1164 NavigationEntry* entry =
1167 web_contents->GetController().GetLastCommittedEntry(); 1165 web_contents->GetController().GetLastCommittedEntry();
1168 ASSERT_TRUE(entry); 1166 ASSERT_TRUE(entry);
1169 EXPECT_EQ(web_ui_url, entry->GetURL()); 1167 EXPECT_EQ(web_ui_url, entry->GetURL());
1170 } 1168 }
1171 1169
1172 } // namespace content 1170 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698