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

Side by Side Diff: chrome/browser/extensions/web_view_browsertest.cc

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. Created 7 years, 11 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
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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.h"
7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 7 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
8 #include "chrome/browser/ui/browser_tabstrip.h" 8 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/test/base/ui_test_utils.h" 9 #include "chrome/test/base/ui_test_utils.h"
10 #include "chrome/test/base/test_launcher_utils.h" 10 #include "chrome/test/base/test_launcher_utils.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 192
193 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, 193 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
194 const char* script, 194 const char* script,
195 const char* title) { 195 const char* title) {
196 string16 expected_title(ASCIIToUTF16(title)); 196 string16 expected_title(ASCIIToUTF16(title));
197 string16 error_title(ASCIIToUTF16("error")); 197 string16 error_title(ASCIIToUTF16("error"));
198 198
199 content::TitleWatcher title_watcher(web_contents, expected_title); 199 content::TitleWatcher title_watcher(web_contents, expected_title);
200 title_watcher.AlsoWaitForTitle(error_title); 200 title_watcher.AlsoWaitForTitle(error_title);
201 EXPECT_TRUE(content::ExecuteJavaScript(web_contents->GetRenderViewHost(), 201 EXPECT_TRUE(content::ExecuteScript(web_contents, script));
202 "", script));
203 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 202 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
204 } 203 }
205 }; 204 };
206 205
207 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) { 206 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) {
208 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_; 207 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_;
209 } 208 }
210 209
211 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { 210 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
212 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute")) 211 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute"))
(...skipping 28 matching lines...) Expand all
241 // between partitions within the same app. 240 // between partitions within the same app.
242 content::WebContents* cookie_contents1; 241 content::WebContents* cookie_contents1;
243 content::WebContents* cookie_contents2; 242 content::WebContents* cookie_contents2;
244 content::WebContents* named_partition_contents1; 243 content::WebContents* named_partition_contents1;
245 content::WebContents* named_partition_contents2; 244 content::WebContents* named_partition_contents2;
246 245
247 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, 246 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
248 &cookie_contents2, &named_partition_contents1, 247 &cookie_contents2, &named_partition_contents1,
249 &named_partition_contents2, NULL, NULL, NULL); 248 &named_partition_contents2, NULL, NULL, NULL);
250 249
251 EXPECT_TRUE(content::ExecuteJavaScript( 250 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
252 cookie_contents1->GetRenderViewHost(), "", cookie_script1)); 251 EXPECT_TRUE(content::ExecuteScript(cookie_contents2, cookie_script2));
253 EXPECT_TRUE(content::ExecuteJavaScript(
254 cookie_contents2->GetRenderViewHost(), "", cookie_script2));
255 252
256 int cookie_size; 253 int cookie_size;
257 std::string cookie_value; 254 std::string cookie_value;
258 255
259 // Test the regular browser context to ensure we have only one cookie. 256 // Test the regular browser context to ensure we have only one cookie.
260 automation_util::GetCookies(GURL("http://localhost"), 257 automation_util::GetCookies(GURL("http://localhost"),
261 chrome::GetWebContentsAt(browser(), 0), 258 chrome::GetWebContentsAt(browser(), 0),
262 &cookie_size, &cookie_value); 259 &cookie_size, &cookie_value);
263 EXPECT_EQ("testCookie=1", cookie_value); 260 EXPECT_EQ("testCookie=1", cookie_value);
264 261
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 content::WebContents* persistent_partition_contents2; 310 content::WebContents* persistent_partition_contents2;
314 content::WebContents* persistent_partition_contents3; 311 content::WebContents* persistent_partition_contents3;
315 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1, 312 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
316 &cookie_contents2, &named_partition_contents1, 313 &cookie_contents2, &named_partition_contents1,
317 &named_partition_contents2, 314 &named_partition_contents2,
318 &persistent_partition_contents1, 315 &persistent_partition_contents1,
319 &persistent_partition_contents2, 316 &persistent_partition_contents2,
320 &persistent_partition_contents3); 317 &persistent_partition_contents3);
321 318
322 // Set the inmemory=true cookie for tags with inmemory partitions. 319 // Set the inmemory=true cookie for tags with inmemory partitions.
323 EXPECT_TRUE(content::ExecuteJavaScript( 320 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
324 cookie_contents1->GetRenderViewHost(), 321 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1,
325 "", 322 cookie_script1));
326 cookie_script1));
327 EXPECT_TRUE(content::ExecuteJavaScript(
328 named_partition_contents1->GetRenderViewHost(),
329 "",
330 cookie_script1));
331 323
332 // For the two different persistent storage partitions, set the 324 // For the two different persistent storage partitions, set the
333 // two different cookies so we can check that they aren't comingled below. 325 // two different cookies so we can check that they aren't comingled below.
334 EXPECT_TRUE(content::ExecuteJavaScript( 326 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1,
335 persistent_partition_contents1->GetRenderViewHost(), 327 cookie_script2));
336 "",
337 cookie_script2));
338 328
339 EXPECT_TRUE(content::ExecuteJavaScript( 329 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3,
340 persistent_partition_contents3->GetRenderViewHost(), 330 cookie_script3));
341 "",
342 cookie_script3));
343 331
344 int cookie_size; 332 int cookie_size;
345 std::string cookie_value; 333 std::string cookie_value;
346 334
347 // Check that all in-memory partitions have a cookie set. 335 // Check that all in-memory partitions have a cookie set.
348 automation_util::GetCookies(GURL("http://localhost"), 336 automation_util::GetCookies(GURL("http://localhost"),
349 cookie_contents1, 337 cookie_contents1,
350 &cookie_size, &cookie_value); 338 &cookie_size, &cookie_value);
351 EXPECT_EQ("inmemory=true", cookie_value); 339 EXPECT_EQ("inmemory=true", cookie_value);
352 automation_util::GetCookies(GURL("http://localhost"), 340 automation_util::GetCookies(GURL("http://localhost"),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 content::WebContents* default_tag_contents2; 444 content::WebContents* default_tag_contents2;
457 content::WebContents* storage_contents1; 445 content::WebContents* storage_contents1;
458 content::WebContents* storage_contents2; 446 content::WebContents* storage_contents2;
459 447
460 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, 448 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
461 &default_tag_contents2, &storage_contents1, 449 &default_tag_contents2, &storage_contents1,
462 &storage_contents2, NULL, NULL, NULL); 450 &storage_contents2, NULL, NULL, NULL);
463 451
464 // Initialize the storage for the first of the two tags that share a storage 452 // Initialize the storage for the first of the two tags that share a storage
465 // partition. 453 // partition.
466 EXPECT_TRUE(content::ExecuteJavaScript( 454 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
467 storage_contents1->GetRenderViewHost(), 455 "initDomStorage('page1')"));
468 "",
469 "initDomStorage('page1')"));
470 456
471 // Let's test that the expected values are present in the first tag, as they 457 // Let's test that the expected values are present in the first tag, as they
472 // will be overwritten once we call the initDomStorage on the second tag. 458 // will be overwritten once we call the initDomStorage on the second tag.
473 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 459 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
474 storage_contents1->GetRenderViewHost(), 460 get_local_storage.c_str(),
475 "", 461 &output));
476 get_local_storage.c_str(),
477 &output));
478 EXPECT_STREQ("local-page1", output.c_str()); 462 EXPECT_STREQ("local-page1", output.c_str());
479 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 463 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
480 storage_contents1->GetRenderViewHost(), 464 get_session_storage.c_str(),
481 "", 465 &output));
482 get_session_storage.c_str(),
483 &output));
484 EXPECT_STREQ("session-page1", output.c_str()); 466 EXPECT_STREQ("session-page1", output.c_str());
485 467
486 // Now, init the storage in the second tag in the same storage partition, 468 // Now, init the storage in the second tag in the same storage partition,
487 // which will overwrite the shared localStorage. 469 // which will overwrite the shared localStorage.
488 EXPECT_TRUE(content::ExecuteJavaScript( 470 EXPECT_TRUE(content::ExecuteScript(storage_contents2,
489 storage_contents2->GetRenderViewHost(), 471 "initDomStorage('page2')"));
490 "",
491 "initDomStorage('page2')"));
492 472
493 // The localStorage value now should reflect the one written through the 473 // The localStorage value now should reflect the one written through the
494 // second tag. 474 // second tag.
495 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 475 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
496 storage_contents1->GetRenderViewHost(), 476 get_local_storage.c_str(),
497 "", 477 &output));
498 get_local_storage.c_str(),
499 &output));
500 EXPECT_STREQ("local-page2", output.c_str()); 478 EXPECT_STREQ("local-page2", output.c_str());
501 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 479 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
502 storage_contents2->GetRenderViewHost(), 480 get_local_storage.c_str(),
503 "", 481 &output));
504 get_local_storage.c_str(),
505 &output));
506 EXPECT_STREQ("local-page2", output.c_str()); 482 EXPECT_STREQ("local-page2", output.c_str());
507 483
508 // Session storage is not shared though, as each webview tag has separate 484 // Session storage is not shared though, as each webview tag has separate
509 // instance, even if they are in the same storage partition. 485 // instance, even if they are in the same storage partition.
510 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 486 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
511 storage_contents1->GetRenderViewHost(), 487 get_session_storage.c_str(),
512 "", 488 &output));
513 get_session_storage.c_str(),
514 &output));
515 EXPECT_STREQ("session-page1", output.c_str()); 489 EXPECT_STREQ("session-page1", output.c_str());
516 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 490 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
517 storage_contents2->GetRenderViewHost(), 491 get_session_storage.c_str(),
518 "", 492 &output));
519 get_session_storage.c_str(),
520 &output));
521 EXPECT_STREQ("session-page2", output.c_str()); 493 EXPECT_STREQ("session-page2", output.c_str());
522 494
523 // Also, let's check that the main browser and another tag that doesn't share 495 // Also, let's check that the main browser and another tag that doesn't share
524 // the same partition don't have those values stored. 496 // the same partition don't have those values stored.
525 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 497 EXPECT_TRUE(ExecuteScriptAndExtractString(
526 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), 498 chrome::GetWebContentsAt(browser(), 0),
527 "",
528 get_local_storage.c_str(), 499 get_local_storage.c_str(),
529 &output)); 500 &output));
530 EXPECT_STREQ("badval", output.c_str()); 501 EXPECT_STREQ("badval", output.c_str());
531 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 502 EXPECT_TRUE(ExecuteScriptAndExtractString(
532 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), 503 chrome::GetWebContentsAt(browser(), 0),
533 "",
534 get_session_storage.c_str(), 504 get_session_storage.c_str(),
535 &output)); 505 &output));
536 EXPECT_STREQ("badval", output.c_str()); 506 EXPECT_STREQ("badval", output.c_str());
537 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 507 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
538 default_tag_contents1->GetRenderViewHost(), 508 get_local_storage.c_str(),
539 "", 509 &output));
540 get_local_storage.c_str(),
541 &output));
542 EXPECT_STREQ("badval", output.c_str()); 510 EXPECT_STREQ("badval", output.c_str());
543 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 511 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
544 default_tag_contents1->GetRenderViewHost(), 512 get_session_storage.c_str(),
545 "", 513 &output));
546 get_session_storage.c_str(),
547 &output));
548 EXPECT_STREQ("badval", output.c_str()); 514 EXPECT_STREQ("badval", output.c_str());
549 } 515 }
550 516
551 // This tests IndexedDB isolation for packaged apps with webview tags. It loads 517 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
552 // an app with multiple webview tags and each tag creates an IndexedDB record, 518 // an app with multiple webview tags and each tag creates an IndexedDB record,
553 // which the test checks to ensure proper storage isolation is enforced. 519 // which the test checks to ensure proper storage isolation is enforced.
554 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) { 520 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) {
555 ASSERT_TRUE(StartTestServer()); 521 ASSERT_TRUE(StartTestServer());
556 GURL regular_url = test_server()->GetURL("files/title1.html"); 522 GURL regular_url = test_server()->GetURL("files/title1.html");
557 523
(...skipping 11 matching lines...) Expand all
569 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); 535 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
570 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", 536 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
571 "addItemIDB complete"); 537 "addItemIDB complete");
572 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", 538 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
573 "readItemIDB complete"); 539 "readItemIDB complete");
574 540
575 std::string output; 541 std::string output;
576 std::string get_value( 542 std::string get_value(
577 "window.domAutomationController.send(getValueIDB() || 'badval')"); 543 "window.domAutomationController.send(getValueIDB() || 'badval')");
578 544
579 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 545 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
580 storage_contents1->GetRenderViewHost(), 546 get_value.c_str(), &output));
581 "",
582 get_value.c_str(), &output));
583 EXPECT_STREQ("page1", output.c_str()); 547 EXPECT_STREQ("page1", output.c_str());
584 548
585 // Initialize the db in the second tag. 549 // Initialize the db in the second tag.
586 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open"); 550 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open");
587 551
588 // Since we share a partition, reading the value should return the existing 552 // Since we share a partition, reading the value should return the existing
589 // one. 553 // one.
590 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", 554 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
591 "readItemIDB complete"); 555 "readItemIDB complete");
592 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 556 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
593 storage_contents2->GetRenderViewHost(), 557 get_value.c_str(), &output));
594 "",
595 get_value.c_str(), &output));
596 EXPECT_STREQ("page1", output.c_str()); 558 EXPECT_STREQ("page1", output.c_str());
597 559
598 // Now write through the second tag and read it back. 560 // Now write through the second tag and read it back.
599 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')", 561 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')",
600 "addItemIDB complete"); 562 "addItemIDB complete");
601 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", 563 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
602 "readItemIDB complete"); 564 "readItemIDB complete");
603 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 565 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
604 storage_contents2->GetRenderViewHost(), 566 get_value.c_str(), &output));
605 "",
606 get_value.c_str(), &output));
607 EXPECT_STREQ("page2", output.c_str()); 567 EXPECT_STREQ("page2", output.c_str());
608 568
609 // Reset the document title, otherwise the next call will not see a change and 569 // Reset the document title, otherwise the next call will not see a change and
610 // will hang waiting for it. 570 // will hang waiting for it.
611 EXPECT_TRUE(content::ExecuteJavaScript( 571 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
612 storage_contents1->GetRenderViewHost(), 572 "document.title = 'foo'"));
613 "",
614 "document.title = 'foo'"));
615 573
616 // Read through the first tag to ensure we have the second value. 574 // Read through the first tag to ensure we have the second value.
617 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", 575 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
618 "readItemIDB complete"); 576 "readItemIDB complete");
619 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 577 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
620 storage_contents1->GetRenderViewHost(), 578 get_value.c_str(), &output));
621 "",
622 get_value.c_str(),
623 &output));
624 EXPECT_STREQ("page2", output.c_str()); 579 EXPECT_STREQ("page2", output.c_str());
625 580
626 // Now, let's confirm there is no database in the main browser and another 581 // Now, let's confirm there is no database in the main browser and another
627 // tag that doesn't share the same partition. Due to the IndexedDB API design, 582 // tag that doesn't share the same partition. Due to the IndexedDB API design,
628 // open will succeed, but the version will be 1, since it creates the database 583 // open will succeed, but the version will be 1, since it creates the database
629 // if it is not found. The two tags use database version 3, so we avoid 584 // if it is not found. The two tags use database version 3, so we avoid
630 // ambiguity. 585 // ambiguity.
631 const char* script = 586 const char* script =
632 "indexedDB.open('isolation').onsuccess = function(e) {" 587 "indexedDB.open('isolation').onsuccess = function(e) {"
633 " if (e.target.result.version == 1)" 588 " if (e.target.result.version == 1)"
634 " document.title = 'db not found';" 589 " document.title = 'db not found';"
635 " else " 590 " else "
636 " document.title = 'error';" 591 " document.title = 'error';"
637 "}"; 592 "}";
638 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), 593 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0),
639 script, "db not found"); 594 script, "db not found");
640 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); 595 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
641 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698