Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / common / extensions / value_counter_unittest.cc
blob84f51b97fb4227b6b59d74163a480b09c15b0d7e
1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
6 #include "base/values.h"
7 #include "extensions/common/value_counter.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using ValueCounterTest = testing::Test;
12 namespace extensions {
14 TEST_F(ValueCounterTest, TestAddingSameValue) {
15 ValueCounter vc;
16 base::ListValue value;
17 ASSERT_TRUE(vc.Add(value));
18 ASSERT_FALSE(vc.Add(value));
21 TEST_F(ValueCounterTest, TestAddingDifferentValue) {
22 ValueCounter vc;
23 base::ListValue value1;
24 base::DictionaryValue value2;
25 ASSERT_TRUE(vc.Add(value1));
26 ASSERT_TRUE(vc.Add(value2));
29 TEST_F(ValueCounterTest, TestRemovingSameValue) {
30 ValueCounter vc;
31 base::ListValue value;
32 vc.Add(value);
33 vc.Add(value);
34 ASSERT_FALSE(vc.Remove(value));
35 ASSERT_TRUE(vc.Remove(value));
36 ASSERT_FALSE(vc.Remove(value));
39 TEST_F(ValueCounterTest, TestReAddingSameValue) {
40 ValueCounter vc;
41 base::ListValue value;
42 ASSERT_FALSE(vc.Remove(value));
43 ASSERT_TRUE(vc.Add(value));
44 ASSERT_TRUE(vc.Remove(value));
45 ASSERT_TRUE(vc.Add(value));
46 ASSERT_TRUE(vc.Remove(value));
47 ASSERT_FALSE(vc.Remove(value));
50 TEST_F(ValueCounterTest, TestIsEmpty) {
51 ValueCounter vc;
52 base::ListValue value1;
53 base::DictionaryValue value2;
54 ASSERT_TRUE(vc.is_empty());
55 vc.Add(value1);
56 ASSERT_FALSE(vc.is_empty());
57 vc.Remove(value1);
58 ASSERT_TRUE(vc.is_empty());
59 vc.Add(value1);
60 vc.Add(value2);
61 ASSERT_FALSE(vc.is_empty());
62 vc.Remove(value1);
63 ASSERT_FALSE(vc.is_empty());
64 vc.Remove(value2);
65 ASSERT_TRUE(vc.is_empty());
68 } // namespace extensions