Index: chrome/browser/pdf/pdf_extension_test.cc |
diff --git a/chrome/browser/pdf/pdf_extension_test.cc b/chrome/browser/pdf/pdf_extension_test.cc |
index c0548d28a8bf8e294324938f5604a88bfedd4721..dd69fd5bbd5b46d9f29ca459fede9c735ac0bc41 100644 |
--- a/chrome/browser/pdf/pdf_extension_test.cc |
+++ b/chrome/browser/pdf/pdf_extension_test.cc |
@@ -43,6 +43,13 @@ |
const int kNumberLoadTestParts = 10; |
+bool GetFirstGuestCallback(content::WebContents** guest_out, |
+ content::WebContents* guest) { |
+ CHECK(!*guest_out); |
Sam McNally
2015/08/25 03:11:20
Why a CHECK?
raymes
2015/08/25 04:02:23
Done.
|
+ *guest_out = guest; |
+ return true; |
+} |
+ |
class PDFExtensionTest : public ExtensionApiTest, |
public testing::WithParamInterface<int> { |
public: |
@@ -158,6 +165,45 @@ class PDFExtensionTest : public ExtensionApiTest, |
// someone deleting the directory and silently making the test pass. |
ASSERT_GE(count, 1u); |
} |
+ |
+ void TestGetSelectedTextReply(GURL url, bool expect_success) { |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ content::WebContents* web_contents = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents)); |
+ |
+ // Reach into the guest and hook into it such that it posts back a 'flush' |
+ // message after every getSelectedTextReply message sent. |
+ content::BrowserPluginGuestManager* guest_manager = |
+ web_contents->GetBrowserContext()->GetGuestManager(); |
+ content::WebContents* guest_contents = nullptr; |
+ guest_manager->ForEachGuest( |
+ web_contents, base::Bind(&GetFirstGuestCallback, &guest_contents)); |
+ ASSERT_TRUE(guest_contents); |
+ ASSERT_TRUE(content::ExecuteScript( |
+ guest_contents, |
+ "window.addEventListener('scripting-message-sent', function(event) {" |
+ " if (event.detail.message.type == 'getSelectedTextReply')" |
+ " event.detail.target.postMessage('flush', '*');" |
+ "});")); |
+ |
+ // Add an event listener for flush messages and request the selected text. |
+ // If we get a flush message without receiving getSelectedText we know that |
+ // the message didn't come through. |
+ bool success = false; |
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
+ web_contents, |
+ "window.addEventListener('message', function(event) {" |
+ " if (event.data == 'flush')" |
+ " window.domAutomationController.send(false);" |
+ " if (event.data.type == 'getSelectedTextReply')" |
+ " window.domAutomationController.send(true);" |
+ "});" |
+ "document.getElementsByTagName('embed')[0].postMessage(" |
+ " {type: 'getSelectedText'});", |
+ &success)); |
+ ASSERT_EQ(expect_success, success); |
+ } |
}; |
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { |
@@ -275,6 +321,49 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ZoomManager) { |
RunTestsInFile("zoom_manager_test.js", "test.pdf"); |
} |
+// Ensure that the internal PDF plugin application/x-google-chrome-pdf won't be |
+// loaded if it's not loaded in the chrome extension page. |
+IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureInternalPluginDisabled) { |
+ std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec(); |
+ std::string data_url = |
+ "data:text/html," |
+ "<html><body>" |
+ "<embed type=\"application/x-google-chrome-pdf\" src=\"" + |
+ url + |
+ "\">" |
+ "</body></html>"; |
+ ui_test_utils::NavigateToURL(browser(), GURL(data_url)); |
+ content::WebContents* web_contents = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ bool plugin_loaded = false; |
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
+ web_contents, |
+ "var plugin_loaded = " |
+ " document.getElementsByTagName('embed')[0].postMessage !== undefined;" |
+ "window.domAutomationController.send(plugin_loaded);", |
+ &plugin_loaded)); |
+ ASSERT_FALSE(plugin_loaded); |
+} |
+ |
+// Ensure cross-origin replies won't work for getSelectedText. |
+IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureCrossOriginRepliesBlocked) { |
+ std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec(); |
+ std::string data_url = |
+ "data:text/html," |
+ "<html><body>" |
+ "<embed type=\"application/pdf\" src=\"" + |
+ url + |
+ "\">" |
+ "</body></html>"; |
+ TestGetSelectedTextReply(GURL(data_url), false); |
+} |
+ |
+// Ensure same-origin replies do work for getSelectedText. |
+IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) { |
+ TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"), |
+ true); |
+} |
+ |
class MaterialPDFExtensionTest : public PDFExtensionTest { |
void SetUpCommandLine(base::CommandLine* command_line) override { |
command_line->AppendSwitch(switches::kEnablePdfMaterialUI); |