Mandoline: Make TransferBufferManager RefCounted
[chromium-blink-merge.git] / components / power / origin_power_map_unittest.cc
blob0cf2981a6a81aae0fd8e45de94fd84a0b7580c9e
1 // Copyright 2014 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 "components/power/origin_power_map.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace power {
11 TEST(OriginPowerMapTest, StartEmpty) {
12 OriginPowerMap origin_power_map;
13 EXPECT_EQ(size_t(0), origin_power_map.GetPercentOriginMap().size());
16 TEST(OriginPowerMapTest, AddOneOriginNotInMap) {
17 OriginPowerMap origin_power_map;
18 GURL url("http://www.google.com");
19 EXPECT_EQ(0, origin_power_map.GetPowerForOrigin(url));
20 origin_power_map.AddPowerForOrigin(url, 10);
21 EXPECT_EQ(size_t(1), origin_power_map.GetPercentOriginMap().size());
22 EXPECT_EQ(100, origin_power_map.GetPowerForOrigin(url));
25 TEST(OriginPowerMapTest, AddMultiplesOrigins) {
26 OriginPowerMap origin_power_map;
27 GURL url1("http://www.google.com");
28 EXPECT_EQ(0, origin_power_map.GetPowerForOrigin(url1));
29 origin_power_map.AddPowerForOrigin(url1, 10);
30 EXPECT_EQ(size_t(1), origin_power_map.GetPercentOriginMap().size());
31 EXPECT_EQ(100, origin_power_map.GetPowerForOrigin(url1));
33 GURL url2("http://www.example.com");
34 origin_power_map.AddPowerForOrigin(url2, 30);
35 EXPECT_EQ(25, origin_power_map.GetPowerForOrigin(url1));
36 EXPECT_EQ(75, origin_power_map.GetPowerForOrigin(url2));
37 origin_power_map.AddPowerForOrigin(url2, 10);
38 EXPECT_EQ(20, origin_power_map.GetPowerForOrigin(url1));
39 EXPECT_EQ(80, origin_power_map.GetPowerForOrigin(url2));
41 GURL url3("https://www.google.com");
42 origin_power_map.AddPowerForOrigin(url3, 50);
43 EXPECT_EQ(10, origin_power_map.GetPowerForOrigin(url1));
44 EXPECT_EQ(40, origin_power_map.GetPowerForOrigin(url2));
45 EXPECT_EQ(50, origin_power_map.GetPowerForOrigin(url3));
48 TEST(OriginPowerMapTest, PercentOriginMap) {
49 OriginPowerMap origin_power_map;
50 GURL url1("http://www.google.com");
51 GURL url2("http://www.example.com");
52 origin_power_map.AddPowerForOrigin(url1, 10);
53 origin_power_map.AddPowerForOrigin(url2, 40);
54 OriginPowerMap::PercentOriginMap origin_map =
55 origin_power_map.GetPercentOriginMap();
56 EXPECT_EQ(20, origin_map.find(url1)->second);
57 EXPECT_EQ(80, origin_map.find(url2)->second);
60 TEST(OriginPowerMapTest, EmptyPercentOriginMapWhenZeroConsumed) {
61 OriginPowerMap origin_power_map;
62 EXPECT_EQ(size_t(0), origin_power_map.GetPercentOriginMap().size());
63 GURL url("http://www.google.com");
64 origin_power_map.AddPowerForOrigin(url, 0);
65 EXPECT_EQ(size_t(0), origin_power_map.GetPercentOriginMap().size());
68 } // namespace power