OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/midi_permission_context.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "chrome/browser/content_settings/permission_queue_controller.h" | |
9 #include "chrome/browser/infobars/infobar_service.h" | |
10 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
12 #include "chrome/test/base/testing_profile.h" | |
13 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
14 #include "components/content_settings/core/common/content_settings.h" | |
15 #include "components/content_settings/core/common/content_settings_types.h" | |
16 #include "components/content_settings/core/common/permission_request_id.h" | |
17 #include "content/public/browser/web_contents.h" | |
18 #include "content/public/test/mock_render_process_host.h" | |
19 #include "content/public/test/web_contents_tester.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | |
21 | |
22 namespace { | |
23 | |
24 class TestPermissionContext : public MidiPermissionContext { | |
25 public: | |
26 explicit TestPermissionContext(Profile* profile) | |
27 : MidiPermissionContext(profile), | |
28 permission_set_(false), | |
29 permission_granted_(false), | |
30 tab_context_updated_(false) {} | |
31 | |
32 ~TestPermissionContext() override {} | |
33 | |
34 PermissionQueueController* GetInfoBarController() { | |
35 return GetQueueController(); | |
36 } | |
37 | |
38 bool permission_granted() { | |
39 return permission_granted_; | |
40 } | |
41 | |
42 bool permission_set() { | |
43 return permission_set_; | |
44 } | |
45 | |
46 bool tab_context_updated() { | |
47 return tab_context_updated_; | |
48 } | |
49 | |
50 void TrackPermissionDecision(ContentSetting content_setting) { | |
51 permission_set_ = true; | |
52 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; | |
53 } | |
54 | |
55 protected: | |
56 void UpdateTabContext(const PermissionRequestID& id, | |
57 const GURL& requesting_origin, | |
58 bool allowed) override { | |
59 tab_context_updated_ = true; | |
60 } | |
61 | |
62 private: | |
63 bool permission_set_; | |
64 bool permission_granted_; | |
65 bool tab_context_updated_; | |
66 }; | |
67 | |
68 } // anonymous namespace | |
69 | |
70 class MidiPermissionContextTests : public ChromeRenderViewHostTestHarness { | |
71 protected: | |
72 MidiPermissionContextTests() = default; | |
73 | |
74 private: | |
75 // ChromeRenderViewHostTestHarness: | |
76 void SetUp() override { | |
77 ChromeRenderViewHostTestHarness::SetUp(); | |
78 InfoBarService::CreateForWebContents(web_contents()); | |
79 PermissionBubbleManager::CreateForWebContents(web_contents()); | |
80 } | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContextTests); | |
83 }; | |
84 | |
85 // Web MIDI permission should be denied for insecure origin. | |
86 TEST_F(MidiPermissionContextTests, TestInsecureRequestingUrl) { | |
87 TestPermissionContext permission_context(profile()); | |
88 GURL url("http://www.example.com"); | |
89 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | |
90 | |
91 const PermissionRequestID id( | |
92 web_contents()->GetRenderProcessHost()->GetID(), | |
93 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
94 -1, GURL()); | |
95 permission_context.RequestPermission( | |
96 web_contents(), | |
97 id, url, true, | |
98 base::Bind(&TestPermissionContext::TrackPermissionDecision, | |
99 base::Unretained(&permission_context))); | |
100 | |
101 EXPECT_TRUE(permission_context.permission_set()); | |
102 EXPECT_FALSE(permission_context.permission_granted()); | |
103 EXPECT_TRUE(permission_context.tab_context_updated()); | |
104 | |
105 ContentSetting setting = | |
106 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
107 url.GetOrigin(), url.GetOrigin(), | |
108 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); | |
109 EXPECT_EQ(CONTENT_SETTING_ASK, setting); | |
110 } | |
111 | |
112 // Web MIDI permission status should be denied for insecure origin. | |
113 TEST_F(MidiPermissionContextTests, TestInsecureQueryingUrl) { | |
114 TestPermissionContext permission_context(profile()); | |
115 GURL insecure_url("http://www.example.com"); | |
116 GURL secure_url("https://www.example.com"); | |
117 | |
118 // Check that there is no saved content settings. | |
119 EXPECT_EQ(CONTENT_SETTING_ASK, | |
120 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
121 insecure_url.GetOrigin(), insecure_url.GetOrigin(), | |
122 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string())); | |
123 EXPECT_EQ(CONTENT_SETTING_ASK, | |
124 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
125 secure_url.GetOrigin(), insecure_url.GetOrigin(), | |
126 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string())); | |
127 EXPECT_EQ(CONTENT_SETTING_ASK, | |
128 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
129 insecure_url.GetOrigin(), secure_url.GetOrigin(), | |
130 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string())); | |
131 | |
132 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | |
133 insecure_url, insecure_url)); | |
134 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | |
135 insecure_url, secure_url)); | |
ddorwin
2015/05/26 17:23:50
Isn't this impossible (secure embedding insecure)?
mlamouri (slow - plz ping)
2015/05/28 13:10:22
It's possible. Also, the opposite wouldn't be usef
| |
136 } | |
OLD | NEW |