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); | |
clamy
2015/10/22 15:37:10
Since WebUI::TypeID is actually a void*, could we
carlosk
2015/10/22 16:23:48
Done.
| |
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(uintptr_t type) { | |
clamy
2015/10/22 15:37:10
nit: add a comment explaining that this allows to
carlosk
2015/10/22 16:23:48
Done. I then also moved the comment below to here.
| |
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_); | |
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 uintptr_t 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 | |
425 // Simulates request creation that triggers the 1st internal call to | |
426 // GetFrameHostForNavigation. | |
427 manager->DidCreateNavigationRequest(*navigation_request); | |
428 | |
429 // And also simulates the 2nd and final call to GetFrameHostForNavigation | |
430 // that determines the final frame that will commit the navigation. | |
412 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( | 431 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( |
413 manager->GetFrameHostForNavigation(*navigation_request)); | 432 manager->GetFrameHostForNavigation(*navigation_request)); |
414 CHECK(frame_host); | 433 CHECK(frame_host); |
415 frame_host->set_pending_commit(true); | 434 frame_host->set_pending_commit(true); |
416 return frame_host; | 435 return frame_host; |
417 } | 436 } |
418 | 437 |
419 return manager->Navigate(frame_entry->url(), *frame_entry, entry); | 438 return manager->Navigate(frame_entry->url(), *frame_entry, entry); |
420 } | 439 } |
421 | 440 |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 | 1120 |
1102 // It's important that the SiteInstance get set on the Web UI page as soon | 1121 // 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 | 1122 // 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 | 1123 // try to re-use the SiteInstance/process for non Web UI things that may |
1105 // get loaded in between. | 1124 // get loaded in between. |
1106 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1125 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1107 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 1126 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
1108 | 1127 |
1109 // The Web UI is committed immediately because the RenderViewHost has not been | 1128 // The Web UI is committed immediately because the RenderViewHost has not been |
1110 // used yet. UpdateStateForNavigate() took the short cut path. | 1129 // used yet. UpdateStateForNavigate() took the short cut path. |
1130 EXPECT_TRUE(manager->web_ui()); | |
1111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1131 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1112 switches::kEnableBrowserSideNavigation)) { | 1132 switches::kEnableBrowserSideNavigation)) { |
1113 EXPECT_FALSE(manager->speculative_web_ui()); | 1133 // For PlzNavigate as GetFrameHostForNavigation is called twice in a row, a |
1134 // speculative WebUI will exist because of the 2nd call but it should just | |
1135 // be the re-using of the current one that has been committed. | |
1136 EXPECT_TRUE(manager->speculative_web_ui()); | |
1137 EXPECT_EQ(manager->web_ui(), manager->speculative_web_ui()); | |
1114 } else { | 1138 } else { |
1115 EXPECT_FALSE(manager->pending_web_ui()); | 1139 EXPECT_FALSE(manager->pending_web_ui()); |
1116 } | 1140 } |
1117 EXPECT_TRUE(manager->web_ui()); | |
1118 | 1141 |
1119 // Commit. | 1142 // Commit. |
1120 manager->DidNavigateFrame(host, true); | 1143 manager->DidNavigateFrame(host, true); |
1121 EXPECT_TRUE( | 1144 EXPECT_TRUE( |
1122 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1145 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1123 } | 1146 } |
1124 | 1147 |
1125 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1148 // 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. | 1149 // grant the correct bindings. http://crbug.com/189101. |
1127 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1150 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]); | 2504 EXPECT_EQ(tree3, opener_frame_trees[2]); |
2482 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2505 EXPECT_EQ(tree4, opener_frame_trees[3]); |
2483 | 2506 |
2484 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2507 EXPECT_EQ(2U, nodes_with_back_links.size()); |
2485 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2508 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
2486 nodes_with_back_links.end()); | 2509 nodes_with_back_links.end()); |
2487 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2510 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
2488 nodes_with_back_links.end()); | 2511 nodes_with_back_links.end()); |
2489 } | 2512 } |
2490 | 2513 |
2514 class RenderFrameHostManagerTestWithBrowserSideNavigation | |
2515 : public RenderFrameHostManagerTest { | |
2516 public: | |
2517 void SetUp() override { | |
2518 EnableBrowserSideNavigation(); | |
2519 RenderFrameHostManagerTest::SetUp(); | |
2520 } | |
2521 }; | |
2522 | |
2523 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation, | |
clamy
2015/10/22 15:37:10
nit: add a comment describing what the test does.
carlosk
2015/10/22 16:23:48
Done. And indeed this looks much better now that i
| |
2524 NavigateBetweenWebUIs) { | |
2525 set_should_create_webui(true); | |
2526 RenderViewHostChangedObserver change_observer(contents()); | |
2527 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting(); | |
2528 | |
2529 // 1) The first navigation to a WebUI. -------------------------- | |
2530 { | |
2531 RenderFrameHostImpl* initial_host = manager->current_frame_host(); | |
2532 ASSERT_TRUE(initial_host); | |
2533 EXPECT_FALSE(initial_host->IsRenderFrameLive()); | |
2534 | |
2535 const GURL kUrl("chrome://foo"); | |
2536 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2537 Referrer(), base::string16() /* title */, | |
2538 ui::PAGE_TRANSITION_TYPED, | |
2539 false /* is_renderer_init */); | |
2540 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2541 scoped_ptr<NavigationRequest> navigation_request = | |
2542 NavigationRequest::CreateBrowserInitiated( | |
2543 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2544 frame_entry->referrer(), *frame_entry, entry, | |
2545 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2546 static_cast<NavigationControllerImpl*>(&controller())); | |
2547 // Navigation request | |
2548 manager->DidCreateNavigationRequest(*navigation_request); | |
2549 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2550 // As the initial renderer was not be live, the new RenderFrameHost should | |
2551 // be made immediately active at request time. | |
2552 EXPECT_TRUE(change_observer.DidHostChange()); | |
2553 TestRenderFrameHost* host = | |
2554 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
2555 ASSERT_TRUE(host); | |
2556 EXPECT_NE(host, initial_host); | |
2557 EXPECT_TRUE(host->IsRenderFrameLive()); | |
2558 WebUIImpl* web_ui = host->web_ui(); | |
2559 EXPECT_TRUE(web_ui); | |
2560 EXPECT_FALSE(manager->speculative_web_ui()); | |
2561 | |
2562 // Preparing to commit, updates the navigating RenderFrameHost | |
2563 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
2564 host->set_pending_commit(true); | |
2565 | |
2566 // No pending RenderFrameHost as the current should be reused | |
2567 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2568 // But now there will be a pending WebUI set to re-using the current one. | |
2569 EXPECT_EQ(web_ui, host->web_ui()); | |
2570 EXPECT_EQ(web_ui, manager->speculative_web_ui()); | |
2571 EXPECT_EQ(web_ui, host->pending_web_ui()); | |
2572 | |
2573 // Commit. | |
2574 manager->DidNavigateFrame(host, true); | |
2575 EXPECT_FALSE(change_observer.DidHostChange()); | |
2576 EXPECT_EQ(host, manager->current_frame_host()); | |
2577 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2578 EXPECT_EQ(web_ui, host->web_ui()); | |
2579 EXPECT_FALSE(manager->speculative_web_ui()); | |
2580 EXPECT_FALSE(host->pending_web_ui()); | |
2581 } | |
2582 | |
2583 // 2) Navigate to next WebUI. ------------------------- | |
2584 { | |
2585 // Same-site navigation and to a different WebUI. | |
2586 set_webui_type(2); | |
2587 const GURL kUrl("chrome://foo/bar"); | |
2588 // Navigation request | |
2589 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2590 Referrer(), base::string16() /* title */, | |
2591 ui::PAGE_TRANSITION_TYPED, | |
2592 false /* is_renderer_init */); | |
2593 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2594 scoped_ptr<NavigationRequest> navigation_request = | |
2595 NavigationRequest::CreateBrowserInitiated( | |
2596 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2597 frame_entry->referrer(), *frame_entry, entry, | |
2598 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2599 static_cast<NavigationControllerImpl*>(&controller())); | |
2600 manager->DidCreateNavigationRequest(*navigation_request); | |
2601 | |
2602 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2603 TestRenderFrameHost* host = | |
2604 static_cast<TestRenderFrameHost*>(manager->current_frame_host()); | |
2605 // Current WebUI should still be in place and a new one should be pending | |
2606 // from the current RenderFrameHost. | |
2607 EXPECT_TRUE(host->web_ui()); | |
2608 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
2609 EXPECT_TRUE(next_web_ui); | |
2610 EXPECT_NE(next_web_ui, host->web_ui()); | |
2611 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
2612 | |
2613 // Preparing to commit, updates the navigating RenderFrameHost | |
2614 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request)); | |
2615 host->set_pending_commit(true); | |
2616 | |
2617 EXPECT_FALSE(GetPendingFrameHost(manager)); | |
2618 EXPECT_TRUE(host->web_ui()); | |
2619 EXPECT_NE(next_web_ui, host->web_ui()); | |
2620 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
2621 EXPECT_EQ(next_web_ui, host->pending_web_ui()); | |
2622 | |
2623 // Commit. | |
2624 manager->DidNavigateFrame(host, true); | |
2625 EXPECT_FALSE(change_observer.DidHostChange()); | |
2626 EXPECT_EQ(next_web_ui, host->web_ui()); | |
2627 EXPECT_FALSE(manager->speculative_web_ui()); | |
2628 EXPECT_FALSE(host->pending_web_ui()); | |
2629 } | |
2630 | |
2631 // 3) Navigate to yet another WebUI. ------------------------- | |
2632 { | |
2633 // Cross-site navigation and to (forcefully) a different WebUI. | |
2634 set_webui_type(3); // Not really necessary; just for consistency. | |
2635 const GURL kUrl("chrome://boo"); | |
2636 // Navigation request | |
2637 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | |
2638 Referrer(), base::string16() /* title */, | |
2639 ui::PAGE_TRANSITION_TYPED, | |
2640 false /* is_renderer_init */); | |
2641 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get(); | |
2642 scoped_ptr<NavigationRequest> navigation_request = | |
2643 NavigationRequest::CreateBrowserInitiated( | |
2644 contents()->GetFrameTree()->root(), frame_entry->url(), | |
2645 frame_entry->referrer(), *frame_entry, entry, | |
2646 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(), | |
2647 static_cast<NavigationControllerImpl*>(&controller())); | |
2648 manager->DidCreateNavigationRequest(*navigation_request); | |
2649 | |
2650 TestRenderFrameHost* speculative_host = | |
2651 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager)); | |
2652 EXPECT_TRUE(speculative_host); | |
2653 // Current WebUI should still be in place and a new one should be pending | |
2654 // from the speculative RenderFrameHost. | |
2655 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
2656 WebUIImpl* next_web_ui = manager->speculative_web_ui(); | |
2657 EXPECT_TRUE(next_web_ui); | |
2658 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
2659 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
2660 | |
2661 // Preparing to commit, updates the navigating RenderFrameHost | |
2662 EXPECT_EQ(speculative_host, | |
2663 manager->GetFrameHostForNavigation(*navigation_request)); | |
2664 speculative_host->set_pending_commit(true); | |
2665 | |
2666 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager)); | |
2667 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | |
2668 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui()); | |
2669 EXPECT_EQ(next_web_ui, manager->speculative_web_ui()); | |
2670 EXPECT_EQ(next_web_ui, speculative_host->web_ui()); | |
2671 | |
2672 // Commit. | |
2673 manager->DidNavigateFrame(speculative_host, true); | |
2674 EXPECT_EQ(speculative_host, manager->current_frame_host()); | |
2675 EXPECT_TRUE(change_observer.DidHostChange()); | |
2676 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui()); | |
2677 EXPECT_FALSE(manager->speculative_web_ui()); | |
2678 EXPECT_FALSE(speculative_host->pending_web_ui()); | |
2679 } | |
2680 } | |
2681 | |
2491 } // namespace content | 2682 } // namespace content |
OLD | NEW |