#include "content/browser/browser_plugin/test_browser_plugin_guest.h"
#include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h"
#include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h"
+#include "content/browser/browser_plugin/test_guest_manager_delegate.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/frame_host/render_widget_host_view_guest.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
+#include "content/shell/browser/shell_browser_context.h"
#include "net/base/net_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
class TestBrowserPluginHostFactory : public BrowserPluginHostFactory {
public:
virtual BrowserPluginGuestManager*
- CreateBrowserPluginGuestManager() OVERRIDE {
+ CreateBrowserPluginGuestManager(BrowserContext* context) OVERRIDE {
guest_manager_instance_count_++;
- if (message_loop_runner_.get())
+ if (message_loop_runner_)
message_loop_runner_->Quit();
- return new TestBrowserPluginGuestManager();
+ return new TestBrowserPluginGuestManager(context);
}
virtual BrowserPluginGuest* CreateBrowserPluginGuest(
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
if (message.type() == message_id_) {
message_received_ = true;
- if (message_loop_runner_.get())
+ if (message_loop_runner_)
message_loop_runner_->Quit();
}
return false;
virtual void SetUp() OVERRIDE {
// Override factory to create tests instances of BrowserPlugin*.
- content::BrowserPluginEmbedder::set_factory_for_testing(
+ BrowserPluginEmbedder::set_factory_for_testing(
TestBrowserPluginHostFactory::GetInstance());
- content::BrowserPluginGuest::set_factory_for_testing(
+ BrowserPluginGuest::set_factory_for_testing(
TestBrowserPluginHostFactory::GetInstance());
- content::BrowserPluginGuestManager::set_factory_for_testing(
+ BrowserPluginGuestManager::set_factory_for_testing(
TestBrowserPluginHostFactory::GetInstance());
ContentBrowserTest::SetUp();
}
virtual void TearDown() OVERRIDE {
- content::BrowserPluginEmbedder::set_factory_for_testing(NULL);
- content::BrowserPluginGuest::set_factory_for_testing(NULL);
+ BrowserPluginEmbedder::set_factory_for_testing(NULL);
+ BrowserPluginGuest::set_factory_for_testing(NULL);
ContentBrowserTest::TearDown();
}
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
- // Enable browser plugin in content_shell for running test.
- command_line->AppendSwitch(switches::kEnableBrowserPluginForAllViewTypes);
- }
-
static void SimulateSpaceKeyPress(WebContents* web_contents) {
SimulateKeyPress(web_contents,
ui::VKEY_SPACE,
WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>(
shell()->web_contents());
+ static_cast<ShellBrowserContext*>(
+ embedder_web_contents->GetBrowserContext())->
+ set_guest_manager_delegate_for_testing(
+ TestGuestManagerDelegate::GetInstance());
RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
embedder_web_contents->GetRenderViewHost());
RenderFrameHost* rfh = embedder_web_contents->GetMainFrame();
ASSERT_TRUE(test_embedder_);
test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>(
- embedder_web_contents->GetBrowserPluginGuestManager());
+ BrowserPluginGuestManager::FromBrowserContext(
+ test_embedder_->GetWebContents()->GetBrowserContext()));
ASSERT_TRUE(test_guest_manager_);
- test_guest_manager_->WaitForGuestAdded();
-
- // Verify that we have exactly one guest.
- const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map =
- test_guest_manager_->guest_web_contents_for_testing();
- EXPECT_EQ(1u, instance_map.size());
-
WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
- instance_map.begin()->second);
+ test_guest_manager_->WaitForGuestAdded());
+
test_guest_ = static_cast<TestBrowserPluginGuest*>(
test_guest_web_contents->GetBrowserPluginGuest());
test_guest_->WaitForLoadStop();
const char kEmbedderURL[] = "/browser_plugin_embedder.html";
StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code);
- // Wait for the guest to receive a damage buffer of size 100x200.
- // This means the guest will be painted properly at that size.
- test_guest()->WaitForDamageBufferWithSize(nxt_size);
+ // Wait for the guest to be resized to 100x200.
+ test_guest()->WaitForResizeGuest(nxt_size);
}
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) {
ASSERT_EQ(test_embedder_after_nav, test_embedder());
}
-// This test verifies that hiding the embedder also hides the guest.
-IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) {
- const char kEmbedderURL[] = "/browser_plugin_embedder.html";
- StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string());
-
- // Hide the Browser Plugin.
- RenderFrameHost* rfh = test_embedder()->web_contents()->GetMainFrame();
- ExecuteSyncJSFunction(
- rfh, "document.getElementById('plugin').style.visibility = 'hidden'");
-
- // Make sure that the guest is hidden.
- test_guest()->WaitUntilHidden();
-}
-
-IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) {
- const char kEmbedderURL[] = "/browser_plugin_embedder.html";
- StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string());
-
- // Hide the embedder.
- test_embedder()->web_contents()->WasHidden();
-
- // Make sure that hiding the embedder also hides the guest.
- test_guest()->WaitUntilHidden();
-}
-
// Verifies that installing/uninstalling touch-event handlers in the guest
// plugin correctly updates the touch-event handling state in the embedder.
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) {
ExecuteSyncJSFunction(
test_embedder()->web_contents()->GetMainFrame(),
base::StringPrintf("SetSrc('%s');", kHTMLForGuest));
- test_guest_manager()->WaitForGuestAdded();
- const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map =
- test_guest_manager()->guest_web_contents_for_testing();
WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
- instance_map.begin()->second);
+ test_guest_manager()->WaitForGuestAdded());
TestBrowserPluginGuest* new_test_guest =
static_cast<TestBrowserPluginGuest*>(
test_guest_web_contents->GetBrowserPluginGuest());