| 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/stringprintf.h" | 5 #include "base/stringprintf.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_tabstrip.h" | 8 #include "chrome/browser/ui/browser_tabstrip.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/mock_host_resolver.h" | 13 #include "net/base/mock_host_resolver.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class ClipboardApiTest : public ExtensionApiTest { | 17 class ClipboardApiTest : public ExtensionApiTest { |
| 18 public: | 18 public: |
| 19 bool LoadHostedApp(const std::string& app_name, | 19 bool LoadHostedApp(const std::string& app_name, |
| 20 const std::string& launch_page); | 20 const std::string& launch_page); |
| 21 bool ExecuteCopyInSelectedTab(bool* result); | 21 bool ExecuteCopyInSelectedTab(bool* result); |
| 22 bool ExecutePasteInSelectedTab(bool* result); | 22 bool ExecutePasteInSelectedTab(bool* result); |
| 23 | 23 |
| 24 private: | 24 private: |
| 25 bool ExecuteScriptInSelectedTab(const std::string& script, bool* result); | 25 bool ExecuteScriptInSelectedTab(const std::wstring& script, bool* result); |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, | 28 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, |
| 29 const std::string& launch_page) { | 29 const std::string& launch_page) { |
| 30 host_resolver()->AddRule("*", "127.0.0.1"); | 30 host_resolver()->AddRule("*", "127.0.0.1"); |
| 31 | 31 |
| 32 if (!StartTestServer()) { | 32 if (!StartTestServer()) { |
| 33 message_ = "Failed to start test server."; | 33 message_ = "Failed to start test server."; |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 base_url = base_url.ReplaceComponents(replace_host); | 47 base_url = base_url.ReplaceComponents(replace_host); |
| 48 | 48 |
| 49 std::string launch_page_path = | 49 std::string launch_page_path = |
| 50 base::StringPrintf("%s/%s", app_name.c_str(), launch_page.c_str()); | 50 base::StringPrintf("%s/%s", app_name.c_str(), launch_page.c_str()); |
| 51 ui_test_utils::NavigateToURL(browser(), base_url.Resolve(launch_page_path)); | 51 ui_test_utils::NavigateToURL(browser(), base_url.Resolve(launch_page_path)); |
| 52 | 52 |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool ClipboardApiTest::ExecuteCopyInSelectedTab(bool* result) { | 56 bool ClipboardApiTest::ExecuteCopyInSelectedTab(bool* result) { |
| 57 const char kScript[] = | 57 const wchar_t kScript[] = |
| 58 "window.domAutomationController.send(document.execCommand('copy'))"; | 58 L"window.domAutomationController.send(document.execCommand('copy'))"; |
| 59 return ExecuteScriptInSelectedTab(kScript, result); | 59 return ExecuteScriptInSelectedTab(kScript, result); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool ClipboardApiTest::ExecutePasteInSelectedTab(bool* result) { | 62 bool ClipboardApiTest::ExecutePasteInSelectedTab(bool* result) { |
| 63 const char kScript[] = | 63 const wchar_t kScript[] = |
| 64 "window.domAutomationController.send(document.execCommand('paste'))"; | 64 L"window.domAutomationController.send(document.execCommand('paste'))"; |
| 65 return ExecuteScriptInSelectedTab(kScript, result); | 65 return ExecuteScriptInSelectedTab(kScript, result); |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::string& script, | 68 bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::wstring& script, |
| 69 bool* result) { | 69 bool* result) { |
| 70 if (!content::ExecuteJavaScriptAndExtractBool( | 70 if (!content::ExecuteJavaScriptAndExtractBool( |
| 71 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), | 71 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 72 "", | 72 L"", |
| 73 script, | 73 script, |
| 74 result)) { | 74 result)) { |
| 75 message_ = "Failed to execute script in selected tab."; | 75 message_ = "Failed to execute script in selected tab."; |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 105 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) | 105 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) |
| 106 << message_; | 106 << message_; |
| 107 | 107 |
| 108 bool result = false; | 108 bool result = false; |
| 109 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; | 109 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; |
| 110 EXPECT_FALSE(result); | 110 EXPECT_FALSE(result); |
| 111 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; | 111 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; |
| 112 EXPECT_FALSE(result); | 112 EXPECT_FALSE(result); |
| 113 } | 113 } |
| 114 | 114 |
| OLD | NEW |