| 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/media/midi_permission_context.h" | 5 #include "chrome/browser/media/midi_permission_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/permissions/permission_queue_controller.h" | 10 #include "chrome/browser/permissions/permission_infobar_manager.h" |
| 11 #include "chrome/browser/permissions/permission_request_id.h" | 11 #include "chrome/browser/permissions/permission_request_id.h" |
| 12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
| 20 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class TestPermissionContext : public MidiPermissionContext { | 25 class TestPermissionContext : public MidiPermissionContext { |
| 26 public: | 26 public: |
| 27 explicit TestPermissionContext(Profile* profile) | 27 explicit TestPermissionContext(Profile* profile) |
| 28 : MidiPermissionContext(profile), | 28 : MidiPermissionContext(profile), |
| 29 permission_set_(false), | 29 permission_set_(false), |
| 30 permission_granted_(false), | 30 permission_granted_(false), |
| 31 tab_context_updated_(false) {} | 31 tab_context_updated_(false) {} |
| 32 | 32 |
| 33 ~TestPermissionContext() override {} | 33 ~TestPermissionContext() override {} |
| 34 | 34 |
| 35 PermissionQueueController* GetInfoBarController() { | |
| 36 return GetQueueController(); | |
| 37 } | |
| 38 | |
| 39 bool permission_granted() { | 35 bool permission_granted() { |
| 40 return permission_granted_; | 36 return permission_granted_; |
| 41 } | 37 } |
| 42 | 38 |
| 43 bool permission_set() { | 39 bool permission_set() { |
| 44 return permission_set_; | 40 return permission_set_; |
| 45 } | 41 } |
| 46 | 42 |
| 47 bool tab_context_updated() { | 43 bool tab_context_updated() { |
| 48 return tab_context_updated_; | 44 return tab_context_updated_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 | 66 |
| 71 class MidiPermissionContextTests : public ChromeRenderViewHostTestHarness { | 67 class MidiPermissionContextTests : public ChromeRenderViewHostTestHarness { |
| 72 protected: | 68 protected: |
| 73 MidiPermissionContextTests() = default; | 69 MidiPermissionContextTests() = default; |
| 74 | 70 |
| 75 private: | 71 private: |
| 76 // ChromeRenderViewHostTestHarness: | 72 // ChromeRenderViewHostTestHarness: |
| 77 void SetUp() override { | 73 void SetUp() override { |
| 78 ChromeRenderViewHostTestHarness::SetUp(); | 74 ChromeRenderViewHostTestHarness::SetUp(); |
| 79 InfoBarService::CreateForWebContents(web_contents()); | 75 InfoBarService::CreateForWebContents(web_contents()); |
| 76 PermissionInfoBarManager::CreateForWebContents(web_contents()); |
| 80 PermissionBubbleManager::CreateForWebContents(web_contents()); | 77 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 81 } | 78 } |
| 82 | 79 |
| 83 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); | 80 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); |
| 84 }; | 81 }; |
| 85 | 82 |
| 86 // Web MIDI permission should be denied for insecure origin. | 83 // Web MIDI permission should be denied for insecure origin. |
| 87 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { | 84 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { |
| 88 TestPermissionContext permission_context(profile()); | 85 TestPermissionContext permission_context(profile()); |
| 89 GURL url("http://www.example.com"); | 86 GURL url("http://www.example.com"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 ->GetContentSetting(insecure_url.GetOrigin(), | 133 ->GetContentSetting(insecure_url.GetOrigin(), |
| 137 secure_url.GetOrigin(), | 134 secure_url.GetOrigin(), |
| 138 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | 135 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 139 std::string())); | 136 std::string())); |
| 140 | 137 |
| 141 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | 138 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( |
| 142 insecure_url, insecure_url)); | 139 insecure_url, insecure_url)); |
| 143 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | 140 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( |
| 144 insecure_url, secure_url)); | 141 insecure_url, secure_url)); |
| 145 } | 142 } |
| OLD | NEW |