[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 1 | // Copyright 2014 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 | |
lalitm | ca47d9c4 | 2015-07-08 13:48:14 | [diff] [blame] | 5 | #include "chrome/browser/permissions/permission_context_base.h" |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 6 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 7 | #include <map> |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 8 | #include <set> |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 13 | #include "base/bind.h" |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 14 | #include "base/feature_list.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 15 | #include "base/macros.h" |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
Robbie McElrath | f763253 | 2019-01-10 19:22:06 | [diff] [blame] | 17 | #include "base/metrics/field_trial_params.h" |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 18 | #include "base/run_loop.h" |
Devlin Cronin | 626d80c | 2018-06-01 01:08:36 | [diff] [blame] | 19 | #include "base/test/metrics/histogram_tester.h" |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 20 | #include "base/test/mock_entropy_provider.h" |
dominickn | c2726ec | 2016-09-15 12:15:39 | [diff] [blame] | 21 | #include "base/test/scoped_feature_list.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 22 | #include "build/build_config.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 23 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 24 | #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
Patricia Lor | acc56f7 | 2017-07-04 01:21:56 | [diff] [blame] | 25 | #include "chrome/browser/permissions/permission_manager.h" |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 26 | #include "chrome/browser/permissions/permission_request_id.h" |
timloh | 90e8cec | 2017-05-22 04:26:19 | [diff] [blame] | 27 | #include "chrome/browser/permissions/permission_request_manager.h" |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 28 | #include "chrome/browser/permissions/permission_uma_util.h" |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 29 | #include "chrome/browser/permissions/permission_util.h" |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 30 | #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 31 | #include "chrome/common/chrome_features.h" |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 32 | #include "chrome/common/chrome_switches.h" |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 33 | #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 34 | #include "chrome/test/base/testing_profile.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 35 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 36 | #include "components/content_settings/core/common/content_settings.h" |
[email protected] | 08f7101 | 2014-07-25 10:27:54 | [diff] [blame] | 37 | #include "components/content_settings/core/common/content_settings_types.h" |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 38 | #include "components/ukm/content/source_url_recorder.h" |
| 39 | #include "components/ukm/test_ukm_recorder.h" |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 40 | #include "components/variations/variations_associated_data.h" |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 41 | #include "content/public/browser/browser_thread.h" |
Robert Ogden | 2437524 | 2018-10-05 21:16:26 | [diff] [blame] | 42 | #include "content/public/browser/navigation_entry.h" |
mlamouri | 5fc460f | 2015-06-03 17:30:28 | [diff] [blame] | 43 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 44 | #include "content/public/browser/web_contents.h" |
| 45 | #include "content/public/test/mock_render_process_host.h" |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 46 | #include "testing/gtest/include/gtest/gtest.h" |
| 47 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 48 | const char* const kPermissionsKillSwitchFieldStudy = |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 49 | PermissionContextBase::kPermissionsKillSwitchFieldStudy; |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 50 | const char* const kPermissionsKillSwitchBlockedValue = |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 51 | PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| 52 | const char kPermissionsKillSwitchTestGroup[] = "TestGroup"; |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 53 | |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 54 | class TestPermissionContext : public PermissionContextBase { |
| 55 | public: |
| 56 | TestPermissionContext(Profile* profile, |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 57 | const ContentSettingsType content_settings_type) |
raymes | 21b9affc | 2017-05-31 06:15:26 | [diff] [blame] | 58 | : PermissionContextBase(profile, |
| 59 | content_settings_type, |
Luna Lu | 730f283f | 2018-02-08 16:38:03 | [diff] [blame] | 60 | blink::mojom::FeaturePolicyFeature::kNotFound), |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 61 | tab_context_updated_(false) {} |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 62 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 63 | ~TestPermissionContext() override {} |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 64 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 65 | const std::vector<ContentSetting>& decisions() const { return decisions_; } |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 66 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 67 | bool tab_context_updated() const { return tab_context_updated_; } |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 68 | |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 69 | // Once a decision for the requested permission has been made, run the |
| 70 | // callback. |
mlamouri | df357a31 | 2015-03-03 17:34:05 | [diff] [blame] | 71 | void TrackPermissionDecision(ContentSetting content_setting) { |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 72 | decisions_.push_back(content_setting); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 73 | // Null check required here as the quit_closure_ can also be run and reset |
| 74 | // first from within DecidePermission. |
| 75 | if (quit_closure_) { |
| 76 | quit_closure_.Run(); |
| 77 | quit_closure_.Reset(); |
| 78 | } |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 79 | } |
| 80 | |
johnme | c41dfee | 2016-01-13 14:35:16 | [diff] [blame] | 81 | ContentSetting GetContentSettingFromMap(const GURL& url_a, |
| 82 | const GURL& url_b) { |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 83 | auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); |
| 84 | return map->GetContentSetting(url_a.GetOrigin(), url_b.GetOrigin(), |
cm.sanchi | 761e67a | 2017-11-16 08:23:28 | [diff] [blame] | 85 | content_settings_type(), std::string()); |
johnme | c41dfee | 2016-01-13 14:35:16 | [diff] [blame] | 86 | } |
| 87 | |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 88 | void RequestPermission(content::WebContents* web_contents, |
| 89 | const PermissionRequestID& id, |
| 90 | const GURL& requesting_frame, |
| 91 | bool user_gesture, |
danakj | 47c8fb5 | 2019-05-02 16:34:36 | [diff] [blame] | 92 | BrowserPermissionCallback callback) override { |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 93 | base::RunLoop run_loop; |
| 94 | quit_closure_ = run_loop.QuitClosure(); |
| 95 | PermissionContextBase::RequestPermission(web_contents, id, requesting_frame, |
danakj | 47c8fb5 | 2019-05-02 16:34:36 | [diff] [blame] | 96 | true /* user_gesture */, |
| 97 | std::move(callback)); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 98 | run_loop.Run(); |
| 99 | } |
| 100 | |
| 101 | void DecidePermission(content::WebContents* web_contents, |
| 102 | const PermissionRequestID& id, |
| 103 | const GURL& requesting_origin, |
| 104 | const GURL& embedding_origin, |
| 105 | bool user_gesture, |
danakj | 47c8fb5 | 2019-05-02 16:34:36 | [diff] [blame] | 106 | BrowserPermissionCallback callback) override { |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 107 | PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
| 108 | embedding_origin, user_gesture, |
danakj | 47c8fb5 | 2019-05-02 16:34:36 | [diff] [blame] | 109 | std::move(callback)); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 110 | if (respond_permission_) { |
| 111 | respond_permission_.Run(); |
| 112 | respond_permission_.Reset(); |
| 113 | } else { |
| 114 | // Stop the run loop from spinning indefinitely if no response callback |
| 115 | // has been set, as is the case with TestParallelRequests. |
| 116 | quit_closure_.Run(); |
| 117 | quit_closure_.Reset(); |
| 118 | } |
| 119 | } |
| 120 | |
meredithl | 03b1285 | 2017-01-25 05:08:01 | [diff] [blame] | 121 | // Set the callback to run if the permission is being responded to in the |
| 122 | // test. This is left empty where no response is needed, such as in parallel |
Timothy Loh | 8fbdac5 | 2018-03-15 03:34:30 | [diff] [blame] | 123 | // requests, invalid origin, and killswitch. |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 124 | void SetRespondPermissionCallback(base::Closure callback) { |
| 125 | respond_permission_ = callback; |
| 126 | } |
| 127 | |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 128 | protected: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 129 | void UpdateTabContext(const PermissionRequestID& id, |
| 130 | const GURL& requesting_origin, |
| 131 | bool allowed) override { |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 132 | tab_context_updated_ = true; |
| 133 | } |
| 134 | |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 135 | bool IsRestrictedToSecureOrigins() const override { return false; } |
mlamouri | a31c6ff1 | 2015-06-01 15:40:52 | [diff] [blame] | 136 | |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 137 | private: |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 138 | std::vector<ContentSetting> decisions_; |
| 139 | bool tab_context_updated_; |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 140 | base::Closure quit_closure_; |
| 141 | // Callback for responding to a permission once the request has been completed |
Timothy Loh | 8fbdac5 | 2018-03-15 03:34:30 | [diff] [blame] | 142 | // (valid URL, kill switch disabled) |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 143 | base::Closure respond_permission_; |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 144 | DISALLOW_COPY_AND_ASSIGN(TestPermissionContext); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | class TestKillSwitchPermissionContext : public TestPermissionContext { |
| 148 | public: |
| 149 | TestKillSwitchPermissionContext( |
| 150 | Profile* profile, |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 151 | const ContentSettingsType content_settings_type) |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 152 | : TestPermissionContext(profile, content_settings_type), |
Jinho Bang | 5f1795e | 2018-01-22 11:49:19 | [diff] [blame] | 153 | field_trial_list_(std::make_unique<base::FieldTrialList>( |
| 154 | std::make_unique<base::MockEntropyProvider>())) {} |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 155 | |
| 156 | void ResetFieldTrialList() { |
| 157 | // Destroy the existing FieldTrialList before creating a new one to avoid |
| 158 | // a DCHECK. |
| 159 | field_trial_list_.reset(); |
Jinho Bang | 5f1795e | 2018-01-22 11:49:19 | [diff] [blame] | 160 | field_trial_list_ = std::make_unique<base::FieldTrialList>( |
| 161 | std::make_unique<base::MockEntropyProvider>()); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 162 | variations::testing::ClearAllVariationParams(); |
| 163 | } |
| 164 | |
| 165 | private: |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 166 | std::unique_ptr<base::FieldTrialList> field_trial_list_; |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(TestKillSwitchPermissionContext); |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 169 | }; |
| 170 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 171 | class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 172 | protected: |
| 173 | PermissionContextBaseTests() {} |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 174 | ~PermissionContextBaseTests() override {} |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 175 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 176 | // Accept or dismiss the permission prompt. |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 177 | void RespondToPermission(TestPermissionContext* context, |
| 178 | const PermissionRequestID& id, |
| 179 | const GURL& url, |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 180 | ContentSetting response) { |
| 181 | DCHECK(response == CONTENT_SETTING_ALLOW || |
| 182 | response == CONTENT_SETTING_BLOCK || |
| 183 | response == CONTENT_SETTING_ASK); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 184 | using AutoResponseType = PermissionRequestManager::AutoResponseType; |
| 185 | AutoResponseType decision = AutoResponseType::DISMISS; |
| 186 | if (response == CONTENT_SETTING_ALLOW) |
| 187 | decision = AutoResponseType::ACCEPT_ALL; |
| 188 | else if (response == CONTENT_SETTING_BLOCK) |
| 189 | decision = AutoResponseType::DENY_ALL; |
| 190 | prompt_factory_->set_response_type(decision); |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 191 | } |
| 192 | |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 193 | void TestAskAndDecide_TestContent(ContentSettingsType content_settings_type, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 194 | ContentSetting decision) { |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 195 | ukm::InitializeSourceUrlRecorderForWebContents(web_contents()); |
| 196 | ukm::TestAutoSetUkmRecorder ukm_recorder; |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 197 | TestPermissionContext permission_context(profile(), content_settings_type); |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 198 | GURL url("https://www.google.com"); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 199 | SetUpUrl(url); |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 200 | base::HistogramTester histograms; |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 201 | |
| 202 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 203 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 204 | web_contents()->GetMainFrame()->GetRoutingID(), -1); |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 205 | permission_context.SetRespondPermissionCallback(base::Bind( |
| 206 | &PermissionContextBaseTests::RespondToPermission, |
| 207 | base::Unretained(this), &permission_context, id, url, decision)); |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 208 | permission_context.RequestPermission( |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 209 | web_contents(), id, url, true /* user_gesture */, |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 210 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 211 | base::Unretained(&permission_context))); |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 212 | ASSERT_EQ(1u, permission_context.decisions().size()); |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 213 | EXPECT_EQ(decision, permission_context.decisions()[0]); |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 214 | EXPECT_TRUE(permission_context.tab_context_updated()); |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 215 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 216 | std::string decision_string; |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 217 | base::Optional<PermissionAction> action; |
| 218 | if (decision == CONTENT_SETTING_ALLOW) { |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 219 | decision_string = "Accepted"; |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 220 | action = PermissionAction::GRANTED; |
| 221 | } else if (decision == CONTENT_SETTING_BLOCK) { |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 222 | decision_string = "Denied"; |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 223 | action = PermissionAction::DENIED; |
| 224 | } else if (decision == CONTENT_SETTING_ASK) { |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 225 | decision_string = "Dismissed"; |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 226 | action = PermissionAction::DISMISSED; |
| 227 | } |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 228 | |
Zinovy Nis | dcc844d | 2019-02-28 07:11:29 | [diff] [blame] | 229 | if (!decision_string.empty()) { |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 230 | histograms.ExpectUniqueSample( |
| 231 | "Permissions.Prompt." + decision_string + ".PriorDismissCount." + |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 232 | PermissionUtil::GetPermissionString(content_settings_type), |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 233 | 0, 1); |
| 234 | histograms.ExpectUniqueSample( |
| 235 | "Permissions.Prompt." + decision_string + ".PriorIgnoreCount." + |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 236 | PermissionUtil::GetPermissionString(content_settings_type), |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 237 | 0, 1); |
| 238 | } |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 239 | |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 240 | EXPECT_EQ(decision, permission_context.GetContentSettingFromMap(url, url)); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 241 | |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 242 | histograms.ExpectUniqueSample( |
| 243 | "Permissions.AutoBlocker.EmbargoPromptSuppression", |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 244 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), 1); |
| 245 | histograms.ExpectUniqueSample( |
| 246 | "Permissions.AutoBlocker.EmbargoStatus", |
| 247 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), 1); |
Yao Xiao | adefb8e | 2019-05-24 18:49:11 | [diff] [blame] | 248 | |
| 249 | if (action.has_value()) { |
| 250 | auto entries = ukm_recorder.GetEntriesByName("Permission"); |
| 251 | EXPECT_EQ(1u, entries.size()); |
| 252 | auto* entry = entries.front(); |
| 253 | ukm_recorder.ExpectEntrySourceHasUrl(entry, url); |
| 254 | |
| 255 | EXPECT_EQ(*ukm_recorder.GetEntryMetric(entry, "Source"), |
| 256 | static_cast<int64_t>(PermissionSourceUI::PROMPT)); |
| 257 | EXPECT_EQ(*ukm_recorder.GetEntryMetric(entry, "PermissionType"), |
| 258 | static_cast<int64_t>(content_settings_type)); |
| 259 | EXPECT_EQ(*ukm_recorder.GetEntryMetric(entry, "Action"), |
| 260 | static_cast<int64_t>(action.value())); |
| 261 | } |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 262 | } |
| 263 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 264 | void DismissMultipleTimesAndExpectBlock( |
| 265 | const GURL& url, |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 266 | ContentSettingsType content_settings_type, |
| 267 | uint32_t iterations) { |
| 268 | base::HistogramTester histograms; |
| 269 | |
| 270 | // Dismiss |iterations| times. The final dismiss should change the decision |
| 271 | // from dismiss to block, and hence change the persisted content setting. |
| 272 | for (uint32_t i = 0; i < iterations; ++i) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 273 | TestPermissionContext permission_context(profile(), |
| 274 | content_settings_type); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 275 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 276 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 277 | web_contents()->GetMainFrame()->GetRoutingID(), i); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 278 | |
| 279 | permission_context.SetRespondPermissionCallback( |
| 280 | base::Bind(&PermissionContextBaseTests::RespondToPermission, |
| 281 | base::Unretained(this), &permission_context, id, url, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 282 | CONTENT_SETTING_ASK)); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 283 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 284 | permission_context.RequestPermission( |
| 285 | web_contents(), id, url, true /* user_gesture */, |
| 286 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 287 | base::Unretained(&permission_context))); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 288 | histograms.ExpectTotalCount( |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 289 | "Permissions.Prompt.Dismissed.PriorDismissCount." + |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 290 | PermissionUtil::GetPermissionString(content_settings_type), |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 291 | i + 1); |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 292 | histograms.ExpectBucketCount( |
| 293 | "Permissions.Prompt.Dismissed.PriorDismissCount." + |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 294 | PermissionUtil::GetPermissionString(content_settings_type), |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 295 | i, 1); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 296 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 297 | histograms.ExpectTotalCount("Permissions.AutoBlocker.EmbargoStatus", |
| 298 | i + 1); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 299 | |
raymes | f6104d49 | 2017-03-09 01:20:18 | [diff] [blame] | 300 | PermissionResult result = permission_context.GetPermissionStatus( |
| 301 | nullptr /* render_frame_host */, url, url); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 302 | |
| 303 | histograms.ExpectUniqueSample( |
| 304 | "Permissions.AutoBlocker.EmbargoPromptSuppression", |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 305 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 306 | if (i < 2) { |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 307 | EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 308 | EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 309 | histograms.ExpectUniqueSample( |
| 310 | "Permissions.AutoBlocker.EmbargoStatus", |
| 311 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 312 | } else { |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 313 | EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 314 | EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 315 | histograms.ExpectBucketCount( |
| 316 | "Permissions.AutoBlocker.EmbargoStatus", |
| 317 | static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 318 | } |
| 319 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 320 | ASSERT_EQ(1u, permission_context.decisions().size()); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 321 | EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.decisions()[0]); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 322 | EXPECT_TRUE(permission_context.tab_context_updated()); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 323 | } |
| 324 | |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 325 | TestPermissionContext permission_context(profile(), content_settings_type); |
meredithl | 03b1285 | 2017-01-25 05:08:01 | [diff] [blame] | 326 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 327 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
meredithl | 03b1285 | 2017-01-25 05:08:01 | [diff] [blame] | 328 | web_contents()->GetMainFrame()->GetRoutingID(), -1); |
| 329 | |
| 330 | permission_context.SetRespondPermissionCallback( |
| 331 | base::Bind(&PermissionContextBaseTests::RespondToPermission, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 332 | base::Unretained(this), &permission_context, id, url, |
meredithl | 03b1285 | 2017-01-25 05:08:01 | [diff] [blame] | 333 | CONTENT_SETTING_ASK)); |
| 334 | |
| 335 | permission_context.RequestPermission( |
| 336 | web_contents(), id, url, true /* user_gesture */, |
| 337 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 338 | base::Unretained(&permission_context))); |
meredithl | cda94daf | 2017-01-19 03:03:35 | [diff] [blame] | 339 | |
raymes | f6104d49 | 2017-03-09 01:20:18 | [diff] [blame] | 340 | PermissionResult result = permission_context.GetPermissionStatus( |
| 341 | nullptr /* render_frame_host */, url, url); |
raymes | ab35971 | 2017-02-15 06:23:25 | [diff] [blame] | 342 | EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 343 | EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 344 | histograms.ExpectBucketCount( |
| 345 | "Permissions.AutoBlocker.EmbargoPromptSuppression", |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 346 | static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void TestBlockOnSeveralDismissals_TestContent() { |
| 350 | GURL url("https://www.google.com"); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 351 | SetUpUrl(url); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 352 | base::HistogramTester histograms; |
| 353 | |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 354 | { |
| 355 | // Ensure that > 3 dismissals behaves correctly when the |
| 356 | // BlockPromptsIfDismissedOften feature is off. |
| 357 | base::test::ScopedFeatureList feature_list; |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 358 | feature_list.InitAndDisableFeature( |
| 359 | features::kBlockPromptsIfDismissedOften); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 360 | |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 361 | for (uint32_t i = 0; i < 4; ++i) { |
| 362 | TestPermissionContext permission_context( |
| 363 | profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 364 | |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 365 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 366 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 367 | web_contents()->GetMainFrame()->GetRoutingID(), i); |
| 368 | |
| 369 | permission_context.SetRespondPermissionCallback( |
| 370 | base::Bind(&PermissionContextBaseTests::RespondToPermission, |
| 371 | base::Unretained(this), &permission_context, id, url, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 372 | CONTENT_SETTING_ASK)); |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 373 | permission_context.RequestPermission( |
| 374 | web_contents(), id, url, true /* user_gesture */, |
| 375 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 376 | base::Unretained(&permission_context))); |
| 377 | histograms.ExpectTotalCount( |
| 378 | "Permissions.Prompt.Dismissed.PriorDismissCount.Geolocation", |
| 379 | i + 1); |
| 380 | histograms.ExpectBucketCount( |
| 381 | "Permissions.Prompt.Dismissed.PriorDismissCount.Geolocation", i, 1); |
| 382 | histograms.ExpectUniqueSample( |
| 383 | "Permissions.AutoBlocker.EmbargoPromptSuppression", |
| 384 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 385 | histograms.ExpectUniqueSample( |
| 386 | "Permissions.AutoBlocker.EmbargoStatus", |
| 387 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 388 | |
dominickn | 5b41f22 | 2017-05-11 03:44:26 | [diff] [blame] | 389 | ASSERT_EQ(1u, permission_context.decisions().size()); |
| 390 | EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.decisions()[0]); |
| 391 | EXPECT_TRUE(permission_context.tab_context_updated()); |
| 392 | EXPECT_EQ(CONTENT_SETTING_ASK, |
| 393 | permission_context.GetContentSettingFromMap(url, url)); |
| 394 | } |
| 395 | |
| 396 | // Flush the dismissal counts. |
| 397 | auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); |
| 398 | map->ClearSettingsForOneType( |
| 399 | CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 400 | } |
| 401 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 402 | EXPECT_TRUE( |
| 403 | base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften)); |
| 404 | |
| 405 | // Sanity check independence per permission type by checking two of them. |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 406 | DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 407 | 3); |
| 408 | DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 409 | 3); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | void TestVariationBlockOnSeveralDismissals_TestContent() { |
| 413 | GURL url("https://www.google.com"); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 414 | SetUpUrl(url); |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 415 | base::HistogramTester histograms; |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 416 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 417 | std::map<std::string, std::string> params; |
| 418 | params[PermissionDecisionAutoBlocker::kPromptDismissCountKey] = "5"; |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 419 | base::test::ScopedFeatureList scoped_feature_list; |
Robbie McElrath | f763253 | 2019-01-10 19:22:06 | [diff] [blame] | 420 | scoped_feature_list.InitAndEnableFeatureWithParameters( |
| 421 | features::kBlockPromptsIfDismissedOften, params); |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 422 | |
Robbie McElrath | f763253 | 2019-01-10 19:22:06 | [diff] [blame] | 423 | std::map<std::string, std::string> actual_params; |
| 424 | EXPECT_TRUE(base::GetFieldTrialParamsByFeature( |
| 425 | features::kBlockPromptsIfDismissedOften, &actual_params)); |
| 426 | EXPECT_EQ(params, actual_params); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 427 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 428 | { |
| 429 | std::map<std::string, std::string> actual_params; |
| 430 | EXPECT_TRUE(variations::GetVariationParamsByFeature( |
| 431 | features::kBlockPromptsIfDismissedOften, &actual_params)); |
| 432 | EXPECT_EQ(params, actual_params); |
| 433 | } |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 434 | |
| 435 | for (uint32_t i = 0; i < 5; ++i) { |
| 436 | TestPermissionContext permission_context( |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 437 | profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 438 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 439 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 440 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 441 | web_contents()->GetMainFrame()->GetRoutingID(), i); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 442 | permission_context.SetRespondPermissionCallback( |
| 443 | base::Bind(&PermissionContextBaseTests::RespondToPermission, |
| 444 | base::Unretained(this), &permission_context, id, url, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 445 | CONTENT_SETTING_ASK)); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 446 | permission_context.RequestPermission( |
| 447 | web_contents(), id, url, true /* user_gesture */, |
| 448 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 449 | base::Unretained(&permission_context))); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 450 | |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 451 | EXPECT_EQ(1u, permission_context.decisions().size()); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 452 | ASSERT_EQ(CONTENT_SETTING_ASK, permission_context.decisions()[0]); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 453 | EXPECT_TRUE(permission_context.tab_context_updated()); |
raymes | f6104d49 | 2017-03-09 01:20:18 | [diff] [blame] | 454 | PermissionResult result = permission_context.GetPermissionStatus( |
| 455 | nullptr /* render_frame_host */, url, url); |
dominickn | 6da2b38 | 2016-08-23 20:21:30 | [diff] [blame] | 456 | |
| 457 | histograms.ExpectTotalCount( |
| 458 | "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i + 1); |
| 459 | histograms.ExpectBucketCount( |
| 460 | "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i, 1); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 461 | histograms.ExpectUniqueSample( |
| 462 | "Permissions.AutoBlocker.EmbargoPromptSuppression", |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 463 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 464 | histograms.ExpectTotalCount("Permissions.AutoBlocker.EmbargoStatus", |
| 465 | i + 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 466 | if (i < 4) { |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 467 | EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 468 | EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 469 | histograms.ExpectUniqueSample( |
| 470 | "Permissions.AutoBlocker.EmbargoStatus", |
| 471 | static_cast<int>(PermissionEmbargoStatus::NOT_EMBARGOED), i + 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 472 | } else { |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 473 | EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 474 | EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 475 | histograms.ExpectBucketCount( |
| 476 | "Permissions.AutoBlocker.EmbargoStatus", |
| 477 | static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); |
dominickn | 79b96cc | 2017-02-14 04:14:21 | [diff] [blame] | 478 | } |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | // Ensure that we finish in the block state. |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 482 | TestPermissionContext permission_context(profile(), |
| 483 | CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
raymes | f6104d49 | 2017-03-09 01:20:18 | [diff] [blame] | 484 | PermissionResult result = permission_context.GetPermissionStatus( |
| 485 | nullptr /* render_frame_host */, url, url); |
raymes | ab35971 | 2017-02-15 06:23:25 | [diff] [blame] | 486 | EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 487 | EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 488 | variations::testing::ClearAllVariationParams(); |
| 489 | } |
| 490 | |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 491 | void TestRequestPermissionInvalidUrl( |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 492 | ContentSettingsType content_settings_type) { |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 493 | base::HistogramTester histograms; |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 494 | TestPermissionContext permission_context(profile(), content_settings_type); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 495 | GURL url; |
| 496 | ASSERT_FALSE(url.is_valid()); |
clamy | 05ebb4e | 2017-08-17 18:59:05 | [diff] [blame] | 497 | controller().LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 498 | std::string()); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 499 | |
| 500 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 501 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 502 | web_contents()->GetMainFrame()->GetRoutingID(), -1); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 503 | permission_context.RequestPermission( |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 504 | web_contents(), id, url, true /* user_gesture */, |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 505 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 506 | base::Unretained(&permission_context))); |
| 507 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 508 | ASSERT_EQ(1u, permission_context.decisions().size()); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 509 | EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 510 | EXPECT_TRUE(permission_context.tab_context_updated()); |
johnme | c41dfee | 2016-01-13 14:35:16 | [diff] [blame] | 511 | EXPECT_EQ(CONTENT_SETTING_ASK, |
| 512 | permission_context.GetContentSettingFromMap(url, url)); |
dominickn | 2391315 | 2017-02-23 12:04:02 | [diff] [blame] | 513 | histograms.ExpectTotalCount( |
| 514 | "Permissions.AutoBlocker.EmbargoPromptSuppression", 0); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 515 | } |
| 516 | |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 517 | void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type, |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 518 | ContentSetting expected_default) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 519 | TestPermissionContext permission_context(profile(), content_settings_type); |
toyoshim | 9eb573f4 | 2015-03-30 10:39:39 | [diff] [blame] | 520 | GURL url("https://www.google.com"); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 521 | SetUpUrl(url); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 522 | |
| 523 | const PermissionRequestID id( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 524 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 525 | web_contents()->GetMainFrame()->GetRoutingID(), -1); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 526 | permission_context.SetRespondPermissionCallback( |
| 527 | base::Bind(&PermissionContextBaseTests::RespondToPermission, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 528 | base::Unretained(this), &permission_context, id, url, |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 529 | CONTENT_SETTING_ALLOW)); |
| 530 | |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 531 | permission_context.RequestPermission( |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 532 | web_contents(), id, url, true /* user_gesture */, |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 533 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 534 | base::Unretained(&permission_context))); |
| 535 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 536 | ASSERT_EQ(1u, permission_context.decisions().size()); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 537 | EXPECT_EQ(CONTENT_SETTING_ALLOW, permission_context.decisions()[0]); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 538 | EXPECT_TRUE(permission_context.tab_context_updated()); |
johnme | c41dfee | 2016-01-13 14:35:16 | [diff] [blame] | 539 | EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 540 | permission_context.GetContentSettingFromMap(url, url)); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 541 | |
| 542 | // Try to reset permission. |
| 543 | permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin()); |
| 544 | ContentSetting setting_after_reset = |
johnme | c41dfee | 2016-01-13 14:35:16 | [diff] [blame] | 545 | permission_context.GetContentSettingFromMap(url, url); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 546 | ContentSetting default_setting = |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 547 | HostContentSettingsMapFactory::GetForProfile(profile()) |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 548 | ->GetDefaultContentSetting(content_settings_type, nullptr); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 549 | EXPECT_EQ(default_setting, setting_after_reset); |
| 550 | } |
| 551 | |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 552 | void TestGlobalPermissionsKillSwitch( |
lshang | 88ec36a | 2015-12-09 04:50:17 | [diff] [blame] | 553 | ContentSettingsType content_settings_type) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 554 | TestKillSwitchPermissionContext permission_context(profile(), |
| 555 | content_settings_type); |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 556 | permission_context.ResetFieldTrialList(); |
| 557 | |
| 558 | EXPECT_FALSE(permission_context.IsPermissionKillSwitchOn()); |
| 559 | std::map<std::string, std::string> params; |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 560 | params[PermissionUtil::GetPermissionString(content_settings_type)] = |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 561 | kPermissionsKillSwitchBlockedValue; |
dominickn | 2e27dea | 2017-02-23 23:00:25 | [diff] [blame] | 562 | variations::AssociateVariationParams(kPermissionsKillSwitchFieldStudy, |
| 563 | kPermissionsKillSwitchTestGroup, |
| 564 | params); |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 565 | base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy, |
| 566 | kPermissionsKillSwitchTestGroup); |
| 567 | EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); |
| 568 | } |
| 569 | |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 570 | // Don't call this more than once in the same test, as it persists data to |
| 571 | // HostContentSettingsMap. |
| 572 | void TestParallelRequests(ContentSetting response) { |
Ian Vollick | 7df9383 | 2019-07-10 22:51:04 | [diff] [blame] | 573 | TestPermissionContext permission_context(profile(), |
| 574 | CONTENT_SETTINGS_TYPE_GEOLOCATION); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 575 | GURL url("http://www.google.com"); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 576 | SetUpUrl(url); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 577 | |
| 578 | const PermissionRequestID id0( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 579 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 580 | web_contents()->GetMainFrame()->GetRoutingID(), 0); |
| 581 | const PermissionRequestID id1( |
Lukasz Anforowicz | 1452b89 | 2017-09-28 20:10:09 | [diff] [blame] | 582 | web_contents()->GetMainFrame()->GetProcess()->GetID(), |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 583 | web_contents()->GetMainFrame()->GetRoutingID(), 1); |
| 584 | |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 585 | // Request a permission without setting the callback to DecidePermission. |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 586 | permission_context.RequestPermission( |
benwells | fd2b155 | 2016-07-05 04:26:53 | [diff] [blame] | 587 | web_contents(), id0, url, true /* user_gesture */, |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 588 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 589 | base::Unretained(&permission_context))); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 590 | |
| 591 | EXPECT_EQ(0u, permission_context.decisions().size()); |
| 592 | |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 593 | // Set the callback, and make a second permission request. |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 594 | permission_context.SetRespondPermissionCallback(base::Bind( |
| 595 | &PermissionContextBaseTests::RespondToPermission, |
| 596 | base::Unretained(this), &permission_context, id0, url, response)); |
meredithl | 62b8c3d | 2017-01-10 05:47:53 | [diff] [blame] | 597 | permission_context.RequestPermission( |
| 598 | web_contents(), id1, url, true /* user_gesture */, |
| 599 | base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 600 | base::Unretained(&permission_context))); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 601 | |
thestig | 9bdf7f2 | 2016-09-28 00:56:20 | [diff] [blame] | 602 | ASSERT_EQ(2u, permission_context.decisions().size()); |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 603 | EXPECT_EQ(response, permission_context.decisions()[0]); |
| 604 | EXPECT_EQ(response, permission_context.decisions()[1]); |
| 605 | EXPECT_TRUE(permission_context.tab_context_updated()); |
| 606 | |
| 607 | EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); |
| 608 | } |
| 609 | |
Robert Ogden | 2437524 | 2018-10-05 21:16:26 | [diff] [blame] | 610 | void TestVirtualURL(const GURL& loaded_url, |
| 611 | const GURL& virtual_url, |
| 612 | const ContentSetting want_response, |
| 613 | const PermissionStatusSource& want_source) { |
Ian Vollick | 7df9383 | 2019-07-10 22:51:04 | [diff] [blame] | 614 | TestPermissionContext permission_context(profile(), |
| 615 | CONTENT_SETTINGS_TYPE_GEOLOCATION); |
Robert Ogden | 2437524 | 2018-10-05 21:16:26 | [diff] [blame] | 616 | |
| 617 | NavigateAndCommit(loaded_url); |
| 618 | web_contents()->GetController().GetVisibleEntry()->SetVirtualURL( |
| 619 | virtual_url); |
| 620 | |
| 621 | PermissionResult result = permission_context.GetPermissionStatus( |
| 622 | web_contents()->GetMainFrame(), virtual_url, virtual_url); |
| 623 | EXPECT_EQ(result.content_setting, want_response); |
| 624 | EXPECT_EQ(result.source, want_source); |
| 625 | } |
| 626 | |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 627 | void SetUpUrl(const GURL& url) { |
| 628 | NavigateAndCommit(url); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 629 | prompt_factory_->DocumentOnLoadCompletedInMainFrame(); |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 630 | } |
| 631 | |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 632 | private: |
| 633 | // ChromeRenderViewHostTestHarness: |
dcheng | 17131836 | 2014-12-29 18:31:25 | [diff] [blame] | 634 | void SetUp() override { |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 635 | ChromeRenderViewHostTestHarness::SetUp(); |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 636 | PermissionRequestManager::CreateForWebContents(web_contents()); |
| 637 | PermissionRequestManager* manager = |
| 638 | PermissionRequestManager::FromWebContents(web_contents()); |
| 639 | prompt_factory_.reset(new MockPermissionPromptFactory(manager)); |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 640 | } |
| 641 | |
timloh | 86d8eaf | 2017-05-09 03:43:09 | [diff] [blame] | 642 | void TearDown() override { |
| 643 | prompt_factory_.reset(); |
| 644 | ChromeRenderViewHostTestHarness::TearDown(); |
| 645 | } |
| 646 | |
| 647 | std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; |
| 648 | |
felt | 88bf98cb | 2014-12-16 03:50:23 | [diff] [blame] | 649 | DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); |
| 650 | }; |
| 651 | |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 652 | // Simulates clicking Accept. The permission should be granted and |
| 653 | // saved for future use. |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 654 | TEST_F(PermissionContextBaseTests, TestAskAndGrant) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 655 | TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 656 | CONTENT_SETTING_ALLOW); |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | // Simulates clicking Block. The permission should be denied and |
| 660 | // saved for future use. |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 661 | TEST_F(PermissionContextBaseTests, TestAskAndBlock) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 662 | TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 663 | CONTENT_SETTING_BLOCK); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 664 | } |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 665 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 666 | // Simulates clicking Dismiss (X) in the prompt. |
[email protected] | 89a8dd5d | 2014-07-11 12:02:07 | [diff] [blame] | 667 | // The permission should be denied but not saved for future use. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 668 | TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 669 | TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
Timothy Loh | f4caae01 | 2017-11-27 05:36:00 | [diff] [blame] | 670 | CONTENT_SETTING_ASK); |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 671 | } |
| 672 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 673 | // Simulates clicking Dismiss (X) in the prompt with the block on too |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 674 | // many dismissals feature active. The permission should be blocked after |
| 675 | // several dismissals. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 676 | TEST_F(PermissionContextBaseTests, TestDismissUntilBlocked) { |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 677 | TestBlockOnSeveralDismissals_TestContent(); |
| 678 | } |
| 679 | |
| 680 | // Test setting a custom number of dismissals before block via variations. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 681 | TEST_F(PermissionContextBaseTests, TestDismissVariations) { |
dominickn | 6947d75 | 2016-08-10 02:00:06 | [diff] [blame] | 682 | TestVariationBlockOnSeveralDismissals_TestContent(); |
| 683 | } |
| 684 | |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 685 | // Simulates non-valid requesting URL. |
| 686 | // The permission should be denied but not saved for future use. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 687 | TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 688 | TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 689 | TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 690 | TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
Xiaohan Wang | 7b4c058 | 2018-08-24 19:30:50 | [diff] [blame] | 691 | #if defined(OS_CHROMEOS) |
timvolodine | a283055 | 2015-01-20 17:21:23 | [diff] [blame] | 692 | TestRequestPermissionInvalidUrl( |
| 693 | CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 694 | #endif |
| 695 | } |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 696 | |
timloh | 90e8cec | 2017-05-22 04:26:19 | [diff] [blame] | 697 | // Simulates granting and revoking of permissions. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 698 | TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 699 | TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 700 | CONTENT_SETTING_ASK); |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 701 | TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 702 | CONTENT_SETTING_ASK); |
timloh | 90e8cec | 2017-05-22 04:26:19 | [diff] [blame] | 703 | #if defined(OS_ANDROID) |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 704 | TestGrantAndRevoke_TestContent( |
| 705 | CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 706 | // TODO(timvolodine): currently no test for |
| 707 | // CONTENT_SETTINGS_TYPE_NOTIFICATIONS because notification permissions work |
| 708 | // differently with infobars as compared to bubbles (crbug.com/453784). |
timloh | 90e8cec | 2017-05-22 04:26:19 | [diff] [blame] | 709 | #else |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 710 | TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
timvolodine | 16be520 | 2015-02-02 17:44:54 | [diff] [blame] | 711 | CONTENT_SETTING_ASK); |
felt | cb9e736 | 2015-06-25 00:36:43 | [diff] [blame] | 712 | #endif |
timloh | 90e8cec | 2017-05-22 04:26:19 | [diff] [blame] | 713 | } |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 714 | |
| 715 | // Tests the global kill switch by enabling/disabling the Field Trials. |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 716 | TEST_F(PermissionContextBaseTests, TestGlobalKillSwitch) { |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 717 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 718 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 719 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 720 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE); |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 721 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 722 | TestGlobalPermissionsKillSwitch( |
| 723 | CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 724 | #endif |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 725 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 726 | TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
kcarattini | 2ee48ad5 | 2015-10-26 23:45:31 | [diff] [blame] | 727 | } |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 728 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 729 | TEST_F(PermissionContextBaseTests, TestParallelRequestsAllowed) { |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 730 | TestParallelRequests(CONTENT_SETTING_ALLOW); |
| 731 | } |
| 732 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 733 | TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 734 | TestParallelRequests(CONTENT_SETTING_BLOCK); |
| 735 | } |
| 736 | |
Timothy Loh | 246355d | 2017-08-18 05:10:30 | [diff] [blame] | 737 | TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { |
johnme | 7fa91f7 | 2016-01-29 22:13:44 | [diff] [blame] | 738 | TestParallelRequests(CONTENT_SETTING_ASK); |
| 739 | } |
Robert Ogden | 2437524 | 2018-10-05 21:16:26 | [diff] [blame] | 740 | |
| 741 | TEST_F(PermissionContextBaseTests, TestVirtualURLDifferentOrigin) { |
| 742 | TestVirtualURL(GURL("http://www.google.com"), GURL("http://foo.com"), |
| 743 | CONTENT_SETTING_BLOCK, |
| 744 | PermissionStatusSource::VIRTUAL_URL_DIFFERENT_ORIGIN); |
| 745 | } |
| 746 | |
| 747 | TEST_F(PermissionContextBaseTests, TestVirtualURLNotHTTP) { |
| 748 | TestVirtualURL(GURL("chrome://foo"), GURL("chrome://newtab"), |
| 749 | CONTENT_SETTING_ASK, PermissionStatusSource::UNSPECIFIED); |
| 750 | } |
| 751 | |
| 752 | TEST_F(PermissionContextBaseTests, TestVirtualURLSameOrigin) { |
| 753 | TestVirtualURL(GURL("http://www.google.com"), |
| 754 | GURL("http://www.google.com/foo"), CONTENT_SETTING_ASK, |
| 755 | PermissionStatusSource::UNSPECIFIED); |
| 756 | } |