Disable accessible touch exploration by default.
[chromium-blink-merge.git] / chrome / browser / guest_view / guest_view_manager_unittest.cc
blob05b53d581bbf4a0357a0017837bb4ead0612846c
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.
5 #include "chrome/browser/guest_view/guest_view_manager.h"
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"
12 using content::WebContents;
13 using content::WebContentsTester;
15 namespace guestview {
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) {}
24 int last_instance_id_removed_for_testing() {
25 return last_instance_id_removed_;
28 size_t GetRemovedInstanceIdSize() { return removed_instance_ids_.size(); }
30 private:
31 using GuestViewManager::last_instance_id_removed_;
32 using GuestViewManager::removed_instance_ids_;
34 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager);
37 } // namespace guestview
39 namespace {
41 class GuestViewManagerTest : public testing::Test {
42 public:
43 GuestViewManagerTest() {}
44 virtual ~GuestViewManagerTest() {}
46 scoped_ptr<WebContents> CreateWebContents() {
47 return scoped_ptr<WebContents>(
48 WebContentsTester::CreateTestWebContents(&profile_, NULL));
51 private:
52 content::TestBrowserThreadBundle thread_bundle_;
53 TestingProfile profile_;
55 DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest);
58 } // namespace
60 TEST_F(GuestViewManagerTest, AddRemove) {
61 TestingProfile profile;
62 scoped_ptr<guestview::TestGuestViewManager> manager(
63 new guestview::TestGuestViewManager(&profile));
65 scoped_ptr<WebContents> web_contents1(CreateWebContents());
66 scoped_ptr<WebContents> web_contents2(CreateWebContents());
67 scoped_ptr<WebContents> web_contents3(CreateWebContents());
69 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing());
71 EXPECT_TRUE(manager->CanUseGuestInstanceID(1));
72 EXPECT_TRUE(manager->CanUseGuestInstanceID(2));
73 EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
75 manager->AddGuest(1, web_contents1.get());
76 manager->AddGuest(2, web_contents2.get());
77 manager->RemoveGuest(2);
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));
84 EXPECT_EQ(0, manager->last_instance_id_removed_for_testing());
86 EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
88 manager->AddGuest(3, web_contents3.get());
89 manager->RemoveGuest(1);
90 EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
91 EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
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());
97 EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
98 EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
99 EXPECT_FALSE(manager->CanUseGuestInstanceID(3));
101 EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize());