Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1417953002: PlzNavigate: Add tests to check WebUI navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Broken test into 3 separate ones. Other minor changes. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 a different WebUI
68 // instance types would be created. This value will be returned in
clamy 2015/10/22 16:51:40 nit: either "a different WebUI instance type" or "
carlosk 2015/10/26 10:33:23 Done.
69 // GetWebUIType, 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
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
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
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
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 dead renderer to a WebUI URL.
clamy 2015/10/22 16:51:40 nit: s/a dead renderer/a renderer that is not live
carlosk 2015/10/26 10:33:23 Done.
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 be live, the new RenderFrameHost should
clamy 2015/10/22 16:51:39 nit: remove be
carlosk 2015/10/26 10:33:23 Done.
2555 // be 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, updates the navigating RenderFrameHost.
clamy 2015/10/22 16:51:40 nit: update
carlosk 2015/10/26 10:33:23 Done.
2568 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
2569 host->set_pending_commit(true);
clamy 2015/10/22 16:51:39 Now that we have the NavigationHandle, I think we
carlosk 2015/10/26 10:33:23 Acknowledged.
2570
2571 // No pending RenderFrameHost as the current one should be reused.
2572 EXPECT_FALSE(GetPendingFrameHost(manager));
2573
2574 // But there should be a pending WebUI set to re-use the current one.
2575 EXPECT_EQ(web_ui, host->web_ui());
2576 EXPECT_EQ(web_ui, manager->speculative_web_ui());
2577 EXPECT_EQ(web_ui, host->pending_web_ui());
2578
2579 // The RenderFrameHost committed.
2580 manager->DidNavigateFrame(host, true);
2581 EXPECT_FALSE(change_observer.DidHostChange());
2582 EXPECT_EQ(host, manager->current_frame_host());
2583 EXPECT_FALSE(GetPendingFrameHost(manager));
2584 EXPECT_EQ(web_ui, host->web_ui());
2585 EXPECT_FALSE(manager->speculative_web_ui());
2586 EXPECT_FALSE(host->pending_web_ui());
2587 }
2588
2589 // PlzNavigate: Tests that the correct intermediary and final navigation states
2590 // are reached when navigating same-site between two different WebUI types.
2591 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2592 NavigateSameSiteBetweenWebUIs) {
2593 set_should_create_webui(true);
2594 set_webui_type(1);
2595 NavigateActiveAndCommit(GURL("chrome://foo"));
2596
2597 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2598 TestRenderFrameHost* host =
2599 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2600 EXPECT_TRUE(host->IsRenderFrameLive());
2601 EXPECT_TRUE(host->web_ui());
2602
2603 RenderViewHostChangedObserver change_observer(contents());
2604 set_webui_type(2);
2605
2606 // Navigation request.
2607 const GURL kUrl("chrome://foo/bar");
2608 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
2609 Referrer(), base::string16() /* title */,
2610 ui::PAGE_TRANSITION_TYPED,
2611 false /* is_renderer_init */);
2612 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2613 scoped_ptr<NavigationRequest> navigation_request =
2614 NavigationRequest::CreateBrowserInitiated(
2615 contents()->GetFrameTree()->root(), frame_entry->url(),
2616 frame_entry->referrer(), *frame_entry, entry,
2617 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2618 static_cast<NavigationControllerImpl*>(&controller()));
2619 manager->DidCreateNavigationRequest(*navigation_request);
2620
2621 // Current WebUI should still be in place and a new one should be pending
clamy 2015/10/22 16:51:39 nit: The current.... and there should be a pending
carlosk 2015/10/26 10:33:23 Done.
2622 // from the current RenderFrameHost.
2623 EXPECT_FALSE(change_observer.DidHostChange());
2624 EXPECT_FALSE(GetPendingFrameHost(manager));
2625 EXPECT_TRUE(host->web_ui());
2626 WebUIImpl* next_web_ui = manager->speculative_web_ui();
2627 EXPECT_TRUE(next_web_ui);
2628 EXPECT_NE(next_web_ui, host->web_ui());
2629 EXPECT_EQ(next_web_ui, host->pending_web_ui());
2630
2631 // Prepare to commit, updates the navigating RenderFrameHost.
clamy 2015/10/22 16:51:39 nit: update
carlosk 2015/10/26 10:33:23 Done.
2632 EXPECT_EQ(host, manager->GetFrameHostForNavigation(*navigation_request));
2633 host->set_pending_commit(true);
clamy 2015/10/22 16:51:39 Again, let's avoid using this boolean.
carlosk 2015/10/26 10:33:23 Acknowledged.
2634
2635 EXPECT_FALSE(GetPendingFrameHost(manager));
2636 EXPECT_TRUE(host->web_ui());
2637 EXPECT_NE(next_web_ui, host->web_ui());
2638 EXPECT_EQ(next_web_ui, manager->speculative_web_ui());
2639 EXPECT_EQ(next_web_ui, host->pending_web_ui());
2640
2641 // The RenderFrameHost committed.
2642 manager->DidNavigateFrame(host, true);
2643 EXPECT_FALSE(change_observer.DidHostChange());
2644 EXPECT_EQ(next_web_ui, host->web_ui());
2645 EXPECT_FALSE(manager->speculative_web_ui());
2646 EXPECT_FALSE(host->pending_web_ui());
2647 }
2648
2649 // PlzNavigate: Tests that the correct intermediary and final navigation states
2650 // are reached when navigating cross-site between two different WebUI types.
2651 TEST_F(RenderFrameHostManagerTestWithBrowserSideNavigation,
2652 NavigateCrossSiteBetweenWebUIs) {
2653 // Cross-site navigations will always cause the change of the WebUI instance
2654 // but for consistency sake different types will be set for each navigation.
2655 set_should_create_webui(true);
2656 set_webui_type(1);
2657 NavigateActiveAndCommit(GURL("chrome://foo"));
2658
2659 RenderFrameHostManager* manager = contents()->GetRenderManagerForTesting();
2660 TestRenderFrameHost* host =
2661 static_cast<TestRenderFrameHost*>(manager->current_frame_host());
2662 EXPECT_TRUE(host->IsRenderFrameLive());
2663 EXPECT_TRUE(host->web_ui());
2664
2665 RenderViewHostChangedObserver change_observer(contents());
2666 set_webui_type(2);
2667
2668 // Navigation request.
2669 const GURL kUrl("chrome://bar");
2670 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
2671 Referrer(), base::string16() /* title */,
2672 ui::PAGE_TRANSITION_TYPED,
2673 false /* is_renderer_init */);
2674 FrameNavigationEntry* frame_entry = entry.root_node()->frame_entry.get();
2675 scoped_ptr<NavigationRequest> navigation_request =
2676 NavigationRequest::CreateBrowserInitiated(
2677 contents()->GetFrameTree()->root(), frame_entry->url(),
2678 frame_entry->referrer(), *frame_entry, entry,
2679 FrameMsg_Navigate_Type::NORMAL, false, base::TimeTicks::Now(),
2680 static_cast<NavigationControllerImpl*>(&controller()));
2681 manager->DidCreateNavigationRequest(*navigation_request);
2682
2683 // Current WebUI should still be in place and a new one should be pending
clamy 2015/10/22 16:51:39 nit: see the comment about this comment above.
carlosk 2015/10/26 10:33:23 I adapted this to follow the same format but they
2684 // from the speculative RenderFrameHost.
2685 EXPECT_FALSE(change_observer.DidHostChange());
2686 TestRenderFrameHost* speculative_host =
2687 static_cast<TestRenderFrameHost*>(GetPendingFrameHost(manager));
2688 EXPECT_TRUE(speculative_host);
2689 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2690 WebUIImpl* next_web_ui = manager->speculative_web_ui();
2691 EXPECT_TRUE(next_web_ui);
2692 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
2693 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2694
2695 // Prepare to commit, updates the navigating RenderFrameHost.
clamy 2015/10/22 16:51:39 Nit: see comment above.
carlosk 2015/10/26 10:33:23 Done.
2696 EXPECT_EQ(speculative_host,
2697 manager->GetFrameHostForNavigation(*navigation_request));
2698 speculative_host->set_pending_commit(true);
2699
2700 EXPECT_EQ(speculative_host, GetPendingFrameHost(manager));
2701 EXPECT_TRUE(manager->current_frame_host()->web_ui());
2702 EXPECT_NE(next_web_ui, manager->current_frame_host()->web_ui());
clamy 2015/10/22 16:51:39 I think we should also test that the current RFH d
carlosk 2015/10/26 10:33:23 Done.
2703 EXPECT_EQ(next_web_ui, manager->speculative_web_ui());
2704 EXPECT_EQ(next_web_ui, speculative_host->web_ui());
2705
2706 // The RenderFrameHost committed.
2707 manager->DidNavigateFrame(speculative_host, true);
2708 EXPECT_EQ(speculative_host, manager->current_frame_host());
2709 EXPECT_TRUE(change_observer.DidHostChange());
2710 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui());
2711 EXPECT_FALSE(manager->speculative_web_ui());
2712 EXPECT_FALSE(speculative_host->pending_web_ui());
2713 }
2714
2491 } // namespace content 2715 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698