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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_browsertest.cc

Issue 10928237: Add support for parsing a 'partition' attribute on the <browser> tag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Testing Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_bindings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/browser_plugin/browser_plugin_browsertest.h" 5 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "content/common/browser_plugin_messages.h" 10 #include "content/common/browser_plugin_messages.h"
11 #include "content/public/common/content_constants.h" 11 #include "content/public/common/content_constants.h"
12 #include "content/renderer/browser_plugin/browser_plugin.h" 12 #include "content/renderer/browser_plugin/browser_plugin.h"
13 #include "content/renderer/browser_plugin/mock_browser_plugin.h" 13 #include "content/renderer/browser_plugin/mock_browser_plugin.h"
14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" 14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h"
15 #include "content/renderer/render_thread_impl.h" 15 #include "content/renderer/render_thread_impl.h"
16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" 16 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
17 #include "content/shell/shell_main_delegate.h" 17 #include "content/shell/shell_main_delegate.h"
18 #include "skia/ext/platform_canvas.h" 18 #include "skia/ext/platform_canvas.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
22 22
23 namespace { 23 namespace {
24 const char kHTMLForBrowserPluginObject[] = 24 const char kHTMLForBrowserPluginObject[] =
25 "<object id='browserplugin' width='640px' height='480px'" 25 "<object id='browserplugin' width='640px' height='480px'"
26 " src='foo' type='%s'>"; 26 " src='foo' type='%s'>";
27 27
28 const char kHTMLForSourcelessPluginObject[] =
29 "<object id='browserplugin' width='640px' height='480px' type='%s'>";
30
31 const char kHTMLForPartitionedPluginObject[] =
32 "<object id='browserplugin' width='640px' height='480px'"
33 " src='foo' type='%s' partition='someid'>";
34
35 const char kHTMLForPartitionedPersistedPluginObject[] =
36 "<object id='browserplugin' width='640px' height='480px'"
37 " src='foo' type='%s' partition='persist:someid'>";
38
28 std::string GetHTMLForBrowserPluginObject() { 39 std::string GetHTMLForBrowserPluginObject() {
29 return StringPrintf(kHTMLForBrowserPluginObject, 40 return StringPrintf(kHTMLForBrowserPluginObject,
30 content::kBrowserPluginNewMimeType); 41 content::kBrowserPluginNewMimeType);
31 } 42 }
32 43
33 } // namespace 44 } // namespace
34 45
35 namespace content { 46 namespace content {
36 47
37 BrowserPluginTest::BrowserPluginTest() {} 48 BrowserPluginTest::BrowserPluginTest() {}
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 359
349 TEST_F(BrowserPluginTest, ReloadMethod) { 360 TEST_F(BrowserPluginTest, ReloadMethod) {
350 const char* kCallReload = 361 const char* kCallReload =
351 "document.getElementById('browserplugin').reload();"; 362 "document.getElementById('browserplugin').reload();";
352 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 363 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
353 ExecuteJavaScript(kCallReload); 364 ExecuteJavaScript(kCallReload);
354 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 365 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
355 BrowserPluginHostMsg_Reload::ID)); 366 BrowserPluginHostMsg_Reload::ID));
356 } 367 }
357 368
369
370 // Verify that the 'partition' attribute on the browser plugin is parsed
371 // correctly.
372 TEST_F(BrowserPluginTest, PartitionAttribute) {
373 std::string html = StringPrintf(kHTMLForPartitionedPluginObject,
374 content::kBrowserPluginNewMimeType);
375 LoadHTML(html.c_str());
376 std::string partition_value = ExecuteScriptAndReturnString(
377 "document.getElementById('browserplugin').partition");
378 EXPECT_STREQ("someid", partition_value.c_str());
379
380 html = StringPrintf(kHTMLForPartitionedPersistedPluginObject,
381 content::kBrowserPluginNewMimeType);
382 LoadHTML(html.c_str());
383 partition_value = ExecuteScriptAndReturnString(
384 "document.getElementById('browserplugin').partition");
385 EXPECT_STREQ("persist:someid", partition_value.c_str());
386
387 // Verify that once HTML has defined a source and partition, we cannot change
388 // the partition anymore.
389 ExecuteJavaScript(
390 "try {"
391 " document.getElementById('browserplugin').partition = 'foo';"
392 " document.title = 'success';"
393 "} catch (e) { document.title = e.message; }");
394 std::string title = ExecuteScriptAndReturnString("document.title");
395 EXPECT_STREQ(
396 "The object has already navigated, so its partition cannot be changed.",
397 title.c_str());
398
399 // Load a browser tag without 'src' defined.
400 html = StringPrintf(kHTMLForSourcelessPluginObject,
401 content::kBrowserPluginNewMimeType);
402 LoadHTML(html.c_str());
403
404 // Ensure we don't parse just "persist:" string and return exception.
405 ExecuteJavaScript(
406 "try {"
407 " document.getElementById('browserplugin').partition = 'persist:';"
408 " document.title = 'success';"
409 "} catch (e) { document.title = e.message; }");
410 title = ExecuteScriptAndReturnString("document.title");
411 EXPECT_STREQ("Invalid empty partition attribute.", title.c_str());
412 }
413
414 // Test to verify that after the first navigation, the partition attribute
415 // cannot be modified.
416 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
417 std::string html = StringPrintf(kHTMLForSourcelessPluginObject,
418 content::kBrowserPluginNewMimeType);
419 LoadHTML(html.c_str());
420
421 ExecuteJavaScript(
422 "document.getElementById('browserplugin').partition = 'storage'");
423 std::string partition_value = ExecuteScriptAndReturnString(
424 "document.getElementById('browserplugin').partition");
425 EXPECT_STREQ("storage", partition_value.c_str());
426
427 std::string src_value = ExecuteScriptAndReturnString(
428 "document.getElementById('browserplugin').src");
429 EXPECT_STREQ("", src_value.c_str());
430
431 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
432 {
433 const IPC::Message* msg =
434 browser_plugin_manager()->sink().GetUniqueMessageMatching(
435 BrowserPluginHostMsg_NavigateGuest::ID);
436 ASSERT_TRUE(msg);
437
438 int instance_id;
439 long long frame_id;
440 std::string src;
441 gfx::Size size;
442 BrowserPluginHostMsg_NavigateGuest::Read(
443 msg,
444 &instance_id,
445 &frame_id,
446 &src,
447 &size);
448 EXPECT_STREQ("bar", src.c_str());
449 }
450
451 // Setting the partition should throw an exception and the value should not
452 // change.
453 ExecuteJavaScript(
454 "try {"
455 " document.getElementById('browserplugin').partition = 'someid';"
456 " document.title = 'success';"
457 "} catch (e) { document.title = e.message; }");
458
459 std::string title = ExecuteScriptAndReturnString("document.title");
460 EXPECT_STREQ(
461 "The object has already navigated, so its partition cannot be changed.",
462 title.c_str());
463
464 partition_value = ExecuteScriptAndReturnString(
465 "document.getElementById('browserplugin').partition");
466 EXPECT_STREQ("storage", partition_value.c_str());
467 }
468
358 } // namespace content 469 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698