Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: content/common/worker_use_counter_unittest.cc

Issue 2586863002: Worker: Enable UseCounter for SharedWorkerGlobalScope (Closed)
Patch Set: ready to review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "content/common/worker_use_counter.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace content {
9
10 TEST(WorkerUseCounterTest, Count) {
11 WorkerUseCounter counter;
12
13 counter.Count(0);
14 EXPECT_TRUE(counter.IsCounted(0));
15 EXPECT_FALSE(counter.IsCounted(1));
16
17 counter.Count(4);
18 EXPECT_FALSE(counter.IsCounted(3));
19 EXPECT_TRUE(counter.IsCounted(4));
20 EXPECT_FALSE(counter.IsCounted(5));
21
22 counter.Count(8);
23 counter.Count(9);
24 EXPECT_FALSE(counter.IsCounted(7));
25 EXPECT_TRUE(counter.IsCounted(8));
26 EXPECT_TRUE(counter.IsCounted(9));
27 EXPECT_FALSE(counter.IsCounted(10));
28
29 counter.Count(1024);
30 counter.Count(4096);
31 EXPECT_TRUE(counter.IsCounted(1024));
32 EXPECT_TRUE(counter.IsCounted(4096));
33
34 int number_of_bits = 0;
35 for (size_t i = 0; i < counter.GetNumberOfBits(); ++i) {
36 if (counter.IsCounted(i))
37 ++number_of_bits;
38 }
39 EXPECT_EQ(6, number_of_bits);
40 }
41
42 TEST(WorkerUseCounterTest, Dump) {
43 WorkerUseCounter counter1;
44
45 counter1.Count(0);
46 counter1.Count(10);
47 counter1.Count(1024);
48 counter1.Count(4096);
49 EXPECT_TRUE(counter1.IsCounted(0));
50 EXPECT_TRUE(counter1.IsCounted(10));
51 EXPECT_TRUE(counter1.IsCounted(1024));
52 EXPECT_TRUE(counter1.IsCounted(4096));
53
54 std::vector<char> dumped = counter1.Dump();
55
56 // Recreate a counter from the dumped counter.
57 WorkerUseCounter counter2(dumped);
58 EXPECT_TRUE(counter2.IsCounted(0));
59 EXPECT_TRUE(counter2.IsCounted(10));
60 EXPECT_TRUE(counter2.IsCounted(1024));
61 EXPECT_TRUE(counter2.IsCounted(4096));
62
63 int number_of_bits = 0;
64 for (size_t i = 0; i < counter2.GetNumberOfBits(); ++i) {
65 if (counter2.IsCounted(i))
66 number_of_bits++;
67 }
68 EXPECT_EQ(4, number_of_bits);
69 }
70
71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698