| Index: chrome/browser/media/chrome_media_stream_infobar_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/media/chrome_media_stream_infobar_browsertest.cc (revision 213248)
|
| +++ chrome/browser/media/chrome_media_stream_infobar_browsertest.cc (working copy)
|
| @@ -41,129 +41,166 @@
|
| static const char kVideoOnlyCallConstraints[] = "'{video: true}'";
|
| static const char kOkGotStream[] = "ok-got-stream";
|
|
|
| -// Media stream infobar test for WebRTC.
|
| +
|
| +// MediaStreamInfoBarTest -----------------------------------------------------
|
| +
|
| class MediaStreamInfobarTest : public InProcessBrowserTest {
|
| public:
|
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| - // This test expects to run with fake devices but real UI.
|
| - command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
|
| - EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream))
|
| - << "Since this test tests the UI we want the real UI!";
|
| - }
|
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
|
| +
|
| protected:
|
| - content::WebContents* LoadTestPageInTab() {
|
| - EXPECT_TRUE(test_server()->Start());
|
| + content::WebContents* LoadTestPageInTab();
|
|
|
| - ui_test_utils::NavigateToURL(
|
| - browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage));
|
| - return browser()->tab_strip_model()->GetActiveWebContents();
|
| - }
|
| -
|
| // TODO(phoglund): upstream and reuse in other browser tests.
|
| MediaStreamInfoBarDelegate* GetUserMediaAndWaitForInfobar(
|
| content::WebContents* tab_contents,
|
| - const std::string& constraints) {
|
| - content::WindowedNotificationObserver infobar_added(
|
| - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
|
| - content::NotificationService::AllSources());
|
| + const std::string& constraints);
|
|
|
| - // Request user media: this will launch the media stream info bar.
|
| - GetUserMedia(constraints, tab_contents);
|
| -
|
| - // Wait for the bar to pop up, then return it
|
| - infobar_added.Wait();
|
| - content::Details<InfoBarAddedDetails> details(infobar_added.details());
|
| - MediaStreamInfoBarDelegate* media_infobar =
|
| - details.ptr()->AsMediaStreamInfoBarDelegate();
|
| - return media_infobar;
|
| - }
|
| -
|
| void CloseInfobarInTab(content::WebContents* tab_contents,
|
| - MediaStreamInfoBarDelegate* infobar) {
|
| - content::WindowedNotificationObserver infobar_removed(
|
| - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
|
| - content::NotificationService::AllSources());
|
| + MediaStreamInfoBarDelegate* infobar);
|
|
|
| - InfoBarService* infobar_service =
|
| - InfoBarService::FromWebContents(tab_contents);
|
| - infobar_service->RemoveInfoBar(infobar);
|
| -
|
| - infobar_removed.Wait();
|
| - }
|
| -
|
| // Convenience method which executes the provided javascript in the context
|
| // of the provided web contents and returns what it evaluated to.
|
| std::string ExecuteJavascript(const std::string& javascript,
|
| - content::WebContents* tab_contents) {
|
| - std::string result;
|
| - EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| - tab_contents, javascript, &result));
|
| - return result;
|
| - }
|
| + content::WebContents* tab_contents);
|
|
|
| - void TestAcceptOnInfobar(content::WebContents* tab_contents) {
|
| - TestAcceptOnInfobarWithSpecificConstraints(tab_contents,
|
| - kAudioVideoCallConstraints);
|
| - }
|
| -
|
| + void TestAcceptOnInfobar(content::WebContents* tab_contents);
|
| void TestAcceptOnInfobarWithSpecificConstraints(
|
| - content::WebContents* tab_contents, const std::string& constraints) {
|
| - MediaStreamInfoBarDelegate* media_infobar =
|
| - GetUserMediaAndWaitForInfobar(tab_contents, constraints);
|
| + content::WebContents* tab_contents, const std::string& constraints);
|
| + void TestDenyOnInfobar(content::WebContents* tab_contents);
|
| + void TestDenyWithSpecificConstraints(content::WebContents* tab_contents,
|
| + const std::string& constraints);
|
| + void TestDismissOnInfobar(content::WebContents* tab_contents);
|
|
|
| - media_infobar->Accept();
|
| + void GetUserMedia(const std::string& constraints,
|
| + content::WebContents* tab_contents);
|
| +};
|
|
|
| - CloseInfobarInTab(tab_contents, media_infobar);
|
| +void MediaStreamInfobarTest::SetUpCommandLine(CommandLine* command_line) {
|
| + // This test expects to run with fake devices but real UI.
|
| + command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
|
| + EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream))
|
| + << "Since this test tests the UI we want the real UI!";
|
| +}
|
|
|
| - // Wait for WebRTC to call the success callback.
|
| - EXPECT_TRUE(PollingWaitUntil(
|
| - "obtainGetUserMediaResult()", kOkGotStream, tab_contents));
|
| - }
|
| +content::WebContents* MediaStreamInfobarTest::LoadTestPageInTab() {
|
| + EXPECT_TRUE(test_server()->Start());
|
|
|
| - void TestDenyOnInfobar(content::WebContents* tab_contents) {
|
| - return TestDenyWithSpecificConstraints(tab_contents,
|
| - kAudioVideoCallConstraints);
|
| - }
|
| + ui_test_utils::NavigateToURL(
|
| + browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage));
|
| + return browser()->tab_strip_model()->GetActiveWebContents();
|
| +}
|
|
|
| - void TestDenyWithSpecificConstraints(content::WebContents* tab_contents,
|
| - const std::string& constraints) {
|
| - MediaStreamInfoBarDelegate* media_infobar =
|
| - GetUserMediaAndWaitForInfobar(tab_contents, constraints);
|
| +MediaStreamInfoBarDelegate*
|
| + MediaStreamInfobarTest::GetUserMediaAndWaitForInfobar(
|
| + content::WebContents* tab_contents,
|
| + const std::string& constraints) {
|
| + content::WindowedNotificationObserver infobar_added(
|
| + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
|
| + content::NotificationService::AllSources());
|
|
|
| - media_infobar->Cancel();
|
| + // Request user media: this will launch the media stream info bar.
|
| + GetUserMedia(constraints, tab_contents);
|
|
|
| - CloseInfobarInTab(tab_contents, media_infobar);
|
| + // Wait for the bar to pop up, then return it
|
| + infobar_added.Wait();
|
| + content::Details<InfoBarAddedDetails> details(infobar_added.details());
|
| + MediaStreamInfoBarDelegate* media_infobar =
|
| + details.ptr()->AsMediaStreamInfoBarDelegate();
|
| + return media_infobar;
|
| +}
|
|
|
| - // Wait for WebRTC to call the fail callback.
|
| - EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
|
| - kFailedWithErrorPermissionDenied,
|
| - tab_contents));
|
| - }
|
| +void MediaStreamInfobarTest::CloseInfobarInTab(
|
| + content::WebContents* tab_contents,
|
| + MediaStreamInfoBarDelegate* infobar) {
|
| + content::WindowedNotificationObserver infobar_removed(
|
| + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
|
| + content::NotificationService::AllSources());
|
|
|
| - void TestDismissOnInfobar(content::WebContents* tab_contents) {
|
| - MediaStreamInfoBarDelegate* media_infobar =
|
| - GetUserMediaAndWaitForInfobar(tab_contents, kAudioVideoCallConstraints);
|
| + InfoBarService* infobar_service =
|
| + InfoBarService::FromWebContents(tab_contents);
|
| + infobar_service->RemoveInfoBar(infobar);
|
|
|
| - media_infobar->InfoBarDismissed();
|
| + infobar_removed.Wait();
|
| +}
|
|
|
| - CloseInfobarInTab(tab_contents, media_infobar);
|
| +std::string MediaStreamInfobarTest::ExecuteJavascript(
|
| + const std::string& javascript,
|
| + content::WebContents* tab_contents) {
|
| + std::string result;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + tab_contents, javascript, &result));
|
| + return result;
|
| +}
|
|
|
| - // A dismiss should be treated like a deny.
|
| - EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
|
| - kFailedWithErrorPermissionDenied,
|
| - tab_contents));
|
| - }
|
| +void MediaStreamInfobarTest::TestAcceptOnInfobar(
|
| + content::WebContents* tab_contents) {
|
| + TestAcceptOnInfobarWithSpecificConstraints(tab_contents,
|
| + kAudioVideoCallConstraints);
|
| +}
|
|
|
| - void GetUserMedia(const std::string& constraints,
|
| - content::WebContents* tab_contents) {
|
| - // Request user media: this will launch the media stream info bar.
|
| - EXPECT_EQ("ok-requested",
|
| - ExecuteJavascript(
|
| - base::StringPrintf("getUserMedia(%s);", constraints.c_str()),
|
| - tab_contents));
|
| - }
|
| -};
|
| +void MediaStreamInfobarTest::TestAcceptOnInfobarWithSpecificConstraints(
|
| + content::WebContents* tab_contents,
|
| + const std::string& constraints) {
|
| + MediaStreamInfoBarDelegate* media_infobar =
|
| + GetUserMediaAndWaitForInfobar(tab_contents, constraints);
|
|
|
| + media_infobar->Accept();
|
| +
|
| + CloseInfobarInTab(tab_contents, media_infobar);
|
| +
|
| + // Wait for WebRTC to call the success callback.
|
| + EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream,
|
| + tab_contents));
|
| +}
|
| +
|
| +void MediaStreamInfobarTest::TestDenyOnInfobar(
|
| + content::WebContents* tab_contents) {
|
| + return TestDenyWithSpecificConstraints(tab_contents,
|
| + kAudioVideoCallConstraints);
|
| +}
|
| +
|
| +void MediaStreamInfobarTest::TestDenyWithSpecificConstraints(
|
| + content::WebContents* tab_contents,
|
| + const std::string& constraints) {
|
| + MediaStreamInfoBarDelegate* media_infobar =
|
| + GetUserMediaAndWaitForInfobar(tab_contents, constraints);
|
| +
|
| + media_infobar->Cancel();
|
| +
|
| + CloseInfobarInTab(tab_contents, media_infobar);
|
| +
|
| + // Wait for WebRTC to call the fail callback.
|
| + EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
|
| + kFailedWithErrorPermissionDenied, tab_contents));
|
| +}
|
| +
|
| +void MediaStreamInfobarTest::TestDismissOnInfobar(
|
| + content::WebContents* tab_contents) {
|
| + MediaStreamInfoBarDelegate* media_infobar =
|
| + GetUserMediaAndWaitForInfobar(tab_contents, kAudioVideoCallConstraints);
|
| +
|
| + media_infobar->InfoBarDismissed();
|
| +
|
| + CloseInfobarInTab(tab_contents, media_infobar);
|
| +
|
| + // A dismiss should be treated like a deny.
|
| + EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
|
| + kFailedWithErrorPermissionDenied, tab_contents));
|
| +}
|
| +
|
| +void MediaStreamInfobarTest::GetUserMedia(const std::string& constraints,
|
| + content::WebContents* tab_contents) {
|
| + // Request user media: this will launch the media stream info bar.
|
| + EXPECT_EQ("ok-requested",
|
| + ExecuteJavascript(
|
| + base::StringPrintf("getUserMedia(%s);", constraints.c_str()),
|
| + tab_contents));
|
| +}
|
| +
|
| +
|
| +// Actual tests ---------------------------------------------------------------
|
| +
|
| IN_PROC_BROWSER_TEST_F(MediaStreamInfobarTest, TestAllowingUserMedia) {
|
| content::WebContents* tab_contents = LoadTestPageInTab();
|
| TestAcceptOnInfobar(tab_contents);
|
|
|