| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/web_state_impl.h" | 5 #import "ios/web/web_state/web_state_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #import "base/mac/bind_objc_block.h" | 14 #import "base/mac/bind_objc_block.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #import "base/test/ios/wait_util.h" | 16 #import "base/test/ios/wait_util.h" |
| 17 #import "ios/web/public/java_script_dialog_presenter.h" | 17 #import "ios/web/public/java_script_dialog_presenter.h" |
| 18 #include "ios/web/public/load_committed_details.h" | 18 #include "ios/web/public/load_committed_details.h" |
| 19 #include "ios/web/public/test/fakes/test_browser_state.h" | 19 #include "ios/web/public/test/fakes/test_browser_state.h" |
| 20 #import "ios/web/public/test/fakes/test_web_state_delegate.h" | 20 #import "ios/web/public/test/fakes/test_web_state_delegate.h" |
| 21 #import "ios/web/public/test/fakes/test_web_state_observer.h" | 21 #import "ios/web/public/test/fakes/test_web_state_observer.h" |
| 22 #include "ios/web/public/test/web_test.h" | 22 #include "ios/web/public/test/web_test.h" |
| 23 #import "ios/web/public/web_state/context_menu_params.h" | 23 #import "ios/web/public/web_state/context_menu_params.h" |
| 24 #include "ios/web/public/web_state/global_web_state_observer.h" | 24 #include "ios/web/public/web_state/global_web_state_observer.h" |
| 25 #include "ios/web/public/web_state/navigation_context.h" | 25 #include "ios/web/public/web_state/navigation_context.h" |
| 26 #import "ios/web/public/web_state/web_state_delegate.h" | 26 #import "ios/web/public/web_state/web_state_delegate.h" |
| 27 #include "ios/web/public/web_state/web_state_observer.h" | 27 #include "ios/web/public/web_state/web_state_observer.h" |
| 28 #import "ios/web/public/web_state/web_state_policy_decider.h" | 28 #import "ios/web/public/web_state/web_state_policy_decider.h" |
| 29 #include "ios/web/web_state/global_web_state_event_tracker.h" | 29 #include "ios/web/web_state/global_web_state_event_tracker.h" |
| 30 #include "ios/web/web_state/navigation_context_impl.h" |
| 30 #import "ios/web/web_state/ui/crw_web_controller.h" | 31 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 31 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_util.h" | 33 #include "net/http/http_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #import "testing/gtest_mac.h" | 36 #import "testing/gtest_mac.h" |
| 36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 37 | 38 |
| 38 using testing::_; | 39 using testing::_; |
| 39 using testing::Assign; | 40 using testing::Assign; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 actual_favicon_url.icon_sizes[0].height()); | 341 actual_favicon_url.icon_sizes[0].height()); |
| 341 | 342 |
| 342 // Test that RenderProcessGone() is called. | 343 // Test that RenderProcessGone() is called. |
| 343 SetIgnoreRenderProcessCrashesDuringTesting(true); | 344 SetIgnoreRenderProcessCrashesDuringTesting(true); |
| 344 ASSERT_FALSE(observer->render_process_gone_info()); | 345 ASSERT_FALSE(observer->render_process_gone_info()); |
| 345 web_state_->OnRenderProcessGone(); | 346 web_state_->OnRenderProcessGone(); |
| 346 ASSERT_TRUE(observer->render_process_gone_info()); | 347 ASSERT_TRUE(observer->render_process_gone_info()); |
| 347 EXPECT_EQ(web_state_.get(), observer->render_process_gone_info()->web_state); | 348 EXPECT_EQ(web_state_.get(), observer->render_process_gone_info()->web_state); |
| 348 | 349 |
| 349 // Test that ProvisionalNavigationStarted() is called. | 350 // Test that ProvisionalNavigationStarted() is called. |
| 351 ASSERT_FALSE(observer->did_finish_navigation_info()); |
| 352 const GURL url("http://test"); |
| 353 std::unique_ptr<web::NavigationContext> context = |
| 354 NavigationContextImpl::CreateNavigationContext( |
| 355 web_state_.get(), url, nullptr /* response_headers */); |
| 356 web_state_->OnNavigationFinished(context.get()); |
| 357 ASSERT_TRUE(observer->did_finish_navigation_info()); |
| 358 EXPECT_EQ(web_state_.get(), |
| 359 observer->did_finish_navigation_info()->web_state); |
| 360 NavigationContext* actual_context = |
| 361 observer->did_finish_navigation_info()->context.get(); |
| 362 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); |
| 363 EXPECT_FALSE(actual_context->IsSameDocument()); |
| 364 EXPECT_FALSE(actual_context->IsErrorPage()); |
| 365 EXPECT_FALSE(actual_context->GetResponseHeaders()); |
| 366 |
| 367 // Test that OnNavigationFinished() is called. |
| 350 ASSERT_FALSE(observer->start_provisional_navigation_info()); | 368 ASSERT_FALSE(observer->start_provisional_navigation_info()); |
| 351 const GURL url("http://test"); | |
| 352 web_state_->OnProvisionalNavigationStarted(url); | 369 web_state_->OnProvisionalNavigationStarted(url); |
| 353 ASSERT_TRUE(observer->start_provisional_navigation_info()); | 370 ASSERT_TRUE(observer->start_provisional_navigation_info()); |
| 354 EXPECT_EQ(web_state_.get(), | 371 EXPECT_EQ(web_state_.get(), |
| 355 observer->start_provisional_navigation_info()->web_state); | 372 observer->start_provisional_navigation_info()->web_state); |
| 356 EXPECT_EQ(url, observer->start_provisional_navigation_info()->url); | 373 EXPECT_EQ(url, observer->start_provisional_navigation_info()->url); |
| 357 | 374 |
| 358 // Test that NavigationItemsPruned() is called. | 375 // Test that NavigationItemsPruned() is called. |
| 359 ASSERT_FALSE(observer->navigation_items_pruned_info()); | 376 ASSERT_FALSE(observer->navigation_items_pruned_info()); |
| 360 web_state_->OnNavigationItemsPruned(1); | 377 web_state_->OnNavigationItemsPruned(1); |
| 361 ASSERT_TRUE(observer->navigation_items_pruned_info()); | 378 ASSERT_TRUE(observer->navigation_items_pruned_info()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 386 ASSERT_FALSE(observer->load_page_info()); | 403 ASSERT_FALSE(observer->load_page_info()); |
| 387 web_state_->OnPageLoaded(url, false); | 404 web_state_->OnPageLoaded(url, false); |
| 388 ASSERT_TRUE(observer->load_page_info()); | 405 ASSERT_TRUE(observer->load_page_info()); |
| 389 EXPECT_EQ(web_state_.get(), observer->load_page_info()->web_state); | 406 EXPECT_EQ(web_state_.get(), observer->load_page_info()->web_state); |
| 390 EXPECT_FALSE(observer->load_page_info()->success); | 407 EXPECT_FALSE(observer->load_page_info()->success); |
| 391 web_state_->OnPageLoaded(url, true); | 408 web_state_->OnPageLoaded(url, true); |
| 392 ASSERT_TRUE(observer->load_page_info()); | 409 ASSERT_TRUE(observer->load_page_info()); |
| 393 EXPECT_EQ(web_state_.get(), observer->load_page_info()->web_state); | 410 EXPECT_EQ(web_state_.get(), observer->load_page_info()->web_state); |
| 394 EXPECT_TRUE(observer->load_page_info()->success); | 411 EXPECT_TRUE(observer->load_page_info()->success); |
| 395 | 412 |
| 396 // Test that DidFinishNavigation() is called for same document navigations. | 413 // Reset the observer and test that DidFinishNavigation() is called |
| 414 // for same document navigations. |
| 415 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); |
| 397 ASSERT_FALSE(observer->did_finish_navigation_info()); | 416 ASSERT_FALSE(observer->did_finish_navigation_info()); |
| 398 web_state_->OnSameDocumentNavigation(url); | 417 web_state_->OnSameDocumentNavigation(url); |
| 399 ASSERT_TRUE(observer->did_finish_navigation_info()); | 418 ASSERT_TRUE(observer->did_finish_navigation_info()); |
| 400 EXPECT_EQ(web_state_.get(), | 419 EXPECT_EQ(web_state_.get(), |
| 401 observer->did_finish_navigation_info()->web_state); | 420 observer->did_finish_navigation_info()->web_state); |
| 402 NavigationContext* context = | 421 actual_context = observer->did_finish_navigation_info()->context.get(); |
| 403 observer->did_finish_navigation_info()->context.get(); | 422 ASSERT_TRUE(actual_context); |
| 404 ASSERT_TRUE(context); | 423 EXPECT_EQ(url, actual_context->GetUrl()); |
| 405 EXPECT_EQ(url, context->GetUrl()); | 424 EXPECT_TRUE(actual_context->IsSameDocument()); |
| 406 EXPECT_TRUE(context->IsSameDocument()); | 425 EXPECT_FALSE(actual_context->IsErrorPage()); |
| 407 EXPECT_FALSE(context->IsErrorPage()); | 426 EXPECT_FALSE(actual_context->GetResponseHeaders()); |
| 408 EXPECT_FALSE(context->GetResponseHeaders()); | |
| 409 | 427 |
| 410 // Reset the observer and test that DidFinishNavigation() is called | 428 // Reset the observer and test that DidFinishNavigation() is called |
| 411 // for error navigations. | 429 // for error navigations. |
| 412 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); | 430 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); |
| 413 ASSERT_FALSE(observer->did_finish_navigation_info()); | 431 ASSERT_FALSE(observer->did_finish_navigation_info()); |
| 414 web_state_->OnErrorPageNavigation(url); | 432 web_state_->OnErrorPageNavigation(url); |
| 415 ASSERT_TRUE(observer->did_finish_navigation_info()); | 433 ASSERT_TRUE(observer->did_finish_navigation_info()); |
| 416 EXPECT_EQ(web_state_.get(), | 434 EXPECT_EQ(web_state_.get(), |
| 417 observer->did_finish_navigation_info()->web_state); | 435 observer->did_finish_navigation_info()->web_state); |
| 418 context = observer->did_finish_navigation_info()->context.get(); | 436 actual_context = observer->did_finish_navigation_info()->context.get(); |
| 419 ASSERT_TRUE(context); | 437 ASSERT_TRUE(actual_context); |
| 420 EXPECT_EQ(url, context->GetUrl()); | 438 EXPECT_EQ(url, actual_context->GetUrl()); |
| 421 EXPECT_FALSE(context->IsSameDocument()); | 439 EXPECT_FALSE(actual_context->IsSameDocument()); |
| 422 EXPECT_TRUE(context->IsErrorPage()); | 440 EXPECT_TRUE(actual_context->IsErrorPage()); |
| 423 EXPECT_FALSE(context->GetResponseHeaders()); | 441 EXPECT_FALSE(actual_context->GetResponseHeaders()); |
| 424 | 442 |
| 425 // Test that OnTitleChanged() is called. | 443 // Test that OnTitleChanged() is called. |
| 426 ASSERT_FALSE(observer->title_was_set_info()); | 444 ASSERT_FALSE(observer->title_was_set_info()); |
| 427 web_state_->OnTitleChanged(); | 445 web_state_->OnTitleChanged(); |
| 428 ASSERT_TRUE(observer->title_was_set_info()); | 446 ASSERT_TRUE(observer->title_was_set_info()); |
| 429 EXPECT_EQ(web_state_.get(), observer->title_was_set_info()->web_state); | 447 EXPECT_EQ(web_state_.get(), observer->title_was_set_info()->web_state); |
| 430 | 448 |
| 431 // Test that WebStateDestroyed() is called. | 449 // Test that WebStateDestroyed() is called. |
| 432 EXPECT_FALSE(observer->web_state_destroyed_info()); | 450 EXPECT_FALSE(observer->web_state_destroyed_info()); |
| 433 web_state_.reset(); | 451 web_state_.reset(); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 // Set |created_with_opener| to true and verify that HasOpener() returns true. | 713 // Set |created_with_opener| to true and verify that HasOpener() returns true. |
| 696 WebState::CreateParams params_with_opener = | 714 WebState::CreateParams params_with_opener = |
| 697 WebState::CreateParams(GetBrowserState()); | 715 WebState::CreateParams(GetBrowserState()); |
| 698 params_with_opener.created_with_opener = true; | 716 params_with_opener.created_with_opener = true; |
| 699 std::unique_ptr<WebState> web_state_with_opener = | 717 std::unique_ptr<WebState> web_state_with_opener = |
| 700 WebState::Create(params_with_opener); | 718 WebState::Create(params_with_opener); |
| 701 EXPECT_TRUE(web_state_with_opener->HasOpener()); | 719 EXPECT_TRUE(web_state_with_opener->HasOpener()); |
| 702 } | 720 } |
| 703 | 721 |
| 704 } // namespace web | 722 } // namespace web |
| OLD | NEW |