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 "chrome/browser/guest_view/guest_view_manager.h" | 5 #include "chrome/browser/guest_view/guest_view_manager.h" |
6 | 6 |
7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
8 #include "content/public/test/test_browser_thread_bundle.h" | 8 #include "content/public/test/test_browser_thread_bundle.h" |
9 #include "content/public/test/web_contents_tester.h" | 9 #include "content/public/test/web_contents_tester.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using content::WebContents; | 12 using content::WebContents; |
13 using content::WebContentsTester; | 13 using content::WebContentsTester; |
14 | 14 |
15 class GuestViewManagerTest : public testing::Test { | 15 namespace guestview { |
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 | 16 |
32 // This class allows us to access some private variables in | 17 // This class allows us to access some private variables in |
33 // GuestViewManager. | 18 // GuestViewManager. |
34 class TestGuestViewManager : public GuestViewManager { | 19 class TestGuestViewManager : public GuestViewManager { |
35 public: | 20 public: |
36 explicit TestGuestViewManager(content::BrowserContext* context) | 21 explicit TestGuestViewManager(content::BrowserContext* context) |
37 : GuestViewManager(context) {} | 22 : GuestViewManager(context) {} |
38 | 23 |
39 int last_instance_id_removed_for_testing() { | 24 int last_instance_id_removed_for_testing() { |
40 return last_instance_id_removed_; | 25 return last_instance_id_removed_; |
41 } | 26 } |
42 | 27 |
43 size_t GetRemovedInstanceIdSize() { return removed_instance_ids_.size(); } | 28 size_t GetRemovedInstanceIdSize() { return removed_instance_ids_.size(); } |
44 | 29 |
45 private: | 30 private: |
46 using GuestViewManager::last_instance_id_removed_; | 31 using GuestViewManager::last_instance_id_removed_; |
47 using GuestViewManager::removed_instance_ids_; | 32 using GuestViewManager::removed_instance_ids_; |
48 | 33 |
49 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager); | 34 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager); |
50 }; | 35 }; |
51 | 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 |
52 TEST_F(GuestViewManagerTest, AddRemove) { | 60 TEST_F(GuestViewManagerTest, AddRemove) { |
53 TestingProfile profile; | 61 TestingProfile profile; |
54 scoped_ptr<TestGuestViewManager> manager(new TestGuestViewManager(&profile)); | 62 scoped_ptr<guestview::TestGuestViewManager> manager( |
| 63 new guestview::TestGuestViewManager(&profile)); |
55 | 64 |
56 scoped_ptr<WebContents> web_contents1(CreateWebContents()); | 65 scoped_ptr<WebContents> web_contents1(CreateWebContents()); |
57 scoped_ptr<WebContents> web_contents2(CreateWebContents()); | 66 scoped_ptr<WebContents> web_contents2(CreateWebContents()); |
58 scoped_ptr<WebContents> web_contents3(CreateWebContents()); | 67 scoped_ptr<WebContents> web_contents3(CreateWebContents()); |
59 | 68 |
60 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing()); | 69 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing()); |
61 | 70 |
62 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); | 71 EXPECT_TRUE(manager->CanUseGuestInstanceID(1)); |
63 EXPECT_TRUE(manager->CanUseGuestInstanceID(2)); | 72 EXPECT_TRUE(manager->CanUseGuestInstanceID(2)); |
64 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); | 73 EXPECT_TRUE(manager->CanUseGuestInstanceID(3)); |
(...skipping 19 matching lines...) Expand all Loading... |
84 EXPECT_EQ(2, manager->last_instance_id_removed_for_testing()); | 93 EXPECT_EQ(2, manager->last_instance_id_removed_for_testing()); |
85 manager->RemoveGuest(3); | 94 manager->RemoveGuest(3); |
86 EXPECT_EQ(3, manager->last_instance_id_removed_for_testing()); | 95 EXPECT_EQ(3, manager->last_instance_id_removed_for_testing()); |
87 | 96 |
88 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); | 97 EXPECT_FALSE(manager->CanUseGuestInstanceID(1)); |
89 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); | 98 EXPECT_FALSE(manager->CanUseGuestInstanceID(2)); |
90 EXPECT_FALSE(manager->CanUseGuestInstanceID(3)); | 99 EXPECT_FALSE(manager->CanUseGuestInstanceID(3)); |
91 | 100 |
92 EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize()); | 101 EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize()); |
93 } | 102 } |
OLD | NEW |