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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_browsertest.cc

Issue 248963004: "Go back" on the block interstitial closes the tab if there is no previous URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved test. Created 6 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/common/cancelable_request.h" 10 #include "chrome/browser/common/cancelable_request.h"
11 #include "chrome/browser/history/history_service_factory.h" 11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
13 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h"
15 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 15 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
16 #include "chrome/browser/managed_mode/managed_user_constants.h" 16 #include "chrome/browser/managed_mode/managed_user_constants.h"
17 #include "chrome/browser/managed_mode/managed_user_service.h" 17 #include "chrome/browser/managed_mode/managed_user_service.h"
18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 18 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
19 #include "chrome/browser/managed_mode/managed_user_settings_service.h" 19 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
20 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" 20 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_navigator.h" 23 #include "chrome/browser/ui/browser_navigator.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/in_process_browser_test.h" 28 #include "chrome/test/base/in_process_browser_test.h"
28 #include "chrome/test/base/ui_test_utils.h" 29 #include "chrome/test/base/ui_test_utils.h"
29 #include "components/infobars/core/infobar.h" 30 #include "components/infobars/core/infobar.h"
30 #include "components/user_prefs/pref_registry_syncable.h" 31 #include "components/user_prefs/pref_registry_syncable.h"
31 #include "content/public/browser/interstitial_page.h" 32 #include "content/public/browser/interstitial_page.h"
32 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_contents_observer.h" 37 #include "content/public/browser/web_contents_observer.h"
37 #include "content/public/test/browser_test_utils.h" 38 #include "content/public/test/browser_test_utils.h"
38 #include "grit/generated_resources.h" 39 #include "grit/generated_resources.h"
40 #include "testing/gmock/include/gmock/gmock.h"
39 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
40 42
41 using content::InterstitialPage; 43 using content::InterstitialPage;
42 using content::NavigationController; 44 using content::NavigationController;
43 using content::NavigationEntry; 45 using content::NavigationEntry;
44 using content::WebContents; 46 using content::WebContents;
45 47
46 namespace { 48 namespace {
47 49
48 // Tests the filter mode in which all sites are blocked by default. 50 // Tests the filter mode in which all sites are blocked by default.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 base::RunLoop* run_loop, 152 base::RunLoop* run_loop,
151 HistoryService::Handle /* handle */, 153 HistoryService::Handle /* handle */,
152 history::QueryResults* results) { 154 history::QueryResults* results) {
153 results->Swap(new_results); 155 results->Swap(new_results);
154 run_loop->Quit(); // Will return out to QueryHistory. 156 run_loop->Quit(); // Will return out to QueryHistory.
155 } 157 }
156 158
157 ManagedUserService* managed_user_service_; 159 ManagedUserService* managed_user_service_;
158 }; 160 };
159 161
162 class MockTabStripModelObserver : public TabStripModelObserver {
163 public:
164 MOCK_METHOD3(TabClosingAt, void(TabStripModel*, content::WebContents*, int));
165 };
166
160 // Navigates to a blocked URL. 167 // Navigates to a blocked URL.
161 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 168 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
162 SendAccessRequestOnBlockedURL) { 169 SendAccessRequestOnBlockedURL) {
163 GURL test_url("http://www.example.com/files/simple.html"); 170 GURL test_url("http://www.example.com/files/simple.html");
164 ui_test_utils::NavigateToURL(browser(), test_url); 171 ui_test_utils::NavigateToURL(browser(), test_url);
165 172
166 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 173 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
167 174
168 CheckShownPageIsInterstitial(tab); 175 CheckShownPageIsInterstitial(tab);
169 176
170 SendAccessRequest(tab); 177 SendAccessRequest(tab);
171 178
172 // TODO(sergiu): Properly check that the access request was sent here. 179 // TODO(sergiu): Properly check that the access request was sent here.
173 180
174 GoBack(tab); 181 GoBack(tab);
175 182
183 // Make sure that the tab is still there.
184 EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents());
185
176 CheckShownPageIsNotInterstitial(tab); 186 CheckShownPageIsNotInterstitial(tab);
177 } 187 }
178 188
189 // Navigates to a blocked URL in a new tab. We expect the tab to be closed
190 // automatically on pressing the "back" button on the interstitial.
191 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, OpenBlockedURLInNewTab) {
192 TabStripModel* tab_strip = browser()->tab_strip_model();
193 WebContents* prev_tab = tab_strip->GetActiveWebContents();
194
195 // Open blocked URL in a new tab.
196 GURL test_url("http://www.example.com/files/simple.html");
197 ui_test_utils::NavigateToURLWithDisposition(
198 browser(), test_url, NEW_FOREGROUND_TAB,
199 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
200
201 // Check that we got the interstitial.
202 WebContents* tab = tab_strip->GetActiveWebContents();
203 CheckShownPageIsInterstitial(tab);
204
205 // On pressing the "back" button, the new tab should be closed, and we should
206 // get back to the previous active tab.
207 MockTabStripModelObserver observer;
208 tab_strip->AddObserver(&observer);
Bernhard Bauer 2014/04/25 08:30:13 You could move the AddObserver() and RemoveObserve
Marc Treib 2014/04/25 08:50:34 Done.
209 EXPECT_CALL(observer,
210 TabClosingAt(tab_strip, tab, tab_strip->active_index()));
211 GoBack(tab);
212 tab_strip->RemoveObserver(&observer);
213 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents());
214 }
215
179 // Tests whether a visit attempt adds a special history entry. 216 // Tests whether a visit attempt adds a special history entry.
180 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 217 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
181 HistoryVisitRecorded) { 218 HistoryVisitRecorded) {
182 GURL allowed_url("http://www.example.com/files/simple.html"); 219 GURL allowed_url("http://www.example.com/files/simple.html");
183 220
184 // Set the host as allowed. 221 // Set the host as allowed.
185 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 222 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
186 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true); 223 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
187 ManagedUserSettingsService* managed_user_settings_service = 224 ManagedUserSettingsService* managed_user_settings_service =
188 ManagedUserSettingsServiceFactory::GetForProfile( 225 ManagedUserSettingsServiceFactory::GetForProfile(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 dict.PassAs<base::Value>()); 294 dict.PassAs<base::Value>());
258 EXPECT_EQ( 295 EXPECT_EQ(
259 ManagedUserService::MANUAL_ALLOW, 296 ManagedUserService::MANUAL_ALLOW,
260 managed_user_service_->GetManualBehaviorForHost(test_url.host())); 297 managed_user_service_->GetManualBehaviorForHost(test_url.host()));
261 298
262 observer.Wait(); 299 observer.Wait();
263 EXPECT_EQ(test_url, web_contents->GetURL()); 300 EXPECT_EQ(test_url, web_contents->GetURL());
264 } 301 }
265 302
266 } // namespace 303 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698