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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 10960003: Browser Plugin: Implement Back, Forward, and Go. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a test 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
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/memory/singleton.h" 5 #include "base/memory/singleton.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/test/test_timeouts.h" 7 #include "base/test/test_timeouts.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "content/browser/browser_plugin/browser_plugin_guest.h" 9 #include "content/browser/browser_plugin/browser_plugin_guest.h"
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
(...skipping 12 matching lines...) Expand all
23 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
24 #include "net/test/test_server.h" 24 #include "net/test/test_server.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
26 26
27 using WebKit::WebInputEvent; 27 using WebKit::WebInputEvent;
28 using WebKit::WebMouseEvent; 28 using WebKit::WebMouseEvent;
29 using content::BrowserPluginEmbedder; 29 using content::BrowserPluginEmbedder;
30 using content::BrowserPluginGuest; 30 using content::BrowserPluginGuest;
31 using content::BrowserPluginHostFactory; 31 using content::BrowserPluginHostFactory;
32 32
33 namespace content { 33 namespace {
34 34
35 const char* kHTMLForGuest = 35 const char* kHTMLForGuest =
36 "data:text/html,<html><body>hello world</body></html>"; 36 "data:text/html,<html><body>hello world</body></html>";
37 const char* kHTMLForGuestInfiniteLoop = 37 const char* kHTMLForGuestInfiniteLoop =
38 "data:text/html,<html><head><script type=\"text/javascript\">" 38 "data:text/html,<html><head><script type=\"text/javascript\">"
39 "function StartInfiniteLoop() {" 39 "function StartInfiniteLoop() {"
40 " setTimeout(function () {while (true) {} }, 0);" 40 " setTimeout(function () {while (true) {} }, 0);"
41 "}" 41 "}"
42 "</script></head><body></body></html>"; 42 "</script></head><body></body></html>";
43 const char* kHTMLForGuestWithTitle =
44 "data:text/html,"
45 "<html><head><title>%s</title></head>"
46 "<body>hello world</body>";
47 "</html>";
48
49 std::string GetHTMLForGuestWithTitle(const std::string& title) {
50 return StringPrintf(kHTMLForGuestWithTitle, title.c_str());
51 }
52
53 } // namespace
54
55 namespace content {
56
43 57
44 // Test factory for creating test instances of BrowserPluginEmbedder and 58 // Test factory for creating test instances of BrowserPluginEmbedder and
45 // BrowserPluginGuest. 59 // BrowserPluginGuest.
46 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { 60 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory {
47 public: 61 public:
48 virtual BrowserPluginGuest* CreateBrowserPluginGuest( 62 virtual BrowserPluginGuest* CreateBrowserPluginGuest(
49 int instance_id, 63 int instance_id,
50 WebContentsImpl* web_contents, 64 WebContentsImpl* web_contents,
51 RenderViewHost* render_view_host) OVERRIDE { 65 RenderViewHost* render_view_host) OVERRIDE {
52 return new TestBrowserPluginGuest(instance_id, 66 return new TestBrowserPluginGuest(instance_id,
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. 487 // Wait for the guest to send an UpdateRectMsg, meaning it is ready.
474 test_guest->WaitForUpdateRectMsg(); 488 test_guest->WaitForUpdateRectMsg();
475 489
476 // Hide the embedder. 490 // Hide the embedder.
477 embedder_web_contents->WasHidden(); 491 embedder_web_contents->WasHidden();
478 492
479 // Make sure that hiding the embedder also hides the guest. 493 // Make sure that hiding the embedder also hides the guest.
480 test_guest->WaitUntilHidden(); 494 test_guest->WaitUntilHidden();
481 } 495 }
482 496
497 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) {
498 ASSERT_TRUE(test_server()->Start());
499 GURL test_url(test_server()->GetURL(
500 "files/browser_plugin_embedder.html"));
501 NavigateToURL(shell(), test_url);
502
503 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>(
504 shell()->web_contents());
505 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
506 embedder_web_contents->GetRenderViewHost());
507
508 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
509 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P1").c_str())));
510
511 // Wait to make sure embedder is created/attached to WebContents.
512 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation();
513
514 TestBrowserPluginEmbedder* test_embedder =
515 static_cast<TestBrowserPluginEmbedder*>(
516 embedder_web_contents->GetBrowserPluginEmbedder());
517 ASSERT_TRUE(test_embedder);
518 test_embedder->WaitForGuestAdded();
519
520 // Verify that we have exactly one guest.
521 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map =
522 test_embedder->guest_web_contents_for_testing();
523 EXPECT_EQ(1u, instance_map.size());
524
525 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
526 instance_map.begin()->second);
527 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>(
528 test_guest_web_contents->GetBrowserPluginGuest());
529
530 // Wait for the guest to send an UpdateRectMsg, meaning it is ready.
531 test_guest->WaitForUpdateRectMsg();
lazyboy 2012/09/20 20:05:42 See below: navigate back and forward here too, and
Fady Samuel 2012/09/21 15:21:56 While I'm not against more test coverage, I feel t
532
533 // Navigate to P2 and verify that the navigation occurred.
534 {
535 const string16 expected_title = ASCIIToUTF16("P2");
536 content::TitleWatcher title_watcher(test_guest_web_contents,
537 expected_title);
538
539 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
540 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())));
541
542 string16 actual_title = title_watcher.WaitAndGetTitle();
543 EXPECT_EQ(expected_title, actual_title);
544 }
545
546 // Navigate to P3 and verify that the navigation occurred.
547 {
548 const string16 expected_title = ASCIIToUTF16("P3");
549 content::TitleWatcher title_watcher(test_guest_web_contents,
550 expected_title);
551
552 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
553 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str())));
554
555 string16 actual_title = title_watcher.WaitAndGetTitle();
556 EXPECT_EQ(expected_title, actual_title);
557 }
558
559 // Go back and verify that we're back at P2.
560 {
561 const string16 expected_title = ASCIIToUTF16("P2");
562 content::TitleWatcher title_watcher(test_guest_web_contents,
563 expected_title);
564
565 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Back();"));
566
567 string16 actual_title = title_watcher.WaitAndGetTitle();
568 EXPECT_EQ(expected_title, actual_title);
569 }
570
571 // Go forward and verify that we're back at P3.
572 {
573 const string16 expected_title = ASCIIToUTF16("P3");
574 content::TitleWatcher title_watcher(test_guest_web_contents,
575 expected_title);
576
577 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Forward();"));
578
579 string16 actual_title = title_watcher.WaitAndGetTitle();
lazyboy 2012/09/20 20:05:42 same as below, try to go one step further forward.
Fady Samuel 2012/09/21 15:21:56 ditto, I'm not convinced this actually improves te
580 EXPECT_EQ(expected_title, actual_title);
581 }
582
583 // Go back two entries and verify that we're back at P1.
584 {
585 const string16 expected_title = ASCIIToUTF16("P1");
586 content::TitleWatcher title_watcher(test_guest_web_contents,
587 expected_title);
588
589 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);"));
lazyboy 2012/09/20 20:05:42 A test to see if we try to go back further and sta
Fady Samuel 2012/09/21 15:21:56 ditto.
590
591 string16 actual_title = title_watcher.WaitAndGetTitle();
592 EXPECT_EQ(expected_title, actual_title);
593 }
594 }
595
483 } // namespace content 596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698