OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/geolocation_settings_state.h" | 5 #include "chrome/browser/geolocation/geolocation_settings_state.h" |
6 | 6 |
7 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 7 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
8 #include "chrome/browser/tab_contents/navigation_entry.h" | 8 #include "chrome/browser/tab_contents/navigation_entry.h" |
9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 EXPECT_TRUE(state.state_map().empty()); | 113 EXPECT_TRUE(state.state_map().empty()); |
114 | 114 |
115 formatted_host_per_state.clear(); | 115 formatted_host_per_state.clear(); |
116 tab_state_flags = 0; | 116 tab_state_flags = 0; |
117 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); | 117 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
118 EXPECT_TRUE(formatted_host_per_state.empty()); | 118 EXPECT_TRUE(formatted_host_per_state.empty()); |
119 EXPECT_EQ(0U, tab_state_flags); | 119 EXPECT_EQ(0U, tab_state_flags); |
120 } | 120 } |
121 | 121 |
| 122 TEST_F(GeolocationSettingsStateTests, ShowPortOnSameHost) { |
| 123 TestingProfile profile; |
| 124 GeolocationSettingsState state(&profile); |
| 125 GURL url_0("http://www.example.com"); |
| 126 |
| 127 NavigationEntry entry; |
| 128 entry.set_url(url_0); |
| 129 NavigationController::LoadCommittedDetails load_committed_details; |
| 130 load_committed_details.entry = &entry; |
| 131 state.DidNavigate(load_committed_details); |
| 132 |
| 133 profile.GetGeolocationContentSettingsMap()->SetContentSetting( |
| 134 url_0, url_0, CONTENT_SETTING_ALLOW); |
| 135 state.OnGeolocationPermissionSet(url_0, true); |
| 136 |
| 137 GURL url_1("https://www.example.com"); |
| 138 profile.GetGeolocationContentSettingsMap()->SetContentSetting( |
| 139 url_1, url_0, CONTENT_SETTING_ALLOW); |
| 140 state.OnGeolocationPermissionSet(url_1, true); |
| 141 |
| 142 GURL url_2("http://www.example1.com"); |
| 143 profile.GetGeolocationContentSettingsMap()->SetContentSetting( |
| 144 url_2, url_0, CONTENT_SETTING_ALLOW); |
| 145 state.OnGeolocationPermissionSet(url_2, true); |
| 146 |
| 147 GeolocationSettingsState::StateMap state_map = |
| 148 state.state_map(); |
| 149 EXPECT_EQ(3U, state_map.size()); |
| 150 |
| 151 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; |
| 152 unsigned int tab_state_flags = 0; |
| 153 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
| 154 |
| 155 EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); |
| 156 EXPECT_EQ(1U, |
| 157 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 158 url_0.spec())); |
| 159 EXPECT_EQ(1U, |
| 160 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 161 url_1.spec())); |
| 162 EXPECT_EQ(1U, |
| 163 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 164 url_2.host())); |
| 165 |
| 166 state.OnGeolocationPermissionSet(url_1, false); |
| 167 formatted_host_per_state.clear(); |
| 168 tab_state_flags = 0; |
| 169 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
| 170 |
| 171 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size()); |
| 172 EXPECT_EQ(1U, |
| 173 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 174 url_0.spec())); |
| 175 EXPECT_EQ(1U, |
| 176 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 177 url_2.host())); |
| 178 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); |
| 179 EXPECT_EQ(1U, |
| 180 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( |
| 181 url_1.spec())); |
| 182 } |
| 183 |
| 184 |
122 } // namespace | 185 } // namespace |
OLD | NEW |