OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/time.h" | 5 #include "base/time.h" |
6 #include "chrome/browser/api/infobars/infobar_service.h" | 6 #include "chrome/browser/api/infobars/infobar_service.h" |
7 #include "chrome/browser/infobars/infobar.h" | 7 #include "chrome/browser/infobars/infobar.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser_tabstrip.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 10 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
15 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
18 #include "net/test/test_server.h" | 19 #include "net/test/test_server.h" |
19 | 20 |
20 // Top-level integration test for WebRTC. Requires a real webcam and microphone | 21 // Top-level integration test for WebRTC. Requires a real webcam and microphone |
(...skipping 20 matching lines...) Expand all Loading... |
41 // javascript. This method is meant to emulate WaitUntil in the PyAuto | 42 // javascript. This method is meant to emulate WaitUntil in the PyAuto |
42 // framework. | 43 // framework. |
43 bool UglyPollingWaitUntil(const std::string& javascript, | 44 bool UglyPollingWaitUntil(const std::string& javascript, |
44 const std::string& evaluates_to) { | 45 const std::string& evaluates_to) { |
45 base::Time start_time = base::Time::Now(); | 46 base::Time start_time = base::Time::Now(); |
46 base::TimeDelta timeout = base::TimeDelta::FromSeconds(20); | 47 base::TimeDelta timeout = base::TimeDelta::FromSeconds(20); |
47 std::string result; | 48 std::string result; |
48 | 49 |
49 while (base::Time::Now() - start_time < timeout) { | 50 while (base::Time::Now() - start_time < timeout) { |
50 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 51 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
51 chrome::GetActiveWebContents(browser()), | 52 browser()->tab_strip_model()->GetActiveWebContents(), |
52 "obtainGetUserMediaResult();", | 53 "obtainGetUserMediaResult();", |
53 &result)); | 54 &result)); |
54 if (result == evaluates_to) | 55 if (result == evaluates_to) |
55 return true; | 56 return true; |
56 } | 57 } |
57 LOG(ERROR) << "Timed out while waiting for " << javascript << | 58 LOG(ERROR) << "Timed out while waiting for " << javascript << |
58 " to evaluate to " << evaluates_to << "; last result was '" << result << | 59 " to evaluate to " << evaluates_to << "; last result was '" << result << |
59 "'"; | 60 "'"; |
60 return false; | 61 return false; |
61 } | 62 } |
62 }; | 63 }; |
63 | 64 |
64 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, | 65 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, |
65 MANUAL_InfobarAppearsWhenRequestingUserMedia) { | 66 MANUAL_InfobarAppearsWhenRequestingUserMedia) { |
66 ASSERT_TRUE(test_server()->Start()); | 67 ASSERT_TRUE(test_server()->Start()); |
67 | 68 |
68 ui_test_utils::NavigateToURL( | 69 ui_test_utils::NavigateToURL( |
69 browser(), | 70 browser(), |
70 test_server()->GetURL("files/webrtc/webrtc_jsep01_test.html")); | 71 test_server()->GetURL("files/webrtc/webrtc_jsep01_test.html")); |
71 | 72 |
72 content::WindowedNotificationObserver infobar_added( | 73 content::WindowedNotificationObserver infobar_added( |
73 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 74 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
74 content::NotificationService::AllSources()); | 75 content::NotificationService::AllSources()); |
75 | 76 |
76 // Request user media: this will launch the media stream info bar. | 77 // Request user media: this will launch the media stream info bar. |
77 std::string result; | 78 std::string result; |
78 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 79 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
79 chrome::GetActiveWebContents(browser()), | 80 browser()->tab_strip_model()->GetActiveWebContents(), |
80 "getUserMedia('{video: true}');", | 81 "getUserMedia('{video: true}');", |
81 &result)); | 82 &result)); |
82 EXPECT_EQ("ok-requested", result); | 83 EXPECT_EQ("ok-requested", result); |
83 | 84 |
84 // Wait for the bar to pop up, then accept. | 85 // Wait for the bar to pop up, then accept. |
85 infobar_added.Wait(); | 86 infobar_added.Wait(); |
86 InfoBarDelegate* infobar = | 87 InfoBarDelegate* infobar = |
87 content::Details<InfoBarAddedDetails>(infobar_added.details()).ptr(); | 88 content::Details<InfoBarAddedDetails>(infobar_added.details()).ptr(); |
88 MediaStreamInfoBarDelegate* media_infobar = | 89 MediaStreamInfoBarDelegate* media_infobar = |
89 infobar->AsMediaStreamInfoBarDelegate(); | 90 infobar->AsMediaStreamInfoBarDelegate(); |
90 media_infobar->Accept(); | 91 media_infobar->Accept(); |
91 | 92 |
92 // Wait for WebRTC to call the success callback. | 93 // Wait for WebRTC to call the success callback. |
93 EXPECT_TRUE(UglyPollingWaitUntil("obtainGetUserMediaResult();", | 94 EXPECT_TRUE(UglyPollingWaitUntil("obtainGetUserMediaResult();", |
94 "ok-got-stream")); | 95 "ok-got-stream")); |
95 } | 96 } |
OLD | NEW |