Index: content/common/worker_use_counter_unittest.cc |
diff --git a/content/common/worker_use_counter_unittest.cc b/content/common/worker_use_counter_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..069839fcae5724d8b5ffe500f2a5e9fad84835f9 |
--- /dev/null |
+++ b/content/common/worker_use_counter_unittest.cc |
@@ -0,0 +1,71 @@ |
+// Copyright 2017 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 "content/common/worker_use_counter.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace content { |
+ |
+TEST(WorkerUseCounterTest, Count) { |
+ WorkerUseCounter counter; |
+ |
+ counter.Count(0); |
+ EXPECT_TRUE(counter.IsCounted(0)); |
+ EXPECT_FALSE(counter.IsCounted(1)); |
+ |
+ counter.Count(4); |
+ EXPECT_FALSE(counter.IsCounted(3)); |
+ EXPECT_TRUE(counter.IsCounted(4)); |
+ EXPECT_FALSE(counter.IsCounted(5)); |
+ |
+ counter.Count(8); |
+ counter.Count(9); |
+ EXPECT_FALSE(counter.IsCounted(7)); |
+ EXPECT_TRUE(counter.IsCounted(8)); |
+ EXPECT_TRUE(counter.IsCounted(9)); |
+ EXPECT_FALSE(counter.IsCounted(10)); |
+ |
+ counter.Count(1024); |
+ counter.Count(4096); |
+ EXPECT_TRUE(counter.IsCounted(1024)); |
+ EXPECT_TRUE(counter.IsCounted(4096)); |
+ |
+ int number_of_bits = 0; |
+ for (size_t i = 0; i < counter.GetNumberOfBits(); ++i) { |
+ if (counter.IsCounted(i)) |
+ ++number_of_bits; |
+ } |
+ EXPECT_EQ(6, number_of_bits); |
+} |
+ |
+TEST(WorkerUseCounterTest, Dump) { |
+ WorkerUseCounter counter1; |
+ |
+ counter1.Count(0); |
+ counter1.Count(10); |
+ counter1.Count(1024); |
+ counter1.Count(4096); |
+ EXPECT_TRUE(counter1.IsCounted(0)); |
+ EXPECT_TRUE(counter1.IsCounted(10)); |
+ EXPECT_TRUE(counter1.IsCounted(1024)); |
+ EXPECT_TRUE(counter1.IsCounted(4096)); |
+ |
+ std::vector<char> dumped = counter1.Dump(); |
+ |
+ // Recreate a counter from the dumped counter. |
+ WorkerUseCounter counter2(dumped); |
+ EXPECT_TRUE(counter2.IsCounted(0)); |
+ EXPECT_TRUE(counter2.IsCounted(10)); |
+ EXPECT_TRUE(counter2.IsCounted(1024)); |
+ EXPECT_TRUE(counter2.IsCounted(4096)); |
+ |
+ int number_of_bits = 0; |
+ for (size_t i = 0; i < counter2.GetNumberOfBits(); ++i) { |
+ if (counter2.IsCounted(i)) |
+ number_of_bits++; |
+ } |
+ EXPECT_EQ(4, number_of_bits); |
+} |
+ |
+} // namespace content |