Roll ANGLE cc54ab3..c5b2ba5
[chromium-blink-merge.git] / components / guest_view / browser / guest_view_manager_unittest.cc
blob1d43dbd545c1e25dab6e25b480a2b9c4c1ccb803
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 "components/guest_view/browser/guest_view_manager.h"
6 #include "components/guest_view/browser/guest_view_manager_delegate.h"
7 #include "components/guest_view/browser/test_guest_view_manager.h"
8 #include "content/public/test/test_browser_context.h"
9 #include "content/public/test/test_renderer_host.h"
10 #include "content/public/test/web_contents_tester.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using content::WebContents;
14 using content::WebContentsTester;
16 namespace guest_view {
18 namespace {
20 class GuestViewManagerTest : public content::RenderViewHostTestHarness {
21 public:
22 GuestViewManagerTest() {}
23 ~GuestViewManagerTest() override {}
25 scoped_ptr<WebContents> CreateWebContents() {
26 return scoped_ptr<WebContents>(
27 WebContentsTester::CreateTestWebContents(&browser_context_, NULL));
30 private:
31 content::TestBrowserContext browser_context_;
33 DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest);
36 } // namespace
38 TEST_F(GuestViewManagerTest, AddRemove) {
39 content::TestBrowserContext browser_context;
40 scoped_ptr<GuestViewManagerDelegate> delegate(
41 new GuestViewManagerDelegate());
42 scoped_ptr<TestGuestViewManager> manager(
43 new TestGuestViewManager(&browser_context, delegate.Pass()));
45 scoped_ptr<WebContents> web_contents1(CreateWebContents());
46 scoped_ptr<WebContents> web_contents2(CreateWebContents());
47 scoped_ptr<WebContents> web_contents3(CreateWebContents());
49 EXPECT_EQ(0, manager->last_instance_id_removed());
51 EXPECT_TRUE(manager->CanUseGuestInstanceID(1));
52 EXPECT_TRUE(manager->CanUseGuestInstanceID(2));
53 EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
55 manager->AddGuest(1, web_contents1.get());
56 manager->AddGuest(2, web_contents2.get());
57 manager->RemoveGuest(2);
59 // Since we removed 2, it would be an invalid ID.
60 EXPECT_TRUE(manager->CanUseGuestInstanceID(1));
61 EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
62 EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
64 EXPECT_EQ(0, manager->last_instance_id_removed());
66 EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
68 manager->AddGuest(3, web_contents3.get());
69 manager->RemoveGuest(1);
70 EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
71 EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
73 EXPECT_EQ(2, manager->last_instance_id_removed());
74 manager->RemoveGuest(3);
75 EXPECT_EQ(3, manager->last_instance_id_removed());
77 EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
78 EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
79 EXPECT_FALSE(manager->CanUseGuestInstanceID(3));
81 EXPECT_EQ(0u, manager->GetNumRemovedInstanceIDs());
84 } // namespace guest_view