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_
10 #include "chrome/test/base/in_process_browser_test.h"
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
{
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
[];
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
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 bool GetUserMediaWithSpecificConstraintsAndAcceptIfPrompted(
57 content::WebContents
* tab_contents
,
58 const std::string
& constraints
) const;
59 void GetUserMediaAndDeny(content::WebContents
* tab_contents
);
60 void GetUserMediaWithSpecificConstraintsAndDeny(
61 content::WebContents
* tab_contents
,
62 const std::string
& constraints
) const;
63 void GetUserMediaAndDismiss(content::WebContents
* tab_contents
) const;
64 void GetUserMediaAndExpectAutoAcceptWithoutPrompt(
65 content::WebContents
* tab_contents
) const;
66 void GetUserMediaAndExpectAutoDenyWithoutPrompt(
67 content::WebContents
* tab_contents
) const;
68 void GetUserMedia(content::WebContents
* tab_contents
,
69 const std::string
& constraints
) const;
71 // Convenience method which opens the page at url, calls GetUserMediaAndAccept
72 // and returns the new tab.
73 content::WebContents
* OpenPageAndGetUserMediaInNewTab(const GURL
& url
) const;
75 // Convenience method which opens the page at url, calls
76 // GetUserMediaAndAcceptWithSpecificConstraints and returns the new tab.
77 content::WebContents
* OpenPageAndGetUserMediaInNewTabWithConstraints(
78 const GURL
& url
, const std::string
& constraints
) const;
80 // Convenience method which gets the URL for |test_page| and calls
81 // OpenPageAndGetUserMediaInNewTab().
82 content::WebContents
* OpenTestPageAndGetUserMediaInNewTab(
83 const std::string
& test_page
) const;
85 // Opens the page at |url| where getUserMedia has been invoked through other
86 // means and accepts the user media request.
87 content::WebContents
* OpenPageAndAcceptUserMedia(const GURL
& url
) const;
89 // Closes the last local stream acquired by the GetUserMedia* methods.
90 void CloseLastLocalStream(content::WebContents
* tab_contents
) const;
92 std::string
ExecuteJavascript(const std::string
& javascript
,
93 content::WebContents
* tab_contents
) const;
95 // Sets up a peer connection in the tab and adds the current local stream
96 // (which you can prepare by calling one of the GetUserMedia* methods above).
97 void SetupPeerconnectionWithLocalStream(content::WebContents
* tab
) const;
99 // Same as above but does not add the local stream.
100 void SetupPeerconnectionWithoutLocalStream(content::WebContents
* tab
) const;
102 // Exchanges offers and answers between the peer connections in the
103 // respective tabs. Before calling this, you must have prepared peer
104 // connections in both tabs and configured them as you like (for instance by
105 // calling SetupPeerconnectionWithLocalStream).
106 void NegotiateCall(content::WebContents
* from_tab
,
107 content::WebContents
* to_tab
) const;
109 // Hangs up a negotiated call.
110 void HangUp(content::WebContents
* from_tab
) const;
112 // Call this to enable monitoring of javascript errors for this test method.
113 // This will only work if the tests are run sequentially by the test runner
114 // (i.e. with --test-launcher-developer-mode or --test-launcher-jobs=1).
115 void DetectErrorsInJavaScript();
117 // Methods for detecting if video is playing (the loaded page must have
118 // chrome/test/data/webrtc/video_detector.js and its dependencies loaded to
119 // make that work). Looks at a 320x240 area of the target video tag.
120 void StartDetectingVideo(content::WebContents
* tab_contents
,
121 const std::string
& video_element
) const;
122 bool WaitForVideoToPlay(content::WebContents
* tab_contents
) const;
124 // Returns the stream size as a string on the format <width>x<height>.
125 std::string
GetStreamSize(content::WebContents
* tab_contents
,
126 const std::string
& video_element
) const;
128 // Methods to check what devices we have on the system.
129 bool HasWebcamAvailableOnSystem(content::WebContents
* tab_contents
) const;
131 // Returns true if we're on WinXP, that lovely operating system of bliss.
132 bool OnWinXp() const;
134 // Returns true if we're on win 8.
138 void CloseInfoBarInTab(content::WebContents
* tab_contents
,
139 infobars::InfoBar
* infobar
) const;
141 std::string
CreateLocalOffer(content::WebContents
* from_tab
) const;
142 std::string
CreateAnswer(std::string local_offer
,
143 content::WebContents
* to_tab
) const;
144 void ReceiveAnswer(std::string answer
, content::WebContents
* from_tab
) const;
145 void GatherAndSendIceCandidates(content::WebContents
* from_tab
,
146 content::WebContents
* to_tab
) const;
148 infobars::InfoBar
* GetUserMediaAndWaitForInfoBar(
149 content::WebContents
* tab_contents
,
150 const std::string
& constraints
) const;
152 bool detect_errors_in_javascript_
;
154 DISALLOW_COPY_AND_ASSIGN(WebRtcTestBase
);
157 #endif // CHROME_BROWSER_MEDIA_WEBRTC_BROWSERTEST_BASE_H_