| Index: ios/web/web_state/web_state_observer_bridge_unittest.mm
|
| diff --git a/ios/web/web_state/web_state_observer_bridge_unittest.mm b/ios/web/web_state/web_state_observer_bridge_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a8dad22930eda7b577ccd3854039a948b4b85961
|
| --- /dev/null
|
| +++ b/ios/web/web_state/web_state_observer_bridge_unittest.mm
|
| @@ -0,0 +1,212 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/web/public/web_state/web_state_observer_bridge.h"
|
| +
|
| +#import "base/mac/scoped_nsobject.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "ios/web/public/favicon_url.h"
|
| +#import "ios/web/public/test/fakes/crw_test_web_state_observer.h"
|
| +#import "ios/web/public/test/fakes/test_web_state.h"
|
| +#import "ios/web/public/web_state/web_state_observer_bridge.h"
|
| +#include "testing/platform_test.h"
|
| +
|
| +namespace web {
|
| +
|
| +// Test fixture to test WebStateObserverBridge class.
|
| +class WebStateObserverBridgeTest : public PlatformTest {
|
| + protected:
|
| + WebStateObserverBridgeTest()
|
| + : observer_([[CRWTestWebStateObserver alloc] init]),
|
| + bridge_(base::MakeUnique<WebStateObserverBridge>(&test_web_state_,
|
| + observer_.get())) {}
|
| +
|
| + web::TestWebState test_web_state_;
|
| + base::scoped_nsobject<CRWTestWebStateObserver> observer_;
|
| + std::unique_ptr<WebStateObserverBridge> bridge_;
|
| +};
|
| +
|
| +// Tests |webState:didStartProvisionalNavigationForURL:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, ProvisionalNavigationStarted) {
|
| + ASSERT_FALSE([observer_ startProvisionalNavigationInfo]);
|
| +
|
| + GURL url("https://chromium.test/");
|
| + bridge_->ProvisionalNavigationStarted(url);
|
| +
|
| + ASSERT_TRUE([observer_ startProvisionalNavigationInfo]);
|
| + EXPECT_EQ(&test_web_state_,
|
| + [observer_ startProvisionalNavigationInfo]->web_state);
|
| + EXPECT_EQ(url, [observer_ startProvisionalNavigationInfo]->url);
|
| +}
|
| +
|
| +// Tests |webState:didCommitNavigationWithDetails:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) {
|
| + ASSERT_FALSE([observer_ commitNavigationInfo]);
|
| +
|
| + LoadCommittedDetails load_details;
|
| + load_details.item = reinterpret_cast<web::NavigationItem*>(1);
|
| + load_details.previous_item_index = 15;
|
| + load_details.previous_url = GURL("https://chromium.test/");
|
| + load_details.is_in_page = true;
|
| +
|
| + bridge_->NavigationItemCommitted(load_details);
|
| +
|
| + ASSERT_TRUE([observer_ commitNavigationInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ commitNavigationInfo]->web_state);
|
| + EXPECT_EQ(load_details.item,
|
| + [observer_ commitNavigationInfo]->load_details.item);
|
| + EXPECT_EQ(load_details.previous_item_index,
|
| + [observer_ commitNavigationInfo]->load_details.previous_item_index);
|
| + EXPECT_EQ(load_details.previous_url,
|
| + [observer_ commitNavigationInfo]->load_details.previous_url);
|
| + EXPECT_EQ(load_details.is_in_page,
|
| + [observer_ commitNavigationInfo]->load_details.is_in_page);
|
| +}
|
| +
|
| +// Tests |webState:didLoadPageWithSuccess:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, PageLoaded) {
|
| + ASSERT_FALSE([observer_ loadPageInfo]);
|
| +
|
| + // Forwarding PageLoadCompletionStatus::SUCCESS.
|
| + bridge_->PageLoaded(PageLoadCompletionStatus::SUCCESS);
|
| + ASSERT_TRUE([observer_ loadPageInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ loadPageInfo]->web_state);
|
| + EXPECT_TRUE([observer_ loadPageInfo]->success);
|
| +
|
| + // Forwarding PageLoadCompletionStatus::FAILURE.
|
| + bridge_->PageLoaded(PageLoadCompletionStatus::FAILURE);
|
| + ASSERT_TRUE([observer_ loadPageInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ loadPageInfo]->web_state);
|
| + EXPECT_FALSE([observer_ loadPageInfo]->success);
|
| +}
|
| +
|
| +// Tests |webState:webStateDidDismissInterstitial:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, InterstitialDismissed) {
|
| + ASSERT_FALSE([observer_ dismissInterstitialInfo]);
|
| +
|
| + // TODO(crbug.com/687735): Fix this method name.
|
| + bridge_->InsterstitialDismissed();
|
| + ASSERT_TRUE([observer_ dismissInterstitialInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ dismissInterstitialInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:webStateDidChangeURLHash:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, UrlHashChanged) {
|
| + ASSERT_FALSE([observer_ changeUrlHashInfo]);
|
| +
|
| + bridge_->UrlHashChanged();
|
| + ASSERT_TRUE([observer_ changeUrlHashInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ changeUrlHashInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:webStateDidChangeHistoryState:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, HistoryStateChanged) {
|
| + ASSERT_FALSE([observer_ changeHistoryStateInfo]);
|
| +
|
| + bridge_->HistoryStateChanged();
|
| + ASSERT_TRUE([observer_ changeHistoryStateInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ changeHistoryStateInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:didChangeLoadingProgress:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, LoadProgressChanged) {
|
| + ASSERT_FALSE([observer_ changeLoadingProgressInfo]);
|
| +
|
| + const double kTestLoadProgress = 0.75;
|
| + bridge_->LoadProgressChanged(kTestLoadProgress);
|
| + ASSERT_TRUE([observer_ changeLoadingProgressInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ changeLoadingProgressInfo]->web_state);
|
| + EXPECT_EQ(kTestLoadProgress, [observer_ changeLoadingProgressInfo]->progress);
|
| +}
|
| +
|
| +// Tests |webState:didSubmitDocumentWithFormNamed:userInitiated:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, DocumentSubmitted) {
|
| + ASSERT_FALSE([observer_ submitDocumentInfo]);
|
| +
|
| + std::string kTestFormName("form-name");
|
| + BOOL user_initiated = YES;
|
| + bridge_->DocumentSubmitted(kTestFormName, user_initiated);
|
| + ASSERT_TRUE([observer_ submitDocumentInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ submitDocumentInfo]->web_state);
|
| + EXPECT_EQ(kTestFormName, [observer_ submitDocumentInfo]->form_name);
|
| + EXPECT_EQ(user_initiated, [observer_ submitDocumentInfo]->user_initiated);
|
| +}
|
| +
|
| +// Tests |webState:didRegisterFormActivityWithFormNamed:...| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, FormActivityRegistered) {
|
| + ASSERT_FALSE([observer_ formActivityInfo]);
|
| +
|
| + std::string kTestFormName("form-name");
|
| + std::string kTestFieldName("field-name");
|
| + std::string kTestTypeType("type");
|
| + std::string kTestValue("value");
|
| + bridge_->FormActivityRegistered(kTestFormName, kTestFieldName, kTestTypeType,
|
| + kTestValue, true);
|
| + ASSERT_TRUE([observer_ formActivityInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ formActivityInfo]->web_state);
|
| + EXPECT_EQ(kTestFormName, [observer_ formActivityInfo]->form_name);
|
| + EXPECT_EQ(kTestFieldName, [observer_ formActivityInfo]->field_name);
|
| + EXPECT_EQ(kTestTypeType, [observer_ formActivityInfo]->type);
|
| + EXPECT_EQ(kTestValue, [observer_ formActivityInfo]->value);
|
| + EXPECT_TRUE([observer_ formActivityInfo]->input_missing);
|
| +}
|
| +
|
| +// Tests |webState:didUpdateFaviconURLCandidates:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, FaviconUrlUpdated) {
|
| + ASSERT_FALSE([observer_ updateFaviconUrlCandidatesInfo]);
|
| +
|
| + web::FaviconURL url(GURL("https://chromium.test/"),
|
| + web::FaviconURL::TOUCH_ICON, {gfx::Size(5, 6)});
|
| +
|
| + bridge_->FaviconUrlUpdated({url});
|
| + ASSERT_TRUE([observer_ updateFaviconUrlCandidatesInfo]);
|
| + EXPECT_EQ(&test_web_state_,
|
| + [observer_ updateFaviconUrlCandidatesInfo]->web_state);
|
| + ASSERT_EQ(1U, [observer_ updateFaviconUrlCandidatesInfo]->candidates.size());
|
| + const web::FaviconURL& actual_url =
|
| + [observer_ updateFaviconUrlCandidatesInfo]->candidates[0];
|
| + EXPECT_EQ(url.icon_url, actual_url.icon_url);
|
| + EXPECT_EQ(url.icon_type, actual_url.icon_type);
|
| + ASSERT_EQ(url.icon_sizes.size(), actual_url.icon_sizes.size());
|
| + EXPECT_EQ(url.icon_sizes[0].width(), actual_url.icon_sizes[0].width());
|
| + EXPECT_EQ(url.icon_sizes[0].height(), actual_url.icon_sizes[0].height());
|
| +}
|
| +
|
| +// Tests |webState:renderProcessGoneForWebState:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, RenderProcessGone) {
|
| + ASSERT_FALSE([observer_ renderProcessGoneInfo]);
|
| +
|
| + bridge_->RenderProcessGone();
|
| + ASSERT_TRUE([observer_ renderProcessGoneInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ renderProcessGoneInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:webStateDestroyed:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, WebStateDestroyed) {
|
| + ASSERT_FALSE([observer_ webStateDestroyedInfo]);
|
| +
|
| + bridge_->WebStateDestroyed();
|
| + ASSERT_TRUE([observer_ webStateDestroyedInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ webStateDestroyedInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:webStateDidStopLoading:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, DidStopLoading) {
|
| + ASSERT_FALSE([observer_ stopLoadingInfo]);
|
| +
|
| + bridge_->DidStopLoading();
|
| + ASSERT_TRUE([observer_ stopLoadingInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ stopLoadingInfo]->web_state);
|
| +}
|
| +
|
| +// Tests |webState:webStateDidStartLoading:| forwarding.
|
| +TEST_F(WebStateObserverBridgeTest, DidStartLoading) {
|
| + ASSERT_FALSE([observer_ startLoadingInfo]);
|
| +
|
| + bridge_->DidStartLoading();
|
| + ASSERT_TRUE([observer_ startLoadingInfo]);
|
| + EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state);
|
| +}
|
| +
|
| +} // namespace web
|
|
|