Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/extensions/api/webrtc_from_web_accessible_resource_browsertest.cc

Issue 1383483007: Add scheme exceptions for isSecureContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Update comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "base/command_line.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "extensions/test/result_catcher.h"
11 #include "media/base/media_switches.h"
12 #include "net/dns/mock_host_resolver.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
14
15 namespace extensions {
16
17 namespace {
18
19 // Used to observe the creation of permission prompt without responding.
20 class PermissionRequestObserver : public PermissionBubbleManager::Observer {
21 public:
22 explicit PermissionRequestObserver(content::WebContents* web_contents)
23 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)),
24 request_shown_(false) {
25 bubble_manager_->AddObserver(this);
26 }
27 ~PermissionRequestObserver() override {
28 // Safe to remove twice if it happens.
29 bubble_manager_->RemoveObserver(this);
30 }
31
32 bool request_shown() const { return request_shown_; }
33
34 private:
35 // PermissionBubbleManager::Observer
36 void OnBubbleAdded() override {
37 request_shown_ = true;
38 bubble_manager_->RemoveObserver(this);
39 }
40
41 PermissionBubbleManager* bubble_manager_;
42 bool request_shown_;
43
44 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
45 };
46
47 } // namespace
48
49 class WebRtcFromWebAccessibleResourceTest : public ExtensionApiTest {
50 public:
51 WebRtcFromWebAccessibleResourceTest() {}
52 ~WebRtcFromWebAccessibleResourceTest() override {}
53
54 // InProcessBrowserTest:
55 void SetUpCommandLine(base::CommandLine* command_line) override {
56 ExtensionApiTest::SetUpCommandLine(command_line);
57
58 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
59 }
60
61 protected:
62 GURL GetTestServerInsecureUrl(const std::string& path) {
63 GURL url = embedded_test_server()->GetURL(path);
64
65 GURL::Replacements replace_host_and_scheme;
66 replace_host_and_scheme.SetHostStr("a.com");
67 replace_host_and_scheme.SetSchemeStr("http");
68 url = url.ReplaceComponents(replace_host_and_scheme);
69
70 return url;
71 }
72
73 void LoadTestExtension() {
74 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
75 "webrtc_from_web_accessible_resource")));
76 }
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(WebRtcFromWebAccessibleResourceTest);
80 };
81
82 // Verify that a chrome-extension:// web accessible URL can successfully access
83 // getUserMedia(), even if it is embedded in an insecure context.
84 IN_PROC_BROWSER_TEST_F(WebRtcFromWebAccessibleResourceTest,
85 GetUserMediaInWebAccessibleResourceSuccess) {
86 host_resolver()->AddRule("a.com", "127.0.0.1");
87 ASSERT_TRUE(StartEmbeddedTestServer());
88
89 LoadTestExtension();
90 GURL url = GetTestServerInsecureUrl("/extensions/test_file.html?succeed");
91 content::WebContents* web_contents =
92 browser()->tab_strip_model()->GetActiveWebContents();
93 PermissionBubbleManager* bubble_manager =
94 PermissionBubbleManager::FromWebContents(web_contents);
95 bubble_manager->set_auto_response_for_test(
96 PermissionBubbleManager::ACCEPT_ALL);
97 PermissionRequestObserver permission_request_observer(web_contents);
98 extensions::ResultCatcher catcher;
99 ui_test_utils::NavigateToURL(browser(), url);
100
101 ASSERT_TRUE(catcher.GetNextResult());
102 EXPECT_TRUE(permission_request_observer.request_shown());
103 }
104
105 // Verify that a chrome-extension:// web accessible URL will fail to access
106 // getUserMedia() if it is denied by the permission bubble, even if it is
107 // embedded in an insecure context.
108 IN_PROC_BROWSER_TEST_F(WebRtcFromWebAccessibleResourceTest,
109 GetUserMediaInWebAccessibleResourceFail) {
110 host_resolver()->AddRule("a.com", "127.0.0.1");
111 ASSERT_TRUE(StartEmbeddedTestServer());
112
113 LoadTestExtension();
114 GURL url = GetTestServerInsecureUrl("/extensions/test_file.html?fail");
115 content::WebContents* web_contents =
116 browser()->tab_strip_model()->GetActiveWebContents();
117 PermissionBubbleManager* bubble_manager =
118 PermissionBubbleManager::FromWebContents(web_contents);
119 bubble_manager->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
120 PermissionRequestObserver permission_request_observer(web_contents);
121 extensions::ResultCatcher catcher;
122 ui_test_utils::NavigateToURL(browser(), url);
123
124 ASSERT_TRUE(catcher.GetNextResult());
125 EXPECT_TRUE(permission_request_observer.request_shown());
126 }
127
128 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698