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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl_browsertest.cc

Issue 2541063002: Revert of Remove about:srcdoc url conversion. (Closed)
Patch Set: Created 4 years 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 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 "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 #include "content/browser/web_contents/web_contents_impl.h" 6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/browser/web_contents.h" 7 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_contents_observer.h" 8 #include "content/public/browser/web_contents_observer.h"
9 #include "content/public/common/request_context_type.h" 9 #include "content/public/common/request_context_type.h"
10 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
(...skipping 18 matching lines...) Expand all
29 NavigationHandleObserver(WebContents* web_contents, 29 NavigationHandleObserver(WebContents* web_contents,
30 const GURL& expected_start_url) 30 const GURL& expected_start_url)
31 : WebContentsObserver(web_contents), 31 : WebContentsObserver(web_contents),
32 handle_(nullptr), 32 handle_(nullptr),
33 has_committed_(false), 33 has_committed_(false),
34 is_error_(false), 34 is_error_(false),
35 is_main_frame_(false), 35 is_main_frame_(false),
36 is_parent_main_frame_(false), 36 is_parent_main_frame_(false),
37 is_renderer_initiated_(true), 37 is_renderer_initiated_(true),
38 is_same_page_(false), 38 is_same_page_(false),
39 is_srcdoc_(false),
39 was_redirected_(false), 40 was_redirected_(false),
40 frame_tree_node_id_(-1), 41 frame_tree_node_id_(-1),
41 page_transition_(ui::PAGE_TRANSITION_LINK), 42 page_transition_(ui::PAGE_TRANSITION_LINK),
42 expected_start_url_(expected_start_url) {} 43 expected_start_url_(expected_start_url) {}
43 44
44 void DidStartNavigation(NavigationHandle* navigation_handle) override { 45 void DidStartNavigation(NavigationHandle* navigation_handle) override {
45 if (handle_ || navigation_handle->GetURL() != expected_start_url_) 46 if (handle_ || navigation_handle->GetURL() != expected_start_url_)
46 return; 47 return;
47 48
48 handle_ = navigation_handle; 49 handle_ = navigation_handle;
49 has_committed_ = false; 50 has_committed_ = false;
50 is_error_ = false; 51 is_error_ = false;
51 page_transition_ = ui::PAGE_TRANSITION_LINK; 52 page_transition_ = ui::PAGE_TRANSITION_LINK;
52 last_committed_url_ = GURL(); 53 last_committed_url_ = GURL();
53 54
54 is_main_frame_ = navigation_handle->IsInMainFrame(); 55 is_main_frame_ = navigation_handle->IsInMainFrame();
55 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); 56 is_parent_main_frame_ = navigation_handle->IsParentMainFrame();
56 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); 57 is_renderer_initiated_ = navigation_handle->IsRendererInitiated();
57 is_same_page_ = navigation_handle->IsSamePage(); 58 is_same_page_ = navigation_handle->IsSamePage();
59 is_srcdoc_ = navigation_handle->IsSrcdoc();
58 was_redirected_ = navigation_handle->WasServerRedirect(); 60 was_redirected_ = navigation_handle->WasServerRedirect();
59 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); 61 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId();
60 } 62 }
61 63
62 void DidFinishNavigation(NavigationHandle* navigation_handle) override { 64 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
63 if (navigation_handle != handle_) 65 if (navigation_handle != handle_)
64 return; 66 return;
65 67
66 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); 68 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame());
67 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); 69 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame());
68 DCHECK_EQ(is_same_page_, navigation_handle->IsSamePage()); 70 DCHECK_EQ(is_same_page_, navigation_handle->IsSamePage());
69 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); 71 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated());
72 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc());
70 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); 73 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId());
71 74
72 was_redirected_ = navigation_handle->WasServerRedirect(); 75 was_redirected_ = navigation_handle->WasServerRedirect();
73 76
74 if (navigation_handle->HasCommitted()) { 77 if (navigation_handle->HasCommitted()) {
75 has_committed_ = true; 78 has_committed_ = true;
76 if (!navigation_handle->IsErrorPage()) { 79 if (!navigation_handle->IsErrorPage()) {
77 page_transition_ = navigation_handle->GetPageTransition(); 80 page_transition_ = navigation_handle->GetPageTransition();
78 last_committed_url_ = navigation_handle->GetURL(); 81 last_committed_url_ = navigation_handle->GetURL();
79 } else { 82 } else {
80 is_error_ = true; 83 is_error_ = true;
81 } 84 }
82 } else { 85 } else {
83 has_committed_ = false; 86 has_committed_ = false;
84 is_error_ = true; 87 is_error_ = true;
85 } 88 }
86 89
87 handle_ = nullptr; 90 handle_ = nullptr;
88 } 91 }
89 92
90 bool has_committed() { return has_committed_; } 93 bool has_committed() { return has_committed_; }
91 bool is_error() { return is_error_; } 94 bool is_error() { return is_error_; }
92 bool is_main_frame() { return is_main_frame_; } 95 bool is_main_frame() { return is_main_frame_; }
93 bool is_parent_main_frame() { return is_parent_main_frame_; } 96 bool is_parent_main_frame() { return is_parent_main_frame_; }
94 bool is_renderer_initiated() { return is_renderer_initiated_; } 97 bool is_renderer_initiated() { return is_renderer_initiated_; }
95 bool is_same_page() { return is_same_page_; } 98 bool is_same_page() { return is_same_page_; }
99 bool is_srcdoc() { return is_srcdoc_; }
96 bool was_redirected() { return was_redirected_; } 100 bool was_redirected() { return was_redirected_; }
97 int frame_tree_node_id() { return frame_tree_node_id_; } 101 int frame_tree_node_id() { return frame_tree_node_id_; }
98 102
99 const GURL& last_committed_url() { return last_committed_url_; } 103 const GURL& last_committed_url() { return last_committed_url_; }
100 104
101 ui::PageTransition page_transition() { return page_transition_; } 105 ui::PageTransition page_transition() { return page_transition_; }
102 106
103 private: 107 private:
104 // A reference to the NavigationHandle so this class will track only 108 // A reference to the NavigationHandle so this class will track only
105 // one navigation at a time. It is set at DidStartNavigation and cleared 109 // one navigation at a time. It is set at DidStartNavigation and cleared
106 // at DidFinishNavigation before the NavigationHandle is destroyed. 110 // at DidFinishNavigation before the NavigationHandle is destroyed.
107 NavigationHandle* handle_; 111 NavigationHandle* handle_;
108 bool has_committed_; 112 bool has_committed_;
109 bool is_error_; 113 bool is_error_;
110 bool is_main_frame_; 114 bool is_main_frame_;
111 bool is_parent_main_frame_; 115 bool is_parent_main_frame_;
112 bool is_renderer_initiated_; 116 bool is_renderer_initiated_;
113 bool is_same_page_; 117 bool is_same_page_;
118 bool is_srcdoc_;
114 bool was_redirected_; 119 bool was_redirected_;
115 int frame_tree_node_id_; 120 int frame_tree_node_id_;
116 ui::PageTransition page_transition_; 121 ui::PageTransition page_transition_;
117 GURL expected_start_url_; 122 GURL expected_start_url_;
118 GURL last_committed_url_; 123 GURL last_committed_url_;
119 }; 124 };
120 125
121 // A test NavigationThrottle that will return pre-determined checks and run 126 // A test NavigationThrottle that will return pre-determined checks and run
122 // callbacks when the various NavigationThrottle methods are called. It is 127 // callbacks when the various NavigationThrottle methods are called. It is
123 // not instantiated directly but through a TestNavigationThrottleInstaller. 128 // not instantiated directly but through a TestNavigationThrottleInstaller.
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 embedded_test_server()->GetURL("a.com", "/bar")); 497 embedded_test_server()->GetURL("a.com", "/bar"));
493 EXPECT_TRUE(ExecuteScript(root->child_at(0), 498 EXPECT_TRUE(ExecuteScript(root->child_at(0),
494 "window.history.pushState({}, '', 'bar');")); 499 "window.history.pushState({}, '', 'bar');"));
495 500
496 EXPECT_TRUE(observer.has_committed()); 501 EXPECT_TRUE(observer.has_committed());
497 EXPECT_FALSE(observer.is_error()); 502 EXPECT_FALSE(observer.is_error());
498 EXPECT_TRUE(observer.is_renderer_initiated()); 503 EXPECT_TRUE(observer.is_renderer_initiated());
499 } 504 }
500 } 505 }
501 506
502 // Ensure that methods on NavigationHandle behave correctly with an iframe that 507 // Ensure that the IsSrcdoc() method on NavigationHandle behaves correctly.
503 // navigates to its srcdoc attribute.
504 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) { 508 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) {
505 GURL url(embedded_test_server()->GetURL( 509 GURL url(embedded_test_server()->GetURL(
506 "/frame_tree/page_with_srcdoc_frame.html")); 510 "/frame_tree/page_with_srcdoc_frame.html"));
507 NavigationHandleObserver observer(shell()->web_contents(), 511 NavigationHandleObserver observer(shell()->web_contents(),
508 GURL(kAboutSrcDocURL)); 512 GURL(url::kAboutBlankURL));
509 513
510 EXPECT_TRUE(NavigateToURL(shell(), url)); 514 EXPECT_TRUE(NavigateToURL(shell(), url));
511 515
512 EXPECT_TRUE(observer.has_committed()); 516 EXPECT_TRUE(observer.has_committed());
513 EXPECT_FALSE(observer.is_error()); 517 EXPECT_FALSE(observer.is_error());
514 EXPECT_EQ(GURL(kAboutSrcDocURL), observer.last_committed_url()); 518 EXPECT_TRUE(observer.is_srcdoc());
515 } 519 }
516 520
517 // Ensure that the IsSamePage() method on NavigationHandle behaves correctly. 521 // Ensure that the IsSamePage() method on NavigationHandle behaves correctly.
518 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySamePage) { 522 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySamePage) {
519 GURL url(embedded_test_server()->GetURL( 523 GURL url(embedded_test_server()->GetURL(
520 "a.com", "/cross_site_iframe_factory.html?a(a())")); 524 "a.com", "/cross_site_iframe_factory.html?a(a())"));
521 EXPECT_TRUE(NavigateToURL(shell(), url)); 525 EXPECT_TRUE(NavigateToURL(shell(), url));
522 526
523 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 527 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
524 ->GetFrameTree() 528 ->GetFrameTree()
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, 902 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest,
899 StartUrlIsHttpsUpgradedCrossSite) { 903 StartUrlIsHttpsUpgradedCrossSite) {
900 GURL start_url( 904 GURL start_url(
901 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); 905 embedded_test_server()->GetURL("/https_upgrade_cross_site.html"));
902 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); 906 GURL cross_site_iframe_secure_url("https://other.com/title1.html");
903 907
904 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); 908 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url);
905 } 909 }
906 910
907 } // namespace content 911 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698