summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/value_counter_unittest.cc
blob: 6ad74541c1bf0630b0a80572ab6491344cab4f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/common/extensions/value_counter.h"
#include "testing/gtest/include/gtest/gtest.h"

class ValueCounterUnittest : public testing::Test {
};

TEST_F(ValueCounterUnittest, TestAddingSameValue) {
  extensions::ValueCounter vc;
  base::ListValue value;
  ASSERT_EQ(1, vc.Add(value));
  ASSERT_EQ(2, vc.Add(value));
}

TEST_F(ValueCounterUnittest, TestAddingDifferentValue) {
  extensions::ValueCounter vc;
  base::ListValue value1;
  base::DictionaryValue value2;
  ASSERT_EQ(1, vc.Add(value1));
  ASSERT_EQ(1, vc.Add(value2));
}

TEST_F(ValueCounterUnittest, TestRemovingValue) {
  extensions::ValueCounter vc;
  base::ListValue value;
  ASSERT_EQ(1, vc.Add(value));
  ASSERT_EQ(2, vc.Add(value));
  ASSERT_EQ(1, vc.Remove(value));
  ASSERT_EQ(0, vc.Remove(value));
}

TEST_F(ValueCounterUnittest, TestAddIfMissing) {
  extensions::ValueCounter vc;
  base::ListValue value;
  ASSERT_EQ(1, vc.AddIfMissing(value));
  ASSERT_EQ(1, vc.AddIfMissing(value));
}