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

Side by Side Diff: chrome/browser/pdf/pdf_extension_test.cc

Issue 1311973002: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <vector> 5 #include <vector>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/hash.h" 10 #include "base/hash.h"
(...skipping 25 matching lines...) Expand all
36 #include "content/public/test/browser_test_utils.h" 36 #include "content/public/test/browser_test_utils.h"
37 #include "extensions/browser/extension_registry.h" 37 #include "extensions/browser/extension_registry.h"
38 #include "extensions/common/manifest_handlers/mime_types_handler.h" 38 #include "extensions/common/manifest_handlers/mime_types_handler.h"
39 #include "extensions/test/result_catcher.h" 39 #include "extensions/test/result_catcher.h"
40 #include "net/test/embedded_test_server/embedded_test_server.h" 40 #include "net/test/embedded_test_server/embedded_test_server.h"
41 #include "ui/base/resource/resource_bundle.h" 41 #include "ui/base/resource/resource_bundle.h"
42 #include "url/gurl.h" 42 #include "url/gurl.h"
43 43
44 const int kNumberLoadTestParts = 10; 44 const int kNumberLoadTestParts = 10;
45 45
46 bool GetFirstGuestCallback(content::WebContents** guest_out,
47 content::WebContents* guest) {
48 CHECK(!*guest_out);
Sam McNally 2015/08/25 03:11:20 Why a CHECK?
raymes 2015/08/25 04:02:23 Done.
49 *guest_out = guest;
50 return true;
51 }
52
46 class PDFExtensionTest : public ExtensionApiTest, 53 class PDFExtensionTest : public ExtensionApiTest,
47 public testing::WithParamInterface<int> { 54 public testing::WithParamInterface<int> {
48 public: 55 public:
49 ~PDFExtensionTest() override {} 56 ~PDFExtensionTest() override {}
50 57
51 void SetUpCommandLine(base::CommandLine* command_line) override { 58 void SetUpCommandLine(base::CommandLine* command_line) override {
52 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); 59 command_line->AppendSwitch(switches::kDisablePdfMaterialUI);
53 } 60 }
54 61
55 void SetUpOnMainThread() override { 62 void SetUpOnMainThread() override {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 LOG(INFO) << "Loading: " << pdf_file; 158 LOG(INFO) << "Loading: " << pdf_file;
152 bool success = LoadPdf(embedded_test_server()->GetURL("/" + pdf_file)); 159 bool success = LoadPdf(embedded_test_server()->GetURL("/" + pdf_file));
153 EXPECT_EQ(!PdfIsExpectedToFailLoad(pdf_file), success); 160 EXPECT_EQ(!PdfIsExpectedToFailLoad(pdf_file), success);
154 } 161 }
155 ++count; 162 ++count;
156 } 163 }
157 // Assume that there is at least 1 pdf in the directory to guard against 164 // Assume that there is at least 1 pdf in the directory to guard against
158 // someone deleting the directory and silently making the test pass. 165 // someone deleting the directory and silently making the test pass.
159 ASSERT_GE(count, 1u); 166 ASSERT_GE(count, 1u);
160 } 167 }
168
169 void TestGetSelectedTextReply(GURL url, bool expect_success) {
170 ui_test_utils::NavigateToURL(browser(), url);
171 content::WebContents* web_contents =
172 browser()->tab_strip_model()->GetActiveWebContents();
173 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
174
175 // Reach into the guest and hook into it such that it posts back a 'flush'
176 // message after every getSelectedTextReply message sent.
177 content::BrowserPluginGuestManager* guest_manager =
178 web_contents->GetBrowserContext()->GetGuestManager();
179 content::WebContents* guest_contents = nullptr;
180 guest_manager->ForEachGuest(
181 web_contents, base::Bind(&GetFirstGuestCallback, &guest_contents));
182 ASSERT_TRUE(guest_contents);
183 ASSERT_TRUE(content::ExecuteScript(
184 guest_contents,
185 "window.addEventListener('scripting-message-sent', function(event) {"
186 " if (event.detail.message.type == 'getSelectedTextReply')"
187 " event.detail.target.postMessage('flush', '*');"
188 "});"));
189
190 // Add an event listener for flush messages and request the selected text.
191 // If we get a flush message without receiving getSelectedText we know that
192 // the message didn't come through.
193 bool success = false;
194 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
195 web_contents,
196 "window.addEventListener('message', function(event) {"
197 " if (event.data == 'flush')"
198 " window.domAutomationController.send(false);"
199 " if (event.data.type == 'getSelectedTextReply')"
200 " window.domAutomationController.send(true);"
201 "});"
202 "document.getElementsByTagName('embed')[0].postMessage("
203 " {type: 'getSelectedText'});",
204 &success));
205 ASSERT_EQ(expect_success, success);
206 }
161 }; 207 };
162 208
163 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 209 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
164 #if defined(GOOGLE_CHROME_BUILD) 210 #if defined(GOOGLE_CHROME_BUILD)
165 // Load private PDFs. 211 // Load private PDFs.
166 LoadAllPdfsTest("pdf_private", GetParam()); 212 LoadAllPdfsTest("pdf_private", GetParam());
167 #endif 213 #endif
168 // Load public PDFs. 214 // Load public PDFs.
169 LoadAllPdfsTest("pdf", GetParam()); 215 LoadAllPdfsTest("pdf", GetParam());
170 } 216 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 314 }
269 315
270 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ParamsParser) { 316 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ParamsParser) {
271 RunTestsInFile("params_parser_test.js", "test.pdf"); 317 RunTestsInFile("params_parser_test.js", "test.pdf");
272 } 318 }
273 319
274 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ZoomManager) { 320 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ZoomManager) {
275 RunTestsInFile("zoom_manager_test.js", "test.pdf"); 321 RunTestsInFile("zoom_manager_test.js", "test.pdf");
276 } 322 }
277 323
324 // Ensure that the internal PDF plugin application/x-google-chrome-pdf won't be
325 // loaded if it's not loaded in the chrome extension page.
326 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureInternalPluginDisabled) {
327 std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec();
328 std::string data_url =
329 "data:text/html,"
330 "<html><body>"
331 "<embed type=\"application/x-google-chrome-pdf\" src=\"" +
332 url +
333 "\">"
334 "</body></html>";
335 ui_test_utils::NavigateToURL(browser(), GURL(data_url));
336 content::WebContents* web_contents =
337 browser()->tab_strip_model()->GetActiveWebContents();
338 bool plugin_loaded = false;
339 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
340 web_contents,
341 "var plugin_loaded = "
342 " document.getElementsByTagName('embed')[0].postMessage !== undefined;"
343 "window.domAutomationController.send(plugin_loaded);",
344 &plugin_loaded));
345 ASSERT_FALSE(plugin_loaded);
346 }
347
348 // Ensure cross-origin replies won't work for getSelectedText.
349 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureCrossOriginRepliesBlocked) {
350 std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec();
351 std::string data_url =
352 "data:text/html,"
353 "<html><body>"
354 "<embed type=\"application/pdf\" src=\"" +
355 url +
356 "\">"
357 "</body></html>";
358 TestGetSelectedTextReply(GURL(data_url), false);
359 }
360
361 // Ensure same-origin replies do work for getSelectedText.
362 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) {
363 TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"),
364 true);
365 }
366
278 class MaterialPDFExtensionTest : public PDFExtensionTest { 367 class MaterialPDFExtensionTest : public PDFExtensionTest {
279 void SetUpCommandLine(base::CommandLine* command_line) override { 368 void SetUpCommandLine(base::CommandLine* command_line) override {
280 command_line->AppendSwitch(switches::kEnablePdfMaterialUI); 369 command_line->AppendSwitch(switches::kEnablePdfMaterialUI);
281 } 370 }
282 }; 371 };
283 372
284 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) { 373 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) {
285 RunTestsInFile("basic_test_material.js", "test.pdf"); 374 RunTestsInFile("basic_test_material.js", "test.pdf");
286 } 375 }
287 376
(...skipping 23 matching lines...) Expand all
311 400
312 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Elements) { 401 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Elements) {
313 // Although this test file does not require a PDF to be loaded, loading the 402 // Although this test file does not require a PDF to be loaded, loading the
314 // elements without loading a PDF is difficult. 403 // elements without loading a PDF is difficult.
315 RunTestsInFile("material_elements_test.js", "test.pdf"); 404 RunTestsInFile("material_elements_test.js", "test.pdf");
316 } 405 }
317 406
318 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ToolbarManager) { 407 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ToolbarManager) {
319 RunTestsInFile("toolbar_manager_test.js", "test.pdf"); 408 RunTestsInFile("toolbar_manager_test.js", "test.pdf");
320 } 409 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698