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 opt_window_open_disposition) { | |
| 170 ASSERT_TRUE(extension_); | 172 ASSERT_TRUE(extension_); |
| 171 | 173 |
| 172 GURL chromoting_main = Chromoting_Main_URL(); | 174 GURL chromoting_main = Chromoting_Main_URL(); |
| 173 // We cannot simply wait for any page load because the first page | 175 // We cannot simply wait for any page load because the first page |
| 174 // loaded could be the generated background page. We need to wait | 176 // loaded could be the generated background page. We need to wait |
| 175 // till the chromoting main page is loaded. | 177 // till the chromoting main page is loaded. |
| 176 PageLoadNotificationObserver observer(chromoting_main); | 178 PageLoadNotificationObserver observer(chromoting_main); |
| 177 observer.set_ignore_url_parameters(true); | 179 observer.set_ignore_url_parameters(true); |
| 178 | 180 |
| 179 // If the app should be started in deferred mode, ensure that a "source" URL | 181 // 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 | 182 // 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). | 183 // the parameter is determined by the AppLaunchParams ("test", in this case). |
| 182 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( | 184 extensions::FeatureSwitch::ScopedOverride override_trace_app_source( |
| 183 extensions::FeatureSwitch::trace_app_source(), | 185 extensions::FeatureSwitch::trace_app_source(), |
| 184 defer_start); | 186 defer_start); |
| 185 | 187 |
| 186 OpenApplication(AppLaunchParams(browser()->profile(), extension_, | 188 OpenApplication(AppLaunchParams(browser()->profile(), extension_, |
| 187 is_platform_app() | 189 is_platform_app() |
| 188 ? extensions::LAUNCH_CONTAINER_NONE | 190 ? extensions::LAUNCH_CONTAINER_NONE |
| 189 : extensions::LAUNCH_CONTAINER_TAB, | 191 : extensions::LAUNCH_CONTAINER_TAB, |
| 190 is_platform_app() ? NEW_WINDOW : CURRENT_TAB, | 192 opt_window_open_disposition, |
| 191 extensions::SOURCE_TEST)); | 193 extensions::SOURCE_TEST)); |
| 192 | 194 |
| 193 observer.Wait(); | 195 observer.Wait(); |
| 194 | 196 |
| 195 | 197 |
| 196 // The active WebContents instance should be the source of the LOAD_STOP | 198 // The active WebContents instance should be the source of the LOAD_STOP |
| 197 // notification. | 199 // notification. |
| 198 content::NavigationController* controller = | 200 content::NavigationController* controller = |
| 199 content::Source<content::NavigationController>(observer.source()).ptr(); | 201 content::Source<content::NavigationController>(observer.source()).ptr(); |
| 200 | 202 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 211 // event. A half second wait is necessary for the subsequent javascript | 213 // event. A half second wait is necessary for the subsequent javascript |
| 212 // injection to work. | 214 // injection to work. |
| 213 // TODO(weitaosu): Find out whether there is a more appropriate notification | 215 // TODO(weitaosu): Find out whether there is a more appropriate notification |
| 214 // to wait for so we can get rid of this wait. | 216 // to wait for so we can get rid of this wait. |
| 215 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); | 217 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); |
| 216 } | 218 } |
| 217 | 219 |
| 218 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); | 220 EXPECT_EQ(Chromoting_Main_URL(), GetCurrentURL()); |
| 219 } | 221 } |
| 220 | 222 |
| 223 void RemoteDesktopBrowserTest::LaunchChromotingApp(bool defer_start) { | |
| 224 LaunchChromotingApp(defer_start, | |
| 225 is_platform_app() ? NEW_WINDOW : CURRENT_TAB); | |
| 226 } | |
| 227 | |
| 221 void RemoteDesktopBrowserTest::StartChromotingApp() { | 228 void RemoteDesktopBrowserTest::StartChromotingApp() { |
| 222 ClickOnControl("browser-test-continue-init"); | 229 ClickOnControl("browser-test-continue-init"); |
| 223 }; | 230 }; |
| 224 | 231 |
| 225 void RemoteDesktopBrowserTest::Authorize() { | 232 void RemoteDesktopBrowserTest::Authorize() { |
| 226 // The chromoting extension should be installed. | 233 // The chromoting extension should be installed. |
| 227 ASSERT_TRUE(extension_); | 234 ASSERT_TRUE(extension_); |
| 228 | 235 |
| 229 // The chromoting main page should be loaded in the current tab | 236 // The chromoting main page should be loaded in the current tab |
| 230 // and isAuthenticated() should be false (auth dialog visible). | 237 // and isAuthenticated() should be false (auth dialog visible). |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 base::FilePath script_path = src_dir.Append(path); | 717 base::FilePath script_path = src_dir.Append(path); |
| 711 | 718 |
| 712 if (!base::ReadFileToString(script_path, &script)) { | 719 if (!base::ReadFileToString(script_path, &script)) { |
| 713 LOG(ERROR) << "Failed to load script " << script_path.value(); | 720 LOG(ERROR) << "Failed to load script " << script_path.value(); |
| 714 return false; | 721 return false; |
| 715 } | 722 } |
| 716 | 723 |
| 717 return content::ExecuteScript(web_contents, script); | 724 return content::ExecuteScript(web_contents, script); |
| 718 } | 725 } |
| 719 | 726 |
| 720 // static | |
| 721 void RemoteDesktopBrowserTest::RunJavaScriptTest( | 727 void RemoteDesktopBrowserTest::RunJavaScriptTest( |
| 722 content::WebContents* web_contents, | 728 content::WebContents* web_contents, |
| 723 const std::string& testName, | 729 const std::string& testName, |
| 724 const std::string& testData) { | 730 const std::string& testData, |
| 731 base::Value** opt_return_value) { | |
| 725 std::string result; | 732 std::string result; |
| 726 std::string script = "browserTest.runTest(browserTest." + testName + ", " + | 733 std::string script = "browserTest.runTest(browserTest." + testName + ", " + |
| 727 testData + ");"; | 734 testData + ");"; |
| 728 | 735 |
| 729 DVLOG(1) << "Executing " << script; | 736 DVLOG(1) << "Executing " << script; |
| 730 | 737 |
| 731 ASSERT_TRUE( | 738 ASSERT_TRUE( |
| 732 content::ExecuteScriptAndExtractString(web_contents, script, &result)); | 739 content::ExecuteScriptAndExtractString(web_contents, script, &result)); |
| 733 | 740 |
| 734 // Read in the JSON | 741 // Read in the JSON |
| 735 base::JSONReader reader; | 742 base::JSONReader reader; |
| 736 scoped_ptr<base::Value> value; | 743 scoped_ptr<base::Value> value; |
| 737 value.reset(reader.Read(result, base::JSON_ALLOW_TRAILING_COMMAS)); | 744 value.reset(reader.Read(result, base::JSON_ALLOW_TRAILING_COMMAS)); |
| 738 | 745 |
| 739 // Convert to dictionary | 746 // Convert to dictionary |
| 740 base::DictionaryValue* dict_value = NULL; | 747 base::DictionaryValue* dict_value = nullptr; |
| 741 ASSERT_TRUE(value->GetAsDictionary(&dict_value)); | 748 ASSERT_TRUE(value->GetAsDictionary(&dict_value)); |
| 742 | 749 |
| 743 bool succeeded; | 750 bool succeeded; |
| 744 std::string error_message; | 751 std::string error_message; |
| 745 std::string stack_trace; | 752 std::string stack_trace; |
| 746 | 753 |
| 747 // Extract the fields | 754 // Extract the fields |
| 748 ASSERT_TRUE(dict_value->GetBoolean("succeeded", &succeeded)); | 755 ASSERT_TRUE(dict_value->GetBoolean("succeeded", &succeeded)); |
| 749 ASSERT_TRUE(dict_value->GetString("error_message", &error_message)); | 756 ASSERT_TRUE(dict_value->GetString("error_message", &error_message)); |
| 750 ASSERT_TRUE(dict_value->GetString("stack_trace", &stack_trace)); | 757 ASSERT_TRUE(dict_value->GetString("stack_trace", &stack_trace)); |
| 751 | 758 |
| 752 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; | 759 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; |
| 760 | |
| 761 base::Value* return_value = nullptr; | |
| 762 if (dict_value->Get("value", &return_value) && return_value != nullptr) { | |
| 763 ASSERT_EQ(*opt_return_value, nullptr); | |
| 764 *opt_return_value = return_value->DeepCopy(); | |
| 765 } | |
| 753 } | 766 } |
| 754 | 767 |
| 768 void RemoteDesktopBrowserTest::RunJavaScriptTest( | |
| 769 content::WebContents* web_contents, | |
| 770 const std::string& testName, | |
| 771 const std::string& testData) { | |
| 772 base::Value* return_value = nullptr; | |
| 773 RunJavaScriptTest(web_contents, testName, testData, &return_value); | |
| 774 if (return_value != nullptr) { | |
| 775 delete return_value; | |
|
Jamie
2015/01/06 22:18:51
No need to test for null before deleting. Better s
kelvinp
2015/01/09 22:21:30
Done.
| |
| 776 } | |
| 777 }; | |
| 778 | |
| 779 | |
| 755 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { | 780 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { |
| 756 ASSERT_TRUE(HtmlElementVisible(name)); | 781 ASSERT_TRUE(HtmlElementVisible(name)); |
| 757 | 782 |
| 758 std::string has_disabled_attribute = | 783 std::string has_disabled_attribute = |
| 759 "document.getElementById('" + name + "').hasAttribute('disabled')"; | 784 "document.getElementById('" + name + "').hasAttribute('disabled')"; |
| 760 | 785 |
| 761 if (ExecuteScriptAndExtractBool(active_web_contents(), | 786 if (ExecuteScriptAndExtractBool(active_web_contents(), |
| 762 has_disabled_attribute)) { | 787 has_disabled_attribute)) { |
| 763 // This element has a disabled attribute. Wait for it become enabled. | 788 // This element has a disabled attribute. Wait for it become enabled. |
| 764 ConditionalTimeoutWaiter waiter( | 789 ConditionalTimeoutWaiter waiter( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 // static | 920 // static |
| 896 bool RemoteDesktopBrowserTest::IsEnabled( | 921 bool RemoteDesktopBrowserTest::IsEnabled( |
| 897 content::WebContents* client_web_content, | 922 content::WebContents* client_web_content, |
| 898 const std::string& element_name) { | 923 const std::string& element_name) { |
| 899 return !ExecuteScriptAndExtractBool( | 924 return !ExecuteScriptAndExtractBool( |
| 900 client_web_content, | 925 client_web_content, |
| 901 "document.getElementById(\"" + element_name + "\").disabled"); | 926 "document.getElementById(\"" + element_name + "\").disabled"); |
| 902 } | 927 } |
| 903 | 928 |
| 904 } // namespace remoting | 929 } // namespace remoting |
| OLD | NEW |