| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_sysex_permission_context.h" |
| 5 #include "base/bind.h" | 6 #include "base/bind.h" |
| 6 #include "base/macros.h" | 7 #include "base/macros.h" |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/media/midi_permission_context.h" | |
| 10 #include "chrome/browser/permissions/permission_request_id.h" | 10 #include "chrome/browser/permissions/permission_request_id.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "components/content_settings/core/common/content_settings.h" | 14 #include "components/content_settings/core/common/content_settings.h" |
| 15 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/mock_render_process_host.h" | 17 #include "content/public/test/mock_render_process_host.h" |
| 18 #include "content/public/test/web_contents_tester.h" | 18 #include "content/public/test/web_contents_tester.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 22 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
| 23 #else | 23 #else |
| 24 #include "chrome/browser/permissions/permission_request_manager.h" | 24 #include "chrome/browser/permissions/permission_request_manager.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class TestPermissionContext : public MidiPermissionContext { | 29 class TestPermissionContext : public MidiSysexPermissionContext { |
| 30 public: | 30 public: |
| 31 explicit TestPermissionContext(Profile* profile) | 31 explicit TestPermissionContext(Profile* profile) |
| 32 : MidiPermissionContext(profile), | 32 : MidiSysexPermissionContext(profile), |
| 33 permission_set_(false), | 33 permission_set_(false), |
| 34 permission_granted_(false), | 34 permission_granted_(false), |
| 35 tab_context_updated_(false) {} | 35 tab_context_updated_(false) {} |
| 36 | 36 |
| 37 ~TestPermissionContext() override {} | 37 ~TestPermissionContext() override {} |
| 38 | 38 |
| 39 bool permission_granted() { return permission_granted_; } | 39 bool permission_granted() { return permission_granted_; } |
| 40 | 40 |
| 41 bool permission_set() { return permission_set_; } | 41 bool permission_set() { return permission_set_; } |
| 42 | 42 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 bool permission_set_; | 58 bool permission_set_; |
| 59 bool permission_granted_; | 59 bool permission_granted_; |
| 60 bool tab_context_updated_; | 60 bool tab_context_updated_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // anonymous namespace | 63 } // anonymous namespace |
| 64 | 64 |
| 65 class MidiPermissionContextTests : public ChromeRenderViewHostTestHarness { | 65 class MidiSysexPermissionContextTests : public ChromeRenderViewHostTestHarness { |
| 66 protected: | 66 protected: |
| 67 MidiPermissionContextTests() = default; | 67 MidiSysexPermissionContextTests() = default; |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 // ChromeRenderViewHostTestHarness: | 70 // ChromeRenderViewHostTestHarness: |
| 71 void SetUp() override { | 71 void SetUp() override { |
| 72 ChromeRenderViewHostTestHarness::SetUp(); | 72 ChromeRenderViewHostTestHarness::SetUp(); |
| 73 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
| 74 InfoBarService::CreateForWebContents(web_contents()); | 74 InfoBarService::CreateForWebContents(web_contents()); |
| 75 #else | 75 #else |
| 76 PermissionRequestManager::CreateForWebContents(web_contents()); | 76 PermissionRequestManager::CreateForWebContents(web_contents()); |
| 77 #endif | 77 #endif |
| 78 } | 78 } |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); | 80 DISALLOW_COPY_AND_ASSIGN(MidiSysexPermissionContextTests); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 // Web MIDI permission should be denied for insecure origin. | 83 // Web MIDI sysex permission should be denied for insecure origin. |
| 84 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { | 84 TEST_F(MidiSysexPermissionContextTests, TestInsecureRequestingUrl) { |
| 85 TestPermissionContext permission_context(profile()); | 85 TestPermissionContext permission_context(profile()); |
| 86 GURL url("http://www.example.com"); | 86 GURL url("http://www.example.com"); |
| 87 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 87 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
| 88 | 88 |
| 89 const PermissionRequestID id(web_contents()->GetRenderProcessHost()->GetID(), | 89 const PermissionRequestID id(web_contents()->GetRenderProcessHost()->GetID(), |
| 90 web_contents()->GetMainFrame()->GetRoutingID(), | 90 web_contents()->GetMainFrame()->GetRoutingID(), |
| 91 -1); | 91 -1); |
| 92 permission_context.RequestPermission( | 92 permission_context.RequestPermission( |
| 93 web_contents(), id, url, true, | 93 web_contents(), id, url, true, |
| 94 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 94 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 95 base::Unretained(&permission_context))); | 95 base::Unretained(&permission_context))); |
| 96 | 96 |
| 97 EXPECT_TRUE(permission_context.permission_set()); | 97 EXPECT_TRUE(permission_context.permission_set()); |
| 98 EXPECT_FALSE(permission_context.permission_granted()); | 98 EXPECT_FALSE(permission_context.permission_granted()); |
| 99 EXPECT_TRUE(permission_context.tab_context_updated()); | 99 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 100 | 100 |
| 101 ContentSetting setting = | 101 ContentSetting setting = |
| 102 HostContentSettingsMapFactory::GetForProfile(profile()) | 102 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 103 ->GetContentSetting(url.GetOrigin(), url.GetOrigin(), | 103 ->GetContentSetting(url.GetOrigin(), url.GetOrigin(), |
| 104 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); | 104 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); |
| 105 EXPECT_EQ(CONTENT_SETTING_ASK, setting); | 105 EXPECT_EQ(CONTENT_SETTING_ASK, setting); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Web MIDI permission status should be denied for insecure origin. | 108 // Web MIDI sysex permission status should be denied for insecure origin. |
| 109 TEST_F(MidiPermissionContextTests, TestInsecureQueryingUrl) { | 109 TEST_F(MidiSysexPermissionContextTests, TestInsecureQueryingUrl) { |
| 110 TestPermissionContext permission_context(profile()); | 110 TestPermissionContext permission_context(profile()); |
| 111 GURL insecure_url("http://www.example.com"); | 111 GURL insecure_url("http://www.example.com"); |
| 112 GURL secure_url("https://www.example.com"); | 112 GURL secure_url("https://www.example.com"); |
| 113 | 113 |
| 114 // Check that there is no saved content settings. | 114 // Check that there is no saved content settings. |
| 115 EXPECT_EQ(CONTENT_SETTING_ASK, | 115 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 116 HostContentSettingsMapFactory::GetForProfile(profile()) | 116 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 117 ->GetContentSetting( | 117 ->GetContentSetting( |
| 118 insecure_url.GetOrigin(), insecure_url.GetOrigin(), | 118 insecure_url.GetOrigin(), insecure_url.GetOrigin(), |
| 119 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string())); | 119 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 133 .GetPermissionStatus(nullptr /* render_frame_host */, | 133 .GetPermissionStatus(nullptr /* render_frame_host */, |
| 134 insecure_url, insecure_url) | 134 insecure_url, insecure_url) |
| 135 .content_setting); | 135 .content_setting); |
| 136 | 136 |
| 137 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 137 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 138 permission_context | 138 permission_context |
| 139 .GetPermissionStatus(nullptr /* render_frame_host */, | 139 .GetPermissionStatus(nullptr /* render_frame_host */, |
| 140 insecure_url, secure_url) | 140 insecure_url, secure_url) |
| 141 .content_setting); | 141 .content_setting); |
| 142 } | 142 } |
| OLD | NEW |