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