Switch media stream permissions to use IsOriginSecure() instead of
[chromium-blink-merge.git] / chrome / browser / media / webrtc_browsertest_base.h
blob600a75d659c197779c213a90541cca88fedf930e
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.
5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_BROWSERTEST_BASE_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_BROWSERTEST_BASE_H_
8 #include <string>
10 #include "chrome/test/base/in_process_browser_test.h"
12 namespace infobars {
13 class InfoBar;
16 namespace content {
17 class WebContents;
20 // Base class for WebRTC browser tests with useful primitives for interacting
21 // getUserMedia. We use inheritance here because it makes the test code look
22 // as clean as it can be.
23 class WebRtcTestBase : public InProcessBrowserTest {
24 public:
25 // Typical constraints.
26 static const char kAudioVideoCallConstraints[];
27 static const char kAudioOnlyCallConstraints[];
28 static const char kVideoOnlyCallConstraints[];
29 static const char kVideoCallConstraintsQVGA[];
30 static const char kVideoCallConstraints360p[];
31 static const char kVideoCallConstraintsVGA[];
32 static const char kVideoCallConstraints720p[];
33 static const char kVideoCallConstraints1080p[];
34 static const char kAudioVideoCallConstraints360p[];
35 static const char kAudioVideoCallConstraints720p[];
37 static const char kOkGotStream[];
38 static const char kFailedWithPermissionDeniedError[];
39 static const char kFailedWithPermissionDismissedError[];
41 protected:
42 WebRtcTestBase();
43 ~WebRtcTestBase() override;
45 // These all require that the loaded page fulfills the public interface in
46 // chrome/test/data/webrtc/getusermedia.js.
47 // If an error is reported back from the getUserMedia call, these functions
48 // will return false.
49 // The ...AndAccept()/...AndDeny()/...AndDismiss() functions expect that a
50 // prompt will be shown (i.e. the current origin in the tab_contents doesn't
51 // have a saved permission).
52 bool GetUserMediaAndAccept(content::WebContents* tab_contents) const;
53 bool GetUserMediaWithSpecificConstraintsAndAccept(
54 content::WebContents* tab_contents,
55 const std::string& constraints) const;
56 void GetUserMediaAndDeny(content::WebContents* tab_contents);
57 void GetUserMediaWithSpecificConstraintsAndDeny(
58 content::WebContents* tab_contents,
59 const std::string& constraints) const;
60 void GetUserMediaAndDismiss(content::WebContents* tab_contents) const;
61 void GetUserMediaAndExpectAutoAcceptWithoutPrompt(
62 content::WebContents* tab_contents) const;
63 void GetUserMediaAndExpectAutoDenyWithoutPrompt(
64 content::WebContents* tab_contents) const;
65 void GetUserMedia(content::WebContents* tab_contents,
66 const std::string& constraints) const;
68 // Convenience method which opens the page at url, calls GetUserMediaAndAccept
69 // and returns the new tab.
70 content::WebContents* OpenPageAndGetUserMediaInNewTab(const GURL& url) const;
72 // Convenience method which opens the page at url, calls
73 // GetUserMediaAndAcceptWithSpecificConstraints and returns the new tab.
74 content::WebContents* OpenPageAndGetUserMediaInNewTabWithConstraints(
75 const GURL& url, const std::string& constraints) const;
77 // Convenience method which gets the URL for |test_page| and calls
78 // OpenPageAndGetUserMediaInNewTab().
79 content::WebContents* OpenTestPageAndGetUserMediaInNewTab(
80 const std::string& test_page) const;
82 // Opens the page at |url| where getUserMedia has been invoked through other
83 // means and accepts the user media request.
84 content::WebContents* OpenPageAndAcceptUserMedia(const GURL& url) const;
86 // Closes the last local stream acquired by the GetUserMedia* methods.
87 void CloseLastLocalStream(content::WebContents* tab_contents) const;
89 std::string ExecuteJavascript(const std::string& javascript,
90 content::WebContents* tab_contents) const;
92 // Sets up a peer connection in the tab and adds the current local stream
93 // (which you can prepare by calling one of the GetUserMedia* methods above).
94 void SetupPeerconnectionWithLocalStream(content::WebContents* tab) const;
96 // Same as above but does not add the local stream.
97 void SetupPeerconnectionWithoutLocalStream(content::WebContents* tab) const;
99 // Exchanges offers and answers between the peer connections in the
100 // respective tabs. Before calling this, you must have prepared peer
101 // connections in both tabs and configured them as you like (for instance by
102 // calling SetupPeerconnectionWithLocalStream).
103 void NegotiateCall(content::WebContents* from_tab,
104 content::WebContents* to_tab) const;
106 // Hangs up a negotiated call.
107 void HangUp(content::WebContents* from_tab) const;
109 // Call this to enable monitoring of javascript errors for this test method.
110 // This will only work if the tests are run sequentially by the test runner
111 // (i.e. with --test-launcher-developer-mode or --test-launcher-jobs=1).
112 void DetectErrorsInJavaScript();
114 // Methods for detecting if video is playing (the loaded page must have
115 // chrome/test/data/webrtc/video_detector.js and its dependencies loaded to
116 // make that work). Looks at a 320x240 area of the target video tag.
117 void StartDetectingVideo(content::WebContents* tab_contents,
118 const std::string& video_element) const;
119 bool WaitForVideoToPlay(content::WebContents* tab_contents) const;
121 // Returns the stream size as a string on the format <width>x<height>.
122 std::string GetStreamSize(content::WebContents* tab_contents,
123 const std::string& video_element) const;
125 // Methods to check what devices we have on the system.
126 bool HasWebcamAvailableOnSystem(content::WebContents* tab_contents) const;
128 // Returns true if we're on WinXP, that lovely operating system of bliss.
129 bool OnWinXp() const;
131 // Returns true if we're on win 8.
132 bool OnWin8() const;
134 private:
135 void CloseInfoBarInTab(content::WebContents* tab_contents,
136 infobars::InfoBar* infobar) const;
138 std::string CreateLocalOffer(content::WebContents* from_tab) const;
139 std::string CreateAnswer(std::string local_offer,
140 content::WebContents* to_tab) const;
141 void ReceiveAnswer(std::string answer, content::WebContents* from_tab) const;
142 void GatherAndSendIceCandidates(content::WebContents* from_tab,
143 content::WebContents* to_tab) const;
145 infobars::InfoBar* GetUserMediaAndWaitForInfoBar(
146 content::WebContents* tab_contents,
147 const std::string& constraints) const;
149 bool detect_errors_in_javascript_;
151 DISALLOW_COPY_AND_ASSIGN(WebRtcTestBase);
154 #endif // CHROME_BROWSER_MEDIA_WEBRTC_BROWSERTEST_BASE_H_