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 2517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 event = SyntheticWebGestureEventBuilder::Build( | 2528 event = SyntheticWebGestureEventBuilder::Build( |
2529 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen); | 2529 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen); |
2530 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3; | 2530 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3; |
2531 EXPECT_FALSE(contents()->HandleGestureEvent(event)); | 2531 EXPECT_FALSE(contents()->HandleGestureEvent(event)); |
2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
2533 | 2533 |
2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime. | 2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime. |
2535 contents()->SetDelegate(NULL); | 2535 contents()->SetDelegate(NULL); |
2536 } | 2536 } |
2537 | 2537 |
| 2538 // Tests that GetRelatedActiveContentsCount is shared between related |
| 2539 // SiteInstances and includes WebContents that have not navigated yet. |
| 2540 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { |
| 2541 scoped_refptr<SiteInstance> instance1( |
| 2542 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); |
| 2543 scoped_refptr<SiteInstance> instance2( |
| 2544 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); |
| 2545 |
| 2546 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
| 2547 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
| 2548 |
| 2549 scoped_ptr<TestWebContents> contents1( |
| 2550 TestWebContents::Create(browser_context(), instance1)); |
| 2551 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
| 2552 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
| 2553 |
| 2554 scoped_ptr<TestWebContents> contents2( |
| 2555 TestWebContents::Create(browser_context(), instance1)); |
| 2556 EXPECT_EQ(2u, instance1->GetRelatedActiveContentsCount()); |
| 2557 EXPECT_EQ(2u, instance2->GetRelatedActiveContentsCount()); |
| 2558 |
| 2559 contents1.reset(); |
| 2560 EXPECT_EQ(1u, instance1->GetRelatedActiveContentsCount()); |
| 2561 EXPECT_EQ(1u, instance2->GetRelatedActiveContentsCount()); |
| 2562 |
| 2563 contents2.reset(); |
| 2564 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
| 2565 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
| 2566 } |
| 2567 |
| 2568 // Tests that GetRelatedActiveContentsCount is preserved correctly across |
| 2569 // same-site and cross-site navigations. |
| 2570 TEST_F(WebContentsImplTest, ActiveContentsCountNavigate) { |
| 2571 scoped_refptr<SiteInstance> instance( |
| 2572 SiteInstance::Create(browser_context())); |
| 2573 |
| 2574 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2575 |
| 2576 scoped_ptr<TestWebContents> contents( |
| 2577 TestWebContents::Create(browser_context(), instance)); |
| 2578 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2579 |
| 2580 // Navigate to a URL. |
| 2581 contents->GetController().LoadURL( |
| 2582 GURL("http://a.com/1"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2583 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2584 contents->CommitPendingNavigation(); |
| 2585 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2586 |
| 2587 // Navigate to a URL in the same site. |
| 2588 contents->GetController().LoadURL( |
| 2589 GURL("http://a.com/2"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2590 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2591 contents->CommitPendingNavigation(); |
| 2592 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2593 |
| 2594 // Navigate to a URL in a different site. |
| 2595 contents->GetController().LoadURL( |
| 2596 GURL("http://b.com"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2597 EXPECT_TRUE(contents->cross_navigation_pending()); |
| 2598 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2599 contents->CommitPendingNavigation(); |
| 2600 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2601 |
| 2602 contents.reset(); |
| 2603 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2604 } |
| 2605 |
| 2606 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes |
| 2607 // from WebUI. |
| 2608 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { |
| 2609 scoped_refptr<SiteInstance> instance( |
| 2610 SiteInstance::Create(browser_context())); |
| 2611 |
| 2612 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2613 |
| 2614 scoped_ptr<TestWebContents> contents( |
| 2615 TestWebContents::Create(browser_context(), instance)); |
| 2616 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2617 |
| 2618 // Navigate to a URL. |
| 2619 contents->NavigateAndCommit(GURL("http://a.com")); |
| 2620 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2621 |
| 2622 // Navigate to a URL with WebUI. This will change BrowsingInstances. |
| 2623 contents->GetController().LoadURL( |
| 2624 GURL(kTestWebUIUrl), Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 2625 EXPECT_TRUE(contents->cross_navigation_pending()); |
| 2626 scoped_refptr<SiteInstance> instance_webui( |
| 2627 contents->GetPendingRenderViewHost()->GetSiteInstance()); |
| 2628 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); |
| 2629 |
| 2630 // At this point, contents still counts for the old BrowsingInstance. |
| 2631 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
| 2632 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
| 2633 |
| 2634 // Commit and contents counts for the new one. |
| 2635 contents->CommitPendingNavigation(); |
| 2636 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2637 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); |
| 2638 |
| 2639 contents.reset(); |
| 2640 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2641 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
| 2642 } |
| 2643 |
2538 } // namespace content | 2644 } // namespace content |
OLD | NEW |