OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 "webrtc_browsertest_base.h" | |
tommi (sloooow) - chröme
2013/07/25 14:09:09
full path
phoglund_chromium
2013/07/25 15:22:46
Done.
phoglund_chromium
2013/07/25 15:22:46
Done.
| |
6 | |
7 #include "base/strings/stringprintf.h" | |
8 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/infobars/infobar.h" | |
10 #include "chrome/browser/infobars/infobar_service.h" | |
11 #include "chrome/browser/media/media_stream_infobar_delegate.h" | |
12 #include "chrome/browser/media/webrtc_browsertest_common.h" | |
13 #include "chrome/browser/ui/browser.h" | |
14 #include "chrome/test/base/ui_test_utils.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 #include "content/public/test/browser_test_utils.h" | |
17 | |
18 const char kAudioVideoCallConstraints[] = "'{audio: true, video: true}'"; | |
19 const char kAudioOnlyCallConstraints[] = "'{audio: true}'"; | |
20 const char kVideoOnlyCallConstraints[] = "'{video: true}'"; | |
21 const char kFailedWithErrorPermissionDenied[] = | |
22 "failed-with-error-PERMISSION_DENIED"; | |
23 const char kOkGotStream[] = "ok-got-stream"; | |
24 | |
25 // Convenience method which executes the provided javascript in the context | |
26 // of the provided web contents and returns what it evaluated to. | |
27 static std::string ExecuteJavascript(const std::string& javascript, | |
28 content::WebContents* tab_contents) { | |
29 std::string result; | |
30 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
31 tab_contents, javascript, &result)); | |
32 return result; | |
33 } | |
34 | |
35 MediaStreamInfoBarDelegate* WebrtcTestBase::GetUserMediaAndWaitForInfobar( | |
36 content::WebContents* tab_contents, | |
37 const std::string& constraints) { | |
38 content::WindowedNotificationObserver infobar_added( | |
39 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
40 content::NotificationService::AllSources()); | |
41 | |
42 // Request user media: this will launch the media stream info bar. | |
43 GetUserMedia(tab_contents, constraints); | |
44 | |
45 // Wait for the bar to pop up, then return it | |
46 infobar_added.Wait(); | |
47 content::Details<InfoBarAddedDetails> details(infobar_added.details()); | |
48 MediaStreamInfoBarDelegate* media_infobar = | |
49 details.ptr()->AsMediaStreamInfoBarDelegate(); | |
50 return media_infobar; | |
51 } | |
52 | |
53 void WebrtcTestBase::CloseInfobarInTab(content::WebContents* tab_contents, | |
54 MediaStreamInfoBarDelegate* infobar) { | |
55 content::WindowedNotificationObserver infobar_removed( | |
56 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
57 content::NotificationService::AllSources()); | |
58 | |
59 InfoBarService* infobar_service = | |
60 InfoBarService::FromWebContents(tab_contents); | |
61 infobar_service->RemoveInfoBar(infobar); | |
62 | |
63 infobar_removed.Wait(); | |
64 } | |
65 | |
66 void WebrtcTestBase::GetUserMediaAndAccept(content::WebContents* tab_contents) { | |
67 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | |
68 kAudioVideoCallConstraints); | |
tommi (sloooow) - chröme
2013/07/25 14:09:09
indent
phoglund_chromium
2013/07/25 15:22:46
Done.
| |
69 } | |
70 | |
71 void WebrtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | |
72 content::WebContents* tab_contents, const std::string& constraints) { | |
73 MediaStreamInfoBarDelegate* media_infobar = | |
74 GetUserMediaAndWaitForInfobar(tab_contents, constraints); | |
75 | |
76 media_infobar->Accept(); | |
77 | |
78 CloseInfobarInTab(tab_contents, media_infobar); | |
79 | |
80 // Wait for WebRTC to call the success callback. | |
81 EXPECT_TRUE(PollingWaitUntil( | |
82 "obtainGetUserMediaResult()", kOkGotStream, tab_contents)); | |
83 } | |
84 | |
85 void WebrtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | |
86 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | |
87 kAudioVideoCallConstraints); | |
tommi (sloooow) - chröme
2013/07/25 14:09:09
indent
phoglund_chromium
2013/07/25 15:22:46
Done.
| |
88 } | |
89 | |
90 void WebrtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | |
91 content::WebContents* tab_contents, | |
92 const std::string& constraints) { | |
93 MediaStreamInfoBarDelegate* media_infobar = | |
94 GetUserMediaAndWaitForInfobar(tab_contents, constraints); | |
95 | |
96 media_infobar->Cancel(); | |
97 | |
98 CloseInfobarInTab(tab_contents, media_infobar); | |
99 | |
100 // Wait for WebRTC to call the fail callback. | |
101 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | |
102 kFailedWithErrorPermissionDenied, | |
103 tab_contents)); | |
104 } | |
105 | |
106 void WebrtcTestBase::GetUserMediaAndDismiss( | |
107 content::WebContents* tab_contents) { | |
108 MediaStreamInfoBarDelegate* media_infobar = | |
109 GetUserMediaAndWaitForInfobar(tab_contents, kAudioVideoCallConstraints); | |
110 | |
111 media_infobar->InfoBarDismissed(); | |
112 | |
113 CloseInfobarInTab(tab_contents, media_infobar); | |
114 | |
115 // A dismiss should be treated like a deny. | |
116 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | |
117 kFailedWithErrorPermissionDenied, | |
118 tab_contents)); | |
119 } | |
120 | |
121 void WebrtcTestBase::GetUserMedia(content::WebContents* tab_contents, | |
122 const std::string& constraints) { | |
123 // Request user media: this will launch the media stream info bar. | |
124 EXPECT_EQ("ok-requested", | |
125 ExecuteJavascript( | |
126 base::StringPrintf("getUserMedia(%s);", constraints.c_str()), | |
127 tab_contents)); | |
128 } | |
129 | |
OLD | NEW |