| OLD | NEW |
| 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 Loading... |
| 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 // The local page file:// URL. |
| 144 GURL local_page_with_iframe_url = ui_test_utils::GetTestUrl( |
| 145 base::FilePath(base::FilePath::kCurrentDirectory), |
| 146 base::FilePath(FILE_PATH_LITERAL("iframe.html"))); |
| 147 |
| 148 // The non-file:// URL of the page to load in the iframe. |
| 149 GURL iframe_target_url = embedded_test_server()->GetURL("/title1.html"); |
| 150 ui_test_utils::NavigateToURL(browser(), local_page_with_iframe_url); |
| 151 content::WebContents* web_contents = |
| 152 browser()->tab_strip_model()->GetActiveWebContents(); |
| 153 |
| 154 content::TestNavigationObserver observer(web_contents); |
| 155 ASSERT_TRUE(content::ExecuteScript( |
| 156 web_contents->GetMainFrame(), |
| 157 base::StringPrintf("var iframe = document.getElementById('test');\n" |
| 158 "iframe.setAttribute('src', '%s');\n", |
| 159 iframe_target_url.spec().c_str()))); |
| 160 observer.Wait(); |
| 161 |
| 162 content::RenderFrameHost* frame = |
| 163 content::ChildFrameAt(web_contents->GetMainFrame(), 0); |
| 164 ASSERT_TRUE(frame); |
| 165 ASSERT_NE(frame, web_contents->GetMainFrame()); |
| 166 |
| 167 content::ContextMenuParams params; |
| 168 params.page_url = local_page_with_iframe_url; |
| 169 params.frame_url = frame->GetLastCommittedURL(); |
| 170 params.frame_page_state = content::PageState::CreateFromURL(params.frame_url); |
| 171 TestRenderViewContextMenu menu(frame, params); |
| 172 menu.Init(); |
| 173 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE, 0); |
| 174 ASSERT_EQ(browser()->tab_strip_model()->count(), 2); |
| 175 content::WebContents* new_web_contents = |
| 176 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 177 ASSERT_NE(new_web_contents, web_contents); |
| 178 WaitForLoadStop(new_web_contents); |
| 179 |
| 180 GURL view_frame_source_url(content::kViewSourceScheme + std::string(":") + |
| 181 iframe_target_url.spec()); |
| 182 EXPECT_EQ(url_formatter::FormatUrl(view_frame_source_url), |
| 183 new_web_contents->GetTitle()); |
| 184 } |
| 185 |
| 135 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 186 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 136 public: | 187 public: |
| 137 ChromeNavigationPortMappedBrowserTest() {} | 188 ChromeNavigationPortMappedBrowserTest() {} |
| 138 ~ChromeNavigationPortMappedBrowserTest() override {} | 189 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 139 | 190 |
| 140 void SetUpCommandLine(base::CommandLine* command_line) override { | 191 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 141 ASSERT_TRUE(embedded_test_server()->Start()); | 192 ASSERT_TRUE(embedded_test_server()->Start()); |
| 142 | 193 |
| 143 // Use the command line parameter for the host resolver, so URLs without | 194 // 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 | 195 // 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 Loading... |
| 193 browser()->tab_strip_model()->GetWebContentsAt( | 244 browser()->tab_strip_model()->GetWebContentsAt( |
| 194 browser()->tab_strip_model()->count() - 1); | 245 browser()->tab_strip_model()->count() - 1); |
| 195 WaitForLoadStop(new_web_contents); | 246 WaitForLoadStop(new_web_contents); |
| 196 | 247 |
| 197 // If the test is unsuccessful, the return value from GetLastCommittedURL | 248 // If the test is unsuccessful, the return value from GetLastCommittedURL |
| 198 // will be the virtual URL for the created NavigationEntry. | 249 // 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 | 250 // 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. | 251 // prepended and one less ":" character after the host. |
| 201 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); | 252 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); |
| 202 } | 253 } |
| OLD | NEW |