| OLD | NEW |
| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} | 75 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} |
| 76 | 76 |
| 77 void set_should_create_webui(bool should_create_webui) { | 77 void set_should_create_webui(bool should_create_webui) { |
| 78 should_create_webui_ = should_create_webui; | 78 should_create_webui_ = should_create_webui; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // WebUIFactory implementation. | 81 // WebUIFactory implementation. |
| 82 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, | 82 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
| 83 const GURL& url) const override { | 83 const GURL& url) const override { |
| 84 if (!(should_create_webui_ && HasWebUIScheme(url))) | 84 // If WebUI creation is enabled for the test and this is a WebUI URL, |
| 85 return NULL; | 85 // returns a new instance. |
| 86 return new WebUIController(web_ui); | 86 if (should_create_webui_ && HasWebUIScheme(url)) |
| 87 return new WebUIController(web_ui); |
| 88 return nullptr; |
| 87 } | 89 } |
| 88 | 90 |
| 89 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 91 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 90 const GURL& url) const override { | 92 const GURL& url) const override { |
| 93 // If WebUI creation is enabled for the test and this is a WebUI URL, |
| 94 // returns a mock WebUI type. |
| 95 if (should_create_webui_ && HasWebUIScheme(url)) { |
| 96 return const_cast<RenderFrameHostManagerTestWebUIControllerFactory*>( |
| 97 this); |
| 98 } |
| 91 return WebUI::kNoWebUI; | 99 return WebUI::kNoWebUI; |
| 92 } | 100 } |
| 93 | 101 |
| 94 bool UseWebUIForURL(BrowserContext* browser_context, | 102 bool UseWebUIForURL(BrowserContext* browser_context, |
| 95 const GURL& url) const override { | 103 const GURL& url) const override { |
| 96 return HasWebUIScheme(url); | 104 return HasWebUIScheme(url); |
| 97 } | 105 } |
| 98 | 106 |
| 99 bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 107 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 100 const GURL& url) const override { | 108 const GURL& url) const override { |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 | 1117 |
| 1110 // It's important that the SiteInstance get set on the Web UI page as soon | 1118 // It's important that the SiteInstance get set on the Web UI page as soon |
| 1111 // as the navigation starts, rather than lazily after it commits, so we don't | 1119 // as the navigation starts, rather than lazily after it commits, so we don't |
| 1112 // try to re-use the SiteInstance/process for non Web UI things that may | 1120 // try to re-use the SiteInstance/process for non Web UI things that may |
| 1113 // get loaded in between. | 1121 // get loaded in between. |
| 1114 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1122 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1115 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 1123 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
| 1116 | 1124 |
| 1117 // The Web UI is committed immediately because the RenderViewHost has not been | 1125 // The Web UI is committed immediately because the RenderViewHost has not been |
| 1118 // used yet. UpdateStateForNavigate() took the short cut path. | 1126 // used yet. UpdateStateForNavigate() took the short cut path. |
| 1119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1127 EXPECT_FALSE(manager->GetNavigatingWebUI()); |
| 1120 switches::kEnableBrowserSideNavigation)) { | |
| 1121 EXPECT_FALSE(manager->speculative_web_ui()); | |
| 1122 } else { | |
| 1123 EXPECT_FALSE(manager->pending_web_ui()); | |
| 1124 } | |
| 1125 EXPECT_TRUE(manager->web_ui()); | 1128 EXPECT_TRUE(manager->web_ui()); |
| 1126 | 1129 |
| 1127 // Commit. | 1130 // Commit. |
| 1128 manager->DidNavigateFrame(host, true); | 1131 manager->DidNavigateFrame(host, true); |
| 1129 EXPECT_TRUE( | 1132 EXPECT_TRUE( |
| 1130 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1133 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1131 } | 1134 } |
| 1132 | 1135 |
| 1133 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1136 // Tests that we can open a WebUI link in a new tab from a WebUI page and still |
| 1134 // grant the correct bindings. http://crbug.com/189101. | 1137 // grant the correct bindings. http://crbug.com/189101. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 const GURL kUrl2("chrome://foo/bar"); | 1187 const GURL kUrl2("chrome://foo/bar"); |
| 1185 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1188 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1186 Referrer(), base::string16() /* title */, | 1189 Referrer(), base::string16() /* title */, |
| 1187 ui::PAGE_TRANSITION_LINK, | 1190 ui::PAGE_TRANSITION_LINK, |
| 1188 true /* is_renderer_init */); | 1191 true /* is_renderer_init */); |
| 1189 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); | 1192 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
| 1190 | 1193 |
| 1191 // No cross-process transition happens because we are already in the right | 1194 // No cross-process transition happens because we are already in the right |
| 1192 // SiteInstance. We should grant bindings immediately. | 1195 // SiteInstance. We should grant bindings immediately. |
| 1193 EXPECT_EQ(host2, manager2->current_frame_host()); | 1196 EXPECT_EQ(host2, manager2->current_frame_host()); |
| 1194 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1197 EXPECT_TRUE(manager2->GetNavigatingWebUI()); |
| 1195 switches::kEnableBrowserSideNavigation)) { | |
| 1196 EXPECT_TRUE(manager2->speculative_web_ui()); | |
| 1197 } else { | |
| 1198 EXPECT_TRUE(manager2->pending_web_ui()); | |
| 1199 } | |
| 1200 EXPECT_TRUE( | 1198 EXPECT_TRUE( |
| 1201 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1199 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1202 | 1200 |
| 1203 manager2->DidNavigateFrame(host2, true); | 1201 manager2->DidNavigateFrame(host2, true); |
| 1204 } | 1202 } |
| 1205 | 1203 |
| 1206 // Tests that a WebUI is correctly reused between chrome:// pages. | 1204 // Tests that a WebUI is correctly reused between chrome:// pages. |
| 1207 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { | 1205 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { |
| 1208 set_should_create_webui(true); | 1206 set_should_create_webui(true); |
| 1209 | 1207 |
| (...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2656 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); | 2654 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); |
| 2657 EXPECT_TRUE(proxy); | 2655 EXPECT_TRUE(proxy); |
| 2658 | 2656 |
| 2659 // Since the B->C navigation happened while the current page was focused, | 2657 // Since the B->C navigation happened while the current page was focused, |
| 2660 // page focus should propagate to the new subframe process. Check that | 2658 // page focus should propagate to the new subframe process. Check that |
| 2661 // process C received the proper focus message. | 2659 // process C received the proper focus message. |
| 2662 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); | 2660 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); |
| 2663 } | 2661 } |
| 2664 | 2662 |
| 2665 } // namespace content | 2663 } // namespace content |
| OLD | NEW |