| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/public/web_state/web_state_delegate_bridge.h" | 5 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #import "ios/web/public/test/fakes/test_web_state.h" |
| 11 #import "ios/web/public/web_state/context_menu_params.h" | 12 #import "ios/web/public/web_state/context_menu_params.h" |
| 12 #import "ios/web/web_state/web_state_delegate_stub.h" | 13 #import "ios/web/web_state/web_state_delegate_stub.h" |
| 13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 14 #import "third_party/ocmock/gtest_support.h" | 15 #import "third_party/ocmock/gtest_support.h" |
| 16 #include "ui/base/page_transition_types.h" |
| 15 | 17 |
| 16 namespace web { | 18 namespace web { |
| 17 | 19 |
| 18 // Test fixture to test WebStateDelegateBridge class. | 20 // Test fixture to test WebStateDelegateBridge class. |
| 19 class WebStateDelegateBridgeTest : public PlatformTest { | 21 class WebStateDelegateBridgeTest : public PlatformTest { |
| 20 protected: | 22 protected: |
| 21 void SetUp() override { | 23 void SetUp() override { |
| 22 PlatformTest::SetUp(); | 24 PlatformTest::SetUp(); |
| 23 | 25 |
| 24 id originalMockDelegate = | 26 id originalMockDelegate = |
| 25 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)]; | 27 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)]; |
| 26 delegate_.reset([[CRWWebStateDelegateStub alloc] | 28 delegate_.reset([[CRWWebStateDelegateStub alloc] |
| 27 initWithRepresentedObject:originalMockDelegate]); | 29 initWithRepresentedObject:originalMockDelegate]); |
| 28 | 30 |
| 29 bridge_.reset(new WebStateDelegateBridge(delegate_.get())); | 31 bridge_.reset(new WebStateDelegateBridge(delegate_.get())); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void TearDown() override { | 34 void TearDown() override { |
| 33 EXPECT_OCMOCK_VERIFY(delegate_); | 35 EXPECT_OCMOCK_VERIFY(delegate_); |
| 34 PlatformTest::TearDown(); | 36 PlatformTest::TearDown(); |
| 35 } | 37 } |
| 36 | 38 |
| 37 base::scoped_nsprotocol<id> delegate_; | 39 base::scoped_nsprotocol<id> delegate_; |
| 38 std::unique_ptr<WebStateDelegateBridge> bridge_; | 40 std::unique_ptr<WebStateDelegateBridge> bridge_; |
| 41 web::TestWebState test_web_state_; |
| 39 }; | 42 }; |
| 40 | 43 |
| 44 // Tests |webState:openURLWithParams:| forwarding. |
| 45 TEST_F(WebStateDelegateBridgeTest, OpenURLFromWebState) { |
| 46 ASSERT_FALSE([delegate_ webState]); |
| 47 ASSERT_FALSE([delegate_ openURLParams]); |
| 48 |
| 49 web::WebState::OpenURLParams params( |
| 50 GURL("https://chromium.test/"), |
| 51 web::Referrer(GURL("https://chromium2.test/"), ReferrerPolicyNever), |
| 52 WindowOpenDisposition::NEW_WINDOW, ui::PAGE_TRANSITION_FORM_SUBMIT, true); |
| 53 EXPECT_EQ(&test_web_state_, |
| 54 bridge_->OpenURLFromWebState(&test_web_state_, params)); |
| 55 |
| 56 EXPECT_EQ(&test_web_state_, [delegate_ webState]); |
| 57 const web::WebState::OpenURLParams* result_params = [delegate_ openURLParams]; |
| 58 ASSERT_TRUE(result_params); |
| 59 EXPECT_EQ(params.url, result_params->url); |
| 60 EXPECT_EQ(params.referrer.url, result_params->referrer.url); |
| 61 EXPECT_EQ(params.referrer.policy, result_params->referrer.policy); |
| 62 EXPECT_EQ(params.disposition, result_params->disposition); |
| 63 EXPECT_EQ(static_cast<int>(params.transition), |
| 64 static_cast<int>(result_params->transition)); |
| 65 EXPECT_EQ(params.is_renderer_initiated, result_params->is_renderer_initiated); |
| 66 } |
| 67 |
| 41 // Tests |LoadProgressChanged| forwarding. | 68 // Tests |LoadProgressChanged| forwarding. |
| 42 TEST_F(WebStateDelegateBridgeTest, LoadProgressChanged) { | 69 TEST_F(WebStateDelegateBridgeTest, LoadProgressChanged) { |
| 43 ASSERT_EQ(0.0, [delegate_ changedProgress]); | 70 ASSERT_EQ(0.0, [delegate_ changedProgress]); |
| 44 bridge_->LoadProgressChanged(nullptr, 1.0); | 71 bridge_->LoadProgressChanged(nullptr, 1.0); |
| 45 EXPECT_EQ(1.0, [delegate_ changedProgress]); | 72 EXPECT_EQ(1.0, [delegate_ changedProgress]); |
| 46 } | 73 } |
| 47 | 74 |
| 48 // Tests |HandleContextMenu| forwarding. | 75 // Tests |HandleContextMenu| forwarding. |
| 49 TEST_F(WebStateDelegateBridgeTest, HandleContextMenu) { | 76 TEST_F(WebStateDelegateBridgeTest, HandleContextMenu) { |
| 50 EXPECT_EQ(nil, [delegate_ contextMenuParams]); | 77 EXPECT_EQ(nil, [delegate_ contextMenuParams]); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 } | 96 } |
| 70 | 97 |
| 71 // Tests |GetJavaScriptDialogPresenter| forwarding. | 98 // Tests |GetJavaScriptDialogPresenter| forwarding. |
| 72 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) { | 99 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) { |
| 73 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]); | 100 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]); |
| 74 bridge_->GetJavaScriptDialogPresenter(nullptr); | 101 bridge_->GetJavaScriptDialogPresenter(nullptr); |
| 75 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]); | 102 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]); |
| 76 } | 103 } |
| 77 | 104 |
| 78 } // namespace web | 105 } // namespace web |
| OLD | NEW |