| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 ExecuteJavaScript(@"__gCrWeb['windowId'] = '';"); | 634 ExecuteJavaScript(@"__gCrWeb['windowId'] = '';"); |
| 635 | 635 |
| 636 // Script is not evaluated because of windowID mismatch. | 636 // Script is not evaluated because of windowID mismatch. |
| 637 ExecuteJavaScript(@"window.test2 = '2';"); | 637 ExecuteJavaScript(@"window.test2 = '2';"); |
| 638 EXPECT_FALSE(ExecuteJavaScript(@"window.test2")); | 638 EXPECT_FALSE(ExecuteJavaScript(@"window.test2")); |
| 639 } | 639 } |
| 640 | 640 |
| 641 TEST_F(CRWWebControllerTest, WebUrlWithTrustLevel) { | 641 TEST_F(CRWWebControllerTest, WebUrlWithTrustLevel) { |
| 642 [web_controller() webStateImpl]->GetNavigationManagerImpl().AddPendingItem( | 642 [web_controller() webStateImpl]->GetNavigationManagerImpl().AddPendingItem( |
| 643 GURL("http://chromium.test"), web::Referrer(), ui::PAGE_TRANSITION_TYPED, | 643 GURL("http://chromium.test"), web::Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 644 web::NavigationInitiationType::USER_INITIATED); | 644 web::NavigationInitiationType::USER_INITIATED, |
| 645 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 645 | 646 |
| 646 [[[mock_web_view_ stub] andReturnBool:NO] hasOnlySecureContent]; | 647 [[[mock_web_view_ stub] andReturnBool:NO] hasOnlySecureContent]; |
| 647 [[[mock_web_view_ stub] andReturn:@""] title]; | 648 [[[mock_web_view_ stub] andReturn:@""] title]; |
| 648 | 649 |
| 649 // Stub out the injection process. | 650 // Stub out the injection process. |
| 650 [[mock_web_view_ stub] evaluateJavaScript:OCMOCK_ANY | 651 [[mock_web_view_ stub] evaluateJavaScript:OCMOCK_ANY |
| 651 completionHandler:OCMOCK_ANY]; | 652 completionHandler:OCMOCK_ANY]; |
| 652 | 653 |
| 653 // Simulate registering load request to avoid failing page load simulation. | 654 // Simulate registering load request to avoid failing page load simulation. |
| 654 [web_controller() simulateLoadRequestWithURL:GURL(kTestURLString)]; | 655 [web_controller() simulateLoadRequestWithURL:GURL(kTestURLString)]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 671 web::WebTestWithWebController::SetUp(); | 672 web::WebTestWithWebController::SetUp(); |
| 672 mock_native_provider_.reset([[TestNativeContentProvider alloc] init]); | 673 mock_native_provider_.reset([[TestNativeContentProvider alloc] init]); |
| 673 [web_controller() setNativeProvider:mock_native_provider_]; | 674 [web_controller() setNativeProvider:mock_native_provider_]; |
| 674 } | 675 } |
| 675 | 676 |
| 676 void Load(const GURL& URL) { | 677 void Load(const GURL& URL) { |
| 677 NavigationManagerImpl& navigation_manager = | 678 NavigationManagerImpl& navigation_manager = |
| 678 [web_controller() webStateImpl]->GetNavigationManagerImpl(); | 679 [web_controller() webStateImpl]->GetNavigationManagerImpl(); |
| 679 navigation_manager.AddPendingItem( | 680 navigation_manager.AddPendingItem( |
| 680 URL, web::Referrer(), ui::PAGE_TRANSITION_TYPED, | 681 URL, web::Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 681 web::NavigationInitiationType::USER_INITIATED); | 682 web::NavigationInitiationType::USER_INITIATED, |
| 683 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 682 [web_controller() loadCurrentURL]; | 684 [web_controller() loadCurrentURL]; |
| 683 } | 685 } |
| 684 | 686 |
| 685 base::scoped_nsobject<TestNativeContentProvider> mock_native_provider_; | 687 base::scoped_nsobject<TestNativeContentProvider> mock_native_provider_; |
| 686 }; | 688 }; |
| 687 | 689 |
| 688 // Tests WebState and NavigationManager correctly return native content URL. | 690 // Tests WebState and NavigationManager correctly return native content URL. |
| 689 TEST_F(CRWWebControllerNativeContentTest, NativeContentURL) { | 691 TEST_F(CRWWebControllerNativeContentTest, NativeContentURL) { |
| 690 GURL url_to_load(kTestAppSpecificURL); | 692 GURL url_to_load(kTestAppSpecificURL); |
| 691 base::scoped_nsobject<TestNativeContent> content( | 693 base::scoped_nsobject<TestNativeContent> content( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 | 918 |
| 917 // Tests evaluating user script on app-specific page. Pages with app-specific | 919 // Tests evaluating user script on app-specific page. Pages with app-specific |
| 918 // URLs have elevated privileges and JavaScript execution should not be allowed | 920 // URLs have elevated privileges and JavaScript execution should not be allowed |
| 919 // for them. | 921 // for them. |
| 920 TEST_F(ScriptExecutionTest, UserScriptOnAppSpecificPage) { | 922 TEST_F(ScriptExecutionTest, UserScriptOnAppSpecificPage) { |
| 921 LoadHtml(@"<html></html>", GURL(kTestURLString)); | 923 LoadHtml(@"<html></html>", GURL(kTestURLString)); |
| 922 | 924 |
| 923 // Change last committed URL to app-specific URL. | 925 // Change last committed URL to app-specific URL. |
| 924 web::NavigationManagerImpl& nav_manager = | 926 web::NavigationManagerImpl& nav_manager = |
| 925 [web_controller() webStateImpl]->GetNavigationManagerImpl(); | 927 [web_controller() webStateImpl]->GetNavigationManagerImpl(); |
| 926 nav_manager.AddPendingItem(GURL(kTestAppSpecificURL), web::Referrer(), | 928 nav_manager.AddPendingItem( |
| 927 ui::PAGE_TRANSITION_TYPED, | 929 GURL(kTestAppSpecificURL), web::Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 928 web::NavigationInitiationType::USER_INITIATED); | 930 web::NavigationInitiationType::USER_INITIATED, |
| 931 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 929 [nav_manager.GetSessionController() commitPendingItem]; | 932 [nav_manager.GetSessionController() commitPendingItem]; |
| 930 | 933 |
| 931 NSError* error = nil; | 934 NSError* error = nil; |
| 932 EXPECT_FALSE(ExecuteUserJavaScript(@"window.w = 0;", &error)); | 935 EXPECT_FALSE(ExecuteUserJavaScript(@"window.w = 0;", &error)); |
| 933 ASSERT_TRUE(error); | 936 ASSERT_TRUE(error); |
| 934 EXPECT_NSEQ(web::kJSEvaluationErrorDomain, error.domain); | 937 EXPECT_NSEQ(web::kJSEvaluationErrorDomain, error.domain); |
| 935 EXPECT_EQ(web::JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW, error.code); | 938 EXPECT_EQ(web::JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW, error.code); |
| 936 | 939 |
| 937 EXPECT_FALSE(ExecuteJavaScript(@"window.w")); | 940 EXPECT_FALSE(ExecuteJavaScript(@"window.w")); |
| 938 }; | 941 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 962 web::TestWebStateObserver* observer_ptr = &observer; | 965 web::TestWebStateObserver* observer_ptr = &observer; |
| 963 web::SimulateWKWebViewCrash(webView_); | 966 web::SimulateWKWebViewCrash(webView_); |
| 964 base::test::ios::WaitUntilCondition(^bool() { | 967 base::test::ios::WaitUntilCondition(^bool() { |
| 965 return observer_ptr->render_process_gone_info(); | 968 return observer_ptr->render_process_gone_info(); |
| 966 }); | 969 }); |
| 967 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); | 970 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); |
| 968 EXPECT_FALSE([web_controller() isViewAlive]); | 971 EXPECT_FALSE([web_controller() isViewAlive]); |
| 969 }; | 972 }; |
| 970 | 973 |
| 971 } // namespace | 974 } // namespace |
| OLD | NEW |