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