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 "chrome/test/remoting/remote_desktop_browsertest.h" | 5 #include "chrome/test/remoting/remote_desktop_browsertest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 extensions::Manifest::Type type = extension_->GetType(); | 162 extensions::Manifest::Type type = extension_->GetType(); |
163 EXPECT_TRUE(type == extensions::Manifest::TYPE_PLATFORM_APP || | 163 EXPECT_TRUE(type == extensions::Manifest::TYPE_PLATFORM_APP || |
164 type == extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); | 164 type == extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); |
165 | 165 |
166 EXPECT_TRUE(extension_->ShouldDisplayInAppLauncher()); | 166 EXPECT_TRUE(extension_->ShouldDisplayInAppLauncher()); |
167 } | 167 } |
168 | 168 |
169 ASSERT_EQ(installed, expected); | 169 ASSERT_EQ(installed, expected); |
170 } | 170 } |
171 | 171 |
172 void RemoteDesktopBrowserTest::LaunchChromotingApp(bool defer_start) { | 172 content::WebContents* RemoteDesktopBrowserTest::LaunchChromotingApp( |
173 ASSERT_TRUE(extension_); | 173 bool defer_start, |
| 174 WindowOpenDisposition window_open_disposition) { |
| 175 _ASSERT_TRUE(extension_); |
174 | 176 |
175 GURL chromoting_main = Chromoting_Main_URL(); | 177 GURL chromoting_main = Chromoting_Main_URL(); |
176 // We cannot simply wait for any page load because the first page | 178 // We cannot simply wait for any page load because the first page |
177 // loaded could be the generated background page. We need to wait | 179 // loaded could be the generated background page. We need to wait |
178 // till the chromoting main page is loaded. | 180 // till the chromoting main page is loaded. |
179 PageLoadNotificationObserver observer(chromoting_main); | 181 PageLoadNotificationObserver observer(chromoting_main); |
180 observer.set_ignore_url_parameters(true); | 182 observer.set_ignore_url_parameters(true); |
181 | 183 |
182 // If the app should be started in deferred mode, ensure that a "source" URL | 184 // If the app should be started in deferred mode, ensure that a "source" URL |
183 // parameter; if not, ensure that no such parameter is present. The value of | 185 // parameter; if not, ensure that no such parameter is present. The value of |
184 // the parameter is determined by the AppLaunchParams ("test", in this case). | 186 // the parameter is determined by the AppLaunchParams ("test", in this case). |
185 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( | 187 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( |
186 extensions::FeatureSwitch::trace_app_source(), | 188 extensions::FeatureSwitch::trace_app_source(), |
187 defer_start); | 189 defer_start); |
188 | 190 |
| 191 if (is_platform_app()) { |
| 192 window_open_disposition = NEW_WINDOW; |
| 193 } |
| 194 |
189 OpenApplication(AppLaunchParams(browser()->profile(), extension_, | 195 OpenApplication(AppLaunchParams(browser()->profile(), extension_, |
190 is_platform_app() | 196 is_platform_app() |
191 ? extensions::LAUNCH_CONTAINER_NONE | 197 ? extensions::LAUNCH_CONTAINER_NONE |
192 : extensions::LAUNCH_CONTAINER_TAB, | 198 : extensions::LAUNCH_CONTAINER_TAB, |
193 is_platform_app() ? NEW_WINDOW : CURRENT_TAB, | 199 window_open_disposition, |
194 extensions::SOURCE_TEST)); | 200 extensions::SOURCE_TEST)); |
195 | 201 |
196 observer.Wait(); | 202 observer.Wait(); |
197 | 203 |
198 | 204 |
199 // The active WebContents instance should be the source of the LOAD_STOP | 205 // The active WebContents instance should be the source of the LOAD_STOP |
200 // notification. | 206 // notification. |
201 content::NavigationController* controller = | 207 content::NavigationController* controller = |
202 content::Source<content::NavigationController>(observer.source()).ptr(); | 208 content::Source<content::NavigationController>(observer.source()).ptr(); |
203 | 209 |
204 content::WebContents* web_contents = controller->GetWebContents(); | 210 content::WebContents* web_contents = controller->GetWebContents(); |
| 211 _ASSERT_TRUE(web_contents); |
| 212 |
205 if (web_contents != active_web_contents()) | 213 if (web_contents != active_web_contents()) |
206 web_contents_stack_.push_back(web_contents); | 214 web_contents_stack_.push_back(web_contents); |
207 | 215 |
208 app_web_content_ = web_contents; | |
209 | |
210 if (is_platform_app()) { | 216 if (is_platform_app()) { |
211 EXPECT_EQ(GetFirstAppWindowWebContents(), active_web_contents()); | 217 EXPECT_EQ(GetFirstAppWindowWebContents(), active_web_contents()); |
212 } else { | 218 } else { |
213 // For apps v1 only, the DOMOperationObserver is not ready at the LOAD_STOP | 219 // For apps v1 only, the DOMOperationObserver is not ready at the LOAD_STOP |
214 // event. A half second wait is necessary for the subsequent javascript | 220 // event. A half second wait is necessary for the subsequent javascript |
215 // injection to work. | 221 // injection to work. |
216 // TODO(weitaosu): Find out whether there is a more appropriate notification | 222 // TODO(weitaosu): Find out whether there is a more appropriate notification |
217 // to wait for so we can get rid of this wait. | 223 // to wait for so we can get rid of this wait. |
218 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); | 224 _ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); |
219 } | 225 } |
220 | 226 |
221 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); | 227 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); |
| 228 return web_contents; |
| 229 } |
| 230 |
| 231 content::WebContents* RemoteDesktopBrowserTest::LaunchChromotingApp( |
| 232 bool defer_start) { |
| 233 return LaunchChromotingApp(defer_start, CURRENT_TAB); |
222 } | 234 } |
223 | 235 |
224 void RemoteDesktopBrowserTest::StartChromotingApp() { | 236 void RemoteDesktopBrowserTest::StartChromotingApp() { |
225 ClickOnControl("browser-test-continue-init"); | 237 ClickOnControl("browser-test-continue-init"); |
226 }; | 238 }; |
227 | 239 |
228 void RemoteDesktopBrowserTest::Authorize() { | 240 void RemoteDesktopBrowserTest::Authorize() { |
229 // The chromoting extension should be installed. | 241 // The chromoting extension should be installed. |
230 ASSERT_TRUE(extension_); | 242 ASSERT_TRUE(extension_); |
231 | 243 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 VerifyChromotingLoaded(false); | 490 VerifyChromotingLoaded(false); |
479 } | 491 } |
480 | 492 |
481 // TODO(chaitali): Remove this additional timeout after we figure out | 493 // TODO(chaitali): Remove this additional timeout after we figure out |
482 // why this is needed for the v1 app to work. | 494 // why this is needed for the v1 app to work. |
483 // Without this timeout the test fail with a "CloseWebContents called for | 495 // Without this timeout the test fail with a "CloseWebContents called for |
484 // tab not in our strip" error for the v1 app. | 496 // tab not in our strip" error for the v1 app. |
485 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(2)).Wait()); | 497 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(2)).Wait()); |
486 } | 498 } |
487 | 499 |
488 void RemoteDesktopBrowserTest::SetUpTestForMe2Me() { | 500 content::WebContents* RemoteDesktopBrowserTest::SetUpTest() { |
489 VerifyInternetAccess(); | 501 VerifyInternetAccess(); |
490 Install(); | 502 Install(); |
491 LaunchChromotingApp(false); | 503 content::WebContents* app_web_content = LaunchChromotingApp(false); |
492 LoadBrowserTestJavaScript(app_web_content()); | |
493 Auth(); | 504 Auth(); |
| 505 LoadBrowserTestJavaScript(app_web_content); |
494 ExpandMe2Me(); | 506 ExpandMe2Me(); |
495 // The call to EnsureRemoteConnectionEnabled() does a PIN reset. | 507 // The call to EnsureRemoteConnectionEnabled() does a PIN reset. |
496 // This causes the test to fail because of a recent bug: | 508 // This causes the test to fail because of a recent bug: |
497 // crbug.com/430676 | 509 // crbug.com/430676 |
498 // TODO(anandc): Reactivate this call after above bug is fixed. | 510 // TODO(anandc): Reactivate this call after above bug is fixed. |
499 //EnsureRemoteConnectionEnabled(); | 511 //EnsureRemoteConnectionEnabled(app_web_content); |
| 512 return app_web_content; |
500 } | 513 } |
501 | 514 |
502 void RemoteDesktopBrowserTest::Auth() { | 515 void RemoteDesktopBrowserTest::Auth() { |
503 // For this test, we must be given the user-name and password. | 516 // For this test, we must be given the user-name and password. |
504 ASSERT_TRUE(!username_.empty() && !password_.empty()); | 517 ASSERT_TRUE(!username_.empty() && !password_.empty()); |
505 | 518 |
506 Authorize(); | 519 Authorize(); |
507 Authenticate(); | 520 Authenticate(); |
508 Approve(); | 521 Approve(); |
509 } | 522 } |
510 | 523 |
511 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled() { | 524 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled( |
| 525 content::WebContents* app_web_contents) { |
512 // browser_test.ensureRemoteConnectionEnabled is defined in | 526 // browser_test.ensureRemoteConnectionEnabled is defined in |
513 // browser_test.js, which must be loaded before calling this function. | 527 // browser_test.js, which must be loaded before calling this function. |
514 // TODO(kelvinp): This function currently only works on linux when the user is | 528 // TODO(kelvinp): This function currently only works on linux when the user is |
515 // already part of the chrome-remote-desktop group. Extend this functionality | 529 // already part of the chrome-remote-desktop group. Extend this functionality |
516 // to Mac (https://crbug.com/397576) and Windows (https://crbug.com/397575). | 530 // to Mac (https://crbug.com/397576) and Windows (https://crbug.com/397575). |
517 bool result; | 531 bool result; |
518 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 532 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
519 app_web_content(), | 533 app_web_contents, |
520 "browserTest.ensureRemoteConnectionEnabled(" + me2me_pin() + ")", | 534 "browserTest.ensureRemoteConnectionEnabled(" + me2me_pin() + ")", |
521 &result)); | 535 &result)); |
522 EXPECT_TRUE(result) << "Cannot start the host with Pin:" << me2me_pin(); | 536 EXPECT_TRUE(result) << "Cannot start the host with Pin:" << me2me_pin(); |
523 } | 537 } |
524 | 538 |
525 void RemoteDesktopBrowserTest::ConnectToLocalHost(bool remember_pin) { | 539 void RemoteDesktopBrowserTest::ConnectToLocalHost(bool remember_pin) { |
526 // Wait for local-host to be ready. | 540 // Wait for local-host to be ready. |
527 ConditionalTimeoutWaiter waiter( | 541 ConditionalTimeoutWaiter waiter( |
528 base::TimeDelta::FromSeconds(5), | 542 base::TimeDelta::FromSeconds(5), |
529 base::TimeDelta::FromMilliseconds(500), | 543 base::TimeDelta::FromMilliseconds(500), |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 // static | 888 // static |
875 bool RemoteDesktopBrowserTest::IsEnabled( | 889 bool RemoteDesktopBrowserTest::IsEnabled( |
876 content::WebContents* client_web_content, | 890 content::WebContents* client_web_content, |
877 const std::string& element_name) { | 891 const std::string& element_name) { |
878 return !RemoteTestHelper::ExecuteScriptAndExtractBool( | 892 return !RemoteTestHelper::ExecuteScriptAndExtractBool( |
879 client_web_content, | 893 client_web_content, |
880 "document.getElementById(\"" + element_name + "\").disabled"); | 894 "document.getElementById(\"" + element_name + "\").disabled"); |
881 } | 895 } |
882 | 896 |
883 } // namespace remoting | 897 } // namespace remoting |
OLD | NEW |