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<WebUI::TypeID>(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 // This method allows simulating the expectation that different WebUI instance | |
clamy
2015/10/27 11:54:44
nit: s/allows simulating/simulates
carlosk
2015/11/12 10:40:39
Done. (it will show up on the other change I merge
| |
68 // types would be created. The |type| value will be returned by GetWebUIType | |
69 // casted to WebUI::TypeID. | |
70 // As WebUI::TypeID is a typedef to void pointer, factory implementations | |
71 // return values that they know to be unique to their respective cases. So | |
72 // values set here should be safe if kept very low (just above zero). | |
73 void set_webui_type(uintptr_t type) { | |
74 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type), WebUI::kNoWebUI); | |
75 type_ = type; | |
76 } | |
77 | |
65 // WebUIFactory implementation. | 78 // WebUIFactory implementation. |
66 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, | 79 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
67 const GURL& url) const override { | 80 const GURL& url) const override { |
68 // If WebUI creation is enabled for the test and this is a WebUI URL, | 81 // If WebUI creation is enabled for the test and this is a WebUI URL, |
69 // returns a new instance. | 82 // returns a new instance. |
70 if (should_create_webui_ && HasWebUIScheme(url)) | 83 if (should_create_webui_ && HasWebUIScheme(url)) |
71 return new WebUIController(web_ui); | 84 return new WebUIController(web_ui); |
72 return nullptr; | 85 return nullptr; |
73 } | 86 } |
74 | 87 |
75 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 88 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
76 const GURL& url) const override { | 89 const GURL& url) const override { |
77 // If WebUI creation is enabled for the test and this is a WebUI URL, | 90 // If WebUI creation is enabled for the test and this is a WebUI URL, |
78 // returns a mock WebUI type. | 91 // returns a mock WebUI type. |
79 if (should_create_webui_ && HasWebUIScheme(url)) { | 92 if (should_create_webui_ && HasWebUIScheme(url)) { |
80 return const_cast<RenderFrameHostManagerTestWebUIControllerFactory*>( | 93 return reinterpret_cast<WebUI::TypeID>(type_); |
81 this); | |
82 } | 94 } |
83 return WebUI::kNoWebUI; | 95 return WebUI::kNoWebUI; |
84 } | 96 } |
85 | 97 |
86 bool UseWebUIForURL(BrowserContext* browser_context, | 98 bool UseWebUIForURL(BrowserContext* browser_context, |
87 const GURL& url) const override { | 99 const GURL& url) const override { |
88 return HasWebUIScheme(url); | 100 return HasWebUIScheme(url); |
89 } | 101 } |
90 | 102 |
91 bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 103 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
92 const GURL& url) const override { | 104 const GURL& url) const override { |
93 return HasWebUIScheme(url); | 105 return HasWebUIScheme(url); |
94 } | 106 } |
95 | 107 |
96 private: | 108 private: |
97 bool should_create_webui_; | 109 bool should_create_webui_; |
110 uintptr_t type_; | |
98 | 111 |
99 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); | 112 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); |
100 }; | 113 }; |
101 | 114 |
102 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { | 115 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { |
103 public: | 116 public: |
104 BeforeUnloadFiredWebContentsDelegate() {} | 117 BeforeUnloadFiredWebContentsDelegate() {} |
105 ~BeforeUnloadFiredWebContentsDelegate() override {} | 118 ~BeforeUnloadFiredWebContentsDelegate() override {} |
106 | 119 |
107 void BeforeUnloadFired(WebContents* web_contents, | 120 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 | 278 // RenderWidgetHostView holds on to a reference to SurfaceManager, so it |
266 // must be shut down before the ImageTransportFactory. | 279 // must be shut down before the ImageTransportFactory. |
267 ImageTransportFactory::Terminate(); | 280 ImageTransportFactory::Terminate(); |
268 #endif | 281 #endif |
269 } | 282 } |
270 | 283 |
271 void set_should_create_webui(bool should_create_webui) { | 284 void set_should_create_webui(bool should_create_webui) { |
272 factory_.set_should_create_webui(should_create_webui); | 285 factory_.set_should_create_webui(should_create_webui); |
273 } | 286 } |
274 | 287 |
288 void set_webui_type(int type) { factory_.set_webui_type(type); } | |
289 | |
275 void NavigateActiveAndCommit(const GURL& url) { | 290 void NavigateActiveAndCommit(const GURL& url) { |
276 // Note: we navigate the active RenderFrameHost because previous navigations | 291 // Note: we navigate the active RenderFrameHost because previous navigations |
277 // won't have committed yet, so NavigateAndCommit does the wrong thing | 292 // won't have committed yet, so NavigateAndCommit does the wrong thing |
278 // for us. | 293 // for us. |
279 controller().LoadURL( | 294 controller().LoadURL( |
280 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 295 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
281 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 296 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
282 | 297 |
283 // Simulate the BeforeUnload_ACK that is received from the current renderer | 298 // Simulate the BeforeUnload_ACK that is received from the current renderer |
284 // for a cross-site navigation. | 299 // 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. | 417 // Tests currently only navigate using main frame FrameNavigationEntries. |
403 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | 418 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); |
404 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 419 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
405 switches::kEnableBrowserSideNavigation)) { | 420 switches::kEnableBrowserSideNavigation)) { |
406 scoped_ptr<NavigationRequest> navigation_request = | 421 scoped_ptr<NavigationRequest> navigation_request = |
407 NavigationRequest::CreateBrowserInitiated( | 422 NavigationRequest::CreateBrowserInitiated( |
408 manager->frame_tree_node_, frame_entry->url(), | 423 manager->frame_tree_node_, frame_entry->url(), |
409 frame_entry->referrer(), *frame_entry, entry, | 424 frame_entry->referrer(), *frame_entry, entry, |
410 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | 425 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), |
411 static_cast<NavigationControllerImpl*>(&controller())); | 426 static_cast<NavigationControllerImpl*>(&controller())); |
427 | |
428 // Simulates request creation that triggers the 1st internal call to | |
429 // GetFrameHostForNavigation. | |
430 manager->DidCreateNavigationRequest(*navigation_request); | |
431 | |
432 // And also simulates the 2nd and final call to GetFrameHostForNavigation | |
433 // that determines the final frame that will commit the navigation. | |
412 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( | 434 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( |
413 manager->GetFrameHostForNavigation(*navigation_request)); | 435 manager->GetFrameHostForNavigation(*navigation_request)); |
414 CHECK(frame_host); | 436 CHECK(frame_host); |
415 frame_host->set_pending_commit(true); | 437 frame_host->set_pending_commit(true); |
416 return frame_host; | 438 return frame_host; |
417 } | 439 } |
418 | 440 |
419 return manager->Navigate(frame_entry->url(), *frame_entry, entry); | 441 return manager->Navigate(frame_entry->url(), *frame_entry, entry); |
420 } | 442 } |
421 | 443 |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 | 1123 |
1102 // It's important that the SiteInstance get set on the Web UI page as soon | 1124 // 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 | 1125 // 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 | 1126 // try to re-use the SiteInstance/process for non Web UI things that may |
1105 // get loaded in between. | 1127 // get loaded in between. |
1106 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1128 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1107 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 1129 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
1108 | 1130 |
1109 // The Web UI is committed immediately because the RenderViewHost has not been | 1131 // The Web UI is committed immediately because the RenderViewHost has not been |
1110 // used yet. UpdateStateForNavigate() took the short cut path. | 1132 // used yet. UpdateStateForNavigate() took the short cut path. |
1133 EXPECT_TRUE(manager->web_ui()); | |
1111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1134 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1112 switches::kEnableBrowserSideNavigation)) { | 1135 switches::kEnableBrowserSideNavigation)) { |
1113 EXPECT_FALSE(manager->speculative_web_ui()); | 1136 // For PlzNavigate as GetFrameHostForNavigation is called twice in a row, a |
1137 // speculative WebUI will exist because of the 2nd call but it should just | |
1138 // be the re-using of the current one that has been committed. | |
1139 EXPECT_TRUE(manager->speculative_web_ui()); | |
1140 EXPECT_EQ(manager->web_ui(), manager->speculative_web_ui()); | |
1114 } else { | 1141 } else { |
1115 EXPECT_FALSE(manager->pending_web_ui()); | 1142 EXPECT_FALSE(manager->pending_web_ui()); |
1116 } | 1143 } |
1117 EXPECT_TRUE(manager->web_ui()); | |
1118 | 1144 |
1119 // Commit. | 1145 // Commit. |
1120 manager->DidNavigateFrame(host, true); | 1146 manager->DidNavigateFrame(host, true); |
1121 EXPECT_TRUE( | 1147 EXPECT_TRUE( |
1122 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1148 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1123 } | 1149 } |
1124 | 1150 |
1125 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1151 // 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. | 1152 // grant the correct bindings. http://crbug.com/189101. |
1127 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1153 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]); | 2507 EXPECT_EQ(tree3, opener_frame_trees[2]); |
2482 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2508 EXPECT_EQ(tree4, opener_frame_trees[3]); |
2483 | 2509 |
2484 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2510 EXPECT_EQ(2U, nodes_with_back_links.size()); |
2485 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2511 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
2486 nodes_with_back_links.end()); | 2512 nodes_with_back_links.end()); |
2487 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2513 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
2488 nodes_with_back_links.end()); | 2514 nodes_with_back_links.end()); |
2489 } | 2515 } |
2490 | 2516 |
2517 // Creates a test class for PlzNavigate tests. | |
2518 class RenderFrameHostManagerTestWithBrowserSideNavigation | |
2519 : public RenderFrameHostManagerTest { | |
2520 public: | |
2521 void SetUp() override { | |
2522 EnableBrowserSideNavigation(); | |
2523 RenderFrameHostManagerTest::SetUp(); | |
2524 } | |
2525 }; | |
2526 | |
2527 // PlzNavigate: Tests that the correct intermediary and final navigation states | |
2528 // are reached when navigating from a renderer that is not live to a WebUI URL. | |
2529 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation, | |
2530 NavigateFromDeadRendererToWebUI) { | |
2531 set_should_create_webui(true); | |
2532 RenderViewHostChangedObserver change_observer(contents()); | |
2533 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | |
2534 | |
2535 RenderFrameHostImpl* initial_host = manager->current_frame_host(); | |
2536 ASSERT_TRUE(initial_host); | |
2537 EXPECT_FALSE(initial_host->IsRenderFrameLive()); | |
2538 | |
2539 // Navigation request. | |
2540 const GURL kUrl("chrome://foo"); | |
2541 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2542 Referrer(), base::string16() /* title */, | |
2543 ui::PAGE_TRANSITION_TYPED, | |
2544 false /* is_renderer_init */); | |
2545 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2546 scoped_ptr<NavigationRequest> navigation_request = | |
2547 NavigationRequest::CreateBrowserInitiated( | |
2548 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2549 frame_entry->referrer(), *frame_entry, entry, | |
2550 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2551 static_cast<NavigationControllerImpl*>(&controller())); | |
2552 manager->DidCreateNavigationRequest(*navigation_request); | |
2553 | |
2554 // As the initial renderer was not live, the new RenderFrameHost should be | |
2555 // made immediately active at request time. | |
2556 EXPECT_TRUE(change_observer.DidHostChange()); | |
2557 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2558 TestRenderFrameHost* host = | |
2559 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
2560 ASSERT_TRUE(host); | |
2561 EXPECT_NE(host, initial_host); | |
2562 EXPECT_TRUE(host->IsRenderFrameLive()); | |
2563 WebUIImpl* web_ui = host->web_ui(); | |
2564 EXPECT_TRUE(web_ui); | |
2565 EXPECT_FALSE(manager->speculative_web_ui()); | |
2566 | |
2567 // Prepare to commit, update the navigating RenderFrameHost. | |
2568 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
2569 | |
2570 // No pending RenderFrameHost as the current one should be reused. | |
2571 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2572 | |
2573 // But there should be a pending WebUI set to re-use the current one. | |
2574 EXPECT_EQ(web_ui, host->web_ui()); | |
2575 EXPECT_EQ(web_ui, manager->speculative_web_ui()); | |
2576 EXPECT_EQ(web_ui, host->pending_web_ui()); | |
2577 | |
2578 // The RenderFrameHost committed. | |
2579 manager->DidNavigateFrame(host, true); | |
2580 EXPECT_FALSE(change_observer.DidHostChange()); | |
2581 EXPECT_EQ(host, manager->current_frame_host()); | |
2582 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2583 EXPECT_EQ(web_ui, host->web_ui()); | |
2584 EXPECT_FALSE(manager->speculative_web_ui()); | |
2585 EXPECT_FALSE(host->pending_web_ui()); | |
2586 } | |
2587 | |
2588 // PlzNavigate: Tests that the correct intermediary and final navigation states | |
2589 // are reached when navigating same-site between two different WebUI types. | |
2590 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation, | |
2591 NavigateSameSiteBetweenWebUIs) { | |
2592 set_should_create_webui(true); | |
2593 set_webui_type(1); | |
2594 NavigateActiveAndCommit(GURL("chrome://foo")); | |
2595 | |
2596 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | |
2597 TestRenderFrameHost* host = | |
2598 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
2599 EXPECT_TRUE(host->IsRenderFrameLive()); | |
2600 EXPECT_TRUE(host->web_ui()); | |
2601 | |
2602 RenderViewHostChangedObserver change_observer(contents()); | |
2603 set_webui_type(2); | |
2604 | |
2605 // Navigation request. | |
2606 const GURL kUrl("chrome://foo/bar"); | |
2607 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2608 Referrer(), base::string16() /* title */, | |
2609 ui::PAGE_TRANSITION_TYPED, | |
2610 false /* is_renderer_init */); | |
2611 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2612 scoped_ptr<NavigationRequest> navigation_request = | |
2613 NavigationRequest::CreateBrowserInitiated( | |
2614 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2615 frame_entry->referrer(), *frame_entry, entry, | |
2616 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2617 static_cast<NavigationControllerImpl*>(&controller())); | |
2618 manager->DidCreateNavigationRequest(*navigation_request); | |
2619 | |
2620 // The current WebUI should still be in place and there should be a new | |
2621 // pending WebUI instance in the current RenderFrameHost. | |
2622 EXPECT_FALSE(change_observer.DidHostChange()); | |
2623 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2624 EXPECT_TRUE(host->web_ui()); | |
2625 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
2626 EXPECT_TRUE(next_web_ui); | |
2627 EXPECT_NE(next_web_ui, host->web_ui()); | |
2628 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
2629 | |
2630 // Prepare to commit, update the navigating RenderFrameHost. | |
2631 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
2632 | |
2633 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2634 EXPECT_TRUE(host->web_ui()); | |
2635 EXPECT_NE(next_web_ui, host->web_ui()); | |
2636 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
2637 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
2638 | |
2639 // The RenderFrameHost committed. | |
2640 manager->DidNavigateFrame(host, true); | |
2641 EXPECT_FALSE(change_observer.DidHostChange()); | |
2642 EXPECT_EQ(next_web_ui, host->web_ui()); | |
2643 EXPECT_FALSE(manager->speculative_web_ui()); | |
2644 EXPECT_FALSE(host->pending_web_ui()); | |
2645 } | |
2646 | |
2647 // PlzNavigate: Tests that the correct intermediary and final navigation states | |
2648 // are reached when navigating cross-site between two different WebUI types. | |
2649 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation, | |
2650 NavigateCrossSiteBetweenWebUIs) { | |
2651 // Cross-site navigations will always cause the change of the WebUI instance | |
2652 // but for consistency sake different types will be set for each navigation. | |
2653 set_should_create_webui(true); | |
2654 set_webui_type(1); | |
2655 NavigateActiveAndCommit(GURL("chrome://foo")); | |
2656 | |
2657 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | |
2658 TestRenderFrameHost* host = | |
2659 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
2660 EXPECT_TRUE(host->IsRenderFrameLive()); | |
2661 EXPECT_TRUE(host->web_ui()); | |
2662 | |
2663 RenderViewHostChangedObserver change_observer(contents()); | |
2664 set_webui_type(2); | |
2665 | |
2666 // Navigation request. | |
2667 const GURL kUrl("chrome://bar"); | |
2668 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2669 Referrer(), base::string16() /* title */, | |
2670 ui::PAGE_TRANSITION_TYPED, | |
2671 false /* is_renderer_init */); | |
2672 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2673 scoped_ptr<NavigationRequest> navigation_request = | |
2674 NavigationRequest::CreateBrowserInitiated( | |
2675 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2676 frame_entry->referrer(), *frame_entry, entry, | |
2677 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2678 static_cast<NavigationControllerImpl*>(&controller())); | |
2679 manager->DidCreateNavigationRequest(*navigation_request); | |
2680 | |
2681 // The current WebUI should still be in place and there should be a new | |
2682 // active WebUI instance in the speculative RenderFrameHost. | |
2683 EXPECT_FALSE(change_observer.DidHostChange()); | |
2684 TestRenderFrameHost* speculative_host = | |
2685 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager)); | |
2686 EXPECT_TRUE(speculative_host); | |
2687 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
2688 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
2689 EXPECT_TRUE(next_web_ui); | |
2690 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
2691 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
2692 EXPECT_FALSE(manager->current_frame_host()->pending_web_ui()); | |
2693 | |
2694 // Prepare to commit, update the navigating RenderFrameHost. | |
2695 EXPECT_EQ(speculative_host, | |
2696 manager->GetFrameHostForNavigation(*navigation_request)); | |
2697 | |
2698 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager)); | |
2699 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
2700 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
2701 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
2702 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
2703 | |
2704 // The RenderFrameHost committed. | |
2705 manager->DidNavigateFrame(speculative_host, true); | |
2706 EXPECT_EQ(speculative_host, manager->current_frame_host()); | |
2707 EXPECT_TRUE(change_observer.DidHostChange()); | |
2708 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui()); | |
2709 EXPECT_FALSE(manager->speculative_web_ui()); | |
2710 EXPECT_FALSE(speculative_host->pending_web_ui()); | |
2711 } | |
2712 | |
2491 } // namespace content | 2713 } // namespace content |
OLD | NEW |