| 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 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // expected. | 120 // expected. |
| 121 class TestWebStateObserver : public WebStateObserver { | 121 class TestWebStateObserver : public WebStateObserver { |
| 122 public: | 122 public: |
| 123 TestWebStateObserver(WebState* web_state) | 123 TestWebStateObserver(WebState* web_state) |
| 124 : WebStateObserver(web_state), | 124 : WebStateObserver(web_state), |
| 125 provisional_navigation_started_called_(false), | 125 provisional_navigation_started_called_(false), |
| 126 navigation_items_pruned_called_(false), | 126 navigation_items_pruned_called_(false), |
| 127 navigation_item_changed_called_(false), | 127 navigation_item_changed_called_(false), |
| 128 navigation_item_committed_called_(false), | 128 navigation_item_committed_called_(false), |
| 129 page_loaded_called_with_success_(false), | 129 page_loaded_called_with_success_(false), |
| 130 url_hash_changed_called_(false), | |
| 131 history_state_changed_called_(false), | 130 history_state_changed_called_(false), |
| 132 did_finish_navigation_called_(false), | 131 did_finish_navigation_called_(false), |
| 133 web_state_destroyed_called_(false) {} | 132 web_state_destroyed_called_(false) {} |
| 134 | 133 |
| 135 // Methods returning true if the corresponding WebStateObserver method has | 134 // Methods returning true if the corresponding WebStateObserver method has |
| 136 // been called. | 135 // been called. |
| 137 bool provisional_navigation_started_called() const { | 136 bool provisional_navigation_started_called() const { |
| 138 return provisional_navigation_started_called_; | 137 return provisional_navigation_started_called_; |
| 139 }; | 138 }; |
| 140 bool navigation_items_pruned_called() const { | 139 bool navigation_items_pruned_called() const { |
| 141 return navigation_items_pruned_called_; | 140 return navigation_items_pruned_called_; |
| 142 } | 141 } |
| 143 bool navigation_item_changed_called() const { | 142 bool navigation_item_changed_called() const { |
| 144 return navigation_item_changed_called_; | 143 return navigation_item_changed_called_; |
| 145 } | 144 } |
| 146 bool navigation_item_committed_called() const { | 145 bool navigation_item_committed_called() const { |
| 147 return navigation_item_committed_called_; | 146 return navigation_item_committed_called_; |
| 148 } | 147 } |
| 149 bool page_loaded_called_with_success() const { | 148 bool page_loaded_called_with_success() const { |
| 150 return page_loaded_called_with_success_; | 149 return page_loaded_called_with_success_; |
| 151 } | 150 } |
| 152 bool url_hash_changed_called() const { return url_hash_changed_called_; } | |
| 153 bool history_state_changed_called() const { | 151 bool history_state_changed_called() const { |
| 154 return history_state_changed_called_; | 152 return history_state_changed_called_; |
| 155 } | 153 } |
| 156 bool did_finish_navigation_called() const { | 154 bool did_finish_navigation_called() const { |
| 157 return did_finish_navigation_called_; | 155 return did_finish_navigation_called_; |
| 158 } | 156 } |
| 159 bool web_state_destroyed_called() const { | 157 bool web_state_destroyed_called() const { |
| 160 return web_state_destroyed_called_; | 158 return web_state_destroyed_called_; |
| 161 } | 159 } |
| 162 | 160 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 const LoadCommittedDetails& load_details) override { | 173 const LoadCommittedDetails& load_details) override { |
| 176 navigation_item_committed_called_ = true; | 174 navigation_item_committed_called_ = true; |
| 177 } | 175 } |
| 178 void DidFinishNavigation(NavigationContext* navigation_context) override { | 176 void DidFinishNavigation(NavigationContext* navigation_context) override { |
| 179 did_finish_navigation_called_ = true; | 177 did_finish_navigation_called_ = true; |
| 180 } | 178 } |
| 181 void PageLoaded(PageLoadCompletionStatus load_completion_status) override { | 179 void PageLoaded(PageLoadCompletionStatus load_completion_status) override { |
| 182 page_loaded_called_with_success_ = | 180 page_loaded_called_with_success_ = |
| 183 load_completion_status == PageLoadCompletionStatus::SUCCESS; | 181 load_completion_status == PageLoadCompletionStatus::SUCCESS; |
| 184 } | 182 } |
| 185 void UrlHashChanged() override { url_hash_changed_called_ = true; } | |
| 186 void HistoryStateChanged() override { history_state_changed_called_ = true; } | |
| 187 void WebStateDestroyed() override { | 183 void WebStateDestroyed() override { |
| 188 EXPECT_TRUE(web_state()->IsBeingDestroyed()); | 184 EXPECT_TRUE(web_state()->IsBeingDestroyed()); |
| 189 web_state_destroyed_called_ = true; | 185 web_state_destroyed_called_ = true; |
| 190 Observe(nullptr); | 186 Observe(nullptr); |
| 191 } | 187 } |
| 192 | 188 |
| 193 bool provisional_navigation_started_called_; | 189 bool provisional_navigation_started_called_; |
| 194 bool navigation_items_pruned_called_; | 190 bool navigation_items_pruned_called_; |
| 195 bool navigation_item_changed_called_; | 191 bool navigation_item_changed_called_; |
| 196 bool navigation_item_committed_called_; | 192 bool navigation_item_committed_called_; |
| 197 bool page_loaded_called_with_success_; | 193 bool page_loaded_called_with_success_; |
| 198 bool url_hash_changed_called_; | |
| 199 bool history_state_changed_called_; | 194 bool history_state_changed_called_; |
| 200 bool did_finish_navigation_called_; | 195 bool did_finish_navigation_called_; |
| 201 bool web_state_destroyed_called_; | 196 bool web_state_destroyed_called_; |
| 202 }; | 197 }; |
| 203 | 198 |
| 204 // Test decider to check that the WebStatePolicyDecider methods are called as | 199 // Test decider to check that the WebStatePolicyDecider methods are called as |
| 205 // expected. | 200 // expected. |
| 206 class MockWebStatePolicyDecider : public WebStatePolicyDecider { | 201 class MockWebStatePolicyDecider : public WebStatePolicyDecider { |
| 207 public: | 202 public: |
| 208 explicit MockWebStatePolicyDecider(WebState* web_state) | 203 explicit MockWebStatePolicyDecider(WebState* web_state) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 web_state_->OnNavigationItemCommitted(details); | 380 web_state_->OnNavigationItemCommitted(details); |
| 386 EXPECT_TRUE(observer->navigation_item_committed_called()); | 381 EXPECT_TRUE(observer->navigation_item_committed_called()); |
| 387 | 382 |
| 388 // Test that OnPageLoaded() is called with success when there is no error. | 383 // Test that OnPageLoaded() is called with success when there is no error. |
| 389 EXPECT_FALSE(observer->page_loaded_called_with_success()); | 384 EXPECT_FALSE(observer->page_loaded_called_with_success()); |
| 390 web_state_->OnPageLoaded(GURL("http://test"), false); | 385 web_state_->OnPageLoaded(GURL("http://test"), false); |
| 391 EXPECT_FALSE(observer->page_loaded_called_with_success()); | 386 EXPECT_FALSE(observer->page_loaded_called_with_success()); |
| 392 web_state_->OnPageLoaded(GURL("http://test"), true); | 387 web_state_->OnPageLoaded(GURL("http://test"), true); |
| 393 EXPECT_TRUE(observer->page_loaded_called_with_success()); | 388 EXPECT_TRUE(observer->page_loaded_called_with_success()); |
| 394 | 389 |
| 395 // Test that UrlHashChanged() is called. | |
| 396 EXPECT_FALSE(observer->url_hash_changed_called()); | |
| 397 web_state_->OnUrlHashChanged(); | |
| 398 EXPECT_TRUE(observer->url_hash_changed_called()); | |
| 399 | |
| 400 // Test that HistoryStateChanged() is called. | |
| 401 EXPECT_FALSE(observer->history_state_changed_called()); | |
| 402 web_state_->OnHistoryStateChanged(); | |
| 403 EXPECT_TRUE(observer->history_state_changed_called()); | |
| 404 | |
| 405 // Test that DidFinishNavigation() is called for same page navigations. | 390 // Test that DidFinishNavigation() is called for same page navigations. |
| 406 EXPECT_FALSE(observer->did_finish_navigation_called()); | 391 EXPECT_FALSE(observer->did_finish_navigation_called()); |
| 407 web_state_->OnSamePageNavigation(GURL("http://test")); | 392 web_state_->OnSamePageNavigation(GURL("http://test")); |
| 408 EXPECT_TRUE(observer->did_finish_navigation_called()); | 393 EXPECT_TRUE(observer->did_finish_navigation_called()); |
| 409 | 394 |
| 410 // Reset the observer and test that DidFinishNavigation() is called | 395 // Reset the observer and test that DidFinishNavigation() is called |
| 411 // for error navigations. | 396 // for error navigations. |
| 412 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); | 397 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); |
| 413 EXPECT_FALSE(observer->did_finish_navigation_called()); | 398 EXPECT_FALSE(observer->did_finish_navigation_called()); |
| 414 web_state_->OnErrorPageNavigation(GURL("http://test")); | 399 web_state_->OnErrorPageNavigation(GURL("http://test")); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 "</script>"); | 674 "</script>"); |
| 690 | 675 |
| 691 base::test::ios::WaitUntilCondition(^{ | 676 base::test::ios::WaitUntilCondition(^{ |
| 692 return message_received; | 677 return message_received; |
| 693 }); | 678 }); |
| 694 web_state_->RemoveScriptCommandCallback("test"); | 679 web_state_->RemoveScriptCommandCallback("test"); |
| 695 } | 680 } |
| 696 | 681 |
| 697 } // namespace | 682 } // namespace |
| 698 } // namespace web | 683 } // namespace web |
| OLD | NEW |