Home | History | Annotate | Download | only in extensions
      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.
      4 
      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"
      9 
     10 class ValueCounterUnittest : public testing::Test {
     11 };
     12 
     13 TEST_F(ValueCounterUnittest, TestAddingSameValue) {
     14   extensions::ValueCounter vc;
     15   base::ListValue value;
     16   ASSERT_EQ(1, vc.Add(value));
     17   ASSERT_EQ(2, vc.Add(value));
     18 }
     19 
     20 TEST_F(ValueCounterUnittest, TestAddingDifferentValue) {
     21   extensions::ValueCounter vc;
     22   base::ListValue value1;
     23   base::DictionaryValue value2;
     24   ASSERT_EQ(1, vc.Add(value1));
     25   ASSERT_EQ(1, vc.Add(value2));
     26 }
     27 
     28 TEST_F(ValueCounterUnittest, TestRemovingValue) {
     29   extensions::ValueCounter vc;
     30   base::ListValue value;
     31   ASSERT_EQ(1, vc.Add(value));
     32   ASSERT_EQ(2, vc.Add(value));
     33   ASSERT_EQ(1, vc.Remove(value));
     34   ASSERT_EQ(0, vc.Remove(value));
     35 }
     36 
     37 TEST_F(ValueCounterUnittest, TestAddIfMissing) {
     38   extensions::ValueCounter vc;
     39   base::ListValue value;
     40   ASSERT_EQ(1, vc.AddIfMissing(value));
     41   ASSERT_EQ(1, vc.AddIfMissing(value));
     42 }
     43