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

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

Issue 2737353006: Replaced webPageOrderedClose with WebStateDelegate API. (Closed)
Patch Set: Addressed review comments 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_delegate.mm » ('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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 835
836 void SetUp() override { 836 void SetUp() override {
837 WebTestWithWebController::SetUp(); 837 WebTestWithWebController::SetUp();
838 web_state()->SetDelegate(&delegate_); 838 web_state()->SetDelegate(&delegate_);
839 LoadHtml(@"<html><body></body></html>", opener_url_); 839 LoadHtml(@"<html><body></body></html>", opener_url_);
840 } 840 }
841 // Executes JavaScript that opens a new window and returns evaluation result 841 // Executes JavaScript that opens a new window and returns evaluation result
842 // as a string. 842 // as a string.
843 id OpenWindowByDom() { 843 id OpenWindowByDom() {
844 NSString* const kOpenWindowScript = 844 NSString* const kOpenWindowScript =
845 @"var w = window.open('javascript:void(0);', target='_blank');" 845 @"w = window.open('javascript:void(0);', target='_blank');"
846 "w ? w.toString() : null;"; 846 "w ? w.toString() : null;";
847 id windowJSObject = ExecuteJavaScript(kOpenWindowScript); 847 id windowJSObject = ExecuteJavaScript(kOpenWindowScript);
848 WaitForBackgroundTasks();
849 return windowJSObject; 848 return windowJSObject;
850 } 849 }
850
851 // Executes JavaScript that closes previously opened window.
852 void CloseWindow() { ExecuteJavaScript(@"w.close()"); }
853
851 // URL of a page which opens child windows. 854 // URL of a page which opens child windows.
852 const GURL opener_url_; 855 const GURL opener_url_;
853 web::TestWebStateDelegate delegate_; 856 web::TestWebStateDelegate delegate_;
854 }; 857 };
855 858
856 // Tests that absence of web state delegate is handled gracefully. 859 // Tests that absence of web state delegate is handled gracefully.
857 TEST_F(WindowOpenByDomTest, NoDelegate) { 860 TEST_F(WindowOpenByDomTest, NoDelegate) {
858 web_state()->SetDelegate(nullptr); 861 web_state()->SetDelegate(nullptr);
859 862
860 EXPECT_NSEQ([NSNull null], OpenWindowByDom()); 863 EXPECT_NSEQ([NSNull null], OpenWindowByDom());
(...skipping 29 matching lines...) Expand all
890 // that delegate allows popups. 893 // that delegate allows popups.
891 TEST_F(WindowOpenByDomTest, DontBlockPopup) { 894 TEST_F(WindowOpenByDomTest, DontBlockPopup) {
892 delegate_.allow_popups(opener_url_); 895 delegate_.allow_popups(opener_url_);
893 EXPECT_NSEQ(@"[object Window]", OpenWindowByDom()); 896 EXPECT_NSEQ(@"[object Window]", OpenWindowByDom());
894 897
895 ASSERT_EQ(1U, delegate_.child_windows().size()); 898 ASSERT_EQ(1U, delegate_.child_windows().size());
896 ASSERT_TRUE(delegate_.child_windows()[0]); 899 ASSERT_TRUE(delegate_.child_windows()[0]);
897 EXPECT_TRUE(delegate_.popups().empty()); 900 EXPECT_TRUE(delegate_.popups().empty());
898 } 901 }
899 902
903 // Tests that window.close closes the web state.
904 TEST_F(WindowOpenByDomTest, CloseWindow) {
905 delegate_.allow_popups(opener_url_);
906 ASSERT_NSEQ(@"[object Window]", OpenWindowByDom());
907
908 ASSERT_EQ(1U, delegate_.child_windows().size());
909 ASSERT_TRUE(delegate_.child_windows()[0]);
910 EXPECT_TRUE(delegate_.popups().empty());
911
912 delegate_.child_windows()[0]->SetDelegate(&delegate_);
913 CloseWindow();
914
915 EXPECT_TRUE(delegate_.child_windows().empty());
916 EXPECT_TRUE(delegate_.popups().empty());
917 }
918
900 // Tests page title changes. 919 // Tests page title changes.
901 typedef web::WebTestWithWebState CRWWebControllerTitleTest; 920 typedef web::WebTestWithWebState CRWWebControllerTitleTest;
902 TEST_F(CRWWebControllerTitleTest, TitleChange) { 921 TEST_F(CRWWebControllerTitleTest, TitleChange) {
903 // Observes and waits for TitleWasSet call. 922 // Observes and waits for TitleWasSet call.
904 class TitleObserver : public web::WebStateObserver { 923 class TitleObserver : public web::WebStateObserver {
905 public: 924 public:
906 explicit TitleObserver(web::WebState* web_state) 925 explicit TitleObserver(web::WebState* web_state)
907 : web::WebStateObserver(web_state) {} 926 : web::WebStateObserver(web_state) {}
908 // Returns number of times |TitleWasSet| was called. 927 // Returns number of times |TitleWasSet| was called.
909 int title_change_count() { return title_change_count_; } 928 int title_change_count() { return title_change_count_; }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 web::TestWebStateObserver* observer_ptr = &observer; 976 web::TestWebStateObserver* observer_ptr = &observer;
958 web::SimulateWKWebViewCrash(webView_); 977 web::SimulateWKWebViewCrash(webView_);
959 base::test::ios::WaitUntilCondition(^bool() { 978 base::test::ios::WaitUntilCondition(^bool() {
960 return observer_ptr->render_process_gone_info(); 979 return observer_ptr->render_process_gone_info();
961 }); 980 });
962 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); 981 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state);
963 EXPECT_FALSE([web_controller() isViewAlive]); 982 EXPECT_FALSE([web_controller() isViewAlive]);
964 }; 983 };
965 984
966 } // namespace 985 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | ios/web/web_state/web_state_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698