Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2227)

Unified Diff: chrome/browser/pdf/pdf_extension_test.cc

Issue 1316803003: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d6718e79b2ec3f81f4daf928376d5ca16ab31b7c..aec07548da8a1c5b72369b3ebc8e10a48386dbe1 100644
--- a/chrome/browser/pdf/pdf_extension_test.cc
+++ b/chrome/browser/pdf/pdf_extension_test.cc
@@ -26,6 +26,15 @@
const int kNumberLoadTestParts = 10;
+bool GetGuestCallback(content::WebContents** guest_out,
+ content::WebContents* guest) {
+ EXPECT_FALSE(*guest_out);
+ *guest_out = guest;
+ // Return false so that we iterate through all the guests and verify there is
+ // only one.
+ return false;
+}
+
class PDFExtensionTest : public ExtensionApiTest,
public testing::WithParamInterface<int> {
public:
@@ -156,6 +165,48 @@ 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;
+ ASSERT_NO_FATAL_FAILURE(guest_manager->ForEachGuest(
+ web_contents, base::Bind(&GetGuestCallback, &guest_contents)));
+ ASSERT_TRUE(guest_contents);
+ ASSERT_TRUE(content::ExecuteScript(
+ guest_contents,
+ "var oldSendScriptingMessage = "
+ " PDFViewer.prototype.sendScriptingMessage_;"
+ "PDFViewer.prototype.sendScriptingMessage_ = function(message) {"
+ " oldSendScriptingMessage.bind(this)(message);"
+ " if (message.type == 'getSelectedTextReply')"
+ " this.parentWindow_.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) {
@@ -200,6 +251,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);
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698