Commit cdc6ee91 authored by mek@chromium.org's avatar mek@chromium.org

Add tests to make sure copy/paste in an about:blank iframe in a hosted app or extension works.

BUG=395376

Review URL: https://codereview.chromium.org/495213002

Cr-Commit-Position: refs/heads/master@{#291268}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291268 0039d316-1c4b-4281-b951-d872f2087c98
parent b1a4853a
......@@ -19,11 +19,13 @@ class ClipboardApiTest : public ExtensionApiTest {
public:
bool LoadHostedApp(const std::string& app_name,
const std::string& launch_page);
bool ExecuteCopyInSelectedTab(bool* result);
bool ExecutePasteInSelectedTab(bool* result);
bool ExecuteCopyInSelectedTab();
bool ExecutePasteInSelectedTab();
bool ExecuteCopyInIframeInSelectedTab();
bool ExecutePasteInIframeInSelectedTab();
private:
bool ExecuteScriptInSelectedTab(const std::string& script, bool* result);
bool ExecuteScriptInSelectedTab(const std::string& script);
};
bool ClipboardApiTest::LoadHostedApp(const std::string& app_name,
......@@ -55,28 +57,43 @@ bool ClipboardApiTest::LoadHostedApp(const std::string& app_name,
return true;
}
bool ClipboardApiTest::ExecuteCopyInSelectedTab(bool* result) {
bool ClipboardApiTest::ExecuteCopyInSelectedTab() {
const char kScript[] =
"window.domAutomationController.send(document.execCommand('copy'))";
return ExecuteScriptInSelectedTab(kScript, result);
return ExecuteScriptInSelectedTab(kScript);
}
bool ClipboardApiTest::ExecutePasteInSelectedTab(bool* result) {
bool ClipboardApiTest::ExecutePasteInSelectedTab() {
const char kScript[] =
"window.domAutomationController.send(document.execCommand('paste'))";
return ExecuteScriptInSelectedTab(kScript, result);
return ExecuteScriptInSelectedTab(kScript);
}
bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::string& script,
bool* result) {
if (!content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetActiveWebContents(),
script,
result)) {
message_ = "Failed to execute script in selected tab.";
return false;
}
return true;
bool ClipboardApiTest::ExecuteCopyInIframeInSelectedTab() {
const char kScript[] =
"var ifr = document.createElement('iframe');\n"
"document.body.appendChild(ifr);\n"
"window.domAutomationController.send("
"ifr.contentDocument.execCommand('copy'));";
return ExecuteScriptInSelectedTab(kScript);
}
bool ClipboardApiTest::ExecutePasteInIframeInSelectedTab() {
const char kScript[] =
"var ifr = document.createElement('iframe');\n"
"document.body.appendChild(ifr);\n"
"window.domAutomationController.send("
"ifr.contentDocument.execCommand('paste'));";
return ExecuteScriptInSelectedTab(kScript);
}
bool ClipboardApiTest::ExecuteScriptInSelectedTab(const std::string& script) {
bool result;
CHECK(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetActiveWebContents(),
script,
&result));
return result;
}
} // namespace
......@@ -95,21 +112,19 @@ IN_PROC_BROWSER_TEST_F(ClipboardApiTest, ExtensionNoPermission) {
IN_PROC_BROWSER_TEST_F(ClipboardApiTest, HostedApp) {
ASSERT_TRUE(LoadHostedApp("hosted_app", "main.html")) << message_;
bool result = false;
ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_;
EXPECT_TRUE(result);
ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_;
EXPECT_TRUE(result);
EXPECT_TRUE(ExecuteCopyInSelectedTab()) << message_;
EXPECT_TRUE(ExecutePasteInSelectedTab()) << message_;
EXPECT_TRUE(ExecuteCopyInIframeInSelectedTab()) << message_;
EXPECT_TRUE(ExecutePasteInIframeInSelectedTab()) << message_;
}
IN_PROC_BROWSER_TEST_F(ClipboardApiTest, HostedAppNoPermission) {
ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html"))
<< message_;
bool result = false;
ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_;
EXPECT_FALSE(result);
ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_;
EXPECT_FALSE(result);
EXPECT_FALSE(ExecuteCopyInSelectedTab()) << message_;
EXPECT_FALSE(ExecutePasteInSelectedTab()) << message_;
EXPECT_FALSE(ExecuteCopyInIframeInSelectedTab()) << message_;
EXPECT_FALSE(ExecutePasteInIframeInSelectedTab()) << message_;
}
......@@ -17,6 +17,22 @@ chrome.test.runTests([
chrome.test.succeed();
else
chrome.test.fail('execCommand("paste") failed');
},
function copyInIframe() {
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
if (ifr.contentDocument.execCommand('copy'))
chrome.test.succeed();
else
chrome.test.fail('execCommand("copy") failed in iframe');
},
function pasteInIframe() {
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
if (ifr.contentDocument.execCommand('paste'))
chrome.test.succeed();
else
chrome.test.fail('execCommand("paste") failed in iframe');
}
]);
......@@ -17,5 +17,21 @@ chrome.test.runTests([
chrome.test.succeed();
else
chrome.test.fail('execCommand("paste") succeeded');
},
function copyInIframe() {
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
if (ifr.contentDocument.execCommand('copy'))
chrome.test.succeed();
else
chrome.test.fail('execCommand("copy") failed in iframe');
},
function pasteInIframe() {
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
if (ifr.contentDocument.execCommand('paste'))
chrome.test.fail('execCommand("paste") succeeded in iframe');
else
chrome.test.succeed();
}
]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment