Update V8 to version 4.7.16.
[chromium-blink-merge.git] / extensions / browser / process_map_unittest.cc
blob5512f75043ada137bb77e431c4dfe810f187422b
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.
5 #include "extensions/browser/process_map.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using extensions::ProcessMap;
11 TEST(ExtensionProcessMapTest, Test) {
12 ProcessMap map;
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());
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());
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());
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());
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));
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));
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());
53 // Should still return true because there were two site instances for this
54 // extension/process pair.
55 EXPECT_TRUE(map.Contains("a", 1));
57 EXPECT_TRUE(map.Remove("a", 1, 5));
58 EXPECT_EQ(3u, map.size());
59 EXPECT_FALSE(map.Contains("a", 1));
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());