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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2755013002: Removed webControllerDidSuppressDialog: callback. (Closed)
Patch Set: Self review Created 3 years, 9 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
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | ios/web/web_state/web_state_impl.h » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "ios/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 GetWebClient()->last_cert_error_ssl_info().cert_status); 277 GetWebClient()->last_cert_error_ssl_info().cert_status);
278 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url()); 278 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url());
279 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable()); 279 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable());
280 280
281 // Verify that |DidChangeVisibleSecurityState| was called. 281 // Verify that |DidChangeVisibleSecurityState| was called.
282 ASSERT_TRUE(observer.did_change_visible_security_state_info()); 282 ASSERT_TRUE(observer.did_change_visible_security_state_info());
283 EXPECT_EQ(web_state(), 283 EXPECT_EQ(web_state(),
284 observer.did_change_visible_security_state_info()->web_state); 284 observer.did_change_visible_security_state_info()->web_state);
285 } 285 }
286 286
287 // Test fixture to test |setPageDialogOpenPolicy:|. 287 // Test fixture to test |WebState::SetShouldSuppressDialogs|.
288 class CRWWebControllerPageDialogOpenPolicyTest 288 class DialogsSuppressionTest : public web::WebTestWithWebState {
289 : public web::WebTestWithWebController {
290 protected: 289 protected:
291 CRWWebControllerPageDialogOpenPolicyTest() 290 DialogsSuppressionTest() : page_url_("https://chromium.test/") {}
292 : page_url_("https://chromium.test/") {}
293 void SetUp() override { 291 void SetUp() override {
294 web::WebTestWithWebController::SetUp(); 292 web::WebTestWithWebState::SetUp();
295 LoadHtml(@"<html><body></body></html>", page_url_); 293 LoadHtml(@"<html><body></body></html>", page_url_);
296 web_delegate_mock_.reset(
297 [[OCMockObject mockForProtocol:@protocol(CRWWebDelegate)] retain]);
298 [web_controller() setDelegate:web_delegate_mock_];
299 web_state()->SetDelegate(&test_web_delegate_); 294 web_state()->SetDelegate(&test_web_delegate_);
300 } 295 }
301 void TearDown() override { 296 void TearDown() override {
302 WaitForBackgroundTasks();
303 EXPECT_OCMOCK_VERIFY(web_delegate_mock_);
304 [web_controller() setDelegate:nil];
305 web_state()->SetDelegate(nullptr); 297 web_state()->SetDelegate(nullptr);
306 298 web::WebTestWithWebState::TearDown();
307 web::WebTestWithWebController::TearDown();
308 } 299 }
309 id web_delegate_mock() { return web_delegate_mock_; };
310 web::TestJavaScriptDialogPresenter* js_dialog_presenter() { 300 web::TestJavaScriptDialogPresenter* js_dialog_presenter() {
311 return test_web_delegate_.GetTestJavaScriptDialogPresenter(); 301 return test_web_delegate_.GetTestJavaScriptDialogPresenter();
312 } 302 }
313 const std::vector<web::TestJavaScriptDialog>& requested_dialogs() { 303 const std::vector<web::TestJavaScriptDialog>& requested_dialogs() {
314 return js_dialog_presenter()->requested_dialogs(); 304 return js_dialog_presenter()->requested_dialogs();
315 } 305 }
316 const GURL& page_url() { return page_url_; } 306 const GURL& page_url() { return page_url_; }
317 307
318 private: 308 private:
319 web::TestWebStateDelegate test_web_delegate_; 309 web::TestWebStateDelegate test_web_delegate_;
320 base::scoped_nsprotocol<id> web_delegate_mock_;
321 GURL page_url_; 310 GURL page_url_;
322 }; 311 };
323 312
324 // Tests that window.alert dialog is suppressed for DIALOG_POLICY_SUPPRESS. 313 // Tests that window.alert dialog is suppressed.
325 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressAlert) { 314 TEST_F(DialogsSuppressionTest, SuppressAlert) {
326 [[web_delegate_mock() expect] 315 web::TestWebStateObserver observer(web_state());
327 webControllerDidSuppressDialog:web_controller()]; 316 ASSERT_FALSE(observer.did_suppress_dialog_info());
328 [web_controller() setShouldSuppressDialogs:YES]; 317 web_state()->SetShouldSuppressDialogs(true);
329 ExecuteJavaScript(@"alert('test')"); 318 ExecuteJavaScript(@"alert('test')");
319 ASSERT_TRUE(observer.did_suppress_dialog_info());
320 EXPECT_EQ(web_state(), observer.did_suppress_dialog_info()->web_state);
330 }; 321 };
331 322
332 // Tests that window.alert dialog is shown for DIALOG_POLICY_ALLOW. 323 // Tests that window.alert dialog is shown.
333 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowAlert) { 324 TEST_F(DialogsSuppressionTest, AllowAlert) {
325 web::TestWebStateObserver observer(web_state());
326 ASSERT_FALSE(observer.did_suppress_dialog_info());
334 ASSERT_TRUE(requested_dialogs().empty()); 327 ASSERT_TRUE(requested_dialogs().empty());
335 328
336 [web_controller() setShouldSuppressDialogs:NO]; 329 web_state()->SetShouldSuppressDialogs(false);
337 ExecuteJavaScript(@"alert('test')"); 330 ExecuteJavaScript(@"alert('test')");
338 331
339 ASSERT_EQ(1U, requested_dialogs().size()); 332 ASSERT_EQ(1U, requested_dialogs().size());
340 web::TestJavaScriptDialog dialog = requested_dialogs()[0]; 333 web::TestJavaScriptDialog dialog = requested_dialogs()[0];
341 EXPECT_EQ(web_state(), dialog.web_state); 334 EXPECT_EQ(web_state(), dialog.web_state);
342 EXPECT_EQ(page_url(), dialog.origin_url); 335 EXPECT_EQ(page_url(), dialog.origin_url);
343 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_ALERT, dialog.java_script_dialog_type); 336 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_ALERT, dialog.java_script_dialog_type);
344 EXPECT_NSEQ(@"test", dialog.message_text); 337 EXPECT_NSEQ(@"test", dialog.message_text);
345 EXPECT_FALSE(dialog.default_prompt_text); 338 EXPECT_FALSE(dialog.default_prompt_text);
339 ASSERT_FALSE(observer.did_suppress_dialog_info());
346 }; 340 };
347 341
348 // Tests that window.confirm dialog is suppressed for DIALOG_POLICY_SUPPRESS. 342 // Tests that window.confirm dialog is suppressed.
349 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressConfirm) { 343 TEST_F(DialogsSuppressionTest, SuppressConfirm) {
344 web::TestWebStateObserver observer(web_state());
345 ASSERT_FALSE(observer.did_suppress_dialog_info());
350 ASSERT_TRUE(requested_dialogs().empty()); 346 ASSERT_TRUE(requested_dialogs().empty());
351 347
352 [[web_delegate_mock() expect] 348 web_state()->SetShouldSuppressDialogs(true);
353 webControllerDidSuppressDialog:web_controller()];
354 [web_controller() setShouldSuppressDialogs:YES];
355 EXPECT_NSEQ(@NO, ExecuteJavaScript(@"confirm('test')")); 349 EXPECT_NSEQ(@NO, ExecuteJavaScript(@"confirm('test')"));
356 350
357 ASSERT_TRUE(requested_dialogs().empty()); 351 ASSERT_TRUE(requested_dialogs().empty());
352 ASSERT_TRUE(observer.did_suppress_dialog_info());
353 EXPECT_EQ(web_state(), observer.did_suppress_dialog_info()->web_state);
358 }; 354 };
359 355
360 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and 356 // Tests that window.confirm dialog is shown and its result is true.
361 // it's result is true. 357 TEST_F(DialogsSuppressionTest, AllowConfirmWithTrue) {
362 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithTrue) { 358 web::TestWebStateObserver observer(web_state());
359 ASSERT_FALSE(observer.did_suppress_dialog_info());
363 ASSERT_TRUE(requested_dialogs().empty()); 360 ASSERT_TRUE(requested_dialogs().empty());
364 361
365 js_dialog_presenter()->set_callback_success_argument(true); 362 js_dialog_presenter()->set_callback_success_argument(true);
366 363
367 [web_controller() setShouldSuppressDialogs:NO]; 364 web_state()->SetShouldSuppressDialogs(false);
368 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"confirm('test')")); 365 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"confirm('test')"));
369 366
370 ASSERT_EQ(1U, requested_dialogs().size()); 367 ASSERT_EQ(1U, requested_dialogs().size());
371 web::TestJavaScriptDialog dialog = requested_dialogs()[0]; 368 web::TestJavaScriptDialog dialog = requested_dialogs()[0];
372 EXPECT_EQ(web_state(), dialog.web_state); 369 EXPECT_EQ(web_state(), dialog.web_state);
373 EXPECT_EQ(page_url(), dialog.origin_url); 370 EXPECT_EQ(page_url(), dialog.origin_url);
374 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_CONFIRM, 371 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_CONFIRM,
375 dialog.java_script_dialog_type); 372 dialog.java_script_dialog_type);
376 EXPECT_NSEQ(@"test", dialog.message_text); 373 EXPECT_NSEQ(@"test", dialog.message_text);
377 EXPECT_FALSE(dialog.default_prompt_text); 374 EXPECT_FALSE(dialog.default_prompt_text);
375 ASSERT_FALSE(observer.did_suppress_dialog_info());
378 } 376 }
379 377
380 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and 378 // Tests that window.confirm dialog is shown and its result is false.
381 // it's result is false. 379 TEST_F(DialogsSuppressionTest, AllowConfirmWithFalse) {
382 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithFalse) { 380 web::TestWebStateObserver observer(web_state());
381 ASSERT_FALSE(observer.did_suppress_dialog_info());
383 ASSERT_TRUE(requested_dialogs().empty()); 382 ASSERT_TRUE(requested_dialogs().empty());
384 383
385 [web_controller() setShouldSuppressDialogs:NO]; 384 web_state()->SetShouldSuppressDialogs(false);
386 EXPECT_NSEQ(@NO, ExecuteJavaScript(@"confirm('test')")); 385 EXPECT_NSEQ(@NO, ExecuteJavaScript(@"confirm('test')"));
387 386
388 ASSERT_EQ(1U, requested_dialogs().size()); 387 ASSERT_EQ(1U, requested_dialogs().size());
389 web::TestJavaScriptDialog dialog = requested_dialogs()[0]; 388 web::TestJavaScriptDialog dialog = requested_dialogs()[0];
390 EXPECT_EQ(web_state(), dialog.web_state); 389 EXPECT_EQ(web_state(), dialog.web_state);
391 EXPECT_EQ(page_url(), dialog.origin_url); 390 EXPECT_EQ(page_url(), dialog.origin_url);
392 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_CONFIRM, 391 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_CONFIRM,
393 dialog.java_script_dialog_type); 392 dialog.java_script_dialog_type);
394 EXPECT_NSEQ(@"test", dialog.message_text); 393 EXPECT_NSEQ(@"test", dialog.message_text);
395 EXPECT_FALSE(dialog.default_prompt_text); 394 EXPECT_FALSE(dialog.default_prompt_text);
395 ASSERT_FALSE(observer.did_suppress_dialog_info());
396 } 396 }
397 397
398 // Tests that window.prompt dialog is suppressed for DIALOG_POLICY_SUPPRESS. 398 // Tests that window.prompt dialog is suppressed.
399 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressPrompt) { 399 TEST_F(DialogsSuppressionTest, SuppressPrompt) {
400 web::TestWebStateObserver observer(web_state());
401 ASSERT_FALSE(observer.did_suppress_dialog_info());
400 ASSERT_TRUE(requested_dialogs().empty()); 402 ASSERT_TRUE(requested_dialogs().empty());
401 403
402 [[web_delegate_mock() expect] 404 web_state()->SetShouldSuppressDialogs(true);
403 webControllerDidSuppressDialog:web_controller()];
404 [web_controller() setShouldSuppressDialogs:YES];
405 EXPECT_EQ([NSNull null], ExecuteJavaScript(@"prompt('Yes?', 'No')")); 405 EXPECT_EQ([NSNull null], ExecuteJavaScript(@"prompt('Yes?', 'No')"));
406 406
407 ASSERT_TRUE(requested_dialogs().empty()); 407 ASSERT_TRUE(requested_dialogs().empty());
408 ASSERT_TRUE(observer.did_suppress_dialog_info());
409 EXPECT_EQ(web_state(), observer.did_suppress_dialog_info()->web_state);
408 } 410 }
409 411
410 // Tests that window.prompt dialog is shown for DIALOG_POLICY_ALLOW. 412 // Tests that window.prompt dialog is shown.
411 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowPrompt) { 413 TEST_F(DialogsSuppressionTest, AllowPrompt) {
414 web::TestWebStateObserver observer(web_state());
415 ASSERT_FALSE(observer.did_suppress_dialog_info());
412 ASSERT_TRUE(requested_dialogs().empty()); 416 ASSERT_TRUE(requested_dialogs().empty());
413 417
414 js_dialog_presenter()->set_callback_user_input_argument(@"Maybe"); 418 js_dialog_presenter()->set_callback_user_input_argument(@"Maybe");
415 419
416 [web_controller() setShouldSuppressDialogs:NO]; 420 web_state()->SetShouldSuppressDialogs(false);
417 EXPECT_NSEQ(@"Maybe", ExecuteJavaScript(@"prompt('Yes?', 'No')")); 421 EXPECT_NSEQ(@"Maybe", ExecuteJavaScript(@"prompt('Yes?', 'No')"));
418 422
419 ASSERT_EQ(1U, requested_dialogs().size()); 423 ASSERT_EQ(1U, requested_dialogs().size());
420 web::TestJavaScriptDialog dialog = requested_dialogs()[0]; 424 web::TestJavaScriptDialog dialog = requested_dialogs()[0];
421 EXPECT_EQ(web_state(), dialog.web_state); 425 EXPECT_EQ(web_state(), dialog.web_state);
422 EXPECT_EQ(page_url(), dialog.origin_url); 426 EXPECT_EQ(page_url(), dialog.origin_url);
423 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_PROMPT, dialog.java_script_dialog_type); 427 EXPECT_EQ(web::JAVASCRIPT_DIALOG_TYPE_PROMPT, dialog.java_script_dialog_type);
424 EXPECT_NSEQ(@"Yes?", dialog.message_text); 428 EXPECT_NSEQ(@"Yes?", dialog.message_text);
425 EXPECT_NSEQ(@"No", dialog.default_prompt_text); 429 EXPECT_NSEQ(@"No", dialog.default_prompt_text);
430 ASSERT_FALSE(observer.did_suppress_dialog_info());
426 } 431 }
427 432
428 // Tests that geolocation dialog is suppressed for DIALOG_POLICY_SUPPRESS. 433 // Tests that geolocation dialog is suppressed.
429 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressGeolocation) { 434 TEST_F(DialogsSuppressionTest, SuppressGeolocation) {
430 // The geolocation APIs require HTTPS on iOS 10, which can not be simulated 435 // The geolocation APIs require HTTPS on iOS 10, which can not be simulated
431 // even using |loadHTMLString:baseURL:| WKWebView API. 436 // even using |loadHTMLString:baseURL:| WKWebView API.
432 if (base::ios::IsRunningOnIOS10OrLater()) { 437 if (base::ios::IsRunningOnIOS10OrLater()) {
433 return; 438 return;
434 } 439 }
440 web::TestWebStateObserver observer(web_state());
441 ASSERT_FALSE(observer.did_suppress_dialog_info());
442 ASSERT_TRUE(requested_dialogs().empty());
435 443
436 [[web_delegate_mock() expect] 444 web_state()->SetShouldSuppressDialogs(true);
437 webControllerDidSuppressDialog:web_controller()];
438 [web_controller() setShouldSuppressDialogs:YES];
439 ExecuteJavaScript(@"navigator.geolocation.getCurrentPosition()"); 445 ExecuteJavaScript(@"navigator.geolocation.getCurrentPosition()");
446 ASSERT_TRUE(observer.did_suppress_dialog_info());
447 EXPECT_EQ(web_state(), observer.did_suppress_dialog_info()->web_state);
440 } 448 }
441 449
442 // Tests that window.open is suppressed for DIALOG_POLICY_SUPPRESS. 450 // Tests that window.open is suppressed.
443 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressWindowOpen) { 451 TEST_F(DialogsSuppressionTest, SuppressWindowOpen) {
444 [[web_delegate_mock() expect] 452 web::TestWebStateObserver observer(web_state());
445 webControllerDidSuppressDialog:web_controller()]; 453 ASSERT_FALSE(observer.did_suppress_dialog_info());
446 [web_controller() setShouldSuppressDialogs:YES]; 454 ASSERT_TRUE(requested_dialogs().empty());
455
456 web_state()->SetShouldSuppressDialogs(true);
447 ExecuteJavaScript(@"window.open('')"); 457 ExecuteJavaScript(@"window.open('')");
458
459 ASSERT_TRUE(observer.did_suppress_dialog_info());
460 EXPECT_EQ(web_state(), observer.did_suppress_dialog_info()->web_state);
448 } 461 }
449 462
450 // A separate test class, as none of the |CRWWebControllerTest| setup is 463 // A separate test class, as none of the |CRWWebControllerTest| setup is
451 // needed. 464 // needed.
452 class CRWWebControllerPageScrollStateTest 465 class CRWWebControllerPageScrollStateTest
453 : public web::WebTestWithWebController { 466 : public web::WebTestWithWebController {
454 protected: 467 protected:
455 // Returns a web::PageDisplayState that will scroll a WKWebView to 468 // Returns a web::PageDisplayState that will scroll a WKWebView to
456 // |scrollOffset| and zoom the content by |relativeZoomScale|. 469 // |scrollOffset| and zoom the content by |relativeZoomScale|.
457 inline web::PageDisplayState CreateTestPageDisplayState( 470 inline web::PageDisplayState CreateTestPageDisplayState(
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 web::TestWebStateObserver* observer_ptr = &observer; 968 web::TestWebStateObserver* observer_ptr = &observer;
956 web::SimulateWKWebViewCrash(webView_); 969 web::SimulateWKWebViewCrash(webView_);
957 base::test::ios::WaitUntilCondition(^bool() { 970 base::test::ios::WaitUntilCondition(^bool() {
958 return observer_ptr->render_process_gone_info(); 971 return observer_ptr->render_process_gone_info();
959 }); 972 });
960 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); 973 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state);
961 EXPECT_FALSE([web_controller() isViewAlive]); 974 EXPECT_FALSE([web_controller() isViewAlive]);
962 }; 975 };
963 976
964 } // namespace 977 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | ios/web/web_state/web_state_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698