OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/storage/durable_storage_permission_context.h" | 5 #include "chrome/browser/storage/durable_storage_permission_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
11 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 11 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
13 #include "chrome/browser/engagement/important_sites_util.h" | 13 #include "chrome/browser/engagement/important_sites_util.h" |
14 #include "chrome/browser/permissions/permission_request_id.h" | 14 #include "chrome/browser/permissions/permission_request_id.h" |
15 #include "chrome/browser/permissions/permission_request_manager.h" | 15 #include "chrome/browser/permissions/permission_request_manager.h" |
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "components/bookmarks/test/bookmark_test_helpers.h" | 18 #include "components/bookmarks/test/bookmark_test_helpers.h" |
19 #include "components/content_settings/core/browser/cookie_settings.h" | 19 #include "components/content_settings/core/browser/cookie_settings.h" |
20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
21 #include "content/public/browser/permission_manager.h" | 21 #include "content/public/browser/permission_manager.h" |
22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/web_contents.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 using bookmarks::BookmarkModel; | 26 using bookmarks::BookmarkModel; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 void DoNothing(ContentSetting content_setting) {} | 30 void DoNothing(ContentSetting content_setting) {} |
30 | 31 |
31 class TestDurablePermissionContext : public DurableStoragePermissionContext { | 32 class TestDurablePermissionContext : public DurableStoragePermissionContext { |
32 public: | 33 public: |
(...skipping 14 matching lines...) Expand all Loading... |
47 ContentSetting GetContentSettingFromMap(const GURL& url_a, | 48 ContentSetting GetContentSettingFromMap(const GURL& url_a, |
48 const GURL& url_b) { | 49 const GURL& url_b) { |
49 return HostContentSettingsMapFactory::GetForProfile(profile()) | 50 return HostContentSettingsMapFactory::GetForProfile(profile()) |
50 ->GetContentSetting(url_a.GetOrigin(), url_b.GetOrigin(), | 51 ->GetContentSetting(url_a.GetOrigin(), url_b.GetOrigin(), |
51 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | 52 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, |
52 std::string()); | 53 std::string()); |
53 } | 54 } |
54 | 55 |
55 private: | 56 private: |
56 // NotificationPermissionContext: | 57 // NotificationPermissionContext: |
57 void NotifyPermissionSet(const PermissionRequestID& id, | 58 void NotifyPermissionSet(content::WebContents* web_contents, |
| 59 const PermissionRequestID& id, |
58 const GURL& requesting_origin, | 60 const GURL& requesting_origin, |
59 const GURL& embedder_origin, | 61 const GURL& embedder_origin, |
60 const BrowserPermissionCallback& callback, | 62 const BrowserPermissionCallback& callback, |
61 bool persist, | 63 bool persist, |
62 ContentSetting content_setting) override { | 64 ContentSetting content_setting) override { |
63 permission_set_count_++; | 65 permission_set_count_++; |
64 last_permission_set_persisted_ = persist; | 66 last_permission_set_persisted_ = persist; |
65 last_permission_set_setting_ = content_setting; | 67 last_permission_set_setting_ = content_setting; |
66 DurableStoragePermissionContext::NotifyPermissionSet( | 68 DurableStoragePermissionContext::NotifyPermissionSet( |
67 id, requesting_origin, embedder_origin, callback, persist, | 69 web_contents, id, requesting_origin, embedder_origin, callback, persist, |
68 content_setting); | 70 content_setting); |
69 } | 71 } |
70 | 72 |
71 int permission_set_count_; | 73 int permission_set_count_; |
72 bool last_permission_set_persisted_; | 74 bool last_permission_set_persisted_; |
73 ContentSetting last_permission_set_setting_; | 75 ContentSetting last_permission_set_setting_; |
74 }; | 76 }; |
75 | 77 |
76 } // namespace | 78 } // namespace |
77 | 79 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 permission_context.last_permission_set_setting()); | 218 permission_context.last_permission_set_setting()); |
217 } | 219 } |
218 | 220 |
219 TEST_F(DurableStoragePermissionContextTest, NonsecureOrigin) { | 221 TEST_F(DurableStoragePermissionContextTest, NonsecureOrigin) { |
220 TestDurablePermissionContext permission_context(profile()); | 222 TestDurablePermissionContext permission_context(profile()); |
221 GURL url("http://www.google.com"); | 223 GURL url("http://www.google.com"); |
222 | 224 |
223 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 225 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
224 permission_context.GetPermissionStatus(url, url)); | 226 permission_context.GetPermissionStatus(url, url)); |
225 } | 227 } |
OLD | NEW |