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

Unified Diff: chrome/browser/plugins/flash_permission_browsertest.cc

Issue 2540683002: Don't defer quitting in ExecuteScript and other helpers that use DOMMessageQueue. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/plugins/flash_permission_browsertest.cc
diff --git a/chrome/browser/plugins/flash_permission_browsertest.cc b/chrome/browser/plugins/flash_permission_browsertest.cc
index 5a934dd64c6ab4a3f07d9e6365ab9f3f4a3c1ec0..c1db46dd3fb8ae8cbf9d1f755597e931bf16e81f 100644
--- a/chrome/browser/plugins/flash_permission_browsertest.cc
+++ b/chrome/browser/plugins/flash_permission_browsertest.cc
@@ -17,6 +17,27 @@
#include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "url/gurl.h"
+namespace {
+
+class PageReloadWaiter {
+ public:
+ explicit PageReloadWaiter(content::WebContents* web_contents)
+ : web_contents_(web_contents),
+ navigation_observer_(web_contents,
+ web_contents->GetLastCommittedURL()) {}
+
+ bool Wait() {
+ navigation_observer_.WaitForNavigationFinished();
+ return content::WaitForLoadStop(web_contents_);
+ }
+
+ private:
+ content::WebContents* web_contents_;
+ content::TestNavigationManager navigation_observer_;
+};
+
+} // namespace
+
class FlashPermissionBrowserTest : public PermissionsBrowserTest {
public:
FlashPermissionBrowserTest()
@@ -44,18 +65,21 @@ class FlashPermissionBrowserTest : public PermissionsBrowserTest {
if (prompt_factory()->response_type() ==
PermissionRequestManager::ACCEPT_ALL) {
// If the prompt will be allowed, we need to wait for the page to refresh.
- content::TestNavigationManager observer(
- GetWebContents(), GetWebContents()->GetLastCommittedURL());
+ PageReloadWaiter reload_waiter(GetWebContents());
EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
- observer.WaitForNavigationFinished();
+ EXPECT_TRUE(reload_waiter.Wait());
} else {
EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
}
}
bool FeatureUsageSucceeds() override {
- // Wait until the page is refreshed before testing whether flash is enabled
- // or disabled.
+ // If flash should have been blocked, reload the page to be sure that it is
+ // blocked.
+ //
+ // NB: In cases where flash is allowed the page reloads automatically,
+ // and tests should always wait for that reload to finish before calling
+ // this method.
ui_test_utils::NavigateToURL(browser(),
GetWebContents()->GetLastCommittedURL());
// If either flash with or without fallback content runs successfully it
@@ -86,7 +110,11 @@ IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) {
IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) {
EXPECT_EQ(0, prompt_factory()->total_request_count());
prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
+ // FlashPermissionContext::UpdateTabContext will reload the page, we'll have
+ // to wait until it is ready.
+ PageReloadWaiter reload_waiter(GetWebContents());
EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();"));
+ EXPECT_TRUE(reload_waiter.Wait());
EXPECT_TRUE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
@@ -98,12 +126,12 @@ IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
EXPECT_FALSE(FeatureUsageSucceeds());
prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
// We need to simulate a mouse click to trigger the placeholder to prompt.
- content::TestNavigationManager observer(
- GetWebContents(), GetWebContents()->GetLastCommittedURL());
+ // When the prompt is auto-accepted, the page will be reloaded.
+ PageReloadWaiter reload_waiter(GetWebContents());
content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */,
blink::WebMouseEvent::Button::Left,
gfx::Point(50, 50));
- observer.WaitForNavigationFinished();
+ EXPECT_TRUE(reload_waiter.Wait());
EXPECT_TRUE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
« no previous file with comments | « chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc ('k') | chromeos/cryptohome/mock_homedir_methods.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698