OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 6 |
| 7 #include "chrome/test/base/testing_profile.h" |
| 8 #include "content/public/test/test_browser_thread_bundle.h" |
| 9 #include "content/public/test/web_contents_tester.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 using content::WebContents; |
| 13 using content::WebContentsTester; |
| 14 |
| 15 class GuestViewManagerTest : public testing::Test { |
| 16 public: |
| 17 GuestViewManagerTest() {} |
| 18 virtual ~GuestViewManagerTest() {} |
| 19 |
| 20 scoped_ptr<WebContents> CreateWebContents() { |
| 21 return scoped_ptr<WebContents>( |
| 22 WebContentsTester::CreateTestWebContents(&profile_, NULL)); |
| 23 } |
| 24 |
| 25 private: |
| 26 content::TestBrowserThreadBundle thread_bundle_; |
| 27 TestingProfile profile_; |
| 28 |
| 29 DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest); |
| 30 }; |
| 31 |
| 32 // This class allows us to access some private variables in |
| 33 // GuestViewManager. |
| 34 class TestGuestViewManager : public GuestViewManager { |
| 35 public: |
| 36 explicit TestGuestViewManager(content::BrowserContext* context) |
| 37 : GuestViewManager(context) {} |
| 38 |
| 39 int last_instance_id_removed_for_testing() { |
| 40 return last_instance_id_removed_; |
| 41 } |
| 42 |
| 43 size_t GetRemovedInstanceIdSize() { return removed_instance_ids_.size(); } |
| 44 |
| 45 private: |
| 46 using GuestViewManager::last_instance_id_removed_; |
| 47 using GuestViewManager::removed_instance_ids_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager); |
| 50 }; |
| 51 |
| 52 TEST_F(GuestViewManagerTest, AddRemove) { |
| 53 TestingProfile profile; |
| 54 scoped_ptr<TestGuestViewManager> manager(new TestGuestViewManager(&profile)); |
| 55 |
| 56 scoped_ptr<WebContents> web_contents1(CreateWebContents()); |
| 57 scoped_ptr<WebContents> web_contents2(CreateWebContents()); |
| 58 scoped_ptr<WebContents> web_contents3(CreateWebContents()); |
| 59 |
| 60 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing()); |
| 61 |
| 62 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); |
| 63 EXPECT_TRUE(manager->CanUseGuestInstanceID(2)); |
| 64 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); |
| 65 |
| 66 manager->AddGuest(1, web_contents1.get()); |
| 67 manager->AddGuest(2, web_contents2.get()); |
| 68 manager->RemoveGuest(2); |
| 69 |
| 70 // Since we removed 2, it would be an invalid ID. |
| 71 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); |
| 72 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); |
| 73 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); |
| 74 |
| 75 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing()); |
| 76 |
| 77 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); |
| 78 |
| 79 manager->AddGuest(3, web_contents3.get()); |
| 80 manager->RemoveGuest(1); |
| 81 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); |
| 82 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); |
| 83 |
| 84 EXPECT_EQ(2, manager->last_instance_id_removed_for_testing()); |
| 85 manager->RemoveGuest(3); |
| 86 EXPECT_EQ(3, manager->last_instance_id_removed_for_testing()); |
| 87 |
| 88 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); |
| 89 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); |
| 90 EXPECT_FALSE(manager->CanUseGuestInstanceID(3)); |
| 91 |
| 92 EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize()); |
| 93 } |
OLD | NEW |