| 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 #include "ios/web/web_state/web_state_impl.h" | 5 #include "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/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "ios/web/public/load_committed_details.h" | 14 #include "ios/web/public/load_committed_details.h" |
| 15 #include "ios/web/public/ssl_status.h" |
| 15 #include "ios/web/public/test/test_browser_state.h" | 16 #include "ios/web/public/test/test_browser_state.h" |
| 16 #include "ios/web/public/web_state/global_web_state_observer.h" | 17 #include "ios/web/public/web_state/global_web_state_observer.h" |
| 18 #include "ios/web/public/web_state/web_state_delegate.h" |
| 17 #include "ios/web/public/web_state/web_state_observer.h" | 19 #include "ios/web/public/web_state/web_state_observer.h" |
| 18 #include "ios/web/public/web_state/web_state_policy_decider.h" | 20 #include "ios/web/public/web_state/web_state_policy_decider.h" |
| 19 #import "ios/web/test/web_test.h" | 21 #import "ios/web/test/web_test.h" |
| 20 #include "ios/web/web_state/global_web_state_event_tracker.h" | 22 #include "ios/web/web_state/global_web_state_event_tracker.h" |
| 21 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_util.h" | 24 #include "net/http/http_util.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "testing/gtest_mac.h" | 27 #include "testing/gtest_mac.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 101 |
| 100 bool navigation_items_pruned_called_; | 102 bool navigation_items_pruned_called_; |
| 101 bool navigation_item_changed_called_; | 103 bool navigation_item_changed_called_; |
| 102 bool navigation_item_committed_called_; | 104 bool navigation_item_committed_called_; |
| 103 bool did_start_loading_called_; | 105 bool did_start_loading_called_; |
| 104 bool did_stop_loading_called_; | 106 bool did_stop_loading_called_; |
| 105 bool page_loaded_called_with_success_; | 107 bool page_loaded_called_with_success_; |
| 106 bool web_state_destroyed_called_; | 108 bool web_state_destroyed_called_; |
| 107 }; | 109 }; |
| 108 | 110 |
| 111 // Test delegate to check that the WebStateDelegate methods are called as |
| 112 // expected. |
| 113 class TestWebStateDelegate : public WebStateDelegate { |
| 114 public: |
| 115 TestWebStateDelegate() : load_progress_changed_called_(false) {} |
| 116 |
| 117 // Methods returning true if the corresponding WebStateObserver method has |
| 118 // been called. |
| 119 bool load_progress_changed_called() const { |
| 120 return load_progress_changed_called_; |
| 121 } |
| 122 |
| 123 private: |
| 124 // WebStateObserver implementation: |
| 125 void LoadProgressChanged(WebState* source, double progress) override { |
| 126 load_progress_changed_called_ = true; |
| 127 } |
| 128 |
| 129 bool load_progress_changed_called_; |
| 130 }; |
| 131 |
| 109 // Test observer to check that the WebStateObserver methods are called as | 132 // Test observer to check that the WebStateObserver methods are called as |
| 110 // expected. | 133 // expected. |
| 111 class TestWebStateObserver : public WebStateObserver { | 134 class TestWebStateObserver : public WebStateObserver { |
| 112 public: | 135 public: |
| 113 TestWebStateObserver(WebState* web_state) | 136 TestWebStateObserver(WebState* web_state) |
| 114 : WebStateObserver(web_state), | 137 : WebStateObserver(web_state), |
| 115 provisional_navigation_started_called_(false), | 138 provisional_navigation_started_called_(false), |
| 116 navigation_items_pruned_called_(false), | 139 navigation_items_pruned_called_(false), |
| 117 navigation_item_changed_called_(false), | 140 navigation_item_changed_called_(false), |
| 118 navigation_item_committed_called_(false), | 141 navigation_item_committed_called_(false), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 EXPECT_TRUE(observer->history_state_changed_called()); | 360 EXPECT_TRUE(observer->history_state_changed_called()); |
| 338 | 361 |
| 339 // Test that WebStateDestroyed() is called. | 362 // Test that WebStateDestroyed() is called. |
| 340 EXPECT_FALSE(observer->web_state_destroyed_called()); | 363 EXPECT_FALSE(observer->web_state_destroyed_called()); |
| 341 web_state_.reset(); | 364 web_state_.reset(); |
| 342 EXPECT_TRUE(observer->web_state_destroyed_called()); | 365 EXPECT_TRUE(observer->web_state_destroyed_called()); |
| 343 | 366 |
| 344 EXPECT_EQ(nullptr, observer->web_state()); | 367 EXPECT_EQ(nullptr, observer->web_state()); |
| 345 } | 368 } |
| 346 | 369 |
| 370 // Tests that WebStateDelegate methods appropriately called. |
| 371 TEST_F(WebStateTest, DelegateTest) { |
| 372 TestWebStateDelegate delegate; |
| 373 web_state_->SetDelegate(&delegate); |
| 374 |
| 375 // Test that LoadProgressChanged() is called. |
| 376 EXPECT_FALSE(delegate.load_progress_changed_called()); |
| 377 web_state_->SendChangeLoadProgress(0.0); |
| 378 EXPECT_TRUE(delegate.load_progress_changed_called()); |
| 379 } |
| 380 |
| 347 // Verifies that GlobalWebStateObservers are called when expected. | 381 // Verifies that GlobalWebStateObservers are called when expected. |
| 348 TEST_F(WebStateTest, GlobalObserverTest) { | 382 TEST_F(WebStateTest, GlobalObserverTest) { |
| 349 std::unique_ptr<TestGlobalWebStateObserver> observer( | 383 std::unique_ptr<TestGlobalWebStateObserver> observer( |
| 350 new TestGlobalWebStateObserver()); | 384 new TestGlobalWebStateObserver()); |
| 351 | 385 |
| 352 // Test that NavigationItemsPruned() is called. | 386 // Test that NavigationItemsPruned() is called. |
| 353 EXPECT_FALSE(observer->navigation_items_pruned_called()); | 387 EXPECT_FALSE(observer->navigation_items_pruned_called()); |
| 354 web_state_->OnNavigationItemsPruned(1); | 388 web_state_->OnNavigationItemsPruned(1); |
| 355 EXPECT_TRUE(observer->navigation_items_pruned_called()); | 389 EXPECT_TRUE(observer->navigation_items_pruned_called()); |
| 356 | 390 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 EXPECT_FALSE( | 528 EXPECT_FALSE( |
| 495 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false)); | 529 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false)); |
| 496 EXPECT_FALSE(is_called_1); | 530 EXPECT_FALSE(is_called_1); |
| 497 EXPECT_TRUE(is_called_2); | 531 EXPECT_TRUE(is_called_2); |
| 498 | 532 |
| 499 web_state_->RemoveScriptCommandCallback(kPrefix2); | 533 web_state_->RemoveScriptCommandCallback(kPrefix2); |
| 500 } | 534 } |
| 501 | 535 |
| 502 } // namespace | 536 } // namespace |
| 503 } // namespace web | 537 } // namespace web |
| OLD | NEW |