| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return tab_context_updated_; | 49 return tab_context_updated_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TrackPermissionDecision(ContentSetting content_setting) { | 52 void TrackPermissionDecision(ContentSetting content_setting) { |
| 53 permission_set_ = true; | 53 permission_set_ = true; |
| 54 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; | 54 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; |
| 55 } | 55 } |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 void UpdateTabContext(const PermissionRequestID& id, | 58 void UpdateTabContext(const PermissionRequestID& id, |
| 59 const GURL& requesting_origin, | 59 const url::Origin& requesting_origin, |
| 60 bool allowed) override { | 60 bool allowed) override { |
| 61 tab_context_updated_ = true; | 61 tab_context_updated_ = true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 bool permission_set_; | 65 bool permission_set_; |
| 66 bool permission_granted_; | 66 bool permission_granted_; |
| 67 bool tab_context_updated_; | 67 bool tab_context_updated_; |
| 68 }; | 68 }; |
| 69 | 69 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 PermissionBubbleManager::CreateForWebContents(web_contents()); | 83 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 84 #endif | 84 #endif |
| 85 } | 85 } |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); | 87 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Web MIDI permission should be denied for insecure origin. | 90 // Web MIDI permission should be denied for insecure origin. |
| 91 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { | 91 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { |
| 92 TestPermissionContext permission_context(profile()); | 92 TestPermissionContext permission_context(profile()); |
| 93 GURL url("http://www.example.com"); | 93 const GURL url("http://www.example.com"); |
| 94 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 94 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
| 95 | 95 |
| 96 const PermissionRequestID id( | 96 const PermissionRequestID id( |
| 97 web_contents()->GetRenderProcessHost()->GetID(), | 97 web_contents()->GetRenderProcessHost()->GetID(), |
| 98 web_contents()->GetMainFrame()->GetRoutingID(), | 98 web_contents()->GetMainFrame()->GetRoutingID(), |
| 99 -1); | 99 -1); |
| 100 const url::Origin origin(url); |
| 100 permission_context.RequestPermission( | 101 permission_context.RequestPermission( |
| 101 web_contents(), id, url, | 102 web_contents(), id, origin, |
| 102 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 103 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 103 base::Unretained(&permission_context))); | 104 base::Unretained(&permission_context))); |
| 104 | 105 |
| 105 EXPECT_TRUE(permission_context.permission_set()); | 106 EXPECT_TRUE(permission_context.permission_set()); |
| 106 EXPECT_FALSE(permission_context.permission_granted()); | 107 EXPECT_FALSE(permission_context.permission_granted()); |
| 107 EXPECT_TRUE(permission_context.tab_context_updated()); | 108 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 108 | 109 |
| 109 ContentSetting setting = | 110 ContentSetting setting = |
| 110 HostContentSettingsMapFactory::GetForProfile(profile()) | 111 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 111 ->GetContentSetting(url.GetOrigin(), | 112 ->GetContentSetting(url.GetOrigin(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 insecure_url.GetOrigin(), | 135 insecure_url.GetOrigin(), |
| 135 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | 136 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 136 std::string())); | 137 std::string())); |
| 137 EXPECT_EQ(CONTENT_SETTING_ASK, | 138 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 138 HostContentSettingsMapFactory::GetForProfile(profile()) | 139 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 139 ->GetContentSetting(insecure_url.GetOrigin(), | 140 ->GetContentSetting(insecure_url.GetOrigin(), |
| 140 secure_url.GetOrigin(), | 141 secure_url.GetOrigin(), |
| 141 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | 142 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 142 std::string())); | 143 std::string())); |
| 143 | 144 |
| 145 const url::Origin insecure_origin(insecure_url); |
| 146 const url::Origin secure_origin(secure_url); |
| 144 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | 147 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( |
| 145 insecure_url, insecure_url)); | 148 insecure_origin, insecure_origin)); |
| 146 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | 149 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( |
| 147 insecure_url, secure_url)); | 150 insecure_origin, secure_origin)); |
| 148 } | 151 } |
| OLD | NEW |