1 // Copyright 2013 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. 4 5 #include "extensions/browser/process_map.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 using extensions::ProcessMap; 10 11 TEST(ExtensionProcessMapTest, Test) { 12 ProcessMap map; 13 14 // Test behavior when empty. 15 EXPECT_FALSE(map.Contains("a", 1)); 16 EXPECT_FALSE(map.Remove("a", 1, 1)); 17 EXPECT_EQ(0u, map.size()); 18 19 // Test insertion and behavior with one item. 20 EXPECT_TRUE(map.Insert("a", 1, 1)); 21 EXPECT_TRUE(map.Contains("a", 1)); 22 EXPECT_FALSE(map.Contains("a", 2)); 23 EXPECT_FALSE(map.Contains("b", 1)); 24 EXPECT_EQ(1u, map.size()); 25 26 // Test inserting a duplicate item. 27 EXPECT_FALSE(map.Insert("a", 1, 1)); 28 EXPECT_TRUE(map.Contains("a", 1)); 29 EXPECT_EQ(1u, map.size()); 30 31 // Insert some more items. 32 EXPECT_TRUE(map.Insert("a", 2, 2)); 33 EXPECT_TRUE(map.Insert("b", 1, 3)); 34 EXPECT_TRUE(map.Insert("b", 2, 4)); 35 EXPECT_EQ(4u, map.size()); 36 37 EXPECT_TRUE(map.Contains("a", 1)); 38 EXPECT_TRUE(map.Contains("a", 2)); 39 EXPECT_TRUE(map.Contains("b", 1)); 40 EXPECT_TRUE(map.Contains("b", 2)); 41 EXPECT_FALSE(map.Contains("a", 3)); 42 43 // Note that this only differs from an existing item because of the site 44 // instance id. 45 EXPECT_TRUE(map.Insert("a", 1, 5)); 46 EXPECT_TRUE(map.Contains("a", 1)); 47 48 // Test removal. 49 EXPECT_TRUE(map.Remove("a", 1, 1)); 50 EXPECT_FALSE(map.Remove("a", 1, 1)); 51 EXPECT_EQ(4u, map.size()); 52 53 // Should still return true because there were two site instances for this 54 // extension/process pair. 55 EXPECT_TRUE(map.Contains("a", 1)); 56 57 EXPECT_TRUE(map.Remove("a", 1, 5)); 58 EXPECT_EQ(3u, map.size()); 59 EXPECT_FALSE(map.Contains("a", 1)); 60 61 EXPECT_EQ(2, map.RemoveAllFromProcess(2)); 62 EXPECT_EQ(1u, map.size()); 63 EXPECT_EQ(0, map.RemoveAllFromProcess(2)); 64 EXPECT_EQ(1u, map.size()); 65 } 66