summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortreib@chromium.org <treib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 22:48:16 +0000
committertreib@chromium.org <treib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 22:48:16 +0000
commitaa1bfc9c457f42546ba4c6d9a373882123b075c7 (patch)
treea83e8cda02c63ac60e37dc56f98d22f6ca9c2f2a
parent08085eb8978a9d317f28bc144658aa01b0d4f9be (diff)
downloadchromium_src-aa1bfc9c457f42546ba4c6d9a373882123b075c7.zip
chromium_src-aa1bfc9c457f42546ba4c6d9a373882123b075c7.tar.gz
chromium_src-aa1bfc9c457f42546ba4c6d9a373882123b075c7.tar.bz2
Pressing the "Go back" button on the managed user block interstitial page closes the tab if there is no previous URL to go back to.
BUG=307215 Review URL: https://codereview.chromium.org/248963004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266982 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/managed_mode/managed_mode_browsertest.cc47
-rw-r--r--chrome/browser/managed_mode/managed_mode_interstitial.cc5
-rw-r--r--content/public/test/test_navigation_observer.cc11
-rw-r--r--content/public/test/test_navigation_observer.h1
4 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc
index e3be689..e5c23f2 100644
--- a/chrome/browser/managed_mode/managed_mode_browsertest.cc
+++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
@@ -36,6 +37,7 @@
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
#include "grit/generated_resources.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"
using content::InterstitialPage;
@@ -157,6 +159,23 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest {
ManagedUserService* managed_user_service_;
};
+class MockTabStripModelObserver : public TabStripModelObserver {
+ public:
+ explicit MockTabStripModelObserver(TabStripModel* tab_strip)
+ : tab_strip_(tab_strip) {
+ tab_strip_->AddObserver(this);
+ }
+
+ ~MockTabStripModelObserver() {
+ tab_strip_->RemoveObserver(this);
+ }
+
+ MOCK_METHOD3(TabClosingAt, void(TabStripModel*, content::WebContents*, int));
+
+ private:
+ TabStripModel* tab_strip_;
+};
+
// Navigates to a blocked URL.
IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
SendAccessRequestOnBlockedURL) {
@@ -173,9 +192,37 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
GoBack(tab);
+ // Make sure that the tab is still there.
+ EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents());
+
CheckShownPageIsNotInterstitial(tab);
}
+// Navigates to a blocked URL in a new tab. We expect the tab to be closed
+// automatically on pressing the "back" button on the interstitial.
+IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, OpenBlockedURLInNewTab) {
+ TabStripModel* tab_strip = browser()->tab_strip_model();
+ WebContents* prev_tab = tab_strip->GetActiveWebContents();
+
+ // Open blocked URL in a new tab.
+ GURL test_url("http://www.example.com/files/simple.html");
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), test_url, NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+
+ // Check that we got the interstitial.
+ WebContents* tab = tab_strip->GetActiveWebContents();
+ CheckShownPageIsInterstitial(tab);
+
+ // On pressing the "back" button, the new tab should be closed, and we should
+ // get back to the previous active tab.
+ MockTabStripModelObserver observer(tab_strip);
+ EXPECT_CALL(observer,
+ TabClosingAt(tab_strip, tab, tab_strip->active_index()));
+ GoBack(tab);
+ EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents());
+}
+
// Tests whether a visit attempt adds a special history entry.
IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
HistoryVisitRecorded) {
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc
index 225b776..9d97ccc 100644
--- a/chrome/browser/managed_mode/managed_mode_interstitial.cc
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc
@@ -224,6 +224,11 @@ void ManagedModeInterstitial::OnFilteringPrefsChanged() {
}
void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) {
+ // If there is no history entry to go back to, close the tab instead.
+ int nav_entry_count = web_contents_->GetController().GetEntryCount();
+ if (!continue_request && nav_entry_count == 0)
+ web_contents_->Close();
+
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
}
diff --git a/content/public/test/test_navigation_observer.cc b/content/public/test/test_navigation_observer.cc
index e2c69b7..cad43a8 100644
--- a/content/public/test/test_navigation_observer.cc
+++ b/content/public/test/test_navigation_observer.cc
@@ -30,6 +30,10 @@ class TestNavigationObserver::TestWebContentsObserver
parent_->OnNavigationEntryCommitted(this, web_contents(), load_details);
}
+ virtual void DidAttachInterstitialPage() OVERRIDE {
+ parent_->OnDidAttachInterstitialPage(web_contents());
+ }
+
virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
parent_->OnWebContentsDestroyed(this, web_contents);
}
@@ -118,6 +122,13 @@ void TestNavigationObserver::OnNavigationEntryCommitted(
navigation_started_ = true;
}
+void TestNavigationObserver::OnDidAttachInterstitialPage(
+ WebContents* web_contents) {
+ // Going to an interstitial page does not trigger NavigationEntryCommitted,
+ // but has the same meaning for us here.
+ navigation_started_ = true;
+}
+
void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) {
navigation_started_ = true;
}
diff --git a/content/public/test/test_navigation_observer.h b/content/public/test/test_navigation_observer.h
index f6e5e41..438af74 100644
--- a/content/public/test/test_navigation_observer.h
+++ b/content/public/test/test_navigation_observer.h
@@ -52,6 +52,7 @@ class TestNavigationObserver {
TestWebContentsObserver* observer,
WebContents* web_contents,
const LoadCommittedDetails& load_details);
+ void OnDidAttachInterstitialPage(WebContents* web_contents);
void OnDidStartLoading(WebContents* web_contents);
void OnDidStopLoading(WebContents* web_contents);