BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_settings_state_unittest.cc
blob1c9197eebffab6bbed3e9f15f1f1aa13672702f8
1 // Copyright (c) 2011 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 <string>
7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/browser/geolocation/geolocation_settings_state.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using content::BrowserThread;
18 using content::NavigationEntry;
20 namespace {
22 class GeolocationSettingsStateTests : public testing::Test {
23 public:
24 GeolocationSettingsStateTests()
25 : ui_thread_(BrowserThread::UI, &message_loop_) {
28 protected:
29 base::MessageLoop message_loop_;
30 content::TestBrowserThread ui_thread_;
33 TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) {
34 TestingProfile profile;
35 GeolocationSettingsState state(&profile);
36 GURL url_0("http://www.example.com");
38 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
39 entry->SetURL(url_0);
40 content::LoadCommittedDetails load_committed_details;
41 load_committed_details.entry = entry.get();
42 state.DidNavigate(load_committed_details);
44 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
45 ContentSettingsPattern::FromURLNoWildcard(url_0),
46 ContentSettingsPattern::FromURLNoWildcard(url_0),
47 CONTENT_SETTINGS_TYPE_GEOLOCATION,
48 std::string(),
49 CONTENT_SETTING_ALLOW);
50 state.OnGeolocationPermissionSet(url_0, true);
52 GURL url_1("http://www.example1.com");
53 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
54 ContentSettingsPattern::FromURLNoWildcard(url_1),
55 ContentSettingsPattern::FromURLNoWildcard(url_0),
56 CONTENT_SETTINGS_TYPE_GEOLOCATION,
57 std::string(),
58 CONTENT_SETTING_BLOCK);
59 state.OnGeolocationPermissionSet(url_1, false);
61 GeolocationSettingsState::StateMap state_map =
62 state.state_map();
63 EXPECT_EQ(2U, state_map.size());
65 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state;
66 unsigned int tab_state_flags = 0;
67 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
68 EXPECT_TRUE(tab_state_flags &
69 GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED)
70 << tab_state_flags;
71 EXPECT_TRUE(tab_state_flags &
72 GeolocationSettingsState::TABSTATE_HAS_EXCEPTION)
73 << tab_state_flags;
74 EXPECT_FALSE(tab_state_flags &
75 GeolocationSettingsState::TABSTATE_HAS_CHANGED)
76 << tab_state_flags;
77 EXPECT_TRUE(tab_state_flags &
78 GeolocationSettingsState::TABSTATE_HAS_ANY_ICON)
79 << tab_state_flags;
80 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
81 EXPECT_EQ(1U,
82 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
83 url_0.host()));
85 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
86 EXPECT_EQ(1U,
87 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
88 url_1.host()));
90 state.OnGeolocationPermissionSet(url_0, false);
92 formatted_host_per_state.clear();
93 tab_state_flags = 0;
94 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
95 EXPECT_FALSE(tab_state_flags &
96 GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED)
97 << tab_state_flags;
98 EXPECT_TRUE(tab_state_flags &
99 GeolocationSettingsState::TABSTATE_HAS_EXCEPTION)
100 << tab_state_flags;
101 EXPECT_TRUE(tab_state_flags &
102 GeolocationSettingsState::TABSTATE_HAS_CHANGED)
103 << tab_state_flags;
104 EXPECT_TRUE(tab_state_flags &
105 GeolocationSettingsState::TABSTATE_HAS_ANY_ICON)
106 << tab_state_flags;
107 EXPECT_EQ(0U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
108 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
109 EXPECT_EQ(1U,
110 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
111 url_0.host()));
112 EXPECT_EQ(1U,
113 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
114 url_1.host()));
116 state.OnGeolocationPermissionSet(url_0, true);
118 load_committed_details.previous_url = url_0;
119 state.DidNavigate(load_committed_details);
121 GeolocationSettingsState::StateMap new_state_map =
122 state.state_map();
123 EXPECT_EQ(state_map.size(), new_state_map.size());
125 GURL different_url("http://foo.com");
126 entry->SetURL(different_url);
127 state.DidNavigate(load_committed_details);
129 EXPECT_TRUE(state.state_map().empty());
131 formatted_host_per_state.clear();
132 tab_state_flags = 0;
133 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
134 EXPECT_TRUE(formatted_host_per_state.empty());
135 EXPECT_EQ(0U, tab_state_flags);
138 TEST_F(GeolocationSettingsStateTests, ShowPortOnSameHost) {
139 TestingProfile profile;
140 GeolocationSettingsState state(&profile);
141 GURL url_0("http://www.example.com");
143 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
144 entry->SetURL(url_0);
145 content::LoadCommittedDetails load_committed_details;
146 load_committed_details.entry = entry.get();
147 state.DidNavigate(load_committed_details);
149 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
150 ContentSettingsPattern::FromURLNoWildcard(url_0),
151 ContentSettingsPattern::FromURLNoWildcard(url_0),
152 CONTENT_SETTINGS_TYPE_GEOLOCATION,
153 std::string(),
154 CONTENT_SETTING_ALLOW);
155 state.OnGeolocationPermissionSet(url_0, true);
157 GURL url_1("https://www.example.com");
158 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
159 ContentSettingsPattern::FromURLNoWildcard(url_1),
160 ContentSettingsPattern::FromURLNoWildcard(url_0),
161 CONTENT_SETTINGS_TYPE_GEOLOCATION,
162 std::string(),
163 CONTENT_SETTING_ALLOW);
164 state.OnGeolocationPermissionSet(url_1, true);
166 GURL url_2("http://www.example1.com");
167 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
168 ContentSettingsPattern::FromURLNoWildcard(url_2),
169 ContentSettingsPattern::FromURLNoWildcard(url_0),
170 CONTENT_SETTINGS_TYPE_GEOLOCATION,
171 std::string(),
172 CONTENT_SETTING_ALLOW);
173 state.OnGeolocationPermissionSet(url_2, true);
175 GeolocationSettingsState::StateMap state_map =
176 state.state_map();
177 EXPECT_EQ(3U, state_map.size());
179 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state;
180 unsigned int tab_state_flags = 0;
181 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
183 EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
184 EXPECT_EQ(1U,
185 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
186 url_0.spec()));
187 EXPECT_EQ(1U,
188 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
189 url_1.spec()));
190 EXPECT_EQ(1U,
191 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
192 url_2.host()));
194 state.OnGeolocationPermissionSet(url_1, false);
195 formatted_host_per_state.clear();
196 tab_state_flags = 0;
197 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
199 EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
200 EXPECT_EQ(1U,
201 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
202 url_0.spec()));
203 EXPECT_EQ(1U,
204 formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
205 url_2.host()));
206 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
207 EXPECT_EQ(1U,
208 formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
209 url_1.spec()));
213 } // namespace