OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/process/launch.h" | 7 #include "base/process/launch.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 "{\n" | 29 "{\n" |
30 " \"name\" : \"webrtc.DEPS\",\n" | 30 " \"name\" : \"webrtc.DEPS\",\n" |
31 " \"url\" : \"svn://svn.chromium.org/chrome/trunk/deps/" | 31 " \"url\" : \"svn://svn.chromium.org/chrome/trunk/deps/" |
32 "third_party/webrtc/webrtc.DEPS\",\n" | 32 "third_party/webrtc/webrtc.DEPS\",\n" |
33 "}"; | 33 "}"; |
34 const char kTitlePageOfAppEngineAdminPage[] = "Instances"; | 34 const char kTitlePageOfAppEngineAdminPage[] = "Instances"; |
35 | 35 |
36 | 36 |
37 // WebRTC-AppRTC integration test. Requires a real webcam and microphone | 37 // WebRTC-AppRTC integration test. Requires a real webcam and microphone |
38 // on the running system. This test is not meant to run in the main browser | 38 // on the running system. This test is not meant to run in the main browser |
39 // test suite since normal tester machines do not have webcams. | 39 // test suite since normal tester machines do not have webcams. Chrome will use |
| 40 // this camera for the regular AppRTC test whereas Firefox will use it in the |
| 41 // Firefox interop test (where case Chrome will use its built-in fake device). |
40 // | 42 // |
41 // This test will bring up a AppRTC instance on localhost and verify that the | 43 // This test will bring up a AppRTC instance on localhost and verify that the |
42 // call gets up when connecting to the same room from two tabs in a browser. | 44 // call gets up when connecting to the same room from two tabs in a browser. |
43 class WebrtcApprtcBrowserTest : public WebRtcTestBase { | 45 class WebrtcApprtcBrowserTest : public WebRtcTestBase { |
44 public: | 46 public: |
| 47 WebrtcApprtcBrowserTest() |
| 48 : dev_appserver_(base::kNullProcessHandle), |
| 49 firefox_(base::kNullProcessHandle) { |
| 50 } |
| 51 |
45 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 52 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
46 EXPECT_FALSE(command_line->HasSwitch( | 53 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); |
47 switches::kUseFakeDeviceForMediaStream)); | |
48 EXPECT_FALSE(command_line->HasSwitch( | |
49 switches::kUseFakeUIForMediaStream)); | |
50 | 54 |
51 // The video playback will not work without a GPU, so force its use here. | 55 // The video playback will not work without a GPU, so force its use here. |
52 command_line->AppendSwitch(switches::kUseGpuInTests); | 56 command_line->AppendSwitch(switches::kUseGpuInTests); |
53 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
54 // TODO(mcasas): Remove this switch when http://crbug.com/327618 is solved. | 58 // TODO(mcasas): Remove this switch when http://crbug.com/327618 is solved. |
55 command_line->AppendSwitch(switches::kDisableAVFoundation); | 59 command_line->AppendSwitch(switches::kDisableAVFoundation); |
56 #endif | 60 #endif |
57 } | 61 } |
58 | 62 |
| 63 virtual void TearDown() OVERRIDE { |
| 64 // Kill any processes we may have brought up. |
| 65 if (dev_appserver_ != base::kNullProcessHandle) |
| 66 base::KillProcess(dev_appserver_, 0, false); |
| 67 // TODO(phoglund): Find some way to shut down Firefox cleanly on Windows. |
| 68 if (firefox_ != base::kNullProcessHandle) |
| 69 base::KillProcess(firefox_, 0, false); |
| 70 } |
| 71 |
59 protected: | 72 protected: |
60 bool LaunchApprtcInstanceOnLocalhost() { | 73 bool LaunchApprtcInstanceOnLocalhost() { |
61 base::FilePath appengine_dev_appserver = | 74 base::FilePath appengine_dev_appserver = |
62 GetSourceDir().Append( | 75 GetSourceDir().Append( |
63 FILE_PATH_LITERAL("../google_appengine/dev_appserver.py")); | 76 FILE_PATH_LITERAL("../google_appengine/dev_appserver.py")); |
64 if (!base::PathExists(appengine_dev_appserver)) { | 77 if (!base::PathExists(appengine_dev_appserver)) { |
65 LOG(ERROR) << "Missing appengine sdk at " << | 78 LOG(ERROR) << "Missing appengine sdk at " << |
66 appengine_dev_appserver.value() << ". " << kAdviseOnGclientSolution; | 79 appengine_dev_appserver.value() << ". " << kAdviseOnGclientSolution; |
67 return false; | 80 return false; |
68 } | 81 } |
69 | 82 |
70 base::FilePath apprtc_dir = | 83 base::FilePath apprtc_dir = |
71 GetSourceDir().Append(FILE_PATH_LITERAL("out/apprtc")); | 84 GetSourceDir().Append(FILE_PATH_LITERAL("out/apprtc")); |
72 if (!base::PathExists(apprtc_dir)) { | 85 if (!base::PathExists(apprtc_dir)) { |
73 LOG(ERROR) << "Missing AppRTC code at " << | 86 LOG(ERROR) << "Missing AppRTC code at " << |
74 apprtc_dir.value() << ". " << kAdviseOnGclientSolution; | 87 apprtc_dir.value() << ". " << kAdviseOnGclientSolution; |
75 return false; | 88 return false; |
76 } | 89 } |
77 | 90 |
78 CommandLine command_line(CommandLine::NO_PROGRAM); | 91 CommandLine command_line(CommandLine::NO_PROGRAM); |
79 EXPECT_TRUE(GetPythonCommand(&command_line)); | 92 EXPECT_TRUE(GetPythonCommand(&command_line)); |
80 | 93 |
81 command_line.AppendArgPath(appengine_dev_appserver); | 94 command_line.AppendArgPath(appengine_dev_appserver); |
82 command_line.AppendArgPath(apprtc_dir); | 95 command_line.AppendArgPath(apprtc_dir); |
83 command_line.AppendArg("--port=9999"); | 96 command_line.AppendArg("--port=9999"); |
84 command_line.AppendArg("--admin_port=9998"); | 97 command_line.AppendArg("--admin_port=9998"); |
85 command_line.AppendArg("--skip_sdk_update_check"); | 98 command_line.AppendArg("--skip_sdk_update_check"); |
86 | 99 |
87 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 100 VLOG(1) << "Running " << command_line.GetCommandLineString(); |
88 return base::LaunchProcess(command_line, base::LaunchOptions(), | 101 return base::LaunchProcess(command_line, base::LaunchOptions(), |
89 &dev_appserver_); | 102 &dev_appserver_); |
90 } | 103 } |
91 | 104 |
92 bool LocalApprtcInstanceIsUp() { | 105 bool LocalApprtcInstanceIsUp() { |
93 // Load the admin page and see if we manage to load it right. | 106 // Load the admin page and see if we manage to load it right. |
94 ui_test_utils::NavigateToURL(browser(), GURL("localhost:9998")); | 107 ui_test_utils::NavigateToURL(browser(), GURL("localhost:9998")); |
95 content::WebContents* tab_contents = | 108 content::WebContents* tab_contents = |
96 browser()->tab_strip_model()->GetActiveWebContents(); | 109 browser()->tab_strip_model()->GetActiveWebContents(); |
97 std::string javascript = | 110 std::string javascript = |
98 "window.domAutomationController.send(document.title)"; | 111 "window.domAutomationController.send(document.title)"; |
99 std::string result; | 112 std::string result; |
100 if (!content::ExecuteScriptAndExtractString(tab_contents, javascript, | 113 if (!content::ExecuteScriptAndExtractString(tab_contents, javascript, |
101 &result)) | 114 &result)) |
102 return false; | 115 return false; |
103 | 116 |
104 return result == kTitlePageOfAppEngineAdminPage; | 117 return result == kTitlePageOfAppEngineAdminPage; |
105 } | 118 } |
106 | 119 |
107 bool StopApprtcInstance() { | |
108 return base::KillProcess(dev_appserver_, 0, false); | |
109 } | |
110 | |
111 bool WaitForCallToComeUp(content::WebContents* tab_contents) { | 120 bool WaitForCallToComeUp(content::WebContents* tab_contents) { |
112 // Apprtc will set remoteVideo.style.opacity to 1 when the call comes up. | 121 // Apprtc will set remoteVideo.style.opacity to 1 when the call comes up. |
113 std::string javascript = | 122 std::string javascript = |
114 "window.domAutomationController.send(remoteVideo.style.opacity)"; | 123 "window.domAutomationController.send(remoteVideo.style.opacity)"; |
115 return PollingWaitUntil(javascript, "1", tab_contents); | 124 return PollingWaitUntil(javascript, "1", tab_contents); |
116 } | 125 } |
117 | 126 |
118 base::FilePath GetSourceDir() { | 127 base::FilePath GetSourceDir() { |
119 base::FilePath source_dir; | 128 base::FilePath source_dir; |
120 PathService::Get(base::DIR_SOURCE_ROOT, &source_dir); | 129 PathService::Get(base::DIR_SOURCE_ROOT, &source_dir); |
121 return source_dir; | 130 return source_dir; |
122 } | 131 } |
123 | 132 |
| 133 bool LaunchFirefoxWithUrl(const GURL& url) { |
| 134 base::FilePath firefox_binary = |
| 135 GetSourceDir().Append( |
| 136 FILE_PATH_LITERAL("../firefox-nightly/firefox/firefox")); |
| 137 if (!base::PathExists(firefox_binary)) { |
| 138 LOG(ERROR) << "Missing firefox binary at " << |
| 139 firefox_binary.value() << ". " << kAdviseOnGclientSolution; |
| 140 return false; |
| 141 } |
| 142 base::FilePath firefox_launcher = |
| 143 GetSourceDir().Append( |
| 144 FILE_PATH_LITERAL("../webrtc.DEPS/run_firefox_webrtc.py")); |
| 145 if (!base::PathExists(firefox_launcher)) { |
| 146 LOG(ERROR) << "Missing firefox launcher at " << |
| 147 firefox_launcher.value() << ". " << kAdviseOnGclientSolution; |
| 148 return false; |
| 149 } |
| 150 |
| 151 CommandLine command_line(firefox_launcher); |
| 152 command_line.AppendSwitchPath("--binary", firefox_binary); |
| 153 command_line.AppendSwitchASCII("--webpage", url.spec()); |
| 154 |
| 155 VLOG(1) << "Running " << command_line.GetCommandLineString(); |
| 156 return base::LaunchProcess(command_line, base::LaunchOptions(), |
| 157 &firefox_); |
| 158 |
| 159 return true; |
| 160 } |
| 161 |
124 private: | 162 private: |
125 base::ProcessHandle dev_appserver_; | 163 base::ProcessHandle dev_appserver_; |
| 164 base::ProcessHandle firefox_; |
126 }; | 165 }; |
127 | 166 |
128 IN_PROC_BROWSER_TEST_F(WebrtcApprtcBrowserTest, MANUAL_WorksOnApprtc) { | 167 IN_PROC_BROWSER_TEST_F(WebrtcApprtcBrowserTest, MANUAL_WorksOnApprtc) { |
129 // TODO(mcasas): Remove Win version filtering when this bug gets fixed: | 168 // TODO(mcasas): Remove Win version filtering when this bug gets fixed: |
130 // http://code.google.com/p/webrtc/issues/detail?id=2703 | 169 // http://code.google.com/p/webrtc/issues/detail?id=2703 |
131 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
132 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 171 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
133 return; | 172 return; |
134 #endif | 173 #endif |
135 DetectErrorsInJavaScript(); | 174 DetectErrorsInJavaScript(); |
136 ASSERT_TRUE(LaunchApprtcInstanceOnLocalhost()); | 175 ASSERT_TRUE(LaunchApprtcInstanceOnLocalhost()); |
137 while (!LocalApprtcInstanceIsUp()) | 176 while (!LocalApprtcInstanceIsUp()) |
138 VLOG(0) << "Waiting for AppRTC to come up..."; | 177 VLOG(1) << "Waiting for AppRTC to come up..."; |
139 | 178 |
140 GURL room_url = GURL(base::StringPrintf("localhost:9999?r=room_%d", | 179 GURL room_url = GURL(base::StringPrintf("localhost:9999?r=room_%d", |
141 base::RandInt(0, 65536))); | 180 base::RandInt(0, 65536))); |
142 | 181 |
143 chrome::AddTabAt(browser(), GURL(), -1, true); | 182 chrome::AddTabAt(browser(), GURL(), -1, true); |
144 content::WebContents* left_tab = OpenPageAndAcceptUserMedia(room_url); | 183 content::WebContents* left_tab = OpenPageAndAcceptUserMedia(room_url); |
145 // TODO(phoglund): Remove when this bug gets fixed: | 184 // TODO(phoglund): Remove when this bug gets fixed: |
146 // http://code.google.com/p/webrtc/issues/detail?id=1742 | 185 // http://code.google.com/p/webrtc/issues/detail?id=1742 |
147 SleepInJavascript(left_tab, 5000); | 186 SleepInJavascript(left_tab, 5000); |
148 chrome::AddTabAt(browser(), GURL(), -1, true); | 187 chrome::AddTabAt(browser(), GURL(), -1, true); |
149 content::WebContents* right_tab = OpenPageAndAcceptUserMedia(room_url); | 188 content::WebContents* right_tab = OpenPageAndAcceptUserMedia(room_url); |
150 | 189 |
151 ASSERT_TRUE(WaitForCallToComeUp(left_tab)); | 190 ASSERT_TRUE(WaitForCallToComeUp(left_tab)); |
152 ASSERT_TRUE(WaitForCallToComeUp(right_tab)); | 191 ASSERT_TRUE(WaitForCallToComeUp(right_tab)); |
| 192 } |
153 | 193 |
154 ASSERT_TRUE(StopApprtcInstance()); | 194 #if defined(OS_LINUX) |
| 195 #define MAYBE_MANUAL_FirefoxApprtcInteropTest MANUAL_FirefoxApprtcInteropTest |
| 196 #else |
| 197 // Not implemented yet on Windows and Mac. |
| 198 #define MAYBE_MANUAL_FirefoxApprtcInteropTest DISABLED_MANUAL_FirefoxApprtcInter
opTest |
| 199 #endif |
| 200 |
| 201 IN_PROC_BROWSER_TEST_F(WebrtcApprtcBrowserTest, |
| 202 MAYBE_MANUAL_FirefoxApprtcInteropTest) { |
| 203 // TODO(mcasas): Remove Win version filtering when this bug gets fixed: |
| 204 // http://code.google.com/p/webrtc/issues/detail?id=2703 |
| 205 #if defined(OS_WIN) |
| 206 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 207 return; |
| 208 #endif |
| 209 |
| 210 DetectErrorsInJavaScript(); |
| 211 ASSERT_TRUE(LaunchApprtcInstanceOnLocalhost()); |
| 212 while (!LocalApprtcInstanceIsUp()) |
| 213 VLOG(1) << "Waiting for AppRTC to come up..."; |
| 214 |
| 215 // Run Chrome with a fake device to avoid having the browsers fight over the |
| 216 // camera (we'll just give that to firefox here). |
| 217 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 218 switches::kUseFakeDeviceForMediaStream); |
| 219 |
| 220 GURL room_url = GURL(base::StringPrintf("http://localhost:9999?r=room_%d", |
| 221 base::RandInt(0, 65536))); |
| 222 content::WebContents* chrome_tab = OpenPageAndAcceptUserMedia(room_url); |
| 223 |
| 224 // TODO(phoglund): Remove when this bug gets fixed: |
| 225 // http://code.google.com/p/webrtc/issues/detail?id=1742 |
| 226 SleepInJavascript(chrome_tab, 5000); |
| 227 |
| 228 ASSERT_TRUE(LaunchFirefoxWithUrl(room_url)); |
| 229 |
| 230 ASSERT_TRUE(WaitForCallToComeUp(chrome_tab)); |
155 } | 231 } |
OLD | NEW |