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

Side by Side Diff: chrome/browser/power/origin_power_map_unittest.cc

Issue 447053002: Add Origin Power Map to Store Battery Auditing Data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove a line from GYPI that shouldn't have been in this patch. Created 6 years, 4 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 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.
4
5 #include "base/prefs/scoped_user_pref_update.h"
6 #include "chrome/browser/power/origin_power_map.h"
sky 2014/08/06 23:59:23 nit: this should be your first include with a newl
Daniel Nishi 2014/08/07 21:15:08 Done.
7 #include "chrome/common/pref_names.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 class OriginPowerMapTest : public testing::Test {
12 public:
13 OriginPowerMapTest() {};
14 virtual ~OriginPowerMapTest() {};
15
16 virtual void SetUp() OVERRIDE {
17 profile_.reset(new TestingProfile);
18 origin_power_map_.reset(new OriginPowerMap(profile_->GetPrefs()));
19 }
20
21 protected:
22 void ReloadProfile() {
23 origin_power_map_.reset(new OriginPowerMap(profile_->GetPrefs()));
24 }
25
26 scoped_ptr<TestingProfile> profile_;
27 scoped_ptr<OriginPowerMap> origin_power_map_;
28 };
29
30 TEST_F(OriginPowerMapTest, StartEmpty) {
31 EXPECT_EQ(size_t(0), origin_power_map_->GetScaledOriginMap()->size());
32 }
33
34 TEST_F(OriginPowerMapTest, AddOneOriginNotInMap) {
35 GURL url("http://www.google.com");
36 EXPECT_EQ(-1, origin_power_map_->GetPowerForOrigin(url));
37 origin_power_map_->AddPowerForOrigin(url, 10);
38 EXPECT_EQ(size_t(1), origin_power_map_->GetScaledOriginMap()->size());
39 EXPECT_EQ(100, origin_power_map_->GetPowerForOrigin(url));
40 }
41
42 TEST_F(OriginPowerMapTest, AddMultiplesOrigins) {
43 GURL url1("http://www.google.com");
44 EXPECT_EQ(-1, origin_power_map_->GetPowerForOrigin(url1));
45 origin_power_map_->AddPowerForOrigin(url1, 10);
46 EXPECT_EQ(size_t(1), origin_power_map_->GetScaledOriginMap()->size());
47 EXPECT_EQ(100, origin_power_map_->GetPowerForOrigin(url1));
48
49 GURL url2("http://www.example.com");
50 origin_power_map_->AddPowerForOrigin(url2, 30);
51 EXPECT_EQ(25, origin_power_map_->GetPowerForOrigin(url1));
52 EXPECT_EQ(75, origin_power_map_->GetPowerForOrigin(url2));
53 origin_power_map_->AddPowerForOrigin(url2, 10);
54 EXPECT_EQ(20, origin_power_map_->GetPowerForOrigin(url1));
55 EXPECT_EQ(80, origin_power_map_->GetPowerForOrigin(url2));
56
57 GURL url3("https://www.google.com");
58 origin_power_map_->AddPowerForOrigin(url3, 50);
59 EXPECT_EQ(10, origin_power_map_->GetPowerForOrigin(url1));
60 EXPECT_EQ(40, origin_power_map_->GetPowerForOrigin(url2));
61 EXPECT_EQ(50, origin_power_map_->GetPowerForOrigin(url3));
62 }
63
64 TEST_F(OriginPowerMapTest, LoadExistingPowerInformationOnConstruction) {
65 DictionaryPrefUpdate update(profile_->GetPrefs(), prefs::kBatteryOriginMap);
66 base::DictionaryValue* origin_entries = update.Get();
67
68 GURL url1("http://www.google.com");
69 GURL url2("http://www.example.com");
70 origin_entries->SetDoubleWithoutPathExpansion(url1.spec(), 10.0);
71 origin_entries->SetDoubleWithoutPathExpansion(url2.spec(), 40.0);
72
73 ReloadProfile();
74 EXPECT_EQ(size_t(2), origin_power_map_->GetScaledOriginMap()->size());
75 EXPECT_EQ(20, origin_power_map_->GetPowerForOrigin(url1));
76 EXPECT_EQ(80, origin_power_map_->GetPowerForOrigin(url2));
77 }
78
79 TEST_F(OriginPowerMapTest, SaveAndLoadExistingPowerInformation) {
80 GURL url1("http://www.google.com");
81 GURL url2("http://www.example.com");
82 origin_power_map_->AddPowerForOrigin(url1, 10);
83 origin_power_map_->AddPowerForOrigin(url2, 40);
84 origin_power_map_->SavePrefs();
85
86 ReloadProfile();
87 EXPECT_EQ(size_t(2), origin_power_map_->GetScaledOriginMap()->size());
88 EXPECT_EQ(20, origin_power_map_->GetPowerForOrigin(url1));
89 EXPECT_EQ(80, origin_power_map_->GetPowerForOrigin(url2));
90 }
91
92 TEST_F(OriginPowerMapTest, ScaledOriginMap) {
93 GURL url1("http://www.google.com");
94 GURL url2("http://www.example.com");
95 origin_power_map_->AddPowerForOrigin(url1, 10);
96 origin_power_map_->AddPowerForOrigin(url2, 40);
97 scoped_ptr<OriginPowerMap::ScaledOriginMap> origin_map =
98 origin_power_map_->GetScaledOriginMap();
99 EXPECT_EQ(20, (*origin_map)[url1]);
100 EXPECT_EQ(80, (*origin_map)[url2]);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698