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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_browsertest.cc

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 SupervisedUserSettingsService* supervised_user_settings_service = 109 SupervisedUserSettingsService* supervised_user_settings_service =
110 SupervisedUserSettingsServiceFactory::GetForProfile(profile); 110 SupervisedUserSettingsServiceFactory::GetForProfile(profile);
111 supervised_user_settings_service->SetLocalSetting( 111 supervised_user_settings_service->SetLocalSetting(
112 supervised_users::kContentPackDefaultFilteringBehavior, 112 supervised_users::kContentPackDefaultFilteringBehavior,
113 scoped_ptr<base::Value>( 113 scoped_ptr<base::Value>(
114 new base::FundamentalValue(SupervisedUserURLFilter::BLOCK))); 114 new base::FundamentalValue(SupervisedUserURLFilter::BLOCK)));
115 } 115 }
116 116
117 void SetUpCommandLine(base::CommandLine* command_line) override { 117 void SetUpCommandLine(base::CommandLine* command_line) override {
118 // Enable the test server and remap all URLs to it. 118 // Enable the test server and remap all URLs to it.
119 ASSERT_TRUE(test_server()->Start()); 119 ASSERT_TRUE(embedded_test_server()->Start());
120 std::string host_port = test_server()->host_port_pair().ToString(); 120 std::string host_port = embedded_test_server()->host_port_pair().ToString();
121 command_line->AppendSwitchASCII(switches::kHostResolverRules, 121 command_line->AppendSwitchASCII(switches::kHostResolverRules,
122 "MAP *.example.com " + host_port + "," + 122 "MAP *.example.com " + host_port + "," +
123 "MAP *.new-example.com " + host_port + "," + 123 "MAP *.new-example.com " + host_port + "," +
124 "MAP *.a.com " + host_port); 124 "MAP *.a.com " + host_port);
125 125
126 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); 126 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
127 } 127 }
128 128
129 // Acts like a synchronous call to history's QueryHistory. Modified from 129 // Acts like a synchronous call to history's QueryHistory. Modified from
130 // history_querying_unittest.cc. 130 // history_querying_unittest.cc.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 MOCK_METHOD3(TabClosingAt, void(TabStripModel*, content::WebContents*, int)); 169 MOCK_METHOD3(TabClosingAt, void(TabStripModel*, content::WebContents*, int));
170 170
171 private: 171 private:
172 TabStripModel* tab_strip_; 172 TabStripModel* tab_strip_;
173 }; 173 };
174 174
175 // Navigates to a blocked URL. 175 // Navigates to a blocked URL.
176 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, 176 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
177 SendAccessRequestOnBlockedURL) { 177 SendAccessRequestOnBlockedURL) {
178 GURL test_url("http://www.example.com/files/simple.html"); 178 GURL test_url("http://www.example.com/simple.html");
179 ui_test_utils::NavigateToURL(browser(), test_url); 179 ui_test_utils::NavigateToURL(browser(), test_url);
180 180
181 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 181 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
182 182
183 CheckShownPageIsInterstitial(tab); 183 CheckShownPageIsInterstitial(tab);
184 184
185 SendAccessRequest(tab); 185 SendAccessRequest(tab);
186 186
187 // TODO(sergiu): Properly check that the access request was sent here. 187 // TODO(sergiu): Properly check that the access request was sent here.
188 188
189 GoBack(tab); 189 GoBack(tab);
190 190
191 // Make sure that the tab is still there. 191 // Make sure that the tab is still there.
192 EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents()); 192 EXPECT_EQ(tab, browser()->tab_strip_model()->GetActiveWebContents());
193 193
194 CheckShownPageIsNotInterstitial(tab); 194 CheckShownPageIsNotInterstitial(tab);
195 } 195 }
196 196
197 // Navigates to a blocked URL in a new tab. We expect the tab to be closed 197 // Navigates to a blocked URL in a new tab. We expect the tab to be closed
198 // automatically on pressing the "back" button on the interstitial. 198 // automatically on pressing the "back" button on the interstitial.
199 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, OpenBlockedURLInNewTab) { 199 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, OpenBlockedURLInNewTab) {
200 TabStripModel* tab_strip = browser()->tab_strip_model(); 200 TabStripModel* tab_strip = browser()->tab_strip_model();
201 WebContents* prev_tab = tab_strip->GetActiveWebContents(); 201 WebContents* prev_tab = tab_strip->GetActiveWebContents();
202 202
203 // Open blocked URL in a new tab. 203 // Open blocked URL in a new tab.
204 GURL test_url("http://www.example.com/files/simple.html"); 204 GURL test_url("http://www.example.com/simple.html");
205 ui_test_utils::NavigateToURLWithDisposition( 205 ui_test_utils::NavigateToURLWithDisposition(
206 browser(), test_url, NEW_FOREGROUND_TAB, 206 browser(), test_url, NEW_FOREGROUND_TAB,
207 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 207 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
208 208
209 // Check that we got the interstitial. 209 // Check that we got the interstitial.
210 WebContents* tab = tab_strip->GetActiveWebContents(); 210 WebContents* tab = tab_strip->GetActiveWebContents();
211 CheckShownPageIsInterstitial(tab); 211 CheckShownPageIsInterstitial(tab);
212 212
213 // On pressing the "back" button, the new tab should be closed, and we should 213 // On pressing the "back" button, the new tab should be closed, and we should
214 // get back to the previous active tab. 214 // get back to the previous active tab.
215 MockTabStripModelObserver observer(tab_strip); 215 MockTabStripModelObserver observer(tab_strip);
216 base::RunLoop run_loop; 216 base::RunLoop run_loop;
217 EXPECT_CALL(observer, 217 EXPECT_CALL(observer,
218 TabClosingAt(tab_strip, tab, tab_strip->active_index())) 218 TabClosingAt(tab_strip, tab, tab_strip->active_index()))
219 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 219 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
220 GoBack(tab); 220 GoBack(tab);
221 run_loop.Run(); 221 run_loop.Run();
222 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents()); 222 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents());
223 } 223 }
224 224
225 // Tests whether a visit attempt adds a special history entry. 225 // Tests whether a visit attempt adds a special history entry.
226 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, 226 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
227 HistoryVisitRecorded) { 227 HistoryVisitRecorded) {
228 GURL allowed_url("http://www.example.com/files/simple.html"); 228 GURL allowed_url("http://www.example.com/simple.html");
229 229
230 scoped_refptr<SupervisedUserURLFilter> filter = 230 scoped_refptr<SupervisedUserURLFilter> filter =
231 supervised_user_service_->GetURLFilterForUIThread(); 231 supervised_user_service_->GetURLFilterForUIThread();
232 232
233 // Set the host as allowed. 233 // Set the host as allowed.
234 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 234 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
235 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true); 235 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
236 SupervisedUserSettingsService* supervised_user_settings_service = 236 SupervisedUserSettingsService* supervised_user_settings_service =
237 SupervisedUserSettingsServiceFactory::GetForProfile( 237 SupervisedUserSettingsServiceFactory::GetForProfile(
238 browser()->profile()); 238 browser()->profile());
239 supervised_user_settings_service->SetLocalSetting( 239 supervised_user_settings_service->SetLocalSetting(
240 supervised_users::kContentPackManualBehaviorHosts, dict.Pass()); 240 supervised_users::kContentPackManualBehaviorHosts, dict.Pass());
241 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 241 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
242 filter->GetFilteringBehaviorForURL(allowed_url)); 242 filter->GetFilteringBehaviorForURL(allowed_url));
243 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 243 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
244 filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath())); 244 filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath()));
245 245
246 ui_test_utils::NavigateToURL(browser(), allowed_url); 246 ui_test_utils::NavigateToURL(browser(), allowed_url);
247 247
248 // Navigate to it and check that we don't get an interstitial. 248 // Navigate to it and check that we don't get an interstitial.
249 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 249 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
250 CheckShownPageIsNotInterstitial(tab); 250 CheckShownPageIsNotInterstitial(tab);
251 251
252 // Navigate to a blocked page and go back on the interstitial. 252 // Navigate to a blocked page and go back on the interstitial.
253 GURL blocked_url("http://www.new-example.com/files/simple.html"); 253 GURL blocked_url("http://www.new-example.com/simple.html");
254 ui_test_utils::NavigateToURL(browser(), blocked_url); 254 ui_test_utils::NavigateToURL(browser(), blocked_url);
255 255
256 tab = browser()->tab_strip_model()->GetActiveWebContents(); 256 tab = browser()->tab_strip_model()->GetActiveWebContents();
257 257
258 CheckShownPageIsInterstitial(tab); 258 CheckShownPageIsInterstitial(tab);
259 GoBack(tab); 259 GoBack(tab);
260 260
261 // Check that we went back to the first URL and that the manual behaviors 261 // Check that we went back to the first URL and that the manual behaviors
262 // have not changed. 262 // have not changed.
263 EXPECT_EQ(allowed_url.spec(), tab->GetURL().spec()); 263 EXPECT_EQ(allowed_url.spec(), tab->GetURL().spec());
(...skipping 12 matching lines...) Expand all
276 276
277 // Check that the entries have the correct blocked_visit value. 277 // Check that the entries have the correct blocked_visit value.
278 ASSERT_EQ(2u, results.size()); 278 ASSERT_EQ(2u, results.size());
279 EXPECT_EQ(blocked_url.spec(), results[0].url().spec()); 279 EXPECT_EQ(blocked_url.spec(), results[0].url().spec());
280 EXPECT_TRUE(results[0].blocked_visit()); 280 EXPECT_TRUE(results[0].blocked_visit());
281 EXPECT_EQ(allowed_url.spec(), results[1].url().spec()); 281 EXPECT_EQ(allowed_url.spec(), results[1].url().spec());
282 EXPECT_FALSE(results[1].blocked_visit()); 282 EXPECT_FALSE(results[1].blocked_visit());
283 } 283 }
284 284
285 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, Unblock) { 285 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, Unblock) {
286 GURL test_url("http://www.example.com/files/simple.html"); 286 GURL test_url("http://www.example.com/simple.html");
287 ui_test_utils::NavigateToURL(browser(), test_url); 287 ui_test_utils::NavigateToURL(browser(), test_url);
288 288
289 WebContents* web_contents = 289 WebContents* web_contents =
290 browser()->tab_strip_model()->GetActiveWebContents(); 290 browser()->tab_strip_model()->GetActiveWebContents();
291 291
292 CheckShownPageIsInterstitial(web_contents); 292 CheckShownPageIsInterstitial(web_contents);
293 293
294 content::WindowedNotificationObserver observer( 294 content::WindowedNotificationObserver observer(
295 content::NOTIFICATION_LOAD_STOP, 295 content::NOTIFICATION_LOAD_STOP,
296 content::NotificationService::AllSources()); 296 content::NotificationService::AllSources());
(...skipping 10 matching lines...) Expand all
307 scoped_refptr<SupervisedUserURLFilter> filter = 307 scoped_refptr<SupervisedUserURLFilter> filter =
308 supervised_user_service_->GetURLFilterForUIThread(); 308 supervised_user_service_->GetURLFilterForUIThread();
309 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 309 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
310 filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath())); 310 filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath()));
311 311
312 observer.Wait(); 312 observer.Wait();
313 EXPECT_EQ(test_url, web_contents->GetURL()); 313 EXPECT_EQ(test_url, web_contents->GetURL());
314 } 314 }
315 315
316 } // namespace 316 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/storage/durable_storage_browsertest.cc ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698