OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 2573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { | 2584 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { |
2585 scoped_refptr<SiteInstance> instance1( | 2585 scoped_refptr<SiteInstance> instance1( |
2586 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); | 2586 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); |
2587 scoped_refptr<SiteInstance> instance2( | 2587 scoped_refptr<SiteInstance> instance2( |
2588 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); | 2588 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); |
2589 | 2589 |
2590 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); | 2590 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
2591 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); | 2591 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
2592 | 2592 |
2593 scoped_ptr<TestWebContents> contents1( | 2593 scoped_ptr<TestWebContents> contents1( |
2594 TestWebContents::Create(browser_context(), instance1)); | 2594 TestWebContents::Create(browser_context(), instance1.get())); |
2595 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); | 2595 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
2596 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); | 2596 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
2597 | 2597 |
2598 scoped_ptr<TestWebContents> contents2( | 2598 scoped_ptr<TestWebContents> contents2( |
2599 TestWebContents::Create(browser_context(), instance1)); | 2599 TestWebContents::Create(browser_context(), instance1.get())); |
2600 EXPECT_EQ(2u, instance1->GetRelatedActiveContentsCount()); | 2600 EXPECT_EQ(2u, instance1->GetRelatedActiveContentsCount()); |
2601 EXPECT_EQ(2u, instance2->GetRelatedActiveContentsCount()); | 2601 EXPECT_EQ(2u, instance2->GetRelatedActiveContentsCount()); |
2602 | 2602 |
2603 contents1.reset(); | 2603 contents1.reset(); |
2604 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); | 2604 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
2605 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); | 2605 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
2606 | 2606 |
2607 contents2.reset(); | 2607 contents2.reset(); |
2608 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); | 2608 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
2609 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); | 2609 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
2610 } | 2610 } |
2611 | 2611 |
2612 // Tests that GetRelatedActiveContentsCount is preserved correctly across | 2612 // Tests that GetRelatedActiveContentsCount is preserved correctly across |
2613 // same-site and cross-site navigations. | 2613 // same-site and cross-site navigations. |
2614 TEST_F(WebContentsImplTest, ActiveContentsCountNavigate) { | 2614 TEST_F(WebContentsImplTest, ActiveContentsCountNavigate) { |
2615 scoped_refptr<SiteInstance> instance( | 2615 scoped_refptr<SiteInstance> instance( |
2616 SiteInstance::Create(browser_context())); | 2616 SiteInstance::Create(browser_context())); |
2617 | 2617 |
2618 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2618 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2619 | 2619 |
2620 scoped_ptr<TestWebContents> contents( | 2620 scoped_ptr<TestWebContents> contents( |
2621 TestWebContents::Create(browser_context(), instance)); | 2621 TestWebContents::Create(browser_context(), instance.get())); |
2622 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2622 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2623 | 2623 |
2624 // Navigate to a URL. | 2624 // Navigate to a URL. |
2625 contents->GetController().LoadURL( | 2625 contents->GetController().LoadURL( |
2626 GURL("http://a.com/1"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2626 GURL("http://a.com/1"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2627 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2627 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2628 contents->CommitPendingNavigation(); | 2628 contents->CommitPendingNavigation(); |
2629 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2629 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2630 | 2630 |
2631 // Navigate to a URL in the same site. | 2631 // Navigate to a URL in the same site. |
(...skipping 17 matching lines...) Expand all Loading... |
2649 | 2649 |
2650 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes | 2650 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes |
2651 // from WebUI. | 2651 // from WebUI. |
2652 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { | 2652 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { |
2653 scoped_refptr<SiteInstance> instance( | 2653 scoped_refptr<SiteInstance> instance( |
2654 SiteInstance::Create(browser_context())); | 2654 SiteInstance::Create(browser_context())); |
2655 | 2655 |
2656 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2656 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2657 | 2657 |
2658 scoped_ptr<TestWebContents> contents( | 2658 scoped_ptr<TestWebContents> contents( |
2659 TestWebContents::Create(browser_context(), instance)); | 2659 TestWebContents::Create(browser_context(), instance.get())); |
2660 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2660 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2661 | 2661 |
2662 // Navigate to a URL. | 2662 // Navigate to a URL. |
2663 contents->NavigateAndCommit(GURL("http://a.com")); | 2663 contents->NavigateAndCommit(GURL("http://a.com")); |
2664 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2664 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2665 | 2665 |
2666 // Navigate to a URL with WebUI. This will change BrowsingInstances. | 2666 // Navigate to a URL with WebUI. This will change BrowsingInstances. |
2667 contents->GetController().LoadURL( | 2667 contents->GetController().LoadURL( |
2668 GURL(kTestWebUIUrl), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2668 GURL(kTestWebUIUrl), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2669 EXPECT_TRUE(contents->cross_navigation_pending()); | 2669 EXPECT_TRUE(contents->cross_navigation_pending()); |
2670 scoped_refptr<SiteInstance> instance_webui( | 2670 scoped_refptr<SiteInstance> instance_webui( |
2671 contents->GetPendingMainFrame()->GetSiteInstance()); | 2671 contents->GetPendingMainFrame()->GetSiteInstance()); |
2672 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); | 2672 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); |
2673 | 2673 |
2674 // At this point, contents still counts for the old BrowsingInstance. | 2674 // At this point, contents still counts for the old BrowsingInstance. |
2675 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2675 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2676 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2676 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
2677 | 2677 |
2678 // Commit and contents counts for the new one. | 2678 // Commit and contents counts for the new one. |
2679 contents->CommitPendingNavigation(); | 2679 contents->CommitPendingNavigation(); |
2680 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2680 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2681 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); | 2681 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); |
2682 | 2682 |
2683 contents.reset(); | 2683 contents.reset(); |
2684 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2684 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2685 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2685 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
2686 } | 2686 } |
2687 | 2687 |
2688 } // namespace content | 2688 } // namespace content |
OLD | NEW |