Chromium Code Reviews| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 extensions::Manifest::Type type = extension_->GetType(); | 159 extensions::Manifest::Type type = extension_->GetType(); |
| 160 EXPECT_TRUE(type == extensions::Manifest::TYPE_PLATFORM_APP || | 160 EXPECT_TRUE(type == extensions::Manifest::TYPE_PLATFORM_APP || |
| 161 type == extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); | 161 type == extensions::Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 162 | 162 |
| 163 EXPECT_TRUE(extension_->ShouldDisplayInAppLauncher()); | 163 EXPECT_TRUE(extension_->ShouldDisplayInAppLauncher()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 ASSERT_EQ(installed, expected); | 166 ASSERT_EQ(installed, expected); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void RemoteDesktopBrowserTest::LaunchChromotingApp(bool defer_start) { | 169 void RemoteDesktopBrowserTest::LaunchChromotingApp( |
| 170 bool defer_start, | |
| 171 WindowOpenDisposition window_open_disposition, | |
| 172 content::WebContents** app_web_contents) { | |
| 170 ASSERT_TRUE(extension_); | 173 ASSERT_TRUE(extension_); |
| 174 ASSERT_EQ(*app_web_contents, nullptr); | |
| 171 | 175 |
| 172 GURL chromoting_main = Chromoting_Main_URL(); | 176 GURL chromoting_main = Chromoting_Main_URL(); |
| 173 // We cannot simply wait for any page load because the first page | 177 // We cannot simply wait for any page load because the first page |
| 174 // loaded could be the generated background page. We need to wait | 178 // loaded could be the generated background page. We need to wait |
| 175 // till the chromoting main page is loaded. | 179 // till the chromoting main page is loaded. |
| 176 PageLoadNotificationObserver observer(chromoting_main); | 180 PageLoadNotificationObserver observer(chromoting_main); |
| 177 observer.set_ignore_url_parameters(true); | 181 observer.set_ignore_url_parameters(true); |
| 178 | 182 |
| 179 // If the app should be started in deferred mode, ensure that a "source" URL | 183 // If the app should be started in deferred mode, ensure that a "source" URL |
| 180 // parameter; if not, ensure that no such parameter is present. The value of | 184 // parameter; if not, ensure that no such parameter is present. The value of |
| 181 // the parameter is determined by the AppLaunchParams ("test", in this case). | 185 // the parameter is determined by the AppLaunchParams ("test", in this case). |
| 182 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( | 186 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( |
| 183 extensions::FeatureSwitch::trace_app_source(), | 187 extensions::FeatureSwitch::trace_app_source(), |
| 184 defer_start); | 188 defer_start); |
| 185 | 189 |
| 190 if (is_platform_app()) { | |
| 191 window_open_disposition = NEW_WINDOW; | |
|
Jamie
2015/01/10 00:14:24
Could we get rid of the disposition parameter if w
kelvinp
2015/01/12 21:15:24
V2 test currently doesn't run reliably. I prefer
| |
| 192 } | |
| 193 | |
| 186 OpenApplication(AppLaunchParams(browser()->profile(), extension_, | 194 OpenApplication(AppLaunchParams(browser()->profile(), extension_, |
| 187 is_platform_app() | 195 is_platform_app() |
| 188 ? extensions::LAUNCH_CONTAINER_NONE | 196 ? extensions::LAUNCH_CONTAINER_NONE |
| 189 : extensions::LAUNCH_CONTAINER_TAB, | 197 : extensions::LAUNCH_CONTAINER_TAB, |
| 190 is_platform_app() ? NEW_WINDOW : CURRENT_TAB, | 198 window_open_disposition, |
| 191 extensions::SOURCE_TEST)); | 199 extensions::SOURCE_TEST)); |
| 192 | 200 |
| 193 observer.Wait(); | 201 observer.Wait(); |
| 194 | 202 |
| 195 | 203 |
| 196 // The active WebContents instance should be the source of the LOAD_STOP | 204 // The active WebContents instance should be the source of the LOAD_STOP |
| 197 // notification. | 205 // notification. |
| 198 content::NavigationController* controller = | 206 content::NavigationController* controller = |
| 199 content::Source<content::NavigationController>(observer.source()).ptr(); | 207 content::Source<content::NavigationController>(observer.source()).ptr(); |
| 200 | 208 |
| 201 content::WebContents* web_contents = controller->GetWebContents(); | 209 content::WebContents* web_contents = controller->GetWebContents(); |
| 210 ASSERT_TRUE(web_contents); | |
| 211 | |
| 202 if (web_contents != active_web_contents()) | 212 if (web_contents != active_web_contents()) |
| 203 web_contents_stack_.push_back(web_contents); | 213 web_contents_stack_.push_back(web_contents); |
| 204 | 214 |
| 205 app_web_content_ = web_contents; | 215 *app_web_contents = web_contents; |
| 206 | 216 |
| 207 if (is_platform_app()) { | 217 if (is_platform_app()) { |
| 208 EXPECT_EQ(GetFirstAppWindowWebContents(), active_web_contents()); | 218 EXPECT_EQ(GetFirstAppWindowWebContents(), active_web_contents()); |
| 209 } else { | 219 } else { |
| 210 // For apps v1 only, the DOMOperationObserver is not ready at the LOAD_STOP | 220 // For apps v1 only, the DOMOperationObserver is not ready at the LOAD_STOP |
| 211 // event. A half second wait is necessary for the subsequent javascript | 221 // event. A half second wait is necessary for the subsequent javascript |
| 212 // injection to work. | 222 // injection to work. |
| 213 // TODO(weitaosu): Find out whether there is a more appropriate notification | 223 // TODO(weitaosu): Find out whether there is a more appropriate notification |
| 214 // to wait for so we can get rid of this wait. | 224 // to wait for so we can get rid of this wait. |
| 215 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); | 225 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); |
| 216 } | 226 } |
| 217 | 227 |
| 218 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); | 228 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); |
| 219 } | 229 } |
| 220 | 230 |
| 231 void RemoteDesktopBrowserTest::LaunchChromotingApp( | |
| 232 bool defer_start, | |
| 233 content::WebContents** app_web_contents) { | |
| 234 LaunchChromotingApp(defer_start, CURRENT_TAB, app_web_contents); | |
| 235 } | |
| 236 | |
| 237 void RemoteDesktopBrowserTest::LaunchChromotingApp(bool defer_start) { | |
| 238 content::WebContents* app_web_contents = nullptr; | |
| 239 LaunchChromotingApp(defer_start, CURRENT_TAB, &app_web_contents); | |
| 240 } | |
| 241 | |
| 221 void RemoteDesktopBrowserTest::StartChromotingApp() { | 242 void RemoteDesktopBrowserTest::StartChromotingApp() { |
| 222 ClickOnControl("browser-test-continue-init"); | 243 ClickOnControl("browser-test-continue-init"); |
| 223 }; | 244 }; |
| 224 | 245 |
| 225 void RemoteDesktopBrowserTest::Authorize() { | 246 void RemoteDesktopBrowserTest::Authorize() { |
| 226 // The chromoting extension should be installed. | 247 // The chromoting extension should be installed. |
| 227 ASSERT_TRUE(extension_); | 248 ASSERT_TRUE(extension_); |
| 228 | 249 |
| 229 // The chromoting main page should be loaded in the current tab | 250 // The chromoting main page should be loaded in the current tab |
| 230 // and isAuthenticated() should be false (auth dialog visible). | 251 // and isAuthenticated() should be false (auth dialog visible). |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 VerifyChromotingLoaded(false); | 484 VerifyChromotingLoaded(false); |
| 464 } | 485 } |
| 465 | 486 |
| 466 // TODO(chaitali): Remove this additional timeout after we figure out | 487 // TODO(chaitali): Remove this additional timeout after we figure out |
| 467 // why this is needed for the v1 app to work. | 488 // why this is needed for the v1 app to work. |
| 468 // Without this timeout the test fail with a "CloseWebContents called for | 489 // Without this timeout the test fail with a "CloseWebContents called for |
| 469 // tab not in our strip" error for the v1 app. | 490 // tab not in our strip" error for the v1 app. |
| 470 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(2)).Wait()); | 491 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(2)).Wait()); |
| 471 } | 492 } |
| 472 | 493 |
| 473 void RemoteDesktopBrowserTest::SetUpTestForMe2Me() { | 494 content::WebContents* RemoteDesktopBrowserTest::SetUpTest() { |
| 495 content::WebContents* app_web_content = nullptr; | |
| 474 VerifyInternetAccess(); | 496 VerifyInternetAccess(); |
| 475 Install(); | 497 Install(); |
| 476 LaunchChromotingApp(false); | 498 LaunchChromotingApp(false, &app_web_content); |
| 477 Auth(); | 499 Auth(); |
| 478 LoadScript(app_web_content(), FILE_PATH_LITERAL("browser_test.js")); | 500 LoadScript(app_web_content, FILE_PATH_LITERAL("browser_test.js")); |
| 479 ExpandMe2Me(); | 501 ExpandMe2Me(); |
| 480 // The call to EnsureRemoteConnectionEnabled() does a PIN reset. | 502 // The call to EnsureRemoteConnectionEnabled() does a PIN reset. |
| 481 // This causes the test to fail because of a recent bug: | 503 // This causes the test to fail because of a recent bug: |
| 482 // crbug.com/430676 | 504 // crbug.com/430676 |
| 483 // TODO(anandc): Reactivate this call after above bug is fixed. | 505 // TODO(anandc): Reactivate this call after above bug is fixed. |
| 484 //EnsureRemoteConnectionEnabled(); | 506 //EnsureRemoteConnectionEnabled(app_web_content); |
| 507 return app_web_content; | |
| 485 } | 508 } |
| 486 | 509 |
| 487 void RemoteDesktopBrowserTest::Auth() { | 510 void RemoteDesktopBrowserTest::Auth() { |
| 488 // For this test, we must be given the user-name and password. | 511 // For this test, we must be given the user-name and password. |
| 489 ASSERT_TRUE(!username_.empty() && !password_.empty()); | 512 ASSERT_TRUE(!username_.empty() && !password_.empty()); |
| 490 | 513 |
| 491 Authorize(); | 514 Authorize(); |
| 492 Authenticate(); | 515 Authenticate(); |
| 493 Approve(); | 516 Approve(); |
| 494 } | 517 } |
| 495 | 518 |
| 496 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled() { | 519 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled( |
| 520 content::WebContents* app_web_content) { | |
| 497 // browser_test.ensureRemoteConnectionEnabled is defined in | 521 // browser_test.ensureRemoteConnectionEnabled is defined in |
| 498 // browser_test.js, which must be loaded before calling this function. | 522 // browser_test.js, which must be loaded before calling this function. |
| 499 // TODO(kelvinp): This function currently only works on linux when the user is | 523 // TODO(kelvinp): This function currently only works on linux when the user is |
| 500 // already part of the chrome-remote-desktop group. Extend this functionality | 524 // already part of the chrome-remote-desktop group. Extend this functionality |
| 501 // to Mac (https://crbug.com/397576) and Windows (https://crbug.com/397575). | 525 // to Mac (https://crbug.com/397576) and Windows (https://crbug.com/397575). |
| 502 bool result; | 526 bool result; |
| 503 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 527 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 504 app_web_content(), | 528 app_web_content, |
| 505 "browserTest.ensureRemoteConnectionEnabled(" + me2me_pin() + ")", | 529 "browserTest.ensureRemoteConnectionEnabled(" + me2me_pin() + ")", |
| 506 &result)); | 530 &result)); |
| 507 EXPECT_TRUE(result) << "Cannot start the host with Pin:" << me2me_pin(); | 531 EXPECT_TRUE(result) << "Cannot start the host with Pin:" << me2me_pin(); |
| 508 } | 532 } |
| 509 | 533 |
| 510 void RemoteDesktopBrowserTest::ConnectToLocalHost(bool remember_pin) { | 534 void RemoteDesktopBrowserTest::ConnectToLocalHost(bool remember_pin) { |
| 511 // Wait for local-host to be ready. | 535 // Wait for local-host to be ready. |
| 512 ConditionalTimeoutWaiter waiter( | 536 ConditionalTimeoutWaiter waiter( |
| 513 base::TimeDelta::FromSeconds(5), | 537 base::TimeDelta::FromSeconds(5), |
| 514 base::TimeDelta::FromMilliseconds(500), | 538 base::TimeDelta::FromMilliseconds(500), |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 base::FilePath script_path = src_dir.Append(path); | 734 base::FilePath script_path = src_dir.Append(path); |
| 711 | 735 |
| 712 if (!base::ReadFileToString(script_path, &script)) { | 736 if (!base::ReadFileToString(script_path, &script)) { |
| 713 LOG(ERROR) << "Failed to load script " << script_path.value(); | 737 LOG(ERROR) << "Failed to load script " << script_path.value(); |
| 714 return false; | 738 return false; |
| 715 } | 739 } |
| 716 | 740 |
| 717 return content::ExecuteScript(web_contents, script); | 741 return content::ExecuteScript(web_contents, script); |
| 718 } | 742 } |
| 719 | 743 |
| 720 // static | |
| 721 void RemoteDesktopBrowserTest::RunJavaScriptTest( | 744 void RemoteDesktopBrowserTest::RunJavaScriptTest( |
| 722 content::WebContents* web_contents, | 745 content::WebContents* web_contents, |
| 723 const std::string& testName, | 746 const std::string& testName, |
| 724 const std::string& testData) { | 747 const std::string& testData) { |
| 725 std::string result; | 748 std::string result; |
| 726 std::string script = "browserTest.runTest(browserTest." + testName + ", " + | 749 std::string script = "browserTest.runTest(browserTest." + testName + ", " + |
| 727 testData + ");"; | 750 testData + ");"; |
| 728 | 751 |
| 729 DVLOG(1) << "Executing " << script; | 752 DVLOG(1) << "Executing " << script; |
| 730 | 753 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 // static | 918 // static |
| 896 bool RemoteDesktopBrowserTest::IsEnabled( | 919 bool RemoteDesktopBrowserTest::IsEnabled( |
| 897 content::WebContents* client_web_content, | 920 content::WebContents* client_web_content, |
| 898 const std::string& element_name) { | 921 const std::string& element_name) { |
| 899 return !ExecuteScriptAndExtractBool( | 922 return !ExecuteScriptAndExtractBool( |
| 900 client_web_content, | 923 client_web_content, |
| 901 "document.getElementById(\"" + element_name + "\").disabled"); | 924 "document.getElementById(\"" + element_name + "\").disabled"); |
| 902 } | 925 } |
| 903 | 926 |
| 904 } // namespace remoting | 927 } // namespace remoting |
| OLD | NEW |