diff options
author | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 11:09:42 +0000 |
---|---|---|
committer | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 11:09:42 +0000 |
commit | e1c913c665472a11722a2e657c54dc3830d85378 (patch) | |
tree | 61eeaa2ab2ee87a56a67706a6cfd26183639c309 | |
parent | de7dac9fe6c237c84d75e7a3d67f0d899a9c7b1a (diff) | |
download | chromium_src-e1c913c665472a11722a2e657c54dc3830d85378.zip chromium_src-e1c913c665472a11722a2e657c54dc3830d85378.tar.gz chromium_src-e1c913c665472a11722a2e657c54dc3830d85378.tar.bz2 |
<webview> Rewrite IME related tests from content_browsertests to WebViewTest.
This is part of onging effort to nuke BrowserPluginHostTest to browser_tests.
This CL also moves ReloadEmbedder test to browser_tests.
This CL also deletes two tests which cannot be written outside of content/.
These tests are:
BrowserPluginHostTest.EmbedderChangedAfterSwap
BrowserPluginHostTest.EmbedderSameAfterNav
The remaining test BrowserPluginHostTest.AcceptDragEvents is also removed b/c:
1. it cannot be directly translated in chrome/ layer
2. we have a bit of coverage for drag and drop for chromeos in WebViewInteractiveTest.
Therefore this CL entirely removes BrowserPluginHostTest class.
BUG=368077,308405,339904,379001
Test=No visible change, internal integration test related changes.
Review URL: https://codereview.chromium.org/309503004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275065 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 735 insertions, 1346 deletions
diff --git a/chrome/browser/apps/web_view_browsertest.cc b/chrome/browser/apps/web_view_browsertest.cc index cb0b05b..20baf7f 100644 --- a/chrome/browser/apps/web_view_browsertest.cc +++ b/chrome/browser/apps/web_view_browsertest.cc @@ -764,6 +764,19 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, EmbedderVisibilityChanged) { loop_runner->Run(); } +// This test verifies that reloading the embedder reloads the guest (and doest +// not crash). +IN_PROC_BROWSER_TEST_F(WebViewTest, ReloadEmbedder) { + // Just load a guest from other test, we do not want to add a separate + // platform_app for this test. + LoadAppWithGuest("web_view/visibility_changed"); + + ExtensionTestMessageListener launched_again_listener("WebViewTest.LAUNCHED", + false); + GetEmbedderWebContents()->GetController().Reload(false); + ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied()); +} + IN_PROC_BROWSER_TEST_F(WebViewTest, AcceptTouchEvents) { LoadAppWithGuest("web_view/accept_touch_events"); diff --git a/chrome/browser/apps/web_view_interactive_browsertest.cc b/chrome/browser/apps/web_view_interactive_browsertest.cc index 11dc70d..1708893 100644 --- a/chrome/browser/apps/web_view_interactive_browsertest.cc +++ b/chrome/browser/apps/web_view_interactive_browsertest.cc @@ -8,6 +8,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/apps/app_browsertest_util.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/guest_view/guest_view_base.h" #include "chrome/browser/profiles/profile.h" @@ -24,6 +25,8 @@ #include "content/public/common/content_switches.h" #include "content/public/test/browser_test_utils.h" #include "net/test/embedded_test_server/embedded_test_server.h" +#include "ui/base/ime/composition_text.h" +#include "ui/base/ime/text_input_client.h" #include "ui/base/test/ui_controls.h" #include "ui/events/keycodes/keyboard_codes.h" @@ -419,6 +422,38 @@ class WebViewInteractiveTest std::string last_drop_data_; }; +// Used to get notified when a guest is created. +class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient { + public: + GuestContentBrowserClient() : web_contents_(NULL) {} + + content::WebContents* WaitForGuestCreated() { + if (web_contents_) + return web_contents_; + + message_loop_runner_ = new content::MessageLoopRunner; + message_loop_runner_->Run(); + return web_contents_; + } + + private: + // ChromeContentBrowserClient implementation: + virtual void GuestWebContentsAttached( + content::WebContents* guest_web_contents, + content::WebContents* embedder_web_contents, + const base::DictionaryValue& extra_params) OVERRIDE { + ChromeContentBrowserClient::GuestWebContentsAttached( + guest_web_contents, embedder_web_contents, extra_params); + web_contents_ = guest_web_contents; + + if (message_loop_runner_) + message_loop_runner_->Quit(); + } + + content::WebContents* web_contents_; + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; +}; + // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and // likely won't work on many other platforms as well, so for now this test // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled @@ -522,16 +557,16 @@ IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusTracksEmbedder) { &embedder_web_contents)); done_listener->WaitUntilSatisfied(); - ExtensionTestMessageListener post_test_listener("POST_TEST_PASSED", false); - post_test_listener.set_failure_message("POST_TEST_FAILED"); + ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false); + next_step_listener.set_failure_message("TEST_STEP_FAILED"); EXPECT_TRUE(content::ExecuteScript( embedder_web_contents, - "window.runCommand('POST_testFocusTracksEmbedder');")); + "window.runCommand('testFocusTracksEmbedderRunNextStep');")); // Blur the embedder. embedder_web_contents->GetRenderViewHost()->Blur(); // Ensure that the guest is also blurred. - ASSERT_TRUE(post_test_listener.WaitUntilSatisfied()); + ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); } IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_AdvanceFocus) { @@ -837,6 +872,166 @@ IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NO_TEST_SERVER); } +// This test exercies the following scenario: +// 1. An <input> in guest has focus. +// 2. User takes focus to embedder by clicking e.g. an <input> in embedder. +// 3. User brings back the focus directly to the <input> in #1. +// +// Now we need to make sure TextInputTypeChanged fires properly for the guest's +// view upon step #3. We simply read the input type's state after #3 to +// make sure it's not TEXT_INPUT_TYPE_NONE. +IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusRestored) { + GuestContentBrowserClient new_client; + content::ContentBrowserClient* old_client = + SetBrowserClientForTesting(&new_client); + + content::WebContents* embedder_web_contents = NULL; + scoped_ptr<ExtensionTestMessageListener> done_listener( + RunAppHelper("testFocusRestored", "web_view/focus", NO_TEST_SERVER, + &embedder_web_contents)); + ASSERT_TRUE(done_listener->WaitUntilSatisfied()); + content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); + // Reset the browser client so that we do not notice any unexpected behavior. + SetBrowserClientForTesting(old_client); + ASSERT_TRUE(guest_web_contents); + + // 1) We click on the guest so that we get a focus event. + ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false); + next_step_listener.set_failure_message("TEST_STEP_FAILED"); + { + content::SimulateMouseClickAt(guest_web_contents, + 0, + blink::WebMouseEvent::ButtonLeft, + gfx::Point(10, 10)); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testFocusRestoredRunNextStep', 1);")); + } + // Wait for the next step to complete. + ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); + + // 2) We click on the embedder so the guest's focus goes away and it observes + // a blur event. + next_step_listener.Reset(); + { + content::SimulateMouseClickAt(embedder_web_contents, + 0, + blink::WebMouseEvent::ButtonLeft, + gfx::Point(200, 20)); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testFocusRestoredRunNextStep', 2);")); + } + // Wait for the next step to complete. + ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); + + // 3) We click on the guest again to bring back focus directly to the previous + // input element, then we ensure text_input_type is properly set. + next_step_listener.Reset(); + { + content::SimulateMouseClickAt(guest_web_contents, + 0, + blink::WebMouseEvent::ButtonLeft, + gfx::Point(10, 10)); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testFocusRestoredRunNextStep', 3)")); + } + // Wait for the next step to complete. + ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); + + // |text_input_client| is not available for mac and android. +#if !defined(OS_MACOSX) && !defined(OS_ANDROID) + ui::TextInputClient* text_input_client = + embedder_web_contents->GetRenderViewHost()->GetView() + ->GetTextInputClient(); + ASSERT_TRUE(text_input_client); + ASSERT_TRUE(text_input_client->GetTextInputType() != + ui::TEXT_INPUT_TYPE_NONE); +#endif +} + +// ui::TextInputClient is NULL for mac and android. +#if !defined(OS_MACOSX) && !defined(OS_ANDROID) +IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_InputMethod) { + content::WebContents* embedder_web_contents = NULL; + scoped_ptr<ExtensionTestMessageListener> done_listener( + RunAppHelper("testInputMethod", "web_view/focus", NO_TEST_SERVER, + &embedder_web_contents)); + ASSERT_TRUE(done_listener->WaitUntilSatisfied()); + + ui::TextInputClient* text_input_client = + embedder_web_contents->GetRenderViewHost()->GetView() + ->GetTextInputClient(); + ASSERT_TRUE(text_input_client); + + ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false); + next_step_listener.set_failure_message("TEST_STEP_FAILED"); + + // An input element inside the <webview> gets focus and is given some + // user input via IME. + { + ui::CompositionText composition; + composition.text = base::UTF8ToUTF16("InputTest123"); + text_input_client->SetCompositionText(composition); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testInputMethodRunNextStep', 1);")); + + // Wait for the next step to complete. + ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); + } + + // A composition is committed via IME. + { + next_step_listener.Reset(); + + ui::CompositionText composition; + composition.text = base::UTF8ToUTF16("InputTest456"); + text_input_client->SetCompositionText(composition); + text_input_client->ConfirmCompositionText(); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testInputMethodRunNextStep', 2);")); + + // Wait for the next step to complete. + EXPECT_TRUE(next_step_listener.WaitUntilSatisfied()); + } + + // Moving focus causes IME cancel, and the composition will be committed + // in first <input> in the <webview>, not in the second <input>. + { + next_step_listener.Reset(); + ui::CompositionText composition; + composition.text = base::UTF8ToUTF16("InputTest789"); + text_input_client->SetCompositionText(composition); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testInputMethodRunNextStep', 3);")); + + // Wait for the next step to complete. + EXPECT_TRUE(next_step_listener.WaitUntilSatisfied()); + } + + // Tests ExtendSelectionAndDelete message works in <webview>. + { + next_step_listener.Reset(); + + // At this point we have set focus on first <input> in the <webview>, + // and the value it contains is 'InputTestABC' with caret set after 'T'. + // Now we delete 'Test' in 'InputTestABC', as the caret is after 'T': + // delete before 1 character ('T') and after 3 characters ('est'). + text_input_client->ExtendSelectionAndDelete(1, 3); + EXPECT_TRUE(content::ExecuteScript( + embedder_web_contents, + "window.runCommand('testInputMethodRunNextStep', 4);")); + + // Wait for the next step to complete. + EXPECT_TRUE(next_step_listener.WaitUntilSatisfied()); + } +} +#endif + #if defined(OS_MACOSX) IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, TextSelection) { SetupTest("web_view/text_selection", diff --git a/chrome/test/data/extensions/platform_apps/web_view/focus/embedder.js b/chrome/test/data/extensions/platform_apps/web_view/focus/embedder.js index 0d71b5b..625e5e2 100644 --- a/chrome/test/data/extensions/platform_apps/web_view/focus/embedder.js +++ b/chrome/test/data/extensions/platform_apps/web_view/focus/embedder.js @@ -8,6 +8,8 @@ var seenFocusCount = 0; embedder.tests = {}; embedder.guestURL = 'data:text/html,<html><body>Guest<body></html>'; +var g_inputMethodTestHelper = null; +var g_focusRestoredTestHelper = null; window.runTest = function(testName) { if (!embedder.test.testList[testName]) { @@ -20,12 +22,17 @@ window.runTest = function(testName) { embedder.test.testList[testName](); }; -window.runCommand = function(command) { +window.runCommand = function(command, opt_step) { window.console.log('window.runCommand: ' + command); switch (command) { - case 'POST_testFocusTracksEmbedder': - POST_testFocusTracksEmbedder(); + case 'testFocusTracksEmbedderRunNextStep': + testFocusTracksEmbedderRunNextStep(); break; + case 'testInputMethodRunNextStep': + testInputMethodRunNextStep(opt_step); + break; + case 'testFocusRestoredRunNextStep': + testFocusRestoredRunNextStep(opt_step); default: embedder.test.fail(); } @@ -77,9 +84,25 @@ embedder.setUpGuest_ = function() { return webview; }; -/** @private */ +/** + * @private + * + * A test helper for focus related tests. + * It does the following steps: + * 1. It navigates |webview|. + * 2. On 'loadstop', it injects the script |inject_js_guest_url|. + * 3. When the injection has completed, it sends a ['connect'] message to the + * guest to initiate a two-way communication channel. + * 4. When the two way channel has been established |channelCreationCallback| is + * called. + * 5. It ignores all messages from the guest until it gets an + * |expectedResponse|. + * If there is no |expectedResponse|, the method is done. + * 6. Once the expected result is received, call |responseCallback|. + */ embedder.waitForResponseFromGuest_ = function(webview, + inject_js_guest_url, channelCreationCallback, expectedResponse, responseCallback) { @@ -88,6 +111,11 @@ embedder.waitForResponseFromGuest_ = var response = data[0]; if (response == 'connected') { channelCreationCallback(webview); + + if (!expectedResponse) { + // We are done. + window.removeEventListener('message', onPostMessageReceived); + } return; } if (response != expectedResponse) { @@ -105,7 +133,7 @@ embedder.waitForResponseFromGuest_ = var onWebViewLoadStop = function(e) { console.log('loadstop'); webview.executeScript( - {file: 'inject_focus.js'}, + {file: inject_js_guest_url}, function(results) { console.log('Injected script into webview.'); // Establish a communication channel with the webview1's guest. @@ -118,6 +146,170 @@ embedder.waitForResponseFromGuest_ = webview.src = embedder.guestURL; }; +// Helper class for testFocusRestored. +// +// This test has multiple steps, WebViewTest instructs this test to advance to +// each step and then performs some action and verification and runs the next +// step. +// See WebViewInteractiveTest.Focus_FocusRestored for details. +function FocusRestoredTestHelper() { + // Total number of steps for this test that we run thru + // testFocusRestoredRunNextStep. + this.TOTAL_STEPS = 3; + // Currently running step index. + this.step_ = 0; + this.messageHandlerRegistered_ = false; + this.doneCallback_ = null; +} + +FocusRestoredTestHelper.prototype.runStep = function(step, doneCallback) { + LOG('runStep: ' + step); + this.doneCallback_ = doneCallback; + + if (step != this.step_ + 1 || step < 0 || step > this.TOTAL_STEPS) { + LOG('Incorrect step, expected:', this.step_ + 1, 'got', step); + this.passStep_(false); + return; + } + this.step_ = step; + + if (!this.messageHandlerRegistered_) { + this.messageHandlerRegistered_ = true; + window.addEventListener('message', this.messageHandler_.bind(this)); + } + + var msgToSend = ''; + if (step == 1) { + msgToSend = 'request-waitForFocus'; + } else if (step == 2) { + msgToSend = 'request-waitForBlur'; + } else if (step == 3) { + msgToSend = 'request-waitForFocusAgain'; + } + + if (!msgToSend) { + this.passStep_(false); + return; + } + + g_webview.contentWindow.postMessage(JSON.stringify([msgToSend]), '*'); +}; + +FocusRestoredTestHelper.prototype.messageHandler_ = function(e) { + var data = JSON.parse(e.data); + LOG('FocusRestoredTestHelper.message, data: ' + data); + switch (this.step_) { + case 1: + this.passStep_(data[0] == 'response-focus'); + break; + case 2: + this.passStep_(data[0] == 'response-blur'); + g_webview.focus(); + break; + case 3: + this.passStep_(data[0] == 'response-focusAgain'); + break; + default: + LOG('Unexpected message: ' + data); + this.passStep_(false); + } +}; + +FocusRestoredTestHelper.prototype.passStep_ = function(passed) { + if (!this.doneCallback_) { + LOG('Expected doneCallback_ in FocusRestoredTestHelper'); + embedder.test.fail(); + return; + } + this.doneCallback_(passed); +}; + +// Helper class for testInputMethod. +// This test has multiple steps, WebViewTest instructs this test to advance to +// each step and then performs some action and verification and runs the next +// step. +// +// See WebViewInteractiveTest.Focus_InputMethod for details about these steps. +function InputMethodTestHelper() { + // Total number of steps for this test that we run thru + // testInputMethodRunNextStep. + this.TOTAL_STEPS = 4; + // Currently running step index. + this.step_ = 0; + // True iff post message handler has been regsitered. + this.messageHandlerRegistered_ = false; + this.doneCallback_ = null; +}; + +InputMethodTestHelper.prototype.passStep_ = function(passed) { + if (!this.doneCallback_) { + LOG('Expected doneCallback_ in InputMethodTestHelper'); + embedder.test.fail(); + return; + } + this.doneCallback_(passed); +}; + +InputMethodTestHelper.prototype.runStep = function(step, doneCallback) { + LOG('runStep: ' + step); + this.doneCallback_ = doneCallback; + + if (step != this.step_ + 1 || step < 0 || step > this.TOTAL_STEPS) { + LOG('Incorrect step, expected:', this.step_ + 1, 'got', step); + this.passStep_(false); + return; + } + this.step_ = step; + + if (!this.messageHandlerRegistered_) { + this.messageHandlerRegistered_ = true; + window.addEventListener('message', this.messageHandler_.bind(this)); + } + + var msgToSend = ''; + if (step == 1) { + msgToSend = 'request-waitForOnInput'; + } else if (step == 2) { + msgToSend = 'request-waitForOnInput'; + } else if (step == 3) { + msgToSend = 'request-moveFocus'; + } else if (step == 4) { + msgToSend = 'request-valueAfterExtendSelection'; + } + if (!msgToSend) { + this.passStep_(false); + return; + } + + g_webview.contentWindow.postMessage(JSON.stringify([msgToSend]), '*'); +}; + +InputMethodTestHelper.prototype.messageHandler_ = function(e) { + var data = JSON.parse(e.data); + LOG('InputMethodTestHelper.message, data: ' + data); + switch (this.step_) { + case 1: + this.passStep_(data[0] == 'response-waitForOnInput' && + data[1] == 'InputTest123'); + break; + case 2: + this.passStep_(data[0] == 'response-waitForOnInput' && + data[1] == 'InputTest456'); + break; + case 3: + this.passStep_(data[0] == 'response-movedFocus' && + data[1] == 'InputTest789'); + break; + case 4: + this.passStep_(data[0] == 'response-valueAfterExtendSelection' && + data[1] == 'InputABC'); + break; + default: + LOG('Unexpected message: ' + data); + this.passStep_(false); + } +}; + // Tests begin. // The embedder has to initiate a post message so that the guest can get a @@ -129,6 +321,7 @@ embedder.testFocus_ = function(channelCreationCallback, var webview = embedder.setUpGuest_(); embedder.waitForResponseFromGuest_(webview, + 'inject_focus.js', channelCreationCallback, expectedResponse, responseCallback); @@ -155,6 +348,7 @@ function testFocusBeforeNavigation() { embedder.waitForResponseFromGuest_( webview, + 'inject_focus.js', onChannelEstablished, 'response-hasFocus', function(data) { @@ -193,6 +387,99 @@ function testBlurEvent() { }); } +// This test verifies IME related stuff for guest. +// +// Briefly: +// 1) We load a guest, the guest gets initial focus and sends message +// back to the embedder. +// 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the +// text is InputTest123, we verify we've seen the change in the guest. +// 3) In InputMethodTestHelper's step 2, we expect the text to be changed +// to InputTest456, this is done from cpp via committing an IME composition. +// 4) In InputMethodTestHelper's step 3, we have a composition (InputTest789) +// on an input element but we move the focus to another input element, we +// make sure the first element gets the composition commit. +// 5) In InputMethodTestHelper's step 4, we verify extending and deleting +// selection through caret works properly. +function testInputMethod() { + var webview = document.createElement('webview'); + g_webview = webview; + document.body.appendChild(webview); + + webview.focus(); + + var onChannelEstablished = function(webview) { + var msg = ['request-waitForFocus']; + webview.contentWindow.postMessage(JSON.stringify(msg), '*'); + }; + embedder.waitForResponseFromGuest_( + webview, + 'inject_input_method.js', + onChannelEstablished, + 'response-seenFocus', + function(data) { embedder.test.succeed(); }); +} + +// Runs additional test steps for testInputMethod. +function testInputMethodRunNextStep(step) { + LOG('testInputMethodRunNextStep, step: ' + step); + if (!g_inputMethodTestHelper) { + g_inputMethodTestHelper = new InputMethodTestHelper(); + } + + g_inputMethodTestHelper.runStep(step, function(stepPassed) { + LOG('runStep callback, stepPassed: ' + stepPassed); + chrome.test.sendMessage(stepPassed ? 'TEST_STEP_PASSED' + : 'TEST_STEP_FAILED'); + }); +} + +// This test ensures we get TextInputTypeChanged event if we bring +// back focus to a guest's <input> after it was initially focused. +// +// Briefly: +// 1) We load a guest. +// 2) In FocusRestoredTestHelper's step 1, we click on the guest to +// focus its <input> element. +// 3) In FocusRestoredTestHelper's step 2, we click outside the guest +// so that the <input> gets a blur event. +// 4. In FocusRestoredTestHelper's step 3, we click on the guest again +// to bring the focus back. +// In the end we check the guest rvh's TextInputType in cpp to make +// sure it initialises properly. +function testFocusRestored() { + var webview = document.createElement('webview'); + webview.style.width = '100px'; + webview.style.height = '100px'; + g_webview = webview; + document.body.appendChild(webview); + + webview.focus(); + + var onChannelEstablished = function(webview) { + chrome.test.sendMessage('TEST_PASSED'); + }; + + embedder.waitForResponseFromGuest_(webview, + 'inject_focus_restored.js', + onChannelEstablished, + undefined, + undefined); +} + +// Runs additional test steps for testFocusRestored. +function testFocusRestoredRunNextStep(step) { + LOG('testFocusRestoredRunNextStep, step: ' + step); + if (!g_focusRestoredTestHelper) { + g_focusRestoredTestHelper = new FocusRestoredTestHelper(); + } + g_focusRestoredTestHelper.runStep(step, function(stepPassed) { + LOG('runStep callback, stepPassed: ' + stepPassed); + chrome.test.sendMessage(stepPassed ? 'TEST_STEP_PASSED' + : 'TEST_STEP_FAILED'); + }); +} + // Tests that if we focus/blur the embedder, it also gets reflected in the // guest. // @@ -200,7 +487,7 @@ function testBlurEvent() { // 1) testFocusTracksEmbedder(), in this step we create a <webview> and // focus it before navigating. After navigating it to a URL, we focus an input // element inside the <webview>, and wait for its 'focus' event to fire. -// 2) POST_testFocusTracksEmbedder(), in this step, we have already called +// 2) testFocusTracksEmbedderRunNextStep(), in this step, we have already called // Blur() on the embedder's RVH (see WebViewTest.Focus_FocusTracksEmbedder), // we make sure we see a 'blur' event on the <webview>'s input element. function testFocusTracksEmbedder() { @@ -219,6 +506,7 @@ function testFocusTracksEmbedder() { embedder.waitForResponseFromGuest_( webview, + 'inject_focus.js', onChannelEstablished, 'response-seenFocus', function(data) { embedder.test.succeed(); }); @@ -226,7 +514,7 @@ function testFocusTracksEmbedder() { // Runs the second step for testFocusTracksEmbedder(). // See WebViewTest.Focus_FocusTracksEmbedder() to see how this is invoked. -function POST_testFocusTracksEmbedder() { +function testFocusTracksEmbedderRunNextStep() { g_webview.contentWindow.postMessage( JSON.stringify(['request-waitForBlurAfterFocus']), '*'); @@ -234,9 +522,9 @@ function POST_testFocusTracksEmbedder() { var data = JSON.parse(e.data); LOG('send window.message, data: ' + data); if (data[0] == 'response-seenBlurAfterFocus') { - chrome.test.sendMessage('POST_TEST_PASSED'); + chrome.test.sendMessage('TEST_STEP_PASSED'); } else { - chrome.test.sendMessage('POST_TEST_FAILED'); + chrome.test.sendMessage('TEST_STEP_FAILED'); } }); } @@ -298,10 +586,12 @@ function testAdvanceFocus() { embedder.test.testList = { 'testAdvanceFocus': testAdvanceFocus, + 'testBlurEvent': testBlurEvent, 'testFocusBeforeNavigation': testFocusBeforeNavigation, 'testFocusEvent': testFocusEvent, 'testFocusTracksEmbedder': testFocusTracksEmbedder, - 'testBlurEvent': testBlurEvent + 'testInputMethod': testInputMethod, + 'testFocusRestored': testFocusRestored }; onload = function() { diff --git a/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_restored.js b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_restored.js new file mode 100644 index 0000000..9b6faa5 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_restored.js @@ -0,0 +1,117 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var embedder = null; +var inputElement = undefined; +var waitingForFocus = false; +var waitingForBlur = false; +var waitingForFocusAgain = false; +var numberOfFocusEvents = 0; +var numberOfBlurEvents = 0; + +var LOG = function(msg) { + window.console.log(msg); +}; + +var sendMessage = function(msg) { + if (!embedder) { + LOG('embedder not found to send message'); + return; + } + embedder.postMessage(JSON.stringify([msg]), '*'); +}; + +var focusHandler = function(e) { + LOG('focusHandler'); + ++numberOfFocusEvents; + respondIfWaitingForFocus(); +}; + +var blurHandler = function(e) { + LOG('blurHandler'); + ++numberOfBlurEvents; + respondIfWaitingForBlur(); + inputElement.removeEventListener('blur', blurHandler); + }; + +var initialize = function() { + inputElement = document.createElement('input'); + inputElement.addEventListener('focus', focusHandler); + inputElement.addEventListener('blur', blurHandler); + document.body.appendChild(inputElement); +}; + +// We respond back to the embedder if we are waiting for a focus event. +var respondIfWaitingForFocus = function() { + if ((waitingForFocus || waitingForFocusAgain) && numberOfFocusEvents >= 1) { + numberOfFocusEvents = 0; + if (waitingForFocus) { + sendMessage('response-focus'); + } else if (waitingForFocusAgain) { + inputElement.removeEventListener('focus', focusHandler); + sendMessage('response-focusAgain'); + } + waitingForFocus = false; + waitingForFocusAgain = false; + return; + } +}; + +// We respond back to the embedder if we are waiting for a blur event. +var respondIfWaitingForBlur = function() { + if (waitingForBlur && numberOfBlurEvents >= 1) { + numberOfBlurEvents = 0; + waitingForBlur = false; + // End of step 2. + sendMessage('response-blur'); + + numberOfFocusEvents = 0; + waitingForFocus = false; + return; + } +}; + +// Wait until we see a focus event, in the case we already have seen a focus, +// this method will respond to the embedder immediately. +var waitForFocus = function() { + waitingForFocus = true; + respondIfWaitingForFocus(); +}; + +// Wait until we see a blur event, in the case we already have seen a blur, +// this method will respond to the embedder immediately. +var waitForBlur = function() { + waitingForBlur = true; + respondIfWaitingForBlur(); +}; + +// Wait until we see a focus event after a focus+blur. In the case we +// already have seen a focus after focus+blur, this method will respond to the +// embedder immediately. +var waitForFocusAgain = function() { + waitingForFocusAgain = true; + respondIfWaitingForFocus(); +}; + +window.addEventListener('message', function(e) { + var data = JSON.parse(e.data); + LOG('message, data: ' + data); + + if (data[0] == 'connect') { + embedder = e.source; + sendMessage('connected'); + } else if (data[0] == 'request-waitForFocus') { + waitForFocus(); + } else if (data[0] == 'request-waitForBlur') { + waitForBlur(); + } else if (data[0] == 'request-waitForFocusAgain') { + waitForFocusAgain(); + } +}); + +document.addEventListener('click', function(e) { + inputElement.focus(); +}); + +initialize(); diff --git a/chrome/test/data/extensions/platform_apps/web_view/focus/inject_input_method.js b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_input_method.js new file mode 100644 index 0000000..9bfe484 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_input_method.js @@ -0,0 +1,101 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var embedder = null; +var inputElement1; +var inputElement2; +var waitingForBlur = false; + +var LOG = function(msg) { + window.console.log(msg); +}; + +var sendMessage = function(data) { + embedder.postMessage(JSON.stringify(data), '*'); +}; + +var onInputState = {fired: false, value: ''}; +// Waits for oninput event to fire on |inputElement1|. +// Upon receiving the event, we ping back the embedder with the value of +// the textbox. +var waitForOnInput = function() { + var inputElement1 = document.querySelector('input'); + LOG('inputElement1: ' + inputElement1); + if (onInputState.fired) { + sendMessage(['response-waitForOnInput', onInputState.value]); + + onInputState.fired = false; + if (inputElement1.value == 'InputTest456') { + // Prepare for next step, step 3. + inputElement1.value = ''; + } + } +}; + +// Waits for the first textbox element to be focused. +var waitForFocus = function() { + inputElement1 = document.createElement('input'); + inputElement1.id = 'input1'; + inputElement1.oninput = function() { + LOG('inputElement1.oninput: ' + inputElement1.value); + onInputState.fired = true; + onInputState.value = inputElement1.value; + }; + var inputElement1FocusListener = function() { + LOG('inputElement1.focus'); + inputElement1.removeEventListener('focus', inputElement1FocusListener); + sendMessage(['response-seenFocus']); + }; + inputElement1.addEventListener('focus', inputElement1FocusListener); + document.body.appendChild(inputElement1); + + inputElement2 = document.createElement('input'); + inputElement2.id = 'input2'; + document.body.appendChild(inputElement2); + + inputElement1.focus(); +}; + +// Waits for the first <input> element to be focused again. +var waitForFocusAgain = function() { + var focusAgainListener = function(e) { + LOG('inputElement1.focus again'); + inputElement1.removeEventListener('focus', focusAgainListener); + sendMessage(['response-focus-again']); + }; + inputElement1.addEventListener('focus', focusAgainListener); + inputElement1.focus(); +}; + +window.addEventListener('message', function(e) { + var data = JSON.parse(e.data); + if (data[0] == 'connect') { + embedder = e.source; + sendMessage(['connected']); + } else if (data[0] == 'request-waitForFocus') { + waitForFocus(); + } else if (data[0] == 'request-waitForOnInput') { + waitForOnInput(); + } else if (data[0] == 'request-moveFocus') { + var onInputElement2Focused = function() { + LOG('inputElement2.focus'); + inputElement2.removeEventListener('focus', onInputElement2Focused); + sendMessage(['response-movedFocus', inputElement1.value]); + + // Prepare for next step. + // Set 'InputTestABC' in inputElement1 and put caret at 6 (after 'T'). + inputElement1.focus(); + inputElement1.value = 'InputTestABC'; + inputElement1.selectionStart = 6; + inputElement1.selectionEnd = 6; + }; + inputElement2.addEventListener('focus', onInputElement2Focused); + + inputElement2.focus(); + } else if (data[0] == 'request-valueAfterExtendSelection') { + sendMessage(['response-valueAfterExtendSelection', inputElement1.value]); + } else if (data[0] == 'request-focus-again') { + waitForFocusAgain(); + } +}); diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc index bccd6e6..b14359cc 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder.cc +++ b/content/browser/browser_plugin/browser_plugin_embedder.cc @@ -6,7 +6,6 @@ #include "base/values.h" #include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/browser/browser_plugin/browser_plugin_host_factory.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/common/browser_plugin/browser_plugin_constants.h" @@ -27,9 +26,6 @@ namespace content { -// static -BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; - BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) : WebContentsObserver(web_contents), weak_ptr_factory_(this) { @@ -41,8 +37,6 @@ BrowserPluginEmbedder::~BrowserPluginEmbedder() { // static BrowserPluginEmbedder* BrowserPluginEmbedder::Create( WebContentsImpl* web_contents) { - if (factory_) - return factory_->CreateBrowserPluginEmbedder(web_contents); return new BrowserPluginEmbedder(web_contents); } diff --git a/content/browser/browser_plugin/browser_plugin_embedder.h b/content/browser/browser_plugin/browser_plugin_embedder.h index 137f0c5..eb7b0ff 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder.h +++ b/content/browser/browser_plugin/browser_plugin_embedder.h @@ -33,7 +33,6 @@ namespace content { class BrowserPluginGuest; class BrowserPluginGuestManager; -class BrowserPluginHostFactory; class RenderWidgetHostImpl; class WebContentsImpl; struct NativeWebKeyboardEvent; @@ -50,12 +49,6 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { // Called when embedder's |rwh| has sent screen rects to renderer. void DidSendScreenRects(); - // Overrides factory for testing. Default (NULL) value indicates regular - // (non-test) environment. - static void set_factory_for_testing(BrowserPluginHostFactory* factory) { - factory_ = factory; - } - // WebContentsObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; @@ -75,8 +68,6 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { void SystemDragEnded(); private: - friend class TestBrowserPluginEmbedder; - explicit BrowserPluginEmbedder(WebContentsImpl* web_contents); BrowserPluginGuestManager* GetBrowserPluginGuestManager() const; @@ -105,9 +96,6 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { int request_id, const gfx::Point& position); - // Static factory instance (always NULL for non-test). - static BrowserPluginHostFactory* factory_; - // Used to correctly update the cursor when dragging over a guest, and to // handle a race condition when dropping onto the guest that started the drag // (the race is that the dragend message arrives before the drop message so diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index d01bbd0..929871e 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -9,7 +9,6 @@ #include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" #include "content/browser/browser_plugin/browser_plugin_embedder.h" -#include "content/browser/browser_plugin/browser_plugin_host_factory.h" #include "content/browser/browser_thread_impl.h" #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h" @@ -40,9 +39,6 @@ namespace content { -// static -BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; - class BrowserPluginGuest::EmbedderWebContentsObserver : public WebContentsObserver { public: @@ -262,14 +258,8 @@ BrowserPluginGuest* BrowserPluginGuest::Create( scoped_ptr<base::DictionaryValue> extra_params, BrowserPluginGuest* opener) { RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); - BrowserPluginGuest* guest = NULL; - if (factory_) { - guest = factory_->CreateBrowserPluginGuest(instance_id, web_contents); - } else { - guest = new BrowserPluginGuest(instance_id, - web_contents->opener() != NULL, - web_contents); - } + BrowserPluginGuest* guest = new BrowserPluginGuest( + instance_id, web_contents->opener() != NULL, web_contents); web_contents->SetBrowserPluginGuest(guest); WebContents* opener_web_contents = NULL; if (opener) { diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index f1c6fe0..3114129 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -58,7 +58,6 @@ class Range; namespace content { class BrowserPluginGuestManager; -class BrowserPluginHostFactory; class RenderViewHostImpl; class RenderWidgetHostView; class SiteInstance; @@ -166,9 +165,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { // Helper to send messages to embedder. This methods fills the message with // the correct routing id. - // Overridden in test implementation since we want to intercept certain - // messages for testing. - virtual void SendMessageToEmbedder(IPC::Message* msg); + void SendMessageToEmbedder(IPC::Message* msg); // Returns whether the guest is attached to an embedder. bool attached() const { return embedder_web_contents_ != NULL; } @@ -203,17 +200,10 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { bool should_allow, const std::string& user_input); - // Overrides factory for testing. Default (NULL) value indicates regular - // (non-test) environment. - static void set_factory_for_testing(BrowserPluginHostFactory* factory) { - BrowserPluginGuest::factory_ = factory; - } - void PointerLockPermissionResponse(bool allow); private: class EmbedderWebContentsObserver; - friend class TestBrowserPluginGuest; // BrowserPluginGuest is a WebContentsObserver of |web_contents| and // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. @@ -252,8 +242,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { int instance_id, const FrameHostMsg_ReclaimCompositorResources_Params& params); - // Overridden in tests. - virtual void OnHandleInputEvent(int instance_id, + void OnHandleInputEvent(int instance_id, const gfx::Rect& guest_window_rect, const blink::WebInputEvent* event); void OnLockMouse(bool user_gesture, @@ -312,8 +301,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { const std::string& text, bool keep_selection); void OnExtendSelectionAndDelete(int instance_id, int before, int after); - // Overridden in tests. - virtual void OnImeCancelComposition(); + void OnImeCancelComposition(); #if defined(OS_MACOSX) || defined(USE_AURA) void OnImeCompositionRangeChanged( const gfx::Range& range, @@ -343,9 +331,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { // Forwards all messages from the |pending_messages_| queue to the embedder. void SendQueuedMessages(); - // Static factory instance (always NULL for non-test). - static BrowserPluginHostFactory* factory_; - scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; WebContentsImpl* embedder_web_contents_; diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc deleted file mode 100644 index 2e3c4c8..0000000 --- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc +++ /dev/null @@ -1,573 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/memory/singleton.h" -#include "base/run_loop.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/browser/browser_plugin/browser_plugin_embedder.h" -#include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/browser/browser_plugin/browser_plugin_host_factory.h" -#include "content/browser/browser_plugin/test_browser_plugin_guest.h" -#include "content/browser/browser_plugin/test_guest_manager.h" -#include "content/browser/child_process_security_policy_impl.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/common/browser_plugin/browser_plugin_messages.h" -#include "content/common/view_messages.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/web_contents_observer.h" -#include "content/public/common/drop_data.h" -#include "content/public/common/url_constants.h" -#include "content/public/test/browser_test_utils.h" -#include "content/public/test/content_browser_test.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" -#include "net/test/embedded_test_server/http_response.h" -#include "net/test/spawned_test_server/spawned_test_server.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" - -using base::ASCIIToUTF16; -using blink::WebInputEvent; -using blink::WebMouseEvent; -using content::BrowserPluginEmbedder; -using content::BrowserPluginGuest; -using content::BrowserPluginHostFactory; -using content::WebContentsImpl; - -const char kHTMLForGuest[] = - "data:text/html,<html><body>hello world</body></html>"; - -const char kHTMLForGuestAcceptDrag[] = - "data:text/html,<html><body>" - "<script>" - "function dropped() {" - " document.title = \"DROPPED\";" - "}" - "</script>" - "<textarea id=\"text\" style=\"width:100%; height: 100%\"" - " ondrop=\"dropped();\">" - "</textarea>" - "</body></html>"; - -namespace content { - -class TestBrowserPluginEmbedder : public BrowserPluginEmbedder { - public: - TestBrowserPluginEmbedder(WebContentsImpl* web_contents) - : BrowserPluginEmbedder(web_contents) { - } - - virtual ~TestBrowserPluginEmbedder() {} - - WebContentsImpl* web_contents() const { - return static_cast<WebContentsImpl*>(BrowserPluginEmbedder::web_contents()); - } - - private: - DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginEmbedder); -}; - -// Test factory for creating test instances of BrowserPluginEmbedder and -// BrowserPluginGuest. -class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { - public: - virtual BrowserPluginGuest* CreateBrowserPluginGuest( - int instance_id, - WebContentsImpl* web_contents) OVERRIDE { - return new TestBrowserPluginGuest(instance_id, web_contents); - } - - // Also keeps track of number of instances created. - virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( - WebContentsImpl* web_contents) OVERRIDE { - - return new TestBrowserPluginEmbedder(web_contents); - } - - // Singleton getter. - static TestBrowserPluginHostFactory* GetInstance() { - return Singleton<TestBrowserPluginHostFactory>::get(); - } - - protected: - TestBrowserPluginHostFactory() {} - virtual ~TestBrowserPluginHostFactory() {} - - private: - // For Singleton. - friend struct DefaultSingletonTraits<TestBrowserPluginHostFactory>; - - scoped_refptr<MessageLoopRunner> message_loop_runner_; - - DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginHostFactory); -}; - -class BrowserPluginHostTest : public ContentBrowserTest { - public: - BrowserPluginHostTest() - : test_embedder_(NULL), - test_guest_(NULL), - test_guest_manager_(NULL) {} - - virtual void SetUp() OVERRIDE { - // Override factory to create tests instances of BrowserPlugin*. - BrowserPluginEmbedder::set_factory_for_testing( - TestBrowserPluginHostFactory::GetInstance()); - BrowserPluginGuest::set_factory_for_testing( - TestBrowserPluginHostFactory::GetInstance()); - ContentBrowserTest::SetUp(); - } - virtual void TearDown() OVERRIDE { - BrowserPluginEmbedder::set_factory_for_testing(NULL); - BrowserPluginGuest::set_factory_for_testing(NULL); - - ContentBrowserTest::TearDown(); - } - - static void SimulateSpaceKeyPress(WebContents* web_contents) { - SimulateKeyPress(web_contents, - ui::VKEY_SPACE, - false, // control. - false, // shift. - false, // alt. - false); // command. - } - - static void SimulateTabKeyPress(WebContents* web_contents) { - SimulateKeyPress(web_contents, - ui::VKEY_TAB, - false, // control. - false, // shift. - false, // alt. - false); // command. - } - - // Executes the JavaScript synchronously and makes sure the returned value is - // freed properly. - void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { - scoped_ptr<base::Value> value = - content::ExecuteScriptAndGetValue(rfh, jscript); - } - - // This helper method does the following: - // 1. Start the test server and navigate the shell to |embedder_url|. - // 2. Execute custom pre-navigation |embedder_code| if provided. - // 3. Navigate the guest to the |guest_url|. - // 4. Verify that the guest has been created and has completed loading. - void StartBrowserPluginTest(const std::string& embedder_url, - const std::string& guest_url, - bool is_guest_data_url, - const std::string& embedder_code) { - ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); - GURL test_url(embedded_test_server()->GetURL(embedder_url)); - NavigateToURL(shell(), test_url); - - WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( - shell()->web_contents()); - static_cast<ShellBrowserContext*>( - embedder_web_contents->GetBrowserContext())-> - set_guest_manager_for_testing( - TestGuestManager::GetInstance()); - RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( - embedder_web_contents->GetRenderViewHost()); - RenderFrameHost* rfh = embedder_web_contents->GetMainFrame(); - // Focus the embedder. - rvh->Focus(); - // Activative IME. - rvh->SetInputMethodActive(true); - - // Allow the test to do some operations on the embedder before we perform - // the first navigation of the guest. - if (!embedder_code.empty()) - ExecuteSyncJSFunction(rfh, embedder_code); - - if (!is_guest_data_url) { - test_url = embedded_test_server()->GetURL(guest_url); - ExecuteSyncJSFunction( - rfh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); - } else { - ExecuteSyncJSFunction( - rfh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); - } - - test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( - embedder_web_contents->GetBrowserPluginEmbedder()); - ASSERT_TRUE(test_embedder_); - - test_guest_manager_ = - static_cast<TestGuestManager*>( - embedder_web_contents->GetBrowserContext()->GetGuestManager()); - - WebContentsImpl* test_guest_web_contents = - test_guest_manager_->WaitForGuestAdded(); - - test_guest_ = static_cast<TestBrowserPluginGuest*>( - test_guest_web_contents->GetBrowserPluginGuest()); - test_guest_->WaitForLoadStop(); - } - - TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; } - TestBrowserPluginGuest* test_guest() const { return test_guest_; } - TestGuestManager* test_guest_manager() const { - return test_guest_manager_; - } - - private: - TestBrowserPluginEmbedder* test_embedder_; - TestBrowserPluginGuest* test_guest_; - TestGuestManager* test_guest_manager_; - DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest); -}; - -// This test opens a page in http and then opens another page in https, forcing -// a RenderViewHost swap in the web_contents. We verify that the embedder in the -// web_contents gets cleared properly. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderChangedAfterSwap) { - net::SpawnedTestServer https_server( - net::SpawnedTestServer::TYPE_HTTPS, - net::SpawnedTestServer::kLocalhost, - base::FilePath(FILE_PATH_LITERAL("content/test/data"))); - ASSERT_TRUE(https_server.Start()); - - // 1. Load an embedder page with one guest in it. - const char kEmbedderURL[] = "/browser_plugin_embedder.html"; - StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); - - // 2. Navigate to a URL in https, so we trigger a RenderViewHost swap. - GURL test_https_url(https_server.GetURL( - "files/browser_plugin_title_change.html")); - content::WindowedNotificationObserver swap_observer( - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, - content::Source<WebContents>(test_embedder()->web_contents())); - NavigateToURL(shell(), test_https_url); - swap_observer.Wait(); - - TestBrowserPluginEmbedder* test_embedder_after_swap = - static_cast<TestBrowserPluginEmbedder*>( - static_cast<WebContentsImpl*>(shell()->web_contents())-> - GetBrowserPluginEmbedder()); - // Verify we have a no embedder in web_contents (since the new page doesn't - // have any browser plugin). - ASSERT_TRUE(!test_embedder_after_swap); - ASSERT_NE(test_embedder(), test_embedder_after_swap); -} - -// This test opens two pages in http and there is no RenderViewHost swap, -// therefore the embedder created on first page navigation stays the same in -// web_contents. -// Failing flakily on Windows: crbug.com/308405 -#if defined(OS_WIN) -#define MAYBE_EmbedderSameAfterNav DISABLED_EmbedderSameAfterNav -#else -#define MAYBE_EmbedderSameAfterNav EmbedderSameAfterNav -#endif -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_EmbedderSameAfterNav) { - const char kEmbedderURL[] = "/browser_plugin_embedder.html"; - StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); - WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); - - // Navigate to another page in same host and port, so RenderViewHost swap - // does not happen and existing embedder doesn't change in web_contents. - GURL test_url_new(embedded_test_server()->GetURL( - "/browser_plugin_title_change.html")); - const base::string16 expected_title = ASCIIToUTF16("done"); - content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); - NavigateToURL(shell(), test_url_new); - VLOG(0) << "Start waiting for title"; - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - VLOG(0) << "Done navigating to second page"; - - TestBrowserPluginEmbedder* test_embedder_after_nav = - static_cast<TestBrowserPluginEmbedder*>( - embedder_web_contents->GetBrowserPluginEmbedder()); - // Embedder must not change in web_contents. - ASSERT_EQ(test_embedder_after_nav, test_embedder()); -} - -// This tests verifies that reloading the embedder does not crash the browser -// and that the guest is reset. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_ReloadEmbedder) { - const char kEmbedderURL[] = "/browser_plugin_embedder.html"; - StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); - RenderFrameHost* rfh = test_embedder()->web_contents()->GetMainFrame(); - - // Change the title of the page to 'modified' so that we know that - // the page has successfully reloaded when it goes back to 'embedder' - // in the next step. - { - const base::string16 expected_title = ASCIIToUTF16("modified"); - content::TitleWatcher title_watcher(test_embedder()->web_contents(), - expected_title); - - ExecuteSyncJSFunction(rfh, - base::StringPrintf("SetTitle('%s');", "modified")); - - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - } - - // Reload the embedder page, and verify that the reload was successful. - // Then navigate the guest to verify that the browser process does not crash. - { - const base::string16 expected_title = ASCIIToUTF16("embedder"); - content::TitleWatcher title_watcher(test_embedder()->web_contents(), - expected_title); - - test_embedder()->web_contents()->GetController().Reload(false); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - - ExecuteSyncJSFunction( - test_embedder()->web_contents()->GetMainFrame(), - base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); - - WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( - test_guest_manager()->WaitForGuestAdded()); - TestBrowserPluginGuest* new_test_guest = - static_cast<TestBrowserPluginGuest*>( - test_guest_web_contents->GetBrowserPluginGuest()); - ASSERT_TRUE(new_test_guest != NULL); - - // Wait for the guest to send an UpdateRectMsg, meaning it is ready. - new_test_guest->WaitForUpdateRectMsg(); - } -} - -// Always failing in the win7 try bot. See http://crbug.com/181107. -// Times out on the Mac. See http://crbug.com/297576. -#if defined(OS_WIN) || defined(OS_MACOSX) -#define MAYBE_AcceptDragEvents DISABLED_AcceptDragEvents -#else -#define MAYBE_AcceptDragEvents AcceptDragEvents -#endif - -// Tests that a drag-n-drop over the browser plugin in the embedder happens -// correctly. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { - const char kEmbedderURL[] = "/browser_plugin_dragging.html"; - StartBrowserPluginTest( - kEmbedderURL, kHTMLForGuestAcceptDrag, true, std::string()); - - RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( - test_embedder()->web_contents()->GetRenderViewHost()); - RenderFrameHost* rfh = test_embedder()->web_contents()->GetMainFrame(); - - // Get a location in the embedder outside of the plugin. - base::ListValue *start, *end; - scoped_ptr<base::Value> value = - content::ExecuteScriptAndGetValue(rfh, "dragLocation()"); - ASSERT_TRUE(value->GetAsList(&start) && start->GetSize() == 2); - double start_x, start_y; - ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y)); - - // Get a location in the embedder that falls inside the plugin. - value = content::ExecuteScriptAndGetValue(rfh, "dropLocation()"); - ASSERT_TRUE(value->GetAsList(&end) && end->GetSize() == 2); - double end_x, end_y; - ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y)); - - DropData drop_data; - GURL url = GURL("https://www.domain.com/index.html"); - drop_data.url = url; - - // Pretend that the URL is being dragged over the embedder. Start the drag - // from outside the plugin, then move the drag inside the plugin and drop. - // This should trigger appropriate messages from the embedder to the guest, - // and end with a drop on the guest. The guest changes title when a drop - // happens. - const base::string16 expected_title = ASCIIToUTF16("DROPPED"); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - expected_title); - - rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), - gfx::Point(start_x, start_y), blink::WebDragOperationEvery, 0); - rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), - blink::WebDragOperationEvery, 0); - rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); - - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); -} - -// This test verifies that if IME is enabled in the embedder, it is also enabled -// in the guest. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VerifyInputMethodActive) { - const char* kEmbedderURL = "/browser_plugin_embedder.html"; - StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); - RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( - test_guest()->web_contents()->GetRenderViewHost()); - EXPECT_TRUE(rvh->input_method_active()); -} - -// This test exercises the following scenario: -// 1. An <input> in guest has focus. -// 2. User takes focus to embedder by clicking e.g. an <input> in embedder. -// 3. User brings back the focus directly to the <input> in #1. -// -// Now we need to make sure TextInputTypeChange fires properly for the guest's -// view (RenderWidgetHostViewGuest) upon step #3. This test ensures that, -// otherwise IME doesn't work after step #3. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusRestored) { - const char kEmbedderURL[] = "/browser_plugin_embedder.html"; - const char kGuestHTML[] = "data:text/html," - "<html><body><input id=\"input1\"></body>" - "<script>" - "var i = document.getElementById(\"input1\");" - "document.body.addEventListener(\"click\", function(e) {" - " i.focus();" - "});" - "i.addEventListener(\"focus\", function(e) {" - " document.title = \"FOCUS\";" - "});" - "i.addEventListener(\"blur\", function(e) {" - " document.title = \"BLUR\";" - "});" - "</script>" - "</html>"; - StartBrowserPluginTest(kEmbedderURL, kGuestHTML, true, - "document.getElementById(\"plugin\").focus();"); - - ASSERT_TRUE(test_embedder()); - const char *kTitles[3] = {"FOCUS", "BLUR", "FOCUS"}; - gfx::Point kClickPoints[3] = { - gfx::Point(20, 20), gfx::Point(700, 20), gfx::Point(20, 20) - }; - - for (int i = 0; i < 3; ++i) { - base::string16 expected_title = base::UTF8ToUTF16(kTitles[i]); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - expected_title); - SimulateMouseClickAt(test_embedder()->web_contents(), 0, - blink::WebMouseEvent::ButtonLeft, - kClickPoints[i]); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - } - TestBrowserPluginGuest* guest = test_guest(); - ASSERT_TRUE(guest); - ui::TextInputType text_input_type = guest->last_text_input_type(); - ASSERT_TRUE(text_input_type != ui::TEXT_INPUT_TYPE_NONE); -} - -// Tests input method. -IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, InputMethod) { - const char kEmbedderURL[] = "/browser_plugin_embedder.html"; - const char kGuestHTML[] = "data:text/html," - "<html><body><input id=\"input1\">" - "<input id=\"input2\"></body>" - "<script>" - "var i = document.getElementById(\"input1\");" - "i.oninput = function() {" - " document.title = i.value;" - "}" - "</script>" - "</html>"; - StartBrowserPluginTest(kEmbedderURL, kGuestHTML, true, - "document.getElementById(\"plugin\").focus();"); - - RenderViewHostImpl* embedder_rvh = static_cast<RenderViewHostImpl*>( - test_embedder()->web_contents()->GetRenderViewHost()); - RenderFrameHost* guest_rfh = test_guest()->web_contents()->GetMainFrame(); - - std::vector<blink::WebCompositionUnderline> underlines; - - // An input field in browser plugin guest gets focus and given some user - // input via IME. - { - ExecuteSyncJSFunction(guest_rfh, - "document.getElementById('input1').focus();"); - base::string16 expected_title = base::UTF8ToUTF16("InputTest123"); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - expected_title); - embedder_rvh->Send( - new ViewMsg_ImeSetComposition( - test_embedder()->web_contents()->GetRoutingID(), - expected_title, - underlines, - 12, 12)); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - } - // A composition is committed via IME. - { - base::string16 expected_title = base::UTF8ToUTF16("InputTest456"); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - expected_title); - embedder_rvh->Send( - new ViewMsg_ImeConfirmComposition( - test_embedder()->web_contents()->GetRoutingID(), - expected_title, - gfx::Range(), - true)); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_title, actual_title); - } - // IME composition starts, but focus moves out, then the composition will - // be committed and get cancel msg. - { - ExecuteSyncJSFunction(guest_rfh, - "document.getElementById('input1').value = '';"); - base::string16 composition = base::UTF8ToUTF16("InputTest789"); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - composition); - embedder_rvh->Send( - new ViewMsg_ImeSetComposition( - test_embedder()->web_contents()->GetRoutingID(), - composition, - underlines, - 12, 12)); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(composition, actual_title); - // Moving focus causes IME cancel, and the composition will be committed - // in input1, not in input2. - ExecuteSyncJSFunction(guest_rfh, - "document.getElementById('input2').focus();"); - test_guest()->WaitForImeCancel(); - scoped_ptr<base::Value> value = - content::ExecuteScriptAndGetValue( - guest_rfh, "document.getElementById('input1').value"); - std::string result; - ASSERT_TRUE(value->GetAsString(&result)); - EXPECT_EQ(base::UTF16ToUTF8(composition), result); - } - // Tests ExtendSelectionAndDelete message works in browser_plugin. - { - // Set 'InputTestABC' in input1 and put caret at 6 (after 'T'). - ExecuteSyncJSFunction(guest_rfh, - "var i = document.getElementById('input1');" - "i.focus();" - "i.value = 'InputTestABC';" - "i.selectionStart=6;" - "i.selectionEnd=6;"); - base::string16 expected_value = base::UTF8ToUTF16("InputABC"); - content::TitleWatcher title_watcher(test_guest()->web_contents(), - expected_value); - // Delete 'Test' in 'InputTestABC', as the caret is after 'T': - // delete before 1 character ('T') and after 3 characters ('est'). - RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( - test_embedder()->web_contents()->GetFocusedFrame()); - rfh->ExtendSelectionAndDelete(1, 3); - base::string16 actual_title = title_watcher.WaitAndGetTitle(); - EXPECT_EQ(expected_value, actual_title); - scoped_ptr<base::Value> value = - content::ExecuteScriptAndGetValue( - guest_rfh, "document.getElementById('input1').value"); - std::string actual_value; - ASSERT_TRUE(value->GetAsString(&actual_value)); - EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); - } -} - -} // namespace content diff --git a/content/browser/browser_plugin/browser_plugin_host_factory.h b/content/browser/browser_plugin/browser_plugin_host_factory.h deleted file mode 100644 index e368fd4..0000000 --- a/content/browser/browser_plugin/browser_plugin_host_factory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_FACTORY_H_ -#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_FACTORY_H_ - -#include "base/base_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/strings/string16.h" -#include "content/common/content_export.h" - -struct BrowserPluginHostMsg_CreateGuest_Params; - -namespace content { - -class BrowserPluginEmbedder; -class BrowserPluginGuest; -class RenderViewHost; -class WebContentsImpl; - -// Factory to create BrowserPlugin embedder and guest. -class CONTENT_EXPORT BrowserPluginHostFactory { - public: - virtual BrowserPluginGuest* CreateBrowserPluginGuest( - int instance_id, - WebContentsImpl* web_contents) = 0; - - virtual BrowserPluginEmbedder* CreateBrowserPluginEmbedder( - WebContentsImpl* web_contents) = 0; - - protected: - virtual ~BrowserPluginHostFactory() {} -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_FACTORY_H_ diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.cc b/content/browser/browser_plugin/test_browser_plugin_guest.cc deleted file mode 100644 index f4b124c..0000000 --- a/content/browser/browser_plugin/test_browser_plugin_guest.cc +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/browser_plugin/test_browser_plugin_guest.h" - -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/common/browser_plugin/browser_plugin_messages.h" - -namespace content { - -class BrowserPluginGuest; - -TestBrowserPluginGuest::TestBrowserPluginGuest( - int instance_id, - WebContentsImpl* web_contents) - : BrowserPluginGuest(instance_id, false, web_contents), - update_rect_count_(0), - input_observed_(false), - load_stop_observed_(false), - ime_cancel_observed_(false) { -} - -TestBrowserPluginGuest::~TestBrowserPluginGuest() { -} - -WebContentsImpl* TestBrowserPluginGuest::web_contents() const { - return static_cast<WebContentsImpl*>(BrowserPluginGuest::web_contents()); -} - -void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { - if (msg->type() == BrowserPluginMsg_UpdateRect::ID) { - update_rect_count_++; - BrowserPluginMsg_UpdateRect::Param param; - BrowserPluginMsg_UpdateRect::Read(msg, ¶m); - BrowserPluginMsg_UpdateRect_Params params = param.b; - if (send_message_loop_runner_) - send_message_loop_runner_->Quit(); - } - BrowserPluginGuest::SendMessageToEmbedder(msg); -} - -void TestBrowserPluginGuest::WaitForUpdateRectMsg() { - // Check if we already got any UpdateRect message. - if (update_rect_count_ > 0) - return; - send_message_loop_runner_ = new MessageLoopRunner(); - send_message_loop_runner_->Run(); -} - -void TestBrowserPluginGuest::OnHandleInputEvent( - int instance_id, - const gfx::Rect& guest_window_rect, - const blink::WebInputEvent* event) { - BrowserPluginGuest::OnHandleInputEvent(instance_id, - guest_window_rect, - event); - input_observed_ = true; - if (input_message_loop_runner_) - input_message_loop_runner_->Quit(); -} - -void TestBrowserPluginGuest::WaitForInput() { - if (input_observed_) { - input_observed_ = false; - return; - } - - input_message_loop_runner_ = new MessageLoopRunner(); - input_message_loop_runner_->Run(); - input_observed_ = false; -} - -void TestBrowserPluginGuest::WaitForLoadStop() { - if (load_stop_observed_) { - load_stop_observed_ = false; - return; - } - - load_stop_message_loop_runner_ = new MessageLoopRunner(); - load_stop_message_loop_runner_->Run(); - load_stop_observed_ = false; -} - -void TestBrowserPluginGuest::WaitForImeCancel() { - if (ime_cancel_observed_) { - ime_cancel_observed_ = false; - return; - } - - ime_cancel_message_loop_runner_ = new MessageLoopRunner(); - ime_cancel_message_loop_runner_->Run(); - ime_cancel_observed_ = false; -} - -void TestBrowserPluginGuest::DidStopLoading( - RenderViewHost* render_view_host) { - BrowserPluginGuest::DidStopLoading(render_view_host); - load_stop_observed_ = true; - if (load_stop_message_loop_runner_) - load_stop_message_loop_runner_->Quit(); -} - -void TestBrowserPluginGuest::OnImeCancelComposition() { - if (!ime_cancel_observed_) { - ime_cancel_observed_ = true; - if (ime_cancel_message_loop_runner_) - ime_cancel_message_loop_runner_->Quit(); - } - BrowserPluginGuest::OnImeCancelComposition(); -} - -} // namespace content diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.h b/content/browser/browser_plugin/test_browser_plugin_guest.h deleted file mode 100644 index 300a602..0000000 --- a/content/browser/browser_plugin/test_browser_plugin_guest.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_ -#define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_ - -#include "base/compiler_specific.h" -#include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/public/test/test_utils.h" -#include "ui/gfx/size.h" - -namespace content { - -class RenderViewHost; -class WebContentsImpl; - -// Test class for BrowserPluginGuest. -// -// Provides utilities to wait for certain state/messages in BrowserPluginGuest -// to be used in tests. -class TestBrowserPluginGuest : public BrowserPluginGuest { - public: - TestBrowserPluginGuest(int instance_id, WebContentsImpl* web_contents); - virtual ~TestBrowserPluginGuest(); - - WebContentsImpl* web_contents() const; - - // Overridden methods from BrowserPluginGuest to intercept in test objects. - virtual void OnHandleInputEvent(int instance_id, - const gfx::Rect& guest_window_rect, - const blink::WebInputEvent* event) OVERRIDE; - virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; - virtual void OnImeCancelComposition() OVERRIDE; - - // Test utilities to wait for a event we are interested in. - // Waits until UpdateRect message is sent from the guest, meaning it is - // ready/rendered. - void WaitForUpdateRectMsg(); - // Waits for blur to reach this guest. - void WaitForInput(); - // Waits until 'loadstop' is observed. - void WaitForLoadStop(); - // Waits until UpdateRect with a particular |view_size| is observed. - void WaitForViewSize(const gfx::Size& view_size); - // Waits until IME cancellation is observed. - void WaitForImeCancel(); - - ui::TextInputType last_text_input_type() { - return last_text_input_type_; - } - - private: - // Overridden methods from BrowserPluginGuest to intercept in test objects. - virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE; - - int update_rect_count_; - bool advance_focus_observed_; - bool input_observed_; - bool load_stop_observed_; - bool ime_cancel_observed_; - - scoped_refptr<MessageLoopRunner> send_message_loop_runner_; - scoped_refptr<MessageLoopRunner> input_message_loop_runner_; - scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_; - scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_; - - DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_ diff --git a/content/browser/browser_plugin/test_browser_plugin_guest_delegate.cc b/content/browser/browser_plugin/test_browser_plugin_guest_delegate.cc deleted file mode 100644 index 41aa7fe..0000000 --- a/content/browser/browser_plugin/test_browser_plugin_guest_delegate.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" - -#include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/common/referrer.h" - -namespace content { - -// This observer ensures that the TestBrowserPluginGuestDelegate destroys itself -// when its embedder goes away. -class TestBrowserPluginGuestDelegate::EmbedderWebContentsObserver : - public WebContentsObserver { - public: - explicit EmbedderWebContentsObserver(TestBrowserPluginGuestDelegate* guest) - : WebContentsObserver(guest->GetEmbedderWebContents()), - guest_(guest) { - } - - virtual ~EmbedderWebContentsObserver() { - } - - // WebContentsObserver implementation. - virtual void WebContentsDestroyed() OVERRIDE { - guest_->Destroy(); - } - - private: - TestBrowserPluginGuestDelegate* guest_; - - DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); -}; - -TestBrowserPluginGuestDelegate::TestBrowserPluginGuestDelegate( - BrowserPluginGuest* guest) : - WebContentsObserver(guest->GetWebContents()), - guest_(guest) { -} - -TestBrowserPluginGuestDelegate::~TestBrowserPluginGuestDelegate() { -} - -WebContents* TestBrowserPluginGuestDelegate::GetEmbedderWebContents() const { - return guest_->embedder_web_contents(); -} - -void TestBrowserPluginGuestDelegate::LoadURLWithParams( - const GURL& url, - const Referrer& referrer, - PageTransition transition_type, - WebContents* web_contents) { - NavigationController::LoadURLParams load_url_params(url); - load_url_params.referrer = referrer; - load_url_params.transition_type = transition_type; - load_url_params.extra_headers = std::string(); - web_contents->GetController().LoadURLWithParams(load_url_params); -} - -void TestBrowserPluginGuestDelegate::WebContentsDestroyed() { - delete this; -} - -void TestBrowserPluginGuestDelegate::DidAttach() { - embedder_web_contents_observer_.reset( - new EmbedderWebContentsObserver(this)); - -} - -void TestBrowserPluginGuestDelegate::Destroy() { - if (!destruction_callback_.is_null()) - destruction_callback_.Run(); - delete guest_->GetWebContents(); -} - -void TestBrowserPluginGuestDelegate::NavigateGuest(const std::string& src) { - GURL url(src); - LoadURLWithParams(url, - Referrer(), - PAGE_TRANSITION_AUTO_TOPLEVEL, - guest_->GetWebContents()); -} - -void TestBrowserPluginGuestDelegate::RegisterDestructionCallback( - const DestructionCallback& callback) { - destruction_callback_ = callback; -} - - -} // namespace content diff --git a/content/browser/browser_plugin/test_browser_plugin_guest_delegate.h b/content/browser/browser_plugin/test_browser_plugin_guest_delegate.h deleted file mode 100644 index 594f768..0000000 --- a/content/browser/browser_plugin/test_browser_plugin_guest_delegate.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_DELEGATE_H_ -#define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_DELEGATE_H_ - -#include "content/public/browser/browser_plugin_guest_delegate.h" - -#include "base/callback.h" -#include "content/public/browser/web_contents_observer.h" -#include "content/public/common/page_transition_types.h" -#include "url/gurl.h" - -namespace content { - -class BrowserPluginGuest; -struct Referrer; - -class TestBrowserPluginGuestDelegate : public BrowserPluginGuestDelegate, - public WebContentsObserver { - public: - explicit TestBrowserPluginGuestDelegate(BrowserPluginGuest* guest); - virtual ~TestBrowserPluginGuestDelegate(); - - WebContents* GetEmbedderWebContents() const; - - private: - class EmbedderWebContentsObserver; - - void LoadURLWithParams(const GURL& url, - const Referrer& referrer, - PageTransition transition_type, - WebContents* web_contents); - - // WebContentsObserver implementation. - virtual void WebContentsDestroyed() OVERRIDE; - - // Overridden from BrowserPluginGuestDelegate: - virtual void DidAttach() OVERRIDE; - virtual void Destroy() OVERRIDE; - virtual void NavigateGuest(const std::string& src) OVERRIDE; - virtual void RegisterDestructionCallback( - const DestructionCallback& callback) OVERRIDE; - - BrowserPluginGuest* guest_; - scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; - - DestructionCallback destruction_callback_; - - DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuestDelegate); -}; - -} // namespace content -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_DELEGATE_H_ diff --git a/content/browser/browser_plugin/test_guest_manager.cc b/content/browser/browser_plugin/test_guest_manager.cc deleted file mode 100644 index e60f842..0000000 --- a/content/browser/browser_plugin/test_guest_manager.cc +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/browser_plugin/test_guest_manager.h" - -#include "base/logging.h" -#include "base/memory/singleton.h" -#include "base/strings/stringprintf.h" -#include "base/values.h" -#include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/public/browser/site_instance.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_observer.h" -#include "content/public/common/url_constants.h" -#include "content/public/test/test_utils.h" -#include "net/base/escape.h" - -namespace content { - -class GuestWebContentsObserver - : public WebContentsObserver { - public: - explicit GuestWebContentsObserver(WebContents* guest_web_contents) - : WebContentsObserver(guest_web_contents) { - BrowserPluginGuest* guest = - static_cast<WebContentsImpl*>(guest_web_contents)-> - GetBrowserPluginGuest(); - guest_instance_id_ = guest->instance_id(); - } - - virtual ~GuestWebContentsObserver() { - } - - virtual void WebContentsDestroyed() OVERRIDE { - TestGuestManager::GetInstance()->RemoveGuest(guest_instance_id_); - delete this; - } - - private: - int guest_instance_id_; - DISALLOW_COPY_AND_ASSIGN(GuestWebContentsObserver); -}; - -TestGuestManager::TestGuestManager() - : last_guest_added_(NULL), - next_instance_id_(0) { -} - -TestGuestManager::~TestGuestManager() { -} - -// static. -TestGuestManager* TestGuestManager::GetInstance() { - return Singleton<TestGuestManager>::get(); -} - -WebContentsImpl* TestGuestManager::WaitForGuestAdded() { - // Check if guests were already created. - if (last_guest_added_) { - WebContentsImpl* last_guest_added = last_guest_added_; - last_guest_added_ = NULL; - return last_guest_added; - } - // Wait otherwise. - message_loop_runner_ = new MessageLoopRunner(); - message_loop_runner_->Run(); - WebContentsImpl* last_guest_added = last_guest_added_; - last_guest_added_ = NULL; - return last_guest_added; -} - -WebContents* TestGuestManager::CreateGuest( - SiteInstance* embedder_site_instance, - int instance_id, - const std::string& storage_partition_id, - bool persist_storage, - scoped_ptr<base::DictionaryValue> extra_params) { - const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); - const std::string& host = embedder_site_url.host(); - - std::string url_encoded_partition = net::EscapeQueryParamValue( - storage_partition_id, false); - GURL guest_site(base::StringPrintf("%s://%s/%s?%s", - kGuestScheme, - host.c_str(), - persist_storage ? "persist" : "", - url_encoded_partition.c_str())); - - // If we already have a webview tag in the same app using the same storage - // partition, we should use the same SiteInstance so the existing tag and - // the new tag can script each other. - SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site); - if (!guest_site_instance) { - // Create the SiteInstance in a new BrowsingInstance, which will ensure - // that webview tags are also not allowed to send messages across - // different partitions. - guest_site_instance = SiteInstance::CreateForURL( - embedder_site_instance->GetBrowserContext(), guest_site); - } - WebContents::CreateParams create_params( - embedder_site_instance->GetBrowserContext(), - guest_site_instance); - create_params.guest_instance_id = instance_id; - create_params.guest_extra_params.reset(extra_params.release()); - WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>( - WebContents::Create(create_params)); - BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); - guest_web_contents->GetBrowserPluginGuest()->set_delegate( - new TestBrowserPluginGuestDelegate(guest)); - AddGuest(instance_id, guest_web_contents); - return guest_web_contents; -} - -int TestGuestManager::GetNextInstanceID() { - return ++next_instance_id_; -} - -void TestGuestManager::AddGuest( - int guest_instance_id, - WebContents* guest_web_contents) { - DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == - guest_web_contents_by_instance_id_.end()); - guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; - new GuestWebContentsObserver(guest_web_contents); - last_guest_added_ = static_cast<WebContentsImpl*>(guest_web_contents); - if (message_loop_runner_) - message_loop_runner_->Quit(); -} - -void TestGuestManager::RemoveGuest( - int guest_instance_id) { - GuestInstanceMap::iterator it = - guest_web_contents_by_instance_id_.find(guest_instance_id); - DCHECK(it != guest_web_contents_by_instance_id_.end()); - guest_web_contents_by_instance_id_.erase(it); -} - -void TestGuestManager::MaybeGetGuestByInstanceIDOrKill( - int guest_instance_id, - int embedder_render_process_id, - const GuestByInstanceIDCallback& callback) { - GuestInstanceMap::const_iterator it = - guest_web_contents_by_instance_id_.find(guest_instance_id); - if (it == guest_web_contents_by_instance_id_.end()) { - callback.Run(NULL); - return; - } - callback.Run(it->second); -} - -SiteInstance* TestGuestManager::GetGuestSiteInstance( - const GURL& guest_site) { - for (GuestInstanceMap::const_iterator it = - guest_web_contents_by_instance_id_.begin(); - it != guest_web_contents_by_instance_id_.end(); ++it) { - if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) - return it->second->GetSiteInstance(); - } - return NULL; -} - -bool TestGuestManager::ForEachGuest( - WebContents* embedder_web_contents, - const GuestCallback& callback) { - for (GuestInstanceMap::iterator it = - guest_web_contents_by_instance_id_.begin(); - it != guest_web_contents_by_instance_id_.end(); ++it) { - WebContentsImpl* guest_web_contents = - static_cast<WebContentsImpl*>(it->second); - BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); - if (embedder_web_contents != guest->embedder_web_contents()) - continue; - - if (callback.Run(guest_web_contents)) - return true; - } - return false; -} - -} // namespace content diff --git a/content/browser/browser_plugin/test_guest_manager.h b/content/browser/browser_plugin/test_guest_manager.h deleted file mode 100644 index 2ae9678..0000000 --- a/content/browser/browser_plugin/test_guest_manager.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_GUEST_MANAGER_H_ -#define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_GUEST_MANAGER_H_ - -#include <map> - -#include "base/memory/singleton.h" -#include "content/public/browser/browser_plugin_guest_manager.h" - -namespace content { - -class MessageLoopRunner; -class WebContentsImpl; - -// This class is temporary until BrowserPluginHostTest.* tests are entirely -// moved out of content. -class TestGuestManager : public BrowserPluginGuestManager { - public: - virtual ~TestGuestManager(); - - static TestGuestManager* GetInstance(); - - void AddGuest(int guest_instance_id, WebContents* guest_web_contents); - void RemoveGuest(int guest_instance_id); - SiteInstance* GetGuestSiteInstance(const GURL& guest_site); - - // Waits until at least one guest is added to this guest manager. - WebContentsImpl* WaitForGuestAdded(); - - // BrowserPluginGuestManager implementation. - virtual WebContents* CreateGuest( - SiteInstance* embedder_site_instance, - int instance_id, - const std::string& storage_partition_id, - bool persist_storage, - scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; - virtual int GetNextInstanceID() OVERRIDE; - virtual void MaybeGetGuestByInstanceIDOrKill( - int guest_instance_id, - int embedder_render_process_id, - const GuestByInstanceIDCallback& callback) OVERRIDE; - virtual bool ForEachGuest(WebContents* embedder_web_contents, - const GuestCallback& callback) OVERRIDE; - - private: - friend struct DefaultSingletonTraits<TestGuestManager>; - TestGuestManager(); - - // Contains guests' WebContents, mapping from their instance ids. - typedef std::map<int, WebContents*> GuestInstanceMap; - GuestInstanceMap guest_web_contents_by_instance_id_; - WebContentsImpl* last_guest_added_; - int next_instance_id_; - scoped_refptr<MessageLoopRunner> message_loop_runner_; - - DISALLOW_COPY_AND_ASSIGN(TestGuestManager); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_GUEST_MANAGER_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 97112b6..228bf8d 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -336,7 +336,6 @@ 'browser/browser_plugin/browser_plugin_embedder.h', 'browser/browser_plugin/browser_plugin_guest.cc', 'browser/browser_plugin/browser_plugin_guest.h', - 'browser/browser_plugin/browser_plugin_host_factory.h', 'browser/browser_plugin/browser_plugin_message_filter.cc', 'browser/browser_plugin/browser_plugin_message_filter.h', 'browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 17658b7..9cdc3df 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -1081,13 +1081,6 @@ 'browser/accessibility/dump_accessibility_tree_browsertest.cc', 'browser/compositor/image_transport_factory_browsertest.cc', 'browser/bookmarklet_browsertest.cc', - 'browser/browser_plugin/browser_plugin_host_browsertest.cc', - 'browser/browser_plugin/test_browser_plugin_guest.cc', - 'browser/browser_plugin/test_browser_plugin_guest.h', - 'browser/browser_plugin/test_browser_plugin_guest_delegate.cc', - 'browser/browser_plugin/test_browser_plugin_guest_delegate.h', - 'browser/browser_plugin/test_guest_manager.cc', - 'browser/browser_plugin/test_guest_manager.h', 'browser/child_process_security_policy_browsertest.cc', 'browser/cross_site_transfer_browsertest.cc', 'browser/database_browsertest.cc', diff --git a/content/test/data/browser_plugin_dragging.html b/content/test/data/browser_plugin_dragging.html deleted file mode 100644 index d22661a..0000000 --- a/content/test/data/browser_plugin_dragging.html +++ /dev/null @@ -1,41 +0,0 @@ -<html> -<head></head> -<body> - -<textarea id='id_message'> -</textarea> - -<object id="plugin" - tabindex="0" - type="application/browser-plugin" - width="240" - height="120" - style='border: solid 1px red' - > -</object> - -<script> -function dragLocation() { - return [id_message.offsetLeft + id_message.offsetWidth / 2, - id_message.offsetTop + id_message.offsetHeight / 2]; -} - -function dropLocation() { - return [plugin.offsetLeft + plugin.offsetWidth / 2, - plugin.offsetTop + plugin.offsetHeight / 2]; -} - -function SetSrc(src) { - plugin = document.getElementById('plugin'); - plugin.src = src; -} - -var plugin = document.getElementById('plugin'); -plugin.addEventListener('-internal-instanceid-allocated', function(e) { - var detail = e.detail ? JSON.parse(e.detail) : {}; - plugin['-internal-attach'](detail.windowId, {}); -}); -</script> - -</body> -</html> diff --git a/content/test/data/browser_plugin_embedder.html b/content/test/data/browser_plugin_embedder.html deleted file mode 100644 index 13f6493..0000000 --- a/content/test/data/browser_plugin_embedder.html +++ /dev/null @@ -1,29 +0,0 @@ -<script type="text/javascript"> -function SetSrc(src) { - var plugin = document.getElementById('plugin'); - plugin.src = src; -} -function SetSize(w, h) { - var plugin = document.getElementById('plugin'); - plugin.width = w; - plugin.height = h; -} -function SetTitle(str) { - document.title = str; -} -document.title = 'embedder'; -</script> - -<object id="plugin" - tabindex="0" - type="application/browser-plugin" - width="640" - height="480" - border="0px"></object> -<script type="text/javascript"> -var plugin = document.getElementById('plugin'); -plugin.addEventListener('-internal-instanceid-allocated', function(e) { - var detail = e.detail ? JSON.parse(e.detail) : {}; - plugin['-internal-attach'](detail.windowId, {}); -}); -</script> diff --git a/content/test/data/browser_plugin_title_change.html b/content/test/data/browser_plugin_title_change.html deleted file mode 100644 index 0ad78e8a..0000000 --- a/content/test/data/browser_plugin_title_change.html +++ /dev/null @@ -1,12 +0,0 @@ -<html> - <head> - <script type="text/javascript"> - function SetTitle(title) { - document.title = title; - } - </script> - </head> - <body> - <script>SetTitle('done');</script> - </body> -</html> |