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

Side by Side Diff: chrome/browser/chrome_content_browser_client_unittest.cc

Issue 1011953003: Refactor Permissions related method out of ContentBrowserClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_type_enum_class
Patch Set: fix cros Created 5 years, 8 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/permissions/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 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 "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "chrome/browser/search_engines/template_url_service_factory.h" 9 #include "chrome/browser/search_engines/template_url_service_factory.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "components/content_settings/core/browser/host_content_settings_map.h" 14 #include "components/content_settings/core/browser/host_content_settings_map.h"
15 #include "components/search_engines/template_url_service.h" 15 #include "components/search_engines/template_url_service.h"
16 #include "components/variations/entropy_provider.h" 16 #include "components/variations/entropy_provider.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/permission_type.h"
20 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 22 #include "url/gurl.h"
24 23
25 using content::PermissionType;
26
27 namespace chrome { 24 namespace chrome {
28 25
29 using ChromeContentBrowserClientTest = testing::Test; 26 using ChromeContentBrowserClientTest = testing::Test;
30 27
31 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { 28 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) {
32 ChromeContentBrowserClient client; 29 ChromeContentBrowserClient client;
33 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); 30 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test")));
34 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); 31 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com")));
35 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); 32 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
36 } 33 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 186
190 NavigationEntry* entry = browser()->tab_strip_model()-> 187 NavigationEntry* entry = browser()->tab_strip_model()->
191 GetActiveWebContents()->GetController().GetLastCommittedEntry(); 188 GetActiveWebContents()->GetController().GetLastCommittedEntry();
192 ASSERT_TRUE(entry != NULL); 189 ASSERT_TRUE(entry != NULL);
193 EXPECT_EQ(url_rewritten, entry->GetURL()); 190 EXPECT_EQ(url_rewritten, entry->GetURL());
194 EXPECT_EQ(url_original, entry->GetVirtualURL()); 191 EXPECT_EQ(url_original, entry->GetVirtualURL());
195 } 192 }
196 193
197 } // namespace content 194 } // namespace content
198 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) 195 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
199
200 namespace chrome {
201
202 // For testing permissions related functionality.
203 class PermissionBrowserClientTest : public testing::Test {
204 public:
205 PermissionBrowserClientTest() : url_("https://www.google.com") {}
206
207 void CheckPermissionStatus(PermissionType type,
208 content::PermissionStatus expected) {
209 EXPECT_EQ(expected, client_.GetPermissionStatus(type, &profile_,
210 url_.GetOrigin(),
211 url_.GetOrigin()));
212 }
213
214 void SetPermission(ContentSettingsType type, ContentSetting value) {
215 profile_.GetHostContentSettingsMap()->SetContentSetting(
216 ContentSettingsPattern::FromURLNoWildcard(url_),
217 ContentSettingsPattern::FromURLNoWildcard(url_),
218 type, std::string(), value);
219 }
220
221 private:
222 content::TestBrowserThreadBundle thread_bundle_;
223 ChromeContentBrowserClient client_;
224 TestingProfile profile_;
225 GURL url_;
226 };
227
228 TEST_F(PermissionBrowserClientTest, GetPermissionStatusDefault) {
229 using namespace content;
230 CheckPermissionStatus(PermissionType::MIDI_SYSEX, PERMISSION_STATUS_ASK);
231 CheckPermissionStatus(PermissionType::PUSH_MESSAGING, PERMISSION_STATUS_ASK);
232 CheckPermissionStatus(PermissionType::NOTIFICATIONS, PERMISSION_STATUS_ASK);
233 CheckPermissionStatus(PermissionType::GEOLOCATION, PERMISSION_STATUS_ASK);
234 #if defined(OS_ANDROID)
235 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER,
236 PERMISSION_STATUS_ASK);
237 #endif
238 }
239
240 TEST_F(PermissionBrowserClientTest, GetPermissionStatusAfterSet) {
241 using namespace content;
242 SetPermission(CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
243 CheckPermissionStatus(PermissionType::GEOLOCATION, PERMISSION_STATUS_GRANTED);
244
245 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
246 CheckPermissionStatus(PermissionType::NOTIFICATIONS,
247 PERMISSION_STATUS_GRANTED);
248
249 SetPermission(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, CONTENT_SETTING_ALLOW);
250 CheckPermissionStatus(PermissionType::MIDI_SYSEX, PERMISSION_STATUS_GRANTED);
251
252 SetPermission(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ALLOW);
253 CheckPermissionStatus(PermissionType::PUSH_MESSAGING,
254 PERMISSION_STATUS_GRANTED);
255
256 #if defined(OS_ANDROID)
257 SetPermission(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
258 CONTENT_SETTING_ALLOW);
259 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER,
260 PERMISSION_STATUS_GRANTED);
261 #endif
262 }
263
264 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/permissions/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698