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