Commit aa1bfc9c authored by treib@chromium.org's avatar treib@chromium.org

Pressing the "Go back" button on the managed user block interstitial page...

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
parent 08085eb8
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.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.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using content::InterstitialPage; using content::InterstitialPage;
...@@ -157,6 +159,23 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { ...@@ -157,6 +159,23 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest {
ManagedUserService* managed_user_service_; 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. // Navigates to a blocked URL.
IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
SendAccessRequestOnBlockedURL) { SendAccessRequestOnBlockedURL) {
...@@ -173,9 +192,37 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, ...@@ -173,9 +192,37 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
GoBack(tab); GoBack(tab);
// Make sure that the tab is still there.
EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents());
CheckShownPageIsNotInterstitial(tab); 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. // Tests whether a visit attempt adds a special history entry.
IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
HistoryVisitRecorded) { HistoryVisitRecorded) {
......
...@@ -224,6 +224,11 @@ void ManagedModeInterstitial::OnFilteringPrefsChanged() { ...@@ -224,6 +224,11 @@ void ManagedModeInterstitial::OnFilteringPrefsChanged() {
} }
void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { 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::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
} }
...@@ -30,6 +30,10 @@ class TestNavigationObserver::TestWebContentsObserver ...@@ -30,6 +30,10 @@ class TestNavigationObserver::TestWebContentsObserver
parent_->OnNavigationEntryCommitted(this, web_contents(), load_details); parent_->OnNavigationEntryCommitted(this, web_contents(), load_details);
} }
virtual void DidAttachInterstitialPage() OVERRIDE {
parent_->OnDidAttachInterstitialPage(web_contents());
}
virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
parent_->OnWebContentsDestroyed(this, web_contents); parent_->OnWebContentsDestroyed(this, web_contents);
} }
...@@ -118,6 +122,13 @@ void TestNavigationObserver::OnNavigationEntryCommitted( ...@@ -118,6 +122,13 @@ void TestNavigationObserver::OnNavigationEntryCommitted(
navigation_started_ = true; 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) { void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) {
navigation_started_ = true; navigation_started_ = true;
} }
......
...@@ -52,6 +52,7 @@ class TestNavigationObserver { ...@@ -52,6 +52,7 @@ class TestNavigationObserver {
TestWebContentsObserver* observer, TestWebContentsObserver* observer,
WebContents* web_contents, WebContents* web_contents,
const LoadCommittedDetails& load_details); const LoadCommittedDetails& load_details);
void OnDidAttachInterstitialPage(WebContents* web_contents);
void OnDidStartLoading(WebContents* web_contents); void OnDidStartLoading(WebContents* web_contents);
void OnDidStopLoading(WebContents* web_contents); void OnDidStopLoading(WebContents* web_contents);
......
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