Commit 204deb5e authored by lazyboy@chromium.org's avatar lazyboy@chromium.org

BrowserPluginHostTest: Rewrite 3 focus related tests and 1 visibility test to browser_tests.

This CL also removes 	BrowserPluginHostTest.HiddenBeforeNavigation, that was disabled under TSAN v2.

BUG=368077, 370240
Test=None, internal only change.

Review URL: https://codereview.chromium.org/281833003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272427 0039d316-1c4b-4281-b951-d872f2087c98
parent 29de18fc
...@@ -1082,6 +1082,10 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) { ...@@ -1082,6 +1082,10 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER); TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER);
} }
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestHiddenBeforeNavigation) {
TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) { IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) {
ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
......
...@@ -502,12 +502,78 @@ IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PointerLock) { ...@@ -502,12 +502,78 @@ IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PointerLock) {
#endif // defined(OS_LINUX) && !defined(USE_AURA) #endif // defined(OS_LINUX) && !defined(USE_AURA)
// Tests that if a <webview> is focused before navigation then the guest starts
// off focused.
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusBeforeNavigation) {
TestHelper("testFocusBeforeNavigation", "web_view/focus", NO_TEST_SERVER);
}
// Tests that setting focus on the <webview> sets focus on the guest. // Tests that setting focus on the <webview> sets focus on the guest.
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) { IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) {
TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER); TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER);
} }
// Tests that setting focus on the <webview> sets focus on the guest. IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusTracksEmbedder) {
content::WebContents* embedder_web_contents = NULL;
scoped_ptr<ExtensionTestMessageListener> done_listener(
RunAppHelper("testFocusTracksEmbedder", "web_view/focus", NO_TEST_SERVER,
&embedder_web_contents));
done_listener->WaitUntilSatisfied();
ExtensionTestMessageListener post_test_listener("POST_TEST_PASSED", false);
post_test_listener.set_failure_message("POST_TEST_FAILED");
EXPECT_TRUE(content::ExecuteScript(
embedder_web_contents,
"window.runCommand('POST_testFocusTracksEmbedder');"));
// Blur the embedder.
embedder_web_contents->GetRenderViewHost()->Blur();
// Ensure that the guest is also blurred.
ASSERT_TRUE(post_test_listener.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_AdvanceFocus) {
content::WebContents* embedder_web_contents = NULL;
{
scoped_ptr<ExtensionTestMessageListener> done_listener(
RunAppHelper("testAdvanceFocus", "web_view/focus", NO_TEST_SERVER,
&embedder_web_contents));
done_listener->WaitUntilSatisfied();
}
{
ExtensionTestMessageListener listener("button1-focused", false);
listener.set_failure_message("TEST_FAILED");
SimulateRWHMouseClick(embedder_web_contents->GetRenderViewHost(),
blink::WebMouseEvent::ButtonLeft, 200, 20);
content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
false, false, false, false);
ASSERT_TRUE(listener.WaitUntilSatisfied());
}
{
// Wait for button1 to be focused again, this means we were asked to
// move the focus to the next focusable element.
ExtensionTestMessageListener listener("button1-advance-focus", false);
listener.set_failure_message("TEST_FAILED");
// TODO(fsamuel): A third Tab key press should not be necessary.
// The <webview> will take keyboard focus but it will not focus an initial
// element. The initial element is dependent upon tab direction which blink
// does not propagate to the plugin.
// See http://crbug.com/147644.
content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
false, false, false, false);
content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
false, false, false, false);
content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
false, false, false, false);
ASSERT_TRUE(listener.WaitUntilSatisfied());
}
}
// Tests that blurring <webview> also blurs the guest.
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) { IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) {
TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER); TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER);
} }
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var g_webview = null;
var embedder = {}; var embedder = {};
var seenFocusCount = 0;
embedder.tests = {}; embedder.tests = {};
embedder.triggerNavUrl = embedder.guestURL =
'data:text/html,<html><body>trigger navigation<body></html>'; 'data:text/html,<html><body>Guest<body></html>';
window.runTest = function(testName) { window.runTest = function(testName) {
if (!embedder.test.testList[testName]) { if (!embedder.test.testList[testName]) {
...@@ -17,8 +19,23 @@ window.runTest = function(testName) { ...@@ -17,8 +19,23 @@ window.runTest = function(testName) {
// Run the test. // Run the test.
embedder.test.testList[testName](); embedder.test.testList[testName]();
}; };
window.runCommand = function(command) {
window.console.log('window.runCommand: ' + command);
switch (command) {
case 'POST_testFocusTracksEmbedder':
POST_testFocusTracksEmbedder();
break;
default:
embedder.test.fail();
}
};
// window.* exported functions end. // window.* exported functions end.
var LOG = function(msg) {
window.console.log(msg);
};
embedder.test = {}; embedder.test = {};
embedder.test.succeed = function() { embedder.test.succeed = function() {
chrome.test.sendMessage('TEST_PASSED'); chrome.test.sendMessage('TEST_PASSED');
...@@ -76,11 +93,15 @@ embedder.waitForResponseFromGuest_ = ...@@ -76,11 +93,15 @@ embedder.waitForResponseFromGuest_ =
if (response != expectedResponse) { if (response != expectedResponse) {
return; return;
} }
responseCallback(); responseCallback(data);
window.removeEventListener('message', onPostMessageReceived); window.removeEventListener('message', onPostMessageReceived);
}; };
window.addEventListener('message', onPostMessageReceived); window.addEventListener('message', onPostMessageReceived);
webview.addEventListener('consolemessage', function(e) {
LOG('g: ' + e.message);
});
var onWebViewLoadStop = function(e) { var onWebViewLoadStop = function(e) {
console.log('loadstop'); console.log('loadstop');
webview.executeScript( webview.executeScript(
...@@ -94,7 +115,7 @@ embedder.waitForResponseFromGuest_ = ...@@ -94,7 +115,7 @@ embedder.waitForResponseFromGuest_ =
webview.removeEventListener('loadstop', onWebViewLoadStop); webview.removeEventListener('loadstop', onWebViewLoadStop);
}; };
webview.addEventListener('loadstop', onWebViewLoadStop); webview.addEventListener('loadstop', onWebViewLoadStop);
webview.src = embedder.triggerNavUrl; webview.src = embedder.guestURL;
}; };
// Tests begin. // Tests begin.
...@@ -113,6 +134,36 @@ embedder.testFocus_ = function(channelCreationCallback, ...@@ -113,6 +134,36 @@ embedder.testFocus_ = function(channelCreationCallback,
responseCallback); responseCallback);
}; };
// Verifies that if a <webview> is focused before navigation then the guest
// starts off focused.
//
// We create a <webview> element and make it focused before navigating it.
// Then we load a URL in it and make sure document.hasFocus() returns true
// for the <webview>.
function testFocusBeforeNavigation() {
var webview = document.createElement('webview');
document.body.appendChild(webview);
var onChannelEstablished = function(webview) {
// Query the guest if it has focus.
var msg = ['request-hasFocus'];
webview.contentWindow.postMessage(JSON.stringify(msg), '*');
};
// Focus the <webview> before navigating it.
webview.focus();
embedder.waitForResponseFromGuest_(
webview,
onChannelEstablished,
'response-hasFocus',
function(data) {
LOG('data, hasFocus: ' + data[1]);
embedder.test.assertEq(true, data[1]);
embedder.test.succeed();
});
}
function testFocusEvent() { function testFocusEvent() {
var seenResponse = false; var seenResponse = false;
embedder.testFocus_(function(webview) { embedder.testFocus_(function(webview) {
...@@ -142,8 +193,114 @@ function testBlurEvent() { ...@@ -142,8 +193,114 @@ function testBlurEvent() {
}); });
} }
// Tests that if we focus/blur the embedder, it also gets reflected in the
// guest.
//
// This test has two steps:
// 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
// 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() {
var webview = document.createElement('webview');
g_webview = webview;
document.body.appendChild(webview);
var onChannelEstablished = function(webview) {
var msg = ['request-waitForFocus'];
webview.contentWindow.postMessage(JSON.stringify(msg), '*');
};
// Focus the <webview> before navigating it.
// This is necessary so that 'blur' event on guest's <input> element fires.
webview.focus();
embedder.waitForResponseFromGuest_(
webview,
onChannelEstablished,
'response-seenFocus',
function(data) { embedder.test.succeed(); });
}
// Runs the second step for testFocusTracksEmbedder().
// See WebViewTest.Focus_FocusTracksEmbedder() to see how this is invoked.
function POST_testFocusTracksEmbedder() {
g_webview.contentWindow.postMessage(
JSON.stringify(['request-waitForBlurAfterFocus']), '*');
window.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
LOG('send window.message, data: ' + data);
if (data[0] == 'response-seenBlurAfterFocus') {
chrome.test.sendMessage('POST_TEST_PASSED');
} else {
chrome.test.sendMessage('POST_TEST_FAILED');
}
});
}
// Tests that <webview> sees advanceFocus() call when we cycle through the
// elements inside it using tab key.
//
// This test has two steps:
// 1) testAdvanceFocus(), in this step, we focus the embedder and press a
// tab key, we expect the input element inside the <webview> to be focused.
// 2) POST_testAdvanceFocus(), in this step we send additional tab keypress
// to the embedder/app (from WebViewInteractiveTest.Focus_AdvanceFocus), this
// would cycle the focus within the elements and will bring focus back to
// the input element present in the <webview> mentioned in step 1.
function testAdvanceFocus() {
var webview = document.createElement('webview');
g_webview = webview;
document.body.appendChild(webview);
webview.addEventListener('consolemessage', function(e) {
LOG('g: ' + e.message);
});
webview.addEventListener('loadstop', function(e) {
LOG('loadstop');
window.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
LOG('message, data: ' + data);
if (data[0] == 'connected') {
embedder.test.succeed();
} else if (data[0] == 'button1-focused') {
var focusCount = data[1];
LOG('focusCount: ' + focusCount);
seenFocusCount++;
if (focusCount == 1) {
chrome.test.sendMessage('button1-focused');
} else {
chrome.test.sendMessage('button1-advance-focus');
}
}
});
webview.executeScript(
{file: 'inject_advance_focus_test.js'},
function(results) {
window.console.log('webview.executeScript response');
if (!results || !results.length) {
LOG('Inject script failure.');
embedder.test.fail();
return;
}
webview.contentWindow.postMessage(JSON.stringify(['connect']), '*');
});
});
webview.src = embedder.guestURL;
}
embedder.test.testList = { embedder.test.testList = {
'testAdvanceFocus': testAdvanceFocus,
'testFocusBeforeNavigation': testFocusBeforeNavigation,
'testFocusEvent': testFocusEvent, 'testFocusEvent': testFocusEvent,
'testFocusTracksEmbedder': testFocusTracksEmbedder,
'testBlurEvent': testBlurEvent 'testBlurEvent': testBlurEvent
}; };
......
// 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 button1FocusCount = 0;
var LOG = function(msg) {
window.console.log(msg);
};
var sendMessage = function(msgArray) {
if (embedder) {
embedder.postMessage(JSON.stringify(msgArray), '*');
}
};
var init = function() {
var button1 = document.createElement('button');
button1.addEventListener('focus', function(e) {
LOG('button1.focus');
++button1FocusCount;
sendMessage(['button1-focused', button1FocusCount]);
});
button1.innerText = 'Before';
button1.setAttribute('tabIndex', 0);
var button2 = document.createElement('button');
button2.innerText = 'Before';
button2.setAttribute('tabIndex', 0);
document.body.appendChild(button1);
document.body.appendChild(button2);
window.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
embedder = e.source;
LOG('message, data: ' + data);
if (data[0] == 'connect') {
sendMessage(['connected']);
}
});
};
init();
...@@ -3,22 +3,69 @@ ...@@ -3,22 +3,69 @@
// found in the LICENSE file. // found in the LICENSE file.
var embedder = null; var embedder = null;
var inputElement;
var waitingForBlur = false;
var seenBlurAfterFocus = false;
var LOG = function(msg) {
window.console.log(msg);
};
var sendMessage = function(data) {
embedder.postMessage(JSON.stringify(data), '*');
};
var waitForBlurAfterFocus = function() {
LOG('seenBlurAfterFocus: ' + seenBlurAfterFocus);
if (seenBlurAfterFocus) {
// Already seen it.
sendMessage(['response-seenBlurAfterFocus']);
return;
}
// Otherwise we will wait.
waitingForBlur = true;
};
var waitForFocus = function() {
inputElement = document.createElement('input');
inputElement.addEventListener('focus', function(e) {
LOG('input.focus');
sendMessage(['response-seenFocus']);
var blurHandler = function(e) {
seenBlurAfterFocus = true;
if (waitingForBlur) {
inputElement.removeEventListener('blur', blurHandler);
sendMessage(['response-seenBlurAfterFocus']);
}
};
inputElement.addEventListener('blur', blurHandler);
});
document.body.appendChild(inputElement);
inputElement.focus();
};
window.addEventListener('message', function(e) { window.addEventListener('message', function(e) {
var data = JSON.parse(e.data); var data = JSON.parse(e.data);
if (data[0] == 'connect') { if (data[0] == 'connect') {
embedder = e.source; embedder = e.source;
var msg = ['connected']; sendMessage(['connected']);
embedder.postMessage(JSON.stringify(msg), '*'); } else if (data[0] == 'request-hasFocus') {
return; var hasFocus = document.hasFocus();
sendMessage(['response-hasFocus', hasFocus]);
} else if (data[0] == 'request-waitForFocus') {
waitForFocus();
} else if (data[0] == 'request-waitForBlurAfterFocus') {
waitForBlurAfterFocus();
} }
}); });
window.addEventListener('focus', function(e) { window.addEventListener('focus', function(e) {
var msg = ['focused']; sendMessage(['focused']);
embedder.postMessage(JSON.stringify(msg), '*');
}); });
window.addEventListener('blur', function(e) { window.addEventListener('blur', function(e) {
var msg = ['blurred']; sendMessage(['blurred']);
embedder.postMessage(JSON.stringify(msg), '*');
}); });
// 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.
window.addEventListener('message', function(e) {
var response = '';
var data = JSON.parse(e.data);
if (data[0] == 'visibilityState-request') {
response = document.visibilityState;
} else {
response = 'FAILED';
}
e.source.postMessage(
JSON.stringify(['visibilityState-response', response]), '*');
});
...@@ -1043,6 +1043,48 @@ function testGetProcessId() { ...@@ -1043,6 +1043,48 @@ function testGetProcessId() {
document.body.appendChild(webview); document.body.appendChild(webview);
} }
function testHiddenBeforeNavigation() {
var webview = document.createElement('webview');
webview.style.visibility = 'hidden';
var postMessageHandler = function(e) {
var data = JSON.parse(e.data);
window.removeEventListener('message', postMessageHandler);
if (data[0] == 'visibilityState-response') {
embedder.test.assertEq('hidden', data[1]);
embedder.test.succeed();
} else {
LOG('Unexpected message: ' + data);
embedder.test.fail();
}
};
webview.addEventListener('loadstop', function(e) {
LOG('webview.loadstop');
window.addEventListener('message', postMessageHandler);
webview.addEventListener('consolemessage', function(e) {
LOG('g: ' + e.message);
});
webview.executeScript(
{file: 'inject_hidden_test.js'},
function(results) {
if (!results || !results.length) {
LOG('Failed to inject script: inject_hidden_test.js');
embedder.test.fail();
return;
}
LOG('script injection success');
webview.contentWindow.postMessage(
JSON.stringify(['visibilityState-request']), '*');
});
});
webview.setAttribute('src', 'data:text/html,<html><body></body></html>');
document.body.appendChild(webview);
}
// This test verifies that the loadstart event fires at the beginning of a load // This test verifies that the loadstart event fires at the beginning of a load
// and the loadredirect event fires when a redirect occurs. // and the loadredirect event fires when a redirect occurs.
function testLoadStartLoadRedirect() { function testLoadStartLoadRedirect() {
...@@ -1642,6 +1684,7 @@ embedder.test.testList = { ...@@ -1642,6 +1684,7 @@ embedder.test.testList = {
'testWebRequestListenerSurvivesReparenting': 'testWebRequestListenerSurvivesReparenting':
testWebRequestListenerSurvivesReparenting, testWebRequestListenerSurvivesReparenting,
'testGetProcessId': testGetProcessId, 'testGetProcessId': testGetProcessId,
'testHiddenBeforeNavigation': testHiddenBeforeNavigation,
'testLoadStartLoadRedirect': testLoadStartLoadRedirect, 'testLoadStartLoadRedirect': testLoadStartLoadRedirect,
'testLoadAbortChromeExtensionURLWrongPartition': 'testLoadAbortChromeExtensionURLWrongPartition':
testLoadAbortChromeExtensionURLWrongPartition, testLoadAbortChromeExtensionURLWrongPartition,
......
...@@ -322,11 +322,12 @@ class CONTENT_EXPORT BrowserPluginGuest ...@@ -322,11 +322,12 @@ class CONTENT_EXPORT BrowserPluginGuest
void OnNavigateGuest(int instance_id, const std::string& src); void OnNavigateGuest(int instance_id, const std::string& src);
void OnPluginDestroyed(int instance_id); void OnPluginDestroyed(int instance_id);
// Resizes the guest's web contents. // Resizes the guest's web contents.
// Overridden in tests. void OnResizeGuest(
virtual void OnResizeGuest(
int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params);
// Overridden in tests. void OnSetFocus(int instance_id, bool focused);
virtual void OnSetFocus(int instance_id, bool focused); // Sets the name of the guest so that other guests in the same partition can
// access it.
void OnSetName(int instance_id, const std::string& name);
// Updates the size state of the guest. // Updates the size state of the guest.
void OnSetSize( void OnSetSize(
int instance_id, int instance_id,
...@@ -392,8 +393,10 @@ class CONTENT_EXPORT BrowserPluginGuest ...@@ -392,8 +393,10 @@ class CONTENT_EXPORT BrowserPluginGuest
void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params); void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
#endif #endif
void OnShowWidget(int route_id, const gfx::Rect& initial_pos); void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
// Overridden in tests. void OnTakeFocus(bool reverse);
virtual void OnTakeFocus(bool reverse); void OnUpdateFrameName(int frame_id,
bool is_top_level,
const std::string& name);
void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
// Forwards all messages from the |pending_messages_| queue to the embedder. // Forwards all messages from the |pending_messages_| queue to the embedder.
......
...@@ -230,28 +230,6 @@ class BrowserPluginHostTest : public ContentBrowserTest { ...@@ -230,28 +230,6 @@ class BrowserPluginHostTest : public ContentBrowserTest {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest); DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest);
}; };
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) {
const char kEmbedderURL[] = "/browser_plugin_focus.html";
const char* kGuestURL = "/browser_plugin_focus_child.html";
StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string());
SimulateMouseClick(test_embedder()->web_contents(), 0,
blink::WebMouseEvent::ButtonLeft);
BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents());
// Wait until we focus into the guest.
test_guest()->WaitForFocus();
// TODO(fsamuel): A third Tab key press should not be necessary.
// The browser plugin will take keyboard focus but it will not
// focus an initial element. The initial element is dependent
// upon tab direction which WebKit does not propagate to the plugin.
// See http://crbug.com/147644.
BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents());
BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents());
BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents());
test_guest()->WaitForAdvanceFocus();
}
// This test opens a page in http and then opens another page in https, forcing // 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 // a RenderViewHost swap in the web_contents. We verify that the embedder in the
// web_contents gets cleared properly. // web_contents gets cleared properly.
...@@ -423,49 +401,6 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) { ...@@ -423,49 +401,6 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_AcceptDragEvents) {
EXPECT_EQ(expected_title, actual_title); EXPECT_EQ(expected_title, actual_title);
} }
// This test verifies that if a browser plugin is hidden before navigation,
// the guest starts off hidden.
// This test is flaky under ThreadSanitizer, see http://crbug.com/370240
#if !defined(THREAD_SANITIZER)
#define MAYBE_HiddenBeforeNavigation HiddenBeforeNavigation
#else
#define MAYBE_HiddenBeforeNavigation DISABLED_HiddenBeforeNavigation
#endif
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_HiddenBeforeNavigation) {
const char* kEmbedderURL = "/browser_plugin_embedder.html";
const std::string embedder_code =
"document.getElementById('plugin').style.visibility = 'hidden'";
StartBrowserPluginTest(
kEmbedderURL, kHTMLForGuest, true, embedder_code);
EXPECT_FALSE(test_guest()->visible());
}
// This test verifies that if a browser plugin is focused before navigation then
// the guest starts off focused.
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusBeforeNavigation) {
const char* kEmbedderURL = "/browser_plugin_embedder.html";
const std::string embedder_code =
"document.getElementById('plugin').focus();";
StartBrowserPluginTest(
kEmbedderURL, kHTMLForGuest, true, embedder_code);
RenderFrameHost* guest_rfh = test_guest()->web_contents()->GetMainFrame();
// Verify that the guest is focused.
scoped_ptr<base::Value> value =
content::ExecuteScriptAndGetValue(guest_rfh, "document.hasFocus()");
bool result = false;
ASSERT_TRUE(value->GetAsBoolean(&result));
EXPECT_TRUE(result);
}
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, FocusTracksEmbedder) {
const char* kEmbedderURL = "/browser_plugin_embedder.html";
StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string());
// Blur the embedder.
test_embedder()->web_contents()->GetRenderViewHost()->Blur();
// Ensure that the guest is also blurred.
test_guest()->WaitForBlur();
}
// This test verifies that if IME is enabled in the embedder, it is also enabled // This test verifies that if IME is enabled in the embedder, it is also enabled
// in the guest. // in the guest.
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VerifyInputMethodActive) { IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VerifyInputMethodActive) {
......
...@@ -17,9 +17,6 @@ TestBrowserPluginGuest::TestBrowserPluginGuest( ...@@ -17,9 +17,6 @@ TestBrowserPluginGuest::TestBrowserPluginGuest(
WebContentsImpl* web_contents) WebContentsImpl* web_contents)
: BrowserPluginGuest(instance_id, false, web_contents), : BrowserPluginGuest(instance_id, false, web_contents),
update_rect_count_(0), update_rect_count_(0),
focus_observed_(false),
blur_observed_(false),
advance_focus_observed_(false),
input_observed_(false), input_observed_(false),
load_stop_observed_(false), load_stop_observed_(false),
ime_cancel_observed_(false) { ime_cancel_observed_(false) {
...@@ -38,12 +35,6 @@ void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { ...@@ -38,12 +35,6 @@ void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
BrowserPluginMsg_UpdateRect::Param param; BrowserPluginMsg_UpdateRect::Param param;
BrowserPluginMsg_UpdateRect::Read(msg, &param); BrowserPluginMsg_UpdateRect::Read(msg, &param);
BrowserPluginMsg_UpdateRect_Params params = param.b; BrowserPluginMsg_UpdateRect_Params params = param.b;
last_view_size_observed_ = params.view_size;
if (!expected_auto_view_size_.IsEmpty() &&
expected_auto_view_size_ == params.view_size) {
if (auto_view_size_message_loop_runner_)
auto_view_size_message_loop_runner_->Quit();
}
if (send_message_loop_runner_) if (send_message_loop_runner_)
send_message_loop_runner_->Quit(); send_message_loop_runner_->Quit();
} }
...@@ -58,10 +49,6 @@ void TestBrowserPluginGuest::WaitForUpdateRectMsg() { ...@@ -58,10 +49,6 @@ void TestBrowserPluginGuest::WaitForUpdateRectMsg() {
send_message_loop_runner_->Run(); send_message_loop_runner_->Run();
} }
void TestBrowserPluginGuest::ResetUpdateRectCount() {
update_rect_count_ = 0;
}
void TestBrowserPluginGuest::OnHandleInputEvent( void TestBrowserPluginGuest::OnHandleInputEvent(
int instance_id, int instance_id,
const gfx::Rect& guest_window_rect, const gfx::Rect& guest_window_rect,
...@@ -74,33 +61,6 @@ void TestBrowserPluginGuest::OnHandleInputEvent( ...@@ -74,33 +61,6 @@ void TestBrowserPluginGuest::OnHandleInputEvent(
input_message_loop_runner_->Quit(); input_message_loop_runner_->Quit();
} }
void TestBrowserPluginGuest::WaitForFocus() {
if (focus_observed_) {
focus_observed_ = false;
return;
}
focus_message_loop_runner_ = new MessageLoopRunner();
focus_message_loop_runner_->Run();
focus_observed_ = false;
}
void TestBrowserPluginGuest::WaitForBlur() {
if (blur_observed_) {
blur_observed_ = false;
return;
}
blur_message_loop_runner_ = new MessageLoopRunner();
blur_message_loop_runner_->Run();
blur_observed_ = false;
}
void TestBrowserPluginGuest::WaitForAdvanceFocus() {
if (advance_focus_observed_)
return;
advance_focus_message_loop_runner_ = new MessageLoopRunner();
advance_focus_message_loop_runner_->Run();
}
void TestBrowserPluginGuest::WaitForInput() { void TestBrowserPluginGuest::WaitForInput() {
if (input_observed_) { if (input_observed_) {
input_observed_ = false; input_observed_ = false;
...@@ -123,18 +83,6 @@ void TestBrowserPluginGuest::WaitForLoadStop() { ...@@ -123,18 +83,6 @@ void TestBrowserPluginGuest::WaitForLoadStop() {
load_stop_observed_ = false; load_stop_observed_ = false;
} }
void TestBrowserPluginGuest::WaitForViewSize(const gfx::Size& view_size) {
if (last_view_size_observed_ == view_size) {
last_view_size_observed_ = gfx::Size();
return;
}
expected_auto_view_size_ = view_size;
auto_view_size_message_loop_runner_ = new MessageLoopRunner();
auto_view_size_message_loop_runner_->Run();
last_view_size_observed_ = gfx::Size();
}
void TestBrowserPluginGuest::WaitForImeCancel() { void TestBrowserPluginGuest::WaitForImeCancel() {
if (ime_cancel_observed_) { if (ime_cancel_observed_) {
ime_cancel_observed_ = false; ime_cancel_observed_ = false;
...@@ -146,26 +94,6 @@ void TestBrowserPluginGuest::WaitForImeCancel() { ...@@ -146,26 +94,6 @@ void TestBrowserPluginGuest::WaitForImeCancel() {
ime_cancel_observed_ = false; ime_cancel_observed_ = false;
} }
void TestBrowserPluginGuest::OnSetFocus(int instance_id, bool focused) {
if (focused) {
focus_observed_ = true;
if (focus_message_loop_runner_)
focus_message_loop_runner_->Quit();
} else {
blur_observed_ = true;
if (blur_message_loop_runner_)
blur_message_loop_runner_->Quit();
}
BrowserPluginGuest::OnSetFocus(instance_id, focused);
}
void TestBrowserPluginGuest::OnTakeFocus(bool reverse) {
advance_focus_observed_ = true;
if (advance_focus_message_loop_runner_)
advance_focus_message_loop_runner_->Quit();
BrowserPluginGuest::OnTakeFocus(reverse);
}
void TestBrowserPluginGuest::DidStopLoading( void TestBrowserPluginGuest::DidStopLoading(
RenderViewHost* render_view_host) { RenderViewHost* render_view_host) {
BrowserPluginGuest::DidStopLoading(render_view_host); BrowserPluginGuest::DidStopLoading(render_view_host);
......
...@@ -30,8 +30,6 @@ class TestBrowserPluginGuest : public BrowserPluginGuest { ...@@ -30,8 +30,6 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
virtual void OnHandleInputEvent(int instance_id, virtual void OnHandleInputEvent(int instance_id,
const gfx::Rect& guest_window_rect, const gfx::Rect& guest_window_rect,
const blink::WebInputEvent* event) OVERRIDE; const blink::WebInputEvent* event) OVERRIDE;
virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
virtual void OnTakeFocus(bool reverse) OVERRIDE;
virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
virtual void OnImeCancelComposition() OVERRIDE; virtual void OnImeCancelComposition() OVERRIDE;
...@@ -39,14 +37,7 @@ class TestBrowserPluginGuest : public BrowserPluginGuest { ...@@ -39,14 +37,7 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
// Waits until UpdateRect message is sent from the guest, meaning it is // Waits until UpdateRect message is sent from the guest, meaning it is
// ready/rendered. // ready/rendered.
void WaitForUpdateRectMsg(); void WaitForUpdateRectMsg();
void ResetUpdateRectCount();
// Waits for focus to reach this guest.
void WaitForFocus();
// Waits for blur to reach this guest. // Waits for blur to reach this guest.
void WaitForBlur();
// Waits for focus to move out of this guest.
void WaitForAdvanceFocus();
// Waits until input is observed.
void WaitForInput(); void WaitForInput();
// Waits until 'loadstop' is observed. // Waits until 'loadstop' is observed.
void WaitForLoadStop(); void WaitForLoadStop();
...@@ -64,22 +55,14 @@ class TestBrowserPluginGuest : public BrowserPluginGuest { ...@@ -64,22 +55,14 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE; virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
int update_rect_count_; int update_rect_count_;
bool focus_observed_;
bool blur_observed_;
bool advance_focus_observed_; bool advance_focus_observed_;
bool input_observed_; bool input_observed_;
bool load_stop_observed_; bool load_stop_observed_;
bool ime_cancel_observed_; bool ime_cancel_observed_;
gfx::Size last_view_size_observed_;
gfx::Size expected_auto_view_size_;
scoped_refptr<MessageLoopRunner> send_message_loop_runner_; scoped_refptr<MessageLoopRunner> send_message_loop_runner_;
scoped_refptr<MessageLoopRunner> focus_message_loop_runner_;
scoped_refptr<MessageLoopRunner> blur_message_loop_runner_;
scoped_refptr<MessageLoopRunner> advance_focus_message_loop_runner_;
scoped_refptr<MessageLoopRunner> input_message_loop_runner_; scoped_refptr<MessageLoopRunner> input_message_loop_runner_;
scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_; scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_;
scoped_refptr<MessageLoopRunner> auto_view_size_message_loop_runner_;
scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_; scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest); DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
......
<html>
<head>
<script type="text/javascript">
function SetSrc(src) {
plugin = document.getElementById('plugin');
plugin.src = src;
}
</script>
</head>
<body>
<button id="before" tabindex="0">Before</button>
<object id="plugin"
tabindex="0"
type="application/browser-plugin"
width="640"
height="480"
border="0px"></object>
<button id="after" tabindex="0">After</button>
<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>
</body>
</html>
<html>
<body>
<button id="before" tabindex="0">Before</button>
<button id="after" tabindex="0">After</button>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment