| Index: chrome/browser/guest_view/guest_view_manager_unittest.cc
|
| diff --git a/chrome/browser/guest_view/guest_view_manager_unittest.cc b/chrome/browser/guest_view/guest_view_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b13c8faab248ebfca2ace80e49281562a2a129bc
|
| --- /dev/null
|
| +++ b/chrome/browser/guest_view/guest_view_manager_unittest.cc
|
| @@ -0,0 +1,72 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/guest_view/guest_view_manager.h"
|
| +
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "content/public/test/web_contents_tester.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::WebContents;
|
| +using content::WebContentsTester;
|
| +
|
| +class GuestViewManagerTest : public testing::Test {
|
| + public:
|
| + GuestViewManagerTest() {}
|
| + virtual ~GuestViewManagerTest() {}
|
| +
|
| + scoped_ptr<WebContents> CreateWebContents() {
|
| + return scoped_ptr<WebContents>(
|
| + WebContentsTester::CreateTestWebContents(&profile_, NULL));
|
| + }
|
| +
|
| + private:
|
| + content::TestBrowserThreadBundle thread_bundle_;
|
| + TestingProfile profile_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(GuestViewManagerTest);
|
| +};
|
| +
|
| +// This class allows us to access some private variables in
|
| +// GuestViewManager.
|
| +class TestGuestViewManager : public GuestViewManager {
|
| + public:
|
| + explicit TestGuestViewManager(content::BrowserContext* context)
|
| + : GuestViewManager(context) {}
|
| +
|
| + int last_instance_id_removed_for_testing() {
|
| + return last_instance_id_removed_;
|
| + }
|
| +
|
| + size_t GetRemovedInstanceIdSize() { return removed_instance_ids_.size(); }
|
| +
|
| + private:
|
| + using GuestViewManager::last_instance_id_removed_;
|
| + using GuestViewManager::removed_instance_ids_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager);
|
| +};
|
| +
|
| +TEST_F(GuestViewManagerTest, AddRemove) {
|
| + TestingProfile profile;
|
| + scoped_ptr<TestGuestViewManager> manager(new TestGuestViewManager(&profile));
|
| +
|
| + scoped_ptr<WebContents> web_contents1(CreateWebContents());
|
| + scoped_ptr<WebContents> web_contents2(CreateWebContents());
|
| + scoped_ptr<WebContents> web_contents3(CreateWebContents());
|
| +
|
| + EXPECT_EQ(0, manager->last_instance_id_removed_for_testing());
|
| + EXPECT_TRUE(manager->AddGuest(1, web_contents1.get()));
|
| + EXPECT_TRUE(manager->AddGuest(2, web_contents2.get()));
|
| + manager->RemoveGuest(2);
|
| + EXPECT_EQ(0, manager->last_instance_id_removed_for_testing());
|
| + EXPECT_TRUE(manager->AddGuest(3, web_contents3.get()));
|
| + manager->RemoveGuest(1);
|
| + EXPECT_EQ(2, manager->last_instance_id_removed_for_testing());
|
| + manager->RemoveGuest(3);
|
| + EXPECT_EQ(3, manager->last_instance_id_removed_for_testing());
|
| +
|
| + EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize());
|
| +}
|
|
|