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

Side by Side Diff: chrome/browser/chrome_navigation_browsertest.cc

Issue 2501083004: Fix View Frame Source for iframe of a file:// URL shows main frame's filename (Closed)
Patch Set: Adding a browsertest Created 4 years, 1 month 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/app/chrome_command_ids.h" 6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "components/url_formatter/url_formatter.h"
15 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/navigation_handle.h" 16 #include "content/public/browser/navigation_handle.h"
14 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/context_menu_params.h" 20 #include "content/public/common/context_menu_params.h"
21 #include "content/public/common/url_constants.h"
17 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/test_navigation_observer.h" 23 #include "content/public/test/test_navigation_observer.h"
19 #include "net/dns/mock_host_resolver.h" 24 #include "net/dns/mock_host_resolver.h"
20 25
21 class ChromeNavigationBrowserTest : public InProcessBrowserTest { 26 class ChromeNavigationBrowserTest : public InProcessBrowserTest {
22 public: 27 public:
23 ChromeNavigationBrowserTest() {} 28 ChromeNavigationBrowserTest() {}
24 ~ChromeNavigationBrowserTest() override {} 29 ~ChromeNavigationBrowserTest() override {}
25 30
26 void SetUpCommandLine(base::CommandLine* command_line) override { 31 void SetUpCommandLine(base::CommandLine* command_line) override {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 DidStartNavigationObserver nav_observer(new_web_contents); 130 DidStartNavigationObserver nav_observer(new_web_contents);
126 EXPECT_TRUE(content::ExecuteScript( 131 EXPECT_TRUE(content::ExecuteScript(
127 main_web_contents, "navigate('" + error_url.spec() + "');")); 132 main_web_contents, "navigate('" + error_url.spec() + "');"));
128 nav_observer.Wait(); 133 nav_observer.Wait();
129 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL()); 134 EXPECT_EQ(error_url, new_web_contents->GetVisibleURL());
130 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry()); 135 EXPECT_TRUE(new_web_contents->GetController().GetTransientEntry());
131 EXPECT_FALSE(new_web_contents->IsLoading()); 136 EXPECT_FALSE(new_web_contents->IsLoading());
132 } 137 }
133 } 138 }
134 139
140 // Tests that viewing frame source on a local file:// page with an iframe
141 // with a remote URL shows the correct tab title.
142 IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, TestViewFrameSource) {
143 StartServerWithExpiredCert();
Charlie Reis 2016/11/23 23:52:20 Why do you need an expired cert? The test above o
afakhry 2016/11/24 01:21:08 Sorry, that was a copy-paste line.
144
145 // The local page file:// URL.
146 GURL local_page_with_iframe_url = ui_test_utils::GetTestUrl(
147 base::FilePath(base::FilePath::kCurrentDirectory),
148 base::FilePath(FILE_PATH_LITERAL("iframe.html")));
149
150 // The non-file:// URL of the page to load in the iframe.
151 GURL iframe_target_url = embedded_test_server()->GetURL("/title1.html");
152 ui_test_utils::NavigateToURL(browser(), local_page_with_iframe_url);
153 content::WebContents* web_contents =
154 browser()->tab_strip_model()->GetActiveWebContents();
155
156 content::TestNavigationManager nav(web_contents, iframe_target_url);
Charlie Reis 2016/11/23 23:52:20 It looks like a TestNavigationObserver might be a
afakhry 2016/11/24 01:21:09 Done.
157 ASSERT_TRUE(content::ExecuteScript(
158 web_contents->GetMainFrame(),
159 base::StringPrintf("var iframe = document.getElementById('test');\n"
160 "iframe.setAttribute('src', '%s');\n",
161 iframe_target_url.spec().c_str())));
162 nav.WaitForNavigationFinished();
163 WaitForLoadStop(web_contents);
Charlie Reis 2016/11/23 23:52:20 I don't think we need this line (especially if we
afakhry 2016/11/24 01:21:09 Done.
164
165 content::RenderFrameHost* frame =
166 content::ChildFrameAt(web_contents->GetMainFrame(), 0);
167 ASSERT_TRUE(frame);
168 ASSERT_NE(frame, web_contents->GetMainFrame());
169
170 content::ContextMenuParams params;
171 params.page_url = local_page_with_iframe_url;
172 params.frame_url = frame->GetLastCommittedURL();
173 params.frame_page_state = content::PageState::CreateFromURL(params.frame_url);
174 TestRenderViewContextMenu menu(frame, params);
175 menu.Init();
176 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE, 0);
177 ASSERT_EQ(browser()->tab_strip_model()->count(), 2);
178 content::WebContents* new_web_contents =
179 browser()->tab_strip_model()->GetWebContentsAt(1);
180 ASSERT_NE(new_web_contents, web_contents);
181 WaitForLoadStop(new_web_contents);
182
183 GURL view_frame_source_url(
184 content::kViewSourceScheme + std::string(":") +
185 embedded_test_server()->GetURL("/title1.html").spec());
Charlie Reis 2016/11/23 23:52:20 Use iframe_target_url here?
afakhry 2016/11/24 01:21:08 Done.
186 EXPECT_EQ(url_formatter::FormatUrl(view_frame_source_url),
187 new_web_contents->GetTitle());
188 }
189
135 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { 190 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest {
136 public: 191 public:
137 ChromeNavigationPortMappedBrowserTest() {} 192 ChromeNavigationPortMappedBrowserTest() {}
138 ~ChromeNavigationPortMappedBrowserTest() override {} 193 ~ChromeNavigationPortMappedBrowserTest() override {}
139 194
140 void SetUpCommandLine(base::CommandLine* command_line) override { 195 void SetUpCommandLine(base::CommandLine* command_line) override {
141 ASSERT_TRUE(embedded_test_server()->Start()); 196 ASSERT_TRUE(embedded_test_server()->Start());
142 197
143 // Use the command line parameter for the host resolver, so URLs without 198 // Use the command line parameter for the host resolver, so URLs without
144 // explicit port numbers can be mapped under the hood to the port number 199 // explicit port numbers can be mapped under the hood to the port number
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 browser()->tab_strip_model()->GetWebContentsAt( 248 browser()->tab_strip_model()->GetWebContentsAt(
194 browser()->tab_strip_model()->count() - 1); 249 browser()->tab_strip_model()->count() - 1);
195 WaitForLoadStop(new_web_contents); 250 WaitForLoadStop(new_web_contents);
196 251
197 // If the test is unsuccessful, the return value from GetLastCommittedURL 252 // If the test is unsuccessful, the return value from GetLastCommittedURL
198 // will be the virtual URL for the created NavigationEntry. 253 // will be the virtual URL for the created NavigationEntry.
199 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme 254 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme
200 // prepended and one less ":" character after the host. 255 // prepended and one less ":" character after the host.
201 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); 256 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL());
202 } 257 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser_commands.cc » ('j') | chrome/browser/ui/browser_commands.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698