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

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: Typo fix. (Also rebase) Created 6 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/managed_mode/managed_mode_interstitial.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 explicit MockTabStripModelObserver(TabStripModel* tab_strip)
165 : tab_strip_(tab_strip) {
166 tab_strip_->AddObserver(this);
167 }
168
169 ~MockTabStripModelObserver() {
170 tab_strip_->RemoveObserver(this);
171 }
172
173 MOCK_METHOD3(TabClosingAt, void(TabStripModel*, content::WebContents*, int));
174
175 private:
176 TabStripModel* tab_strip_;
177 };
178
160 // Navigates to a blocked URL. 179 // Navigates to a blocked URL.
161 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 180 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
162 SendAccessRequestOnBlockedURL) { 181 SendAccessRequestOnBlockedURL) {
163 GURL test_url("http://www.example.com/files/simple.html"); 182 GURL test_url("http://www.example.com/files/simple.html");
164 ui_test_utils::NavigateToURL(browser(), test_url); 183 ui_test_utils::NavigateToURL(browser(), test_url);
165 184
166 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 185 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
167 186
168 CheckShownPageIsInterstitial(tab); 187 CheckShownPageIsInterstitial(tab);
169 188
170 SendAccessRequest(tab); 189 SendAccessRequest(tab);
171 190
172 // TODO(sergiu): Properly check that the access request was sent here. 191 // TODO(sergiu): Properly check that the access request was sent here.
173 192
174 GoBack(tab); 193 GoBack(tab);
175 194
195 // Make sure that the tab is still there.
196 EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents());
197
176 CheckShownPageIsNotInterstitial(tab); 198 CheckShownPageIsNotInterstitial(tab);
177 } 199 }
178 200
201 // Navigates to a blocked URL in a new tab. We expect the tab to be closed
202 // automatically on pressing the "back" button on the interstitial.
203 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, OpenBlockedURLInNewTab) {
204 TabStripModel* tab_strip = browser()->tab_strip_model();
205 WebContents* prev_tab = tab_strip->GetActiveWebContents();
206
207 // Open blocked URL in a new tab.
208 GURL test_url("http://www.example.com/files/simple.html");
209 ui_test_utils::NavigateToURLWithDisposition(
210 browser(), test_url, NEW_FOREGROUND_TAB,
211 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
212
213 // Check that we got the interstitial.
214 WebContents* tab = tab_strip->GetActiveWebContents();
215 CheckShownPageIsInterstitial(tab);
216
217 // On pressing the "back" button, the new tab should be closed, and we should
218 // get back to the previous active tab.
219 MockTabStripModelObserver observer(tab_strip);
220 EXPECT_CALL(observer,
221 TabClosingAt(tab_strip, tab, tab_strip->active_index()));
222 GoBack(tab);
223 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents());
224 }
225
179 // Tests whether a visit attempt adds a special history entry. 226 // Tests whether a visit attempt adds a special history entry.
180 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 227 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
181 HistoryVisitRecorded) { 228 HistoryVisitRecorded) {
182 GURL allowed_url("http://www.example.com/files/simple.html"); 229 GURL allowed_url("http://www.example.com/files/simple.html");
183 230
184 // Set the host as allowed. 231 // Set the host as allowed.
185 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 232 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
186 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true); 233 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
187 ManagedUserSettingsService* managed_user_settings_service = 234 ManagedUserSettingsService* managed_user_settings_service =
188 ManagedUserSettingsServiceFactory::GetForProfile( 235 ManagedUserSettingsServiceFactory::GetForProfile(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 dict.PassAs<base::Value>()); 304 dict.PassAs<base::Value>());
258 EXPECT_EQ( 305 EXPECT_EQ(
259 ManagedUserService::MANUAL_ALLOW, 306 ManagedUserService::MANUAL_ALLOW,
260 managed_user_service_->GetManualBehaviorForHost(test_url.host())); 307 managed_user_service_->GetManualBehaviorForHost(test_url.host()));
261 308
262 observer.Wait(); 309 observer.Wait();
263 EXPECT_EQ(test_url, web_contents->GetURL()); 310 EXPECT_EQ(test_url, web_contents->GetURL());
264 } 311 }
265 312
266 } // namespace 313 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/managed_mode/managed_mode_interstitial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698