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