Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
| 31 #include "content/public/browser/web_ui_controller.h" | 31 #include "content/public/browser/web_ui_controller.h" |
| 32 #include "content/public/common/bindings_policy.h" | 32 #include "content/public/common/bindings_policy.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/javascript_message_type.h" | 34 #include "content/public/common/javascript_message_type.h" |
| 35 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
| 36 #include "content/public/common/url_utils.h" | 36 #include "content/public/common/url_utils.h" |
| 37 #include "content/public/test/mock_render_process_host.h" | 37 #include "content/public/test/mock_render_process_host.h" |
| 38 #include "content/public/test/test_notification_tracker.h" | 38 #include "content/public/test/test_notification_tracker.h" |
| 39 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
| 40 #include "content/test/browser_side_navigation_test_utils.h" | |
| 40 #include "content/test/test_content_browser_client.h" | 41 #include "content/test/test_content_browser_client.h" |
| 41 #include "content/test/test_content_client.h" | 42 #include "content/test/test_content_client.h" |
| 42 #include "content/test/test_render_frame_host.h" | 43 #include "content/test/test_render_frame_host.h" |
| 43 #include "content/test/test_render_view_host.h" | 44 #include "content/test/test_render_view_host.h" |
| 44 #include "content/test/test_web_contents.h" | 45 #include "content/test/test_web_contents.h" |
| 45 #include "net/base/load_flags.h" | 46 #include "net/base/load_flags.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 48 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 48 #include "ui/base/page_transition_types.h" | 49 #include "ui/base/page_transition_types.h" |
| 49 | 50 |
| 50 namespace content { | 51 namespace content { |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 class RenderFrameHostManagerTestWebUIControllerFactory | 54 class RenderFrameHostManagerTestWebUIControllerFactory |
| 54 : public WebUIControllerFactory { | 55 : public WebUIControllerFactory { |
| 55 public: | 56 public: |
| 56 RenderFrameHostManagerTestWebUIControllerFactory() | 57 RenderFrameHostManagerTestWebUIControllerFactory() |
| 57 : should_create_webui_(false) { | 58 : should_create_webui_(false), type_(1) { |
| 59 CHECK_NE(reinterpret_cast<void*>(type_), WebUI::kNoWebUI); | |
| 58 } | 60 } |
| 59 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} | 61 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} |
| 60 | 62 |
| 61 void set_should_create_webui(bool should_create_webui) { | 63 void set_should_create_webui(bool should_create_webui) { |
| 62 should_create_webui_ = should_create_webui; | 64 should_create_webui_ = should_create_webui; |
| 63 } | 65 } |
| 64 | 66 |
| 67 void set_webui_type(int type) { | |
| 68 CHECK_NE(reinterpret_cast<void*>(type), WebUI::kNoWebUI); | |
| 69 type_ = type; | |
| 70 } | |
| 71 | |
| 65 // WebUIFactory implementation. | 72 // WebUIFactory implementation. |
| 66 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, | 73 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
| 67 const GURL& url) const override { | 74 const GURL& url) const override { |
| 68 // If WebUI creation is enabled for the test and this is a WebUI URL, | 75 // If WebUI creation is enabled for the test and this is a WebUI URL, |
| 69 // returns a new instance. | 76 // returns a new instance. |
| 70 if (should_create_webui_ && HasWebUIScheme(url)) | 77 if (should_create_webui_ && HasWebUIScheme(url)) |
| 71 return new WebUIController(web_ui); | 78 return new WebUIController(web_ui); |
| 72 return nullptr; | 79 return nullptr; |
| 73 } | 80 } |
| 74 | 81 |
| 75 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 82 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 76 const GURL& url) const override { | 83 const GURL& url) const override { |
| 77 // If WebUI creation is enabled for the test and this is a WebUI URL, | 84 // If WebUI creation is enabled for the test and this is a WebUI URL, |
| 78 // returns a mock WebUI type. | 85 // returns a mock WebUI type. |
| 79 if (should_create_webui_ && HasWebUIScheme(url)) { | 86 if (should_create_webui_ && HasWebUIScheme(url)) { |
| 80 return const_cast<RenderFrameHostManagerTestWebUIControllerFactory*>( | 87 // WebUI::TypeID values are void pointers to structures each factory knows |
| 81 this); | 88 // are unique to their respective cases. So these return values should be |
| 89 // safe if very low values are used (just above zero). | |
| 90 return reinterpret_cast<void*>(type_); | |
|
clamy
2015/10/21 16:54:22
If you want to cast back and from a pointer, you s
carlosk
2015/10/22 13:36:19
Done for using uintptr_t.
But, as I tried to expl
| |
| 82 } | 91 } |
| 83 return WebUI::kNoWebUI; | 92 return WebUI::kNoWebUI; |
| 84 } | 93 } |
| 85 | 94 |
| 86 bool UseWebUIForURL(BrowserContext* browser_context, | 95 bool UseWebUIForURL(BrowserContext* browser_context, |
| 87 const GURL& url) const override { | 96 const GURL& url) const override { |
| 88 return HasWebUIScheme(url); | 97 return HasWebUIScheme(url); |
| 89 } | 98 } |
| 90 | 99 |
| 91 bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 100 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 92 const GURL& url) const override { | 101 const GURL& url) const override { |
| 93 return HasWebUIScheme(url); | 102 return HasWebUIScheme(url); |
| 94 } | 103 } |
| 95 | 104 |
| 96 private: | 105 private: |
| 97 bool should_create_webui_; | 106 bool should_create_webui_; |
| 107 int type_; | |
| 98 | 108 |
| 99 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); | 109 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); |
| 100 }; | 110 }; |
| 101 | 111 |
| 102 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { | 112 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { |
| 103 public: | 113 public: |
| 104 BeforeUnloadFiredWebContentsDelegate() {} | 114 BeforeUnloadFiredWebContentsDelegate() {} |
| 105 ~BeforeUnloadFiredWebContentsDelegate() override {} | 115 ~BeforeUnloadFiredWebContentsDelegate() override {} |
| 106 | 116 |
| 107 void BeforeUnloadFired(WebContents* web_contents, | 117 void BeforeUnloadFired(WebContents* web_contents, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it | 275 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it |
| 266 // must be shut down before the ImageTransportFactory. | 276 // must be shut down before the ImageTransportFactory. |
| 267 ImageTransportFactory::Terminate(); | 277 ImageTransportFactory::Terminate(); |
| 268 #endif | 278 #endif |
| 269 } | 279 } |
| 270 | 280 |
| 271 void set_should_create_webui(bool should_create_webui) { | 281 void set_should_create_webui(bool should_create_webui) { |
| 272 factory_.set_should_create_webui(should_create_webui); | 282 factory_.set_should_create_webui(should_create_webui); |
| 273 } | 283 } |
| 274 | 284 |
| 285 void set_webui_type(int type) { factory_.set_webui_type(type); } | |
| 286 | |
| 275 void NavigateActiveAndCommit(const GURL& url) { | 287 void NavigateActiveAndCommit(const GURL& url) { |
| 276 // Note: we navigate the active RenderFrameHost because previous navigations | 288 // Note: we navigate the active RenderFrameHost because previous navigations |
| 277 // won't have committed yet, so NavigateAndCommit does the wrong thing | 289 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 278 // for us. | 290 // for us. |
| 279 controller().LoadURL( | 291 controller().LoadURL( |
| 280 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 292 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 281 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 293 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 282 | 294 |
| 283 // Simulate the BeforeUnload_ACK that is received from the current renderer | 295 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 284 // for a cross-site navigation. | 296 // for a cross-site navigation. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 // Tests currently only navigate using main frame FrameNavigationEntries. | 414 // Tests currently only navigate using main frame FrameNavigationEntries. |
| 403 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | 415 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); |
| 404 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 416 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 405 switches::kEnableBrowserSideNavigation)) { | 417 switches::kEnableBrowserSideNavigation)) { |
| 406 scoped_ptr<NavigationRequest> navigation_request = | 418 scoped_ptr<NavigationRequest> navigation_request = |
| 407 NavigationRequest::CreateBrowserInitiated( | 419 NavigationRequest::CreateBrowserInitiated( |
| 408 manager->frame_tree_node_, frame_entry->url(), | 420 manager->frame_tree_node_, frame_entry->url(), |
| 409 frame_entry->referrer(), *frame_entry, entry, | 421 frame_entry->referrer(), *frame_entry, entry, |
| 410 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | 422 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), |
| 411 static_cast<NavigationControllerImpl*>(&controller())); | 423 static_cast<NavigationControllerImpl*>(&controller())); |
| 424 // Simulates request creation that triggers the 1st internal call to | |
|
clamy
2015/10/21 16:54:22
nit: add a line before the comment.
carlosk
2015/10/22 13:36:19
Done.
| |
| 425 // GetFrameHostForNavigation. | |
| 426 manager->DidCreateNavigationRequest(*navigation_request); | |
| 427 // And also simulates the 2nd and final call to GetFrameHostForNavigation | |
|
clamy
2015/10/21 16:54:22
nit: same here.
carlosk
2015/10/22 13:36:19
Done.
| |
| 428 // that determines the final frame that will commit the navigation. | |
| 412 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( | 429 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( |
| 413 manager->GetFrameHostForNavigation(*navigation_request)); | 430 manager->GetFrameHostForNavigation(*navigation_request)); |
| 414 CHECK(frame_host); | 431 CHECK(frame_host); |
| 415 frame_host->set_pending_commit(true); | 432 frame_host->set_pending_commit(true); |
| 416 return frame_host; | 433 return frame_host; |
| 417 } | 434 } |
| 418 | 435 |
| 419 return manager->Navigate(frame_entry->url(), *frame_entry, entry); | 436 return manager->Navigate(frame_entry->url(), *frame_entry, entry); |
| 420 } | 437 } |
| 421 | 438 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 | 1118 |
| 1102 // It's important that the SiteInstance get set on the Web UI page as soon | 1119 // It's important that the SiteInstance get set on the Web UI page as soon |
| 1103 // as the navigation starts, rather than lazily after it commits, so we don't | 1120 // as the navigation starts, rather than lazily after it commits, so we don't |
| 1104 // try to re-use the SiteInstance/process for non Web UI things that may | 1121 // try to re-use the SiteInstance/process for non Web UI things that may |
| 1105 // get loaded in between. | 1122 // get loaded in between. |
| 1106 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1123 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1107 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 1124 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
| 1108 | 1125 |
| 1109 // The Web UI is committed immediately because the RenderViewHost has not been | 1126 // The Web UI is committed immediately because the RenderViewHost has not been |
| 1110 // used yet. UpdateStateForNavigate() took the short cut path. | 1127 // used yet. UpdateStateForNavigate() took the short cut path. |
| 1128 EXPECT_TRUE(manager->web_ui()); | |
| 1111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1112 switches::kEnableBrowserSideNavigation)) { | 1130 switches::kEnableBrowserSideNavigation)) { |
| 1113 EXPECT_FALSE(manager->speculative_web_ui()); | 1131 // For PlzNavigate as GetFrameHostForNavigation is called twice in a row, a |
| 1132 // speculative WebUI will exist because of the 2nd call but it should just | |
| 1133 // be the re-using of the current one that has been committed. | |
| 1134 EXPECT_TRUE(manager->speculative_web_ui()); | |
| 1135 EXPECT_EQ(manager->web_ui(), manager->speculative_web_ui()); | |
| 1114 } else { | 1136 } else { |
| 1115 EXPECT_FALSE(manager->pending_web_ui()); | 1137 EXPECT_FALSE(manager->pending_web_ui()); |
| 1116 } | 1138 } |
| 1117 EXPECT_TRUE(manager->web_ui()); | |
| 1118 | 1139 |
| 1119 // Commit. | 1140 // Commit. |
| 1120 manager->DidNavigateFrame(host, true); | 1141 manager->DidNavigateFrame(host, true); |
| 1121 EXPECT_TRUE( | 1142 EXPECT_TRUE( |
| 1122 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1143 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1123 } | 1144 } |
| 1124 | 1145 |
| 1125 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1146 // Tests that we can open a WebUI link in a new tab from a WebUI page and still |
| 1126 // grant the correct bindings. http://crbug.com/189101. | 1147 // grant the correct bindings. http://crbug.com/189101. |
| 1127 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1148 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { |
| (...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2481 EXPECT_EQ(tree3, opener_frame_trees[2]); | 2502 EXPECT_EQ(tree3, opener_frame_trees[2]); |
| 2482 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2503 EXPECT_EQ(tree4, opener_frame_trees[3]); |
| 2483 | 2504 |
| 2484 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2505 EXPECT_EQ(2U, nodes_with_back_links.size()); |
| 2485 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2506 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
| 2486 nodes_with_back_links.end()); | 2507 nodes_with_back_links.end()); |
| 2487 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2508 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
| 2488 nodes_with_back_links.end()); | 2509 nodes_with_back_links.end()); |
| 2489 } | 2510 } |
| 2490 | 2511 |
| 2512 class RenderFrameHostManagerTestWithBrowserSideNavigation | |
| 2513 : public RenderFrameHostManagerTest { | |
| 2514 public: | |
| 2515 void SetUp() override { | |
| 2516 EnableBrowserSideNavigation(); | |
| 2517 RenderFrameHostManagerTest::SetUp(); | |
| 2518 } | |
| 2519 }; | |
| 2520 | |
| 2521 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation, | |
| 2522 NavigateBetweenWebUIs) { | |
| 2523 set_should_create_webui(true); | |
| 2524 RenderViewHostChangedObserver change_observer(contents()); | |
| 2525 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | |
| 2526 | |
| 2527 // 1) The first navigation to a WebUI. -------------------------- | |
| 2528 { | |
| 2529 RenderFrameHostImpl* initial_host = manager->current_frame_host(); | |
| 2530 ASSERT_TRUE(initial_host); | |
| 2531 EXPECT_FALSE(initial_host->IsRenderFrameLive()); | |
| 2532 | |
| 2533 const GURL kUrl("chrome://foo"); | |
| 2534 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
| 2535 Referrer(), base::string16() /* title */, | |
| 2536 ui::PAGE_TRANSITION_TYPED, | |
| 2537 false /* is_renderer_init */); | |
| 2538 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
| 2539 scoped_ptr<NavigationRequest> navigation_request = | |
| 2540 NavigationRequest::CreateBrowserInitiated( | |
| 2541 contents()->GetFrameTree()->root(), frame_entry->url(), | |
| 2542 frame_entry->referrer(), *frame_entry, entry, | |
| 2543 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
| 2544 static_cast<NavigationControllerImpl*>(&controller())); | |
| 2545 // Navigation request | |
| 2546 manager->DidCreateNavigationRequest(*navigation_request); | |
| 2547 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
| 2548 // As the initial renderer was not be live, the new RenderFrameHost should | |
| 2549 // be made immediately active at request time. | |
| 2550 EXPECT_TRUE(change_observer.DidHostChange()); | |
| 2551 TestRenderFrameHost* host = | |
| 2552 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
| 2553 ASSERT_TRUE(host); | |
| 2554 EXPECT_NE(host, initial_host); | |
| 2555 EXPECT_TRUE(host->IsRenderFrameLive()); | |
| 2556 WebUIImpl* web_ui = host->web_ui(); | |
| 2557 EXPECT_TRUE(web_ui); | |
| 2558 EXPECT_FALSE(manager->speculative_web_ui()); | |
| 2559 | |
| 2560 // Preparing to commit, updates the navigating RenderFrameHost | |
| 2561 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
| 2562 host->set_pending_commit(true); | |
| 2563 | |
| 2564 // No pending RenderFrameHost as the current should be reused | |
| 2565 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
| 2566 // But now there will be a pending WebUI set to re-using the current one. | |
| 2567 EXPECT_EQ(web_ui, host->web_ui()); | |
| 2568 EXPECT_EQ(web_ui, manager->speculative_web_ui()); | |
| 2569 EXPECT_EQ(web_ui, host->pending_web_ui()); | |
| 2570 | |
| 2571 // Commit. | |
| 2572 manager->DidNavigateFrame(host, true); | |
| 2573 EXPECT_FALSE(change_observer.DidHostChange()); | |
| 2574 EXPECT_EQ(host, manager->current_frame_host()); | |
| 2575 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
| 2576 EXPECT_EQ(web_ui, host->web_ui()); | |
| 2577 EXPECT_FALSE(manager->speculative_web_ui()); | |
| 2578 EXPECT_FALSE(host->pending_web_ui()); | |
| 2579 } | |
| 2580 | |
| 2581 // 2) Navigate to next WebUI. ------------------------- | |
| 2582 { | |
| 2583 // Same-site navigation and to a different WebUI. | |
| 2584 set_webui_type(2); | |
| 2585 const GURL kUrl("chrome://foo/bar"); | |
| 2586 // Navigation request | |
| 2587 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
| 2588 Referrer(), base::string16() /* title */, | |
| 2589 ui::PAGE_TRANSITION_TYPED, | |
| 2590 false /* is_renderer_init */); | |
| 2591 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
| 2592 scoped_ptr<NavigationRequest> navigation_request = | |
| 2593 NavigationRequest::CreateBrowserInitiated( | |
| 2594 contents()->GetFrameTree()->root(), frame_entry->url(), | |
| 2595 frame_entry->referrer(), *frame_entry, entry, | |
| 2596 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
| 2597 static_cast<NavigationControllerImpl*>(&controller())); | |
| 2598 manager->DidCreateNavigationRequest(*navigation_request); | |
| 2599 | |
| 2600 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
| 2601 TestRenderFrameHost* host = | |
| 2602 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
| 2603 // Current WebUI should still be in place and a new one should be pending | |
| 2604 // from the current RenderFrameHost. | |
| 2605 EXPECT_TRUE(host->web_ui()); | |
| 2606 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
| 2607 EXPECT_TRUE(next_web_ui); | |
| 2608 EXPECT_NE(next_web_ui, host->web_ui()); | |
| 2609 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
| 2610 | |
| 2611 // Preparing to commit, updates the navigating RenderFrameHost | |
| 2612 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
| 2613 host->set_pending_commit(true); | |
| 2614 | |
| 2615 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
| 2616 EXPECT_TRUE(host->web_ui()); | |
| 2617 EXPECT_NE(next_web_ui, host->web_ui()); | |
| 2618 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
| 2619 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
| 2620 | |
| 2621 // Commit. | |
| 2622 manager->DidNavigateFrame(host, true); | |
| 2623 EXPECT_FALSE(change_observer.DidHostChange()); | |
| 2624 EXPECT_EQ(next_web_ui, host->web_ui()); | |
| 2625 EXPECT_FALSE(manager->speculative_web_ui()); | |
| 2626 EXPECT_FALSE(host->pending_web_ui()); | |
| 2627 } | |
| 2628 | |
| 2629 // 3) Navigate to yet another WebUI. ------------------------- | |
| 2630 { | |
| 2631 // Cross-site navigation and to (forcefully) a different WebUI. | |
| 2632 set_webui_type(3); // Not really necessary; just for consistency. | |
| 2633 const GURL kUrl("chrome://boo"); | |
| 2634 // Navigation request | |
| 2635 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
| 2636 Referrer(), base::string16() /* title */, | |
| 2637 ui::PAGE_TRANSITION_TYPED, | |
| 2638 false /* is_renderer_init */); | |
| 2639 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
| 2640 scoped_ptr<NavigationRequest> navigation_request = | |
| 2641 NavigationRequest::CreateBrowserInitiated( | |
| 2642 contents()->GetFrameTree()->root(), frame_entry->url(), | |
| 2643 frame_entry->referrer(), *frame_entry, entry, | |
| 2644 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
| 2645 static_cast<NavigationControllerImpl*>(&controller())); | |
| 2646 manager->DidCreateNavigationRequest(*navigation_request); | |
| 2647 | |
| 2648 TestRenderFrameHost* speculative_host = | |
| 2649 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager)); | |
| 2650 EXPECT_TRUE(speculative_host); | |
| 2651 // Current WebUI should still be in place and a new one should be pending | |
| 2652 // from the speculative RenderFrameHost. | |
| 2653 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
| 2654 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
| 2655 EXPECT_TRUE(next_web_ui); | |
| 2656 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
| 2657 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
| 2658 | |
| 2659 // Preparing to commit, updates the navigating RenderFrameHost | |
| 2660 EXPECT_EQ(speculative_host, | |
| 2661 manager->GetFrameHostForNavigation(*navigation_request)); | |
| 2662 speculative_host->set_pending_commit(true); | |
| 2663 | |
| 2664 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager)); | |
| 2665 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
| 2666 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
| 2667 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
| 2668 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
| 2669 | |
| 2670 // Commit. | |
| 2671 manager->DidNavigateFrame(speculative_host, true); | |
| 2672 EXPECT_EQ(speculative_host, manager->current_frame_host()); | |
| 2673 EXPECT_TRUE(change_observer.DidHostChange()); | |
| 2674 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui()); | |
| 2675 EXPECT_FALSE(manager->speculative_web_ui()); | |
| 2676 EXPECT_FALSE(speculative_host->pending_web_ui()); | |
| 2677 } | |
| 2678 } | |
| 2679 | |
| 2491 } // namespace content | 2680 } // namespace content |
| OLD | NEW |