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

Side by Side Diff: chrome/browser/permissions/permission_manager_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
OLDNEW
(Empty)
1 // Copyright 2015 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 "chrome/browser/permissions/permission_manager.h"
6
7 #include "chrome/browser/permissions/permission_manager_factory.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "components/content_settings/core/browser/host_content_settings_map.h"
10 #include "content/public/browser/permission_type.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using content::PermissionType;
15 using content::PermissionStatus;
16
17 namespace {
18
19 class PermissionManagerTestingProfile final : public TestingProfile {
20 public:
21 PermissionManagerTestingProfile() {}
22 ~PermissionManagerTestingProfile() override {}
23
24 PermissionManager* GetPermissionManager() override {
25 return PermissionManagerFactory::GetForProfile(this);
26 }
27
28 DISALLOW_COPY_AND_ASSIGN(PermissionManagerTestingProfile);
29 };
30
31 } // anonymous namespace
32
33 class PermissionManagerTest : public testing::Test {
34 public:
35 PermissionManagerTest() : url_("https://example.com") {}
36
37 void CheckPermissionStatus(PermissionType type,
38 PermissionStatus expected) {
39 EXPECT_EQ(expected,
40 profile_.GetPermissionManager()->GetPermissionStatus(
41 type, url_.GetOrigin(), url_.GetOrigin()));
42 }
43
44 void SetPermission(ContentSettingsType type, ContentSetting value) {
45 profile_.GetHostContentSettingsMap()->SetContentSetting(
46 ContentSettingsPattern::FromURLNoWildcard(url_),
47 ContentSettingsPattern::FromURLNoWildcard(url_),
48 type, std::string(), value);
49 }
50
51 private:
52 const GURL url_;
53 content::TestBrowserThreadBundle thread_bundle_;
54 PermissionManagerTestingProfile profile_;
55 };
56
57 TEST_F(PermissionManagerTest, GetPermissionStatusDefault) {
58 CheckPermissionStatus(PermissionType::MIDI_SYSEX,
59 content::PERMISSION_STATUS_ASK);
60 CheckPermissionStatus(PermissionType::PUSH_MESSAGING,
61 content::PERMISSION_STATUS_ASK);
62 CheckPermissionStatus(PermissionType::NOTIFICATIONS,
63 content::PERMISSION_STATUS_ASK);
64 CheckPermissionStatus(PermissionType::GEOLOCATION,
65 content::PERMISSION_STATUS_ASK);
66 #if defined(OS_ANDROID)
67 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER,
68 content::PERMISSION_STATUS_ASK);
69 #endif
70 }
71
72 TEST_F(PermissionManagerTest, GetPermissionStatusAfterSet) {
73 SetPermission(CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
74 CheckPermissionStatus(PermissionType::GEOLOCATION,
75 content::PERMISSION_STATUS_GRANTED);
76
77 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
78 CheckPermissionStatus(PermissionType::NOTIFICATIONS,
79 content::PERMISSION_STATUS_GRANTED);
80
81 SetPermission(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, CONTENT_SETTING_ALLOW);
82 CheckPermissionStatus(PermissionType::MIDI_SYSEX,
83 content::PERMISSION_STATUS_GRANTED);
84
85 SetPermission(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ALLOW);
86 CheckPermissionStatus(PermissionType::PUSH_MESSAGING,
87 content::PERMISSION_STATUS_GRANTED);
88
89 #if defined(OS_ANDROID)
90 SetPermission(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
91 CONTENT_SETTING_ALLOW);
92 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER,
93 content::PERMISSION_STATUS_GRANTED);
94 #endif
95 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_manager_factory.cc ('k') | chrome/browser/profiles/off_the_record_profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698