| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/guest_view/browser/guest_view_manager.h" | 5 #include "components/guest_view/browser/guest_view_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 11 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
| 12 #include "components/guest_view/browser/test_guest_view_manager.h" | 12 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 13 #include "content/public/test/test_browser_context.h" | |
| 14 #include "content/public/test/test_renderer_host.h" | 13 #include "content/public/test/test_renderer_host.h" |
| 15 #include "content/public/test/web_contents_tester.h" | 14 #include "content/public/test/web_contents_tester.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 using content::WebContents; | 17 using content::WebContents; |
| 19 using content::WebContentsTester; | 18 using content::WebContentsTester; |
| 20 | 19 |
| 21 namespace guest_view { | 20 namespace guest_view { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class GuestViewManagerTest : public content::RenderViewHostTestHarness { | 24 class GuestViewManagerTest : public content::RenderViewHostTestHarness { |
| 26 public: | 25 public: |
| 27 GuestViewManagerTest() {} | 26 GuestViewManagerTest() {} |
| 28 ~GuestViewManagerTest() override {} | 27 ~GuestViewManagerTest() override {} |
| 29 | 28 |
| 30 std::unique_ptr<WebContents> CreateWebContents() { | 29 std::unique_ptr<WebContents> CreateWebContents() { |
| 31 return std::unique_ptr<WebContents>( | 30 return std::unique_ptr<WebContents>( |
| 32 WebContentsTester::CreateTestWebContents(&browser_context_, NULL)); | 31 WebContentsTester::CreateTestWebContents(browser_context(), nullptr)); |
| 33 } | 32 } |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 content::TestBrowserContext browser_context_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest); | 35 DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest); |
| 39 }; | 36 }; |
| 40 | 37 |
| 41 } // namespace | 38 } // namespace |
| 42 | 39 |
| 43 TEST_F(GuestViewManagerTest, AddRemove) { | 40 TEST_F(GuestViewManagerTest, AddRemove) { |
| 44 content::TestBrowserContext browser_context; | |
| 45 std::unique_ptr<GuestViewManagerDelegate> delegate( | 41 std::unique_ptr<GuestViewManagerDelegate> delegate( |
| 46 new GuestViewManagerDelegate()); | 42 new GuestViewManagerDelegate()); |
| 47 std::unique_ptr<TestGuestViewManager> manager( | 43 std::unique_ptr<TestGuestViewManager> manager( |
| 48 new TestGuestViewManager(&browser_context, std::move(delegate))); | 44 new TestGuestViewManager(browser_context(), std::move(delegate))); |
| 49 | 45 |
| 50 std::unique_ptr<WebContents> web_contents1(CreateWebContents()); | 46 std::unique_ptr<WebContents> web_contents1(CreateWebContents()); |
| 51 std::unique_ptr<WebContents> web_contents2(CreateWebContents()); | 47 std::unique_ptr<WebContents> web_contents2(CreateWebContents()); |
| 52 std::unique_ptr<WebContents> web_contents3(CreateWebContents()); | 48 std::unique_ptr<WebContents> web_contents3(CreateWebContents()); |
| 53 | 49 |
| 54 EXPECT_EQ(0, manager->last_instance_id_removed()); | 50 EXPECT_EQ(0, manager->last_instance_id_removed()); |
| 55 | 51 |
| 56 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); | 52 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); |
| 57 EXPECT_TRUE(manager->CanUseGuestInstanceID(2)); | 53 EXPECT_TRUE(manager->CanUseGuestInstanceID(2)); |
| 58 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); | 54 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 EXPECT_EQ(3, manager->last_instance_id_removed()); | 76 EXPECT_EQ(3, manager->last_instance_id_removed()); |
| 81 | 77 |
| 82 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); | 78 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); |
| 83 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); | 79 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); |
| 84 EXPECT_FALSE(manager->CanUseGuestInstanceID(3)); | 80 EXPECT_FALSE(manager->CanUseGuestInstanceID(3)); |
| 85 | 81 |
| 86 EXPECT_EQ(0u, manager->GetNumRemovedInstanceIDs()); | 82 EXPECT_EQ(0u, manager->GetNumRemovedInstanceIDs()); |
| 87 } | 83 } |
| 88 | 84 |
| 89 } // namespace guest_view | 85 } // namespace guest_view |
| OLD | NEW |