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

Side by Side Diff: chrome/browser/content_settings/content_settings_usages_state_unittest.cc

Issue 19375002: Move GeolocationSettingsState to ContentSettingsUsagesState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove wrong explicit Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/browser/content_settings/content_settings_usages_state.h"
bulach 2013/07/18 08:56:50 nit: this should actually be up there, before <str
Takashi Toyoshima 2013/07/22 12:59:18 Done.
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/geolocation/geolocation_settings_state.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "content/public/browser/navigation_details.h" 11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 using content::NavigationEntry; 17 using content::NavigationEntry;
18 18
19 namespace { 19 namespace {
20 20
21 class GeolocationSettingsStateTests : public testing::Test { 21 class ContentSettingsUsagesStateTests : public testing::Test {
22 public: 22 public:
23 GeolocationSettingsStateTests() 23 ContentSettingsUsagesStateTests()
24 : ui_thread_(BrowserThread::UI, &message_loop_) { 24 : ui_thread_(BrowserThread::UI, &message_loop_) {
25 } 25 }
26 26
27 protected: 27 protected:
28 base::MessageLoop message_loop_; 28 base::MessageLoop message_loop_;
29 content::TestBrowserThread ui_thread_; 29 content::TestBrowserThread ui_thread_;
30 }; 30 };
31 31
32 TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) { 32 TEST_F(ContentSettingsUsagesStateTests, ClearOnNewOrigin) {
33 TestingProfile profile; 33 TestingProfile profile;
34 GeolocationSettingsState state(&profile); 34 ContentSettingsUsagesState state(&profile, CONTENT_SETTINGS_TYPE_GEOLOCATION);
bulach 2013/07/18 08:56:50 nit: CONTENT_SETTINGS_TYPE_GEOLOCATION is hard-cod
Takashi Toyoshima 2013/07/22 12:59:18 Using a named constant is done. On testing with o
35 GURL url_0("http://www.example.com"); 35 GURL url_0("http://www.example.com");
36 36
37 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); 37 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
38 entry->SetURL(url_0); 38 entry->SetURL(url_0);
39 content::LoadCommittedDetails load_committed_details; 39 content::LoadCommittedDetails load_committed_details;
40 load_committed_details.entry = entry.get(); 40 load_committed_details.entry = entry.get();
41 state.DidNavigate(load_committed_details); 41 state.DidNavigate(load_committed_details);
42 42
43 profile.GetHostContentSettingsMap()->SetContentSetting( 43 profile.GetHostContentSettingsMap()->SetContentSetting(
44 ContentSettingsPattern::FromURLNoWildcard(url_0), 44 ContentSettingsPattern::FromURLNoWildcard(url_0),
45 ContentSettingsPattern::FromURLNoWildcard(url_0), 45 ContentSettingsPattern::FromURLNoWildcard(url_0),
46 CONTENT_SETTINGS_TYPE_GEOLOCATION, 46 CONTENT_SETTINGS_TYPE_GEOLOCATION,
47 std::string(), 47 std::string(),
48 CONTENT_SETTING_ALLOW); 48 CONTENT_SETTING_ALLOW);
49 state.OnGeolocationPermissionSet(url_0, true); 49 state.OnPermissionSet(url_0, true);
50 50
51 GURL url_1("http://www.example1.com"); 51 GURL url_1("http://www.example1.com");
52 profile.GetHostContentSettingsMap()->SetContentSetting( 52 profile.GetHostContentSettingsMap()->SetContentSetting(
53 ContentSettingsPattern::FromURLNoWildcard(url_1), 53 ContentSettingsPattern::FromURLNoWildcard(url_1),
54 ContentSettingsPattern::FromURLNoWildcard(url_0), 54 ContentSettingsPattern::FromURLNoWildcard(url_0),
55 CONTENT_SETTINGS_TYPE_GEOLOCATION, 55 CONTENT_SETTINGS_TYPE_GEOLOCATION,
56 std::string(), 56 std::string(),
57 CONTENT_SETTING_BLOCK); 57 CONTENT_SETTING_BLOCK);
58 state.OnGeolocationPermissionSet(url_1, false); 58 state.OnPermissionSet(url_1, false);
59 59
60 GeolocationSettingsState::StateMap state_map = 60 ContentSettingsUsagesState::StateMap state_map =
61 state.state_map(); 61 state.state_map();
62 EXPECT_EQ(2U, state_map.size()); 62 EXPECT_EQ(2U, state_map.size());
63 63
64 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; 64 ContentSettingsUsagesState::FormattedHostsPerState formatted_host_per_state;
65 unsigned int tab_state_flags = 0; 65 unsigned int tab_state_flags = 0;
66 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); 66 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
67 EXPECT_TRUE(tab_state_flags & 67 EXPECT_TRUE(tab_state_flags &
68 GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED) 68 ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED)
69 << tab_state_flags; 69 << tab_state_flags;
70 EXPECT_TRUE(tab_state_flags & 70 EXPECT_TRUE(tab_state_flags &
71 GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) 71 ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION)
72 << tab_state_flags; 72 << tab_state_flags;
73 EXPECT_FALSE(tab_state_flags & 73 EXPECT_FALSE(tab_state_flags &
74 GeolocationSettingsState::TABSTATE_HAS_CHANGED) 74 ContentSettingsUsagesState::TABSTATE_HAS_CHANGED)
75 << tab_state_flags; 75 << tab_state_flags;
76 EXPECT_TRUE(tab_state_flags & 76 EXPECT_TRUE(tab_state_flags &
77 GeolocationSettingsState::TABSTATE_HAS_ANY_ICON) 77 ContentSettingsUsagesState::TABSTATE_HAS_ANY_ICON)
78 << tab_state_flags; 78 << tab_state_flags;
79 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); 79 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
80 EXPECT_EQ(1U, 80 EXPECT_EQ(1U,
81 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 81 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
82 url_0.host())); 82 url_0.host()));
83 83
84 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); 84 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
85 EXPECT_EQ(1U, 85 EXPECT_EQ(1U,
86 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( 86 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
87 url_1.host())); 87 url_1.host()));
88 88
89 state.OnGeolocationPermissionSet(url_0, false); 89 state.OnPermissionSet(url_0, false);
90 90
91 formatted_host_per_state.clear(); 91 formatted_host_per_state.clear();
92 tab_state_flags = 0; 92 tab_state_flags = 0;
93 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); 93 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
94 EXPECT_FALSE(tab_state_flags & 94 EXPECT_FALSE(tab_state_flags &
95 GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED) 95 ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED)
96 << tab_state_flags; 96 << tab_state_flags;
97 EXPECT_TRUE(tab_state_flags & 97 EXPECT_TRUE(tab_state_flags &
98 GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) 98 ContentSettingsUsagesState::TABSTATE_HAS_EXCEPTION)
99 << tab_state_flags; 99 << tab_state_flags;
100 EXPECT_TRUE(tab_state_flags & 100 EXPECT_TRUE(tab_state_flags &
101 GeolocationSettingsState::TABSTATE_HAS_CHANGED) 101 ContentSettingsUsagesState::TABSTATE_HAS_CHANGED)
102 << tab_state_flags; 102 << tab_state_flags;
103 EXPECT_TRUE(tab_state_flags & 103 EXPECT_TRUE(tab_state_flags &
104 GeolocationSettingsState::TABSTATE_HAS_ANY_ICON) 104 ContentSettingsUsagesState::TABSTATE_HAS_ANY_ICON)
105 << tab_state_flags; 105 << tab_state_flags;
106 EXPECT_EQ(0U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); 106 EXPECT_EQ(0U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
107 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); 107 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
108 EXPECT_EQ(1U, 108 EXPECT_EQ(1U,
109 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( 109 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
110 url_0.host())); 110 url_0.host()));
111 EXPECT_EQ(1U, 111 EXPECT_EQ(1U,
112 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( 112 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
113 url_1.host())); 113 url_1.host()));
114 114
115 state.OnGeolocationPermissionSet(url_0, true); 115 state.OnPermissionSet(url_0, true);
116 116
117 load_committed_details.previous_url = url_0; 117 load_committed_details.previous_url = url_0;
118 state.DidNavigate(load_committed_details); 118 state.DidNavigate(load_committed_details);
119 119
120 GeolocationSettingsState::StateMap new_state_map = 120 ContentSettingsUsagesState::StateMap new_state_map =
121 state.state_map(); 121 state.state_map();
122 EXPECT_EQ(state_map.size(), new_state_map.size()); 122 EXPECT_EQ(state_map.size(), new_state_map.size());
123 123
124 GURL different_url("http://foo.com"); 124 GURL different_url("http://foo.com");
125 entry->SetURL(different_url); 125 entry->SetURL(different_url);
126 state.DidNavigate(load_committed_details); 126 state.DidNavigate(load_committed_details);
127 127
128 EXPECT_TRUE(state.state_map().empty()); 128 EXPECT_TRUE(state.state_map().empty());
129 129
130 formatted_host_per_state.clear(); 130 formatted_host_per_state.clear();
131 tab_state_flags = 0; 131 tab_state_flags = 0;
132 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); 132 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
133 EXPECT_TRUE(formatted_host_per_state.empty()); 133 EXPECT_TRUE(formatted_host_per_state.empty());
134 EXPECT_EQ(0U, tab_state_flags); 134 EXPECT_EQ(0U, tab_state_flags);
135 } 135 }
136 136
137 TEST_F(GeolocationSettingsStateTests, ShowPortOnSameHost) { 137 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHost) {
138 TestingProfile profile; 138 TestingProfile profile;
139 GeolocationSettingsState state(&profile); 139 ContentSettingsUsagesState state(&profile, CONTENT_SETTINGS_TYPE_GEOLOCATION);
140 GURL url_0("http://www.example.com"); 140 GURL url_0("http://www.example.com");
141 141
142 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); 142 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
143 entry->SetURL(url_0); 143 entry->SetURL(url_0);
144 content::LoadCommittedDetails load_committed_details; 144 content::LoadCommittedDetails load_committed_details;
145 load_committed_details.entry = entry.get(); 145 load_committed_details.entry = entry.get();
146 state.DidNavigate(load_committed_details); 146 state.DidNavigate(load_committed_details);
147 147
148 profile.GetHostContentSettingsMap()->SetContentSetting( 148 profile.GetHostContentSettingsMap()->SetContentSetting(
149 ContentSettingsPattern::FromURLNoWildcard(url_0), 149 ContentSettingsPattern::FromURLNoWildcard(url_0),
150 ContentSettingsPattern::FromURLNoWildcard(url_0), 150 ContentSettingsPattern::FromURLNoWildcard(url_0),
151 CONTENT_SETTINGS_TYPE_GEOLOCATION, 151 CONTENT_SETTINGS_TYPE_GEOLOCATION,
152 std::string(), 152 std::string(),
153 CONTENT_SETTING_ALLOW); 153 CONTENT_SETTING_ALLOW);
154 state.OnGeolocationPermissionSet(url_0, true); 154 state.OnPermissionSet(url_0, true);
155 155
156 GURL url_1("https://www.example.com"); 156 GURL url_1("https://www.example.com");
157 profile.GetHostContentSettingsMap()->SetContentSetting( 157 profile.GetHostContentSettingsMap()->SetContentSetting(
158 ContentSettingsPattern::FromURLNoWildcard(url_1), 158 ContentSettingsPattern::FromURLNoWildcard(url_1),
159 ContentSettingsPattern::FromURLNoWildcard(url_0), 159 ContentSettingsPattern::FromURLNoWildcard(url_0),
160 CONTENT_SETTINGS_TYPE_GEOLOCATION, 160 CONTENT_SETTINGS_TYPE_GEOLOCATION,
161 std::string(), 161 std::string(),
162 CONTENT_SETTING_ALLOW); 162 CONTENT_SETTING_ALLOW);
163 state.OnGeolocationPermissionSet(url_1, true); 163 state.OnPermissionSet(url_1, true);
164 164
165 GURL url_2("http://www.example1.com"); 165 GURL url_2("http://www.example1.com");
166 profile.GetHostContentSettingsMap()->SetContentSetting( 166 profile.GetHostContentSettingsMap()->SetContentSetting(
167 ContentSettingsPattern::FromURLNoWildcard(url_2), 167 ContentSettingsPattern::FromURLNoWildcard(url_2),
168 ContentSettingsPattern::FromURLNoWildcard(url_0), 168 ContentSettingsPattern::FromURLNoWildcard(url_0),
169 CONTENT_SETTINGS_TYPE_GEOLOCATION, 169 CONTENT_SETTINGS_TYPE_GEOLOCATION,
170 std::string(), 170 std::string(),
171 CONTENT_SETTING_ALLOW); 171 CONTENT_SETTING_ALLOW);
172 state.OnGeolocationPermissionSet(url_2, true); 172 state.OnPermissionSet(url_2, true);
173 173
174 GeolocationSettingsState::StateMap state_map = 174 ContentSettingsUsagesState::StateMap state_map =
175 state.state_map(); 175 state.state_map();
176 EXPECT_EQ(3U, state_map.size()); 176 EXPECT_EQ(3U, state_map.size());
177 177
178 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; 178 ContentSettingsUsagesState::FormattedHostsPerState formatted_host_per_state;
179 unsigned int tab_state_flags = 0; 179 unsigned int tab_state_flags = 0;
180 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); 180 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
181 181
182 EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); 182 EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
183 EXPECT_EQ(1U, 183 EXPECT_EQ(1U,
184 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 184 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
185 url_0.spec())); 185 url_0.spec()));
186 EXPECT_EQ(1U, 186 EXPECT_EQ(1U,
187 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 187 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
188 url_1.spec())); 188 url_1.spec()));
189 EXPECT_EQ(1U, 189 EXPECT_EQ(1U,
190 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 190 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
191 url_2.host())); 191 url_2.host()));
192 192
193 state.OnGeolocationPermissionSet(url_1, false); 193 state.OnPermissionSet(url_1, false);
194 formatted_host_per_state.clear(); 194 formatted_host_per_state.clear();
195 tab_state_flags = 0; 195 tab_state_flags = 0;
196 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); 196 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
197 197
198 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); 198 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
199 EXPECT_EQ(1U, 199 EXPECT_EQ(1U,
200 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 200 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
201 url_0.spec())); 201 url_0.spec()));
202 EXPECT_EQ(1U, 202 EXPECT_EQ(1U,
203 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( 203 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
204 url_2.host())); 204 url_2.host()));
205 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); 205 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
206 EXPECT_EQ(1U, 206 EXPECT_EQ(1U,
207 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( 207 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
208 url_1.spec())); 208 url_1.spec()));
209 } 209 }
210 210
211 211
212 } // namespace 212 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698