| 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 "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/mock_host_resolver.h" | 13 #include "net/base/mock_host_resolver.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class ClipboardApiTest : public ExtensionApiTest { | 17 class ClipboardApiTest : public ExtensionApiTest { |
| 17 public: | 18 public: |
| 18 bool LoadHostedApp(const std::string& app_name, | 19 bool LoadHostedApp(const std::string& app_name, |
| 19 const std::string& launch_page); | 20 const std::string& launch_page); |
| 20 bool ExecuteCopyInSelectedTab(bool* result); | 21 bool ExecuteCopyInSelectedTab(bool* result); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool ClipboardApiTest::ExecutePasteInSelectedTab(bool* result) { | 62 bool ClipboardApiTest::ExecutePasteInSelectedTab(bool* result) { |
| 62 const wchar_t kScript[] = | 63 const wchar_t kScript[] = |
| 63 L"window.domAutomationController.send(document.execCommand('paste'))"; | 64 L"window.domAutomationController.send(document.execCommand('paste'))"; |
| 64 return ExecuteScriptInSelectedTab(kScript, result); | 65 return ExecuteScriptInSelectedTab(kScript, result); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::wstring& script, | 68 bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::wstring& script, |
| 68 bool* result) { | 69 bool* result) { |
| 69 if (!ui_test_utils::ExecuteJavaScriptAndExtractBool( | 70 if (!content::ExecuteJavaScriptAndExtractBool( |
| 70 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), | 71 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 71 L"", | 72 L"", |
| 72 script, | 73 script, |
| 73 result)) { | 74 result)) { |
| 74 message_ = "Failed to execute script in selected tab."; | 75 message_ = "Failed to execute script in selected tab."; |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 return true; | 78 return true; |
| 78 } | 79 } |
| 79 | 80 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) | 105 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) |
| 105 << message_; | 106 << message_; |
| 106 | 107 |
| 107 bool result = false; | 108 bool result = false; |
| 108 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; | 109 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; |
| 109 EXPECT_FALSE(result); | 110 EXPECT_FALSE(result); |
| 110 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; | 111 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; |
| 111 EXPECT_FALSE(result); | 112 EXPECT_FALSE(result); |
| 112 } | 113 } |
| 113 | 114 |
| OLD | NEW |