Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2132)

Unified Diff: chrome/browser/guest_view/guest_view_manager_unittest.cc

Issue 298913003: Do not allow GuestViewManager to (re)use an instance ID that was already removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/guest_view/guest_view_manager.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..21ca720f506173378eb59f2c1b86a88a5aeacbaa
--- /dev/null
+++ b/chrome/browser/guest_view/guest_view_manager_unittest.cc
@@ -0,0 +1,93 @@
+// 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->CanUseGuestInstanceID(1));
+ EXPECT_TRUE(manager->CanUseGuestInstanceID(2));
+ EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
+
+ manager->AddGuest(1, web_contents1.get());
+ manager->AddGuest(2, web_contents2.get());
+ manager->RemoveGuest(2);
+
+ // Since we removed 2, it would be an invalid ID.
+ EXPECT_TRUE(manager->CanUseGuestInstanceID(1));
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
+ EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
+
+ EXPECT_EQ(0, manager->last_instance_id_removed_for_testing());
+
+ EXPECT_TRUE(manager->CanUseGuestInstanceID(3));
+
+ manager->AddGuest(3, web_contents3.get());
+ manager->RemoveGuest(1);
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
+
+ EXPECT_EQ(2, manager->last_instance_id_removed_for_testing());
+ manager->RemoveGuest(3);
+ EXPECT_EQ(3, manager->last_instance_id_removed_for_testing());
+
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(1));
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(2));
+ EXPECT_FALSE(manager->CanUseGuestInstanceID(3));
+
+ EXPECT_EQ(0u, manager->GetRemovedInstanceIdSize());
+}
« no previous file with comments | « chrome/browser/guest_view/guest_view_manager.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698