Commit 91ed49a3 authored by jcampan@chromium.org's avatar jcampan@chromium.org

This CL makes sure JavaScript alerts are not shown while an interstitial is showing.

(The interstitial is displayed on top of an existing page. We don't want the hidden page to interfere with the interstitial.)

BUG=http://crbug.com/3256
TEST=Open the page attached in the bug (interstitial_test.html), no alert boxes should show.
Review URL: http://codereview.chromium.org/149261

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20084 0039d316-1c4b-4281-b951-d872f2087c98
parent 9840dd70
...@@ -1929,7 +1929,11 @@ void TabContents::RunJavaScriptMessage( ...@@ -1929,7 +1929,11 @@ void TabContents::RunJavaScriptMessage(
// Suppress javascript messages when requested and when inside a constrained // Suppress javascript messages when requested and when inside a constrained
// popup window (because that activates them and breaks them out of the // popup window (because that activates them and breaks them out of the
// constrained window jail). // constrained window jail).
bool suppress_this_message = suppress_javascript_messages_; // Also suppress messages when showing an interstitial. The interstitial is
// shown over the previous page, we don't want the hidden page dialogs to
// interfere with the interstitial.
bool suppress_this_message = suppress_javascript_messages_ ||
showing_interstitial_page();
if (delegate()) if (delegate())
suppress_this_message |= suppress_this_message |=
(delegate()->GetConstrainingContents(this) != this); (delegate()->GetConstrainingContents(this) != this);
......
...@@ -578,8 +578,9 @@ class TabContents : public PageNavigator, ...@@ -578,8 +578,9 @@ class TabContents : public PageNavigator,
friend class BlockedPopupContainerTest; friend class BlockedPopupContainerTest;
friend class BlockedPopupContainerControllerTest; friend class BlockedPopupContainerControllerTest;
FRIEND_TEST(TabContentsTest, UpdateTitle);
FRIEND_TEST(BlockedPopupContainerTest, TestReposition); FRIEND_TEST(BlockedPopupContainerTest, TestReposition);
FRIEND_TEST(TabContentsTest, NoJSMessageOnInterstitials);
FRIEND_TEST(TabContentsTest, UpdateTitle);
// Temporary until the view/contents separation is complete. // Temporary until the view/contents separation is complete.
friend class TabContentsView; friend class TabContentsView;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// 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.
#include "app/message_box_flags.h"
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/render_widget_host_view.h"
...@@ -1256,3 +1257,36 @@ TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) { ...@@ -1256,3 +1257,36 @@ TEST_F(TabContentsTest, NewInterstitialDoesNotCancelPendingEntry) {
EXPECT_FALSE(deleted2); EXPECT_FALSE(deleted2);
EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
} }
// Tests that Javascript messages are not shown while an interstitial is
// showing.
TEST_F(TabContentsTest, NoJSMessageOnInterstitials) {
const char kUrl[] = "http://www.badguys.com/";
const GURL kGURL(kUrl);
// Start a navigation to a page
contents()->controller().LoadURL(kGURL, GURL(), PageTransition::TYPED);
// DidNavigate from the page
ViewHostMsg_FrameNavigate_Params params;
InitNavigateParams(&params, 1, kGURL);
contents()->TestDidNavigate(rvh(), params);
// Simulate showing an interstitial while the page is showing.
TestInterstitialPage::InterstitialState state =
TestInterstitialPage::UNDECIDED;
bool deleted = false;
TestInterstitialPage* interstitial =
new TestInterstitialPage(contents(), true, kGURL, &state, &deleted);
TestInterstitialPageStateGuard state_guard(interstitial);
interstitial->Show();
interstitial->TestDidNavigate(1, kGURL);
// While the interstitial is showing, let's simulate the hidden page
// attempting to show a JS message.
IPC::Message* dummy_message = new IPC::Message;
bool did_suppress_message = false;
contents()->RunJavaScriptMessage(L"This is an informative message", L"OK",
kGURL, MessageBoxFlags::kIsJavascriptAlert, dummy_message,
&did_suppress_message);
EXPECT_TRUE(did_suppress_message);
}
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