Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 5 | #include "chrome/browser/extensions/api/file_system/consent_provider_impl.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 6 | |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 7 | #include <memory> |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 8 | #include <string> |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 9 | #include <utility> |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 10 | |
Avi Drissman | 02e49e58 | 2023-01-07 01:23:18 | [diff] [blame] | 11 | #include "base/functional/bind.h" |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 12 | #include "base/memory/ptr_util.h" |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 13 | #include "base/memory/raw_ptr.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 15 | #include "base/run_loop.h" |
Henrique Ferreiro | 1ab7f12f | 2021-03-04 19:54:40 | [diff] [blame] | 16 | #include "chrome/browser/ash/login/users/fake_chrome_user_manager.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 17 | #include "chrome/test/base/testing_browser_process.h" |
| 18 | #include "components/prefs/testing_pref_service.h" |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 19 | #include "components/user_manager/scoped_user_manager.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 20 | #include "components/user_manager/user.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 21 | #include "content/public/test/browser_task_environment.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 22 | #include "extensions/common/extension.h" |
| 23 | #include "extensions/common/extension_builder.h" |
| 24 | #include "extensions/common/manifest.h" |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 25 | #include "testing/gtest/include/gtest/gtest.h" |
| 26 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 27 | using extensions::file_system_api::ConsentProviderImpl; |
Gyuyoung Kim | d140658 | 2021-03-16 10:06:22 | [diff] [blame] | 28 | using extensions::mojom::ManifestLocation; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 29 | |
| 30 | namespace extensions { |
| 31 | namespace { |
| 32 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 33 | // Configurations and results for TestingConsentProviderDelegate, with directly |
| 34 | // accessible fields. |
| 35 | struct TestDelegateState { |
| 36 | // Used to assign a fake dialog response. |
| 37 | ui::DialogButton dialog_button = ui::DIALOG_BUTTON_NONE; |
| 38 | |
| 39 | // Used to assign fake result of detection the auto launch kiosk mode. |
| 40 | bool is_auto_launched = false; |
| 41 | |
| 42 | // Used to set allowlisted components list with a single id. |
| 43 | std::string allowlisted_component_id; |
| 44 | |
| 45 | // Counters to record calls. |
| 46 | int show_dialog_counter = 0; |
| 47 | int show_notification_counter = 0; |
| 48 | }; |
| 49 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 50 | // Test implementation of ConsentProviderImpl::DelegateInterface that exposes |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 51 | // states to a TestDelegateState instance. |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 52 | class TestingConsentProviderDelegate |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 53 | : public ConsentProviderImpl::DelegateInterface { |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 54 | public: |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 55 | explicit TestingConsentProviderDelegate(TestDelegateState* state) |
| 56 | : state_(state) {} |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 57 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 58 | TestingConsentProviderDelegate(const TestingConsentProviderDelegate&) = |
| 59 | delete; |
| 60 | TestingConsentProviderDelegate& operator=( |
| 61 | const TestingConsentProviderDelegate&) = delete; |
| 62 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 63 | ~TestingConsentProviderDelegate() override = default; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 64 | |
| 65 | private: |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 66 | // ConsentProviderImpl::DelegateInterface: |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 67 | void ShowDialog(content::RenderFrameHost* host, |
| 68 | const extensions::ExtensionId& extension_id, |
| 69 | const std::string& extension_name, |
| 70 | const std::string& volume_id, |
| 71 | const std::string& volume_label, |
Clark DuVall | 18fd85d9 | 2020-07-09 12:19:48 | [diff] [blame] | 72 | bool writable, |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 73 | ConsentProviderImpl::ShowDialogCallback callback) override { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 74 | ++state_->show_dialog_counter; |
| 75 | std::move(callback).Run(state_->dialog_button); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 76 | } |
| 77 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 78 | // ConsentProviderImpl::DelegateInterface: |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 79 | void ShowNotification(const extensions::ExtensionId& extension_id, |
| 80 | const std::string& extension_name, |
| 81 | const std::string& volume_id, |
| 82 | const std::string& volume_label, |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 83 | bool writable) override { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 84 | ++state_->show_notification_counter; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 85 | } |
| 86 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 87 | // ConsentProviderImpl::DelegateInterface: |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 88 | bool IsAutoLaunched(const extensions::Extension& extension) override { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 89 | return state_->is_auto_launched; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 90 | } |
| 91 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 92 | // ConsentProviderImpl::DelegateInterface: |
Alex Danilo | a8ed617 | 2020-09-15 12:03:04 | [diff] [blame] | 93 | bool IsAllowlistedComponent(const extensions::Extension& extension) override { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 94 | return state_->allowlisted_component_id.compare(extension.id()) == 0; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 95 | } |
| 96 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 97 | // Use raw_ptr since |state| is owned by owner. |
| 98 | base::raw_ptr<TestDelegateState> state_; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | // Rewrites result of a consent request from |result| to |log|. |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 102 | void OnConsentReceived(ConsentProviderImpl::Consent* log, |
| 103 | const ConsentProviderImpl::Consent result) { |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 104 | *log = result; |
| 105 | } |
| 106 | |
| 107 | } // namespace |
| 108 | |
| 109 | class FileSystemApiConsentProviderTest : public testing::Test { |
| 110 | public: |
| 111 | FileSystemApiConsentProviderTest() {} |
| 112 | |
| 113 | void SetUp() override { |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 114 | testing_pref_service_ = std::make_unique<TestingPrefServiceSimple>(); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 115 | TestingBrowserProcess::GetGlobal()->SetLocalState( |
| 116 | testing_pref_service_.get()); |
Henrique Ferreiro | 4c2fc0a | 2021-03-26 10:42:47 | [diff] [blame] | 117 | user_manager_ = new ash::FakeChromeUserManager; |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 118 | scoped_user_manager_enabler_ = |
| 119 | std::make_unique<user_manager::ScopedUserManager>( |
Arthur Sonzogni | 3939693 | 2023-04-24 09:41:33 | [diff] [blame] | 120 | base::WrapUnique(user_manager_.get())); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void TearDown() override { |
| 124 | scoped_user_manager_enabler_.reset(); |
| 125 | user_manager_ = nullptr; |
| 126 | testing_pref_service_.reset(); |
| 127 | TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| 128 | } |
| 129 | |
| 130 | protected: |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 131 | std::unique_ptr<TestingPrefServiceSimple> testing_pref_service_; |
Arthur Sonzogni | 3939693 | 2023-04-24 09:41:33 | [diff] [blame] | 132 | raw_ptr<ash::FakeChromeUserManager, ExperimentalAsh> |
| 133 | user_manager_; // Owned by the scope enabler. |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 134 | std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_enabler_; |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 135 | content::BrowserTaskEnvironment task_environment_; |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | TEST_F(FileSystemApiConsentProviderTest, ForNonKioskApps) { |
Alex Danilo | a8ed617 | 2020-09-15 12:03:04 | [diff] [blame] | 139 | // Component apps are not granted unless they are allowlisted. |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 140 | { |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 141 | scoped_refptr<const Extension> component_extension( |
Devlin Cronin | ef4a7b2 | 2017-08-21 20:23:58 | [diff] [blame] | 142 | ExtensionBuilder("Test", ExtensionBuilder::Type::PLATFORM_APP) |
Gyuyoung Kim | d140658 | 2021-03-16 10:06:22 | [diff] [blame] | 143 | .SetLocation(ManifestLocation::kComponent) |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 144 | .Build()); |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 145 | TestDelegateState state; |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 146 | ConsentProviderImpl provider( |
| 147 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 148 | EXPECT_FALSE(provider.IsGrantable(*component_extension)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 149 | } |
| 150 | |
Alex Danilo | a8ed617 | 2020-09-15 12:03:04 | [diff] [blame] | 151 | // Allowlisted component apps are instantly granted access without asking |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 152 | // user. |
| 153 | { |
Alex Danilo | a8ed617 | 2020-09-15 12:03:04 | [diff] [blame] | 154 | scoped_refptr<const Extension> allowlisted_component_extension( |
Devlin Cronin | ef4a7b2 | 2017-08-21 20:23:58 | [diff] [blame] | 155 | ExtensionBuilder("Test", ExtensionBuilder::Type::PLATFORM_APP) |
Gyuyoung Kim | d140658 | 2021-03-16 10:06:22 | [diff] [blame] | 156 | .SetLocation(ManifestLocation::kComponent) |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 157 | .Build()); |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 158 | TestDelegateState state; |
| 159 | state.allowlisted_component_id = allowlisted_component_extension->id(); |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 160 | ConsentProviderImpl provider( |
| 161 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 162 | EXPECT_TRUE(provider.IsGrantable(*allowlisted_component_extension)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 163 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 164 | ConsentProviderImpl::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 165 | provider.RequestConsent(nullptr, *allowlisted_component_extension.get(), |
| 166 | "Volume ID 1", "Volume Label 1", |
| 167 | true /* writable */, |
Clark DuVall | 18fd85d9 | 2020-07-09 12:19:48 | [diff] [blame] | 168 | base::BindOnce(&OnConsentReceived, &result)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 169 | base::RunLoop().RunUntilIdle(); |
| 170 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 171 | EXPECT_EQ(0, state.show_dialog_counter); |
| 172 | EXPECT_EQ(0, state.show_notification_counter); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 173 | EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); |
| 174 | } |
| 175 | |
| 176 | // Non-component apps in non-kiosk mode will be rejected instantly, without |
| 177 | // asking for user consent. |
| 178 | { |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 179 | scoped_refptr<const Extension> non_component_extension( |
Devlin Cronin | c89373f | 2017-08-21 22:08:33 | [diff] [blame] | 180 | ExtensionBuilder("Test").Build()); |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 181 | TestDelegateState state; |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 182 | ConsentProviderImpl provider( |
| 183 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 184 | EXPECT_FALSE(provider.IsGrantable(*non_component_extension)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | TEST_F(FileSystemApiConsentProviderTest, ForKioskApps) { |
| 189 | // Non-component apps in auto-launch kiosk mode will be granted access |
| 190 | // instantly without asking for user consent, but with a notification. |
| 191 | { |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 192 | scoped_refptr<const Extension> auto_launch_kiosk_app( |
Devlin Cronin | ef4a7b2 | 2017-08-21 20:23:58 | [diff] [blame] | 193 | ExtensionBuilder("Test", ExtensionBuilder::Type::PLATFORM_APP) |
Devlin Cronin | 98cd658 | 2018-05-08 19:18:12 | [diff] [blame] | 194 | .SetManifestKey("kiosk_enabled", true) |
| 195 | .SetManifestKey("kiosk_only", true) |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 196 | .Build()); |
| 197 | user_manager_->AddKioskAppUser( |
| 198 | AccountId::FromUserEmail(auto_launch_kiosk_app->id())); |
| 199 | user_manager_->LoginUser( |
| 200 | AccountId::FromUserEmail(auto_launch_kiosk_app->id())); |
| 201 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 202 | TestDelegateState state; |
| 203 | state.is_auto_launched = true; |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 204 | ConsentProviderImpl provider( |
| 205 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 206 | EXPECT_TRUE(provider.IsGrantable(*auto_launch_kiosk_app)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 207 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 208 | ConsentProviderImpl::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 209 | provider.RequestConsent( |
| 210 | nullptr, *auto_launch_kiosk_app.get(), "Volume ID 2", "Volume Label 2", |
| 211 | true /* writable */, base::BindOnce(&OnConsentReceived, &result)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 212 | base::RunLoop().RunUntilIdle(); |
| 213 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 214 | EXPECT_EQ(0, state.show_dialog_counter); |
| 215 | EXPECT_EQ(1, state.show_notification_counter); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 216 | EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); |
| 217 | } |
| 218 | |
| 219 | // Non-component apps in manual-launch kiosk mode will be granted access after |
| 220 | // receiving approval from the user. |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 221 | scoped_refptr<const Extension> manual_launch_kiosk_app( |
Devlin Cronin | ef4a7b2 | 2017-08-21 20:23:58 | [diff] [blame] | 222 | ExtensionBuilder("Test", ExtensionBuilder::Type::PLATFORM_APP) |
Devlin Cronin | 98cd658 | 2018-05-08 19:18:12 | [diff] [blame] | 223 | .SetManifestKey("kiosk_enabled", true) |
| 224 | .SetManifestKey("kiosk_only", true) |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 225 | .Build()); |
| 226 | user_manager::User* const manual_kiosk_app_user = |
| 227 | user_manager_->AddKioskAppUser( |
| 228 | AccountId::FromUserEmail(manual_launch_kiosk_app->id())); |
| 229 | user_manager_->KioskAppLoggedIn(manual_kiosk_app_user); |
| 230 | { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 231 | TestDelegateState state; |
| 232 | state.dialog_button = ui::DIALOG_BUTTON_OK; |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 233 | ConsentProviderImpl provider( |
| 234 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 235 | EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 236 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 237 | ConsentProviderImpl::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 238 | provider.RequestConsent(nullptr, *manual_launch_kiosk_app.get(), |
| 239 | "Volume ID 3", "Volume Label 3", |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 240 | true /* writable */, |
Clark DuVall | 18fd85d9 | 2020-07-09 12:19:48 | [diff] [blame] | 241 | base::BindOnce(&OnConsentReceived, &result)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 242 | base::RunLoop().RunUntilIdle(); |
| 243 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 244 | EXPECT_EQ(1, state.show_dialog_counter); |
| 245 | EXPECT_EQ(0, state.show_notification_counter); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 246 | EXPECT_EQ(ConsentProvider::CONSENT_GRANTED, result); |
| 247 | } |
| 248 | |
| 249 | // Non-component apps in manual-launch kiosk mode will be rejected access |
| 250 | // after rejecting by a user. |
| 251 | { |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 252 | TestDelegateState state; |
| 253 | state.dialog_button = ui::DIALOG_BUTTON_CANCEL; |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 254 | ConsentProviderImpl provider( |
| 255 | std::make_unique<TestingConsentProviderDelegate>(&state)); |
Wei Lee | 3ddd594 | 2022-07-04 07:50:29 | [diff] [blame] | 256 | EXPECT_TRUE(provider.IsGrantable(*manual_launch_kiosk_app)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 257 | |
Samuel Huang | 5f0f93a7 | 2022-08-18 23:26:40 | [diff] [blame] | 258 | ConsentProviderImpl::Consent result = ConsentProvider::CONSENT_IMPOSSIBLE; |
Samuel Huang | 43a33780 | 2022-07-18 19:35:54 | [diff] [blame] | 259 | provider.RequestConsent(nullptr, *manual_launch_kiosk_app.get(), |
| 260 | "Volume ID 4", "Volume Label 4", |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 261 | true /* writable */, |
Clark DuVall | 18fd85d9 | 2020-07-09 12:19:48 | [diff] [blame] | 262 | base::BindOnce(&OnConsentReceived, &result)); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 263 | base::RunLoop().RunUntilIdle(); |
| 264 | |
Samuel Huang | aff2add | 2022-08-16 14:37:26 | [diff] [blame] | 265 | EXPECT_EQ(1, state.show_dialog_counter); |
| 266 | EXPECT_EQ(0, state.show_notification_counter); |
michaelpg | c1c4932 | 2017-06-09 18:22:37 | [diff] [blame] | 267 | EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | } // namespace extensions |