| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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), | 130 url_hash_changed_called_(false), |
| 131 history_state_changed_called_(false), | 131 history_state_changed_called_(false), |
| 132 did_finish_navigation_called_(false), | 132 did_finish_navigation_called_(false), |
| 133 title_was_set_called_(false), |
| 133 web_state_destroyed_called_(false) {} | 134 web_state_destroyed_called_(false) {} |
| 134 | 135 |
| 135 // Methods returning true if the corresponding WebStateObserver method has | 136 // Methods returning true if the corresponding WebStateObserver method has |
| 136 // been called. | 137 // been called. |
| 137 bool provisional_navigation_started_called() const { | 138 bool provisional_navigation_started_called() const { |
| 138 return provisional_navigation_started_called_; | 139 return provisional_navigation_started_called_; |
| 139 }; | 140 }; |
| 140 bool navigation_items_pruned_called() const { | 141 bool navigation_items_pruned_called() const { |
| 141 return navigation_items_pruned_called_; | 142 return navigation_items_pruned_called_; |
| 142 } | 143 } |
| 143 bool navigation_item_changed_called() const { | 144 bool navigation_item_changed_called() const { |
| 144 return navigation_item_changed_called_; | 145 return navigation_item_changed_called_; |
| 145 } | 146 } |
| 146 bool navigation_item_committed_called() const { | 147 bool navigation_item_committed_called() const { |
| 147 return navigation_item_committed_called_; | 148 return navigation_item_committed_called_; |
| 148 } | 149 } |
| 149 bool page_loaded_called_with_success() const { | 150 bool page_loaded_called_with_success() const { |
| 150 return page_loaded_called_with_success_; | 151 return page_loaded_called_with_success_; |
| 151 } | 152 } |
| 152 bool url_hash_changed_called() const { return url_hash_changed_called_; } | 153 bool url_hash_changed_called() const { return url_hash_changed_called_; } |
| 153 bool history_state_changed_called() const { | 154 bool history_state_changed_called() const { |
| 154 return history_state_changed_called_; | 155 return history_state_changed_called_; |
| 155 } | 156 } |
| 156 bool did_finish_navigation_called() const { | 157 bool did_finish_navigation_called() const { |
| 157 return did_finish_navigation_called_; | 158 return did_finish_navigation_called_; |
| 158 } | 159 } |
| 160 bool title_was_set_called() const { return title_was_set_called_; } |
| 159 bool web_state_destroyed_called() const { | 161 bool web_state_destroyed_called() const { |
| 160 return web_state_destroyed_called_; | 162 return web_state_destroyed_called_; |
| 161 } | 163 } |
| 162 | 164 |
| 163 private: | 165 private: |
| 164 // WebStateObserver implementation: | 166 // WebStateObserver implementation: |
| 165 void ProvisionalNavigationStarted(const GURL& url) override { | 167 void ProvisionalNavigationStarted(const GURL& url) override { |
| 166 provisional_navigation_started_called_ = true; | 168 provisional_navigation_started_called_ = true; |
| 167 } | 169 } |
| 168 void NavigationItemsPruned(size_t pruned_item_count) override { | 170 void NavigationItemsPruned(size_t pruned_item_count) override { |
| 169 navigation_items_pruned_called_ = true; | 171 navigation_items_pruned_called_ = true; |
| 170 } | 172 } |
| 171 void NavigationItemChanged() override { | 173 void NavigationItemChanged() override { |
| 172 navigation_item_changed_called_ = true; | 174 navigation_item_changed_called_ = true; |
| 173 } | 175 } |
| 174 void NavigationItemCommitted( | 176 void NavigationItemCommitted( |
| 175 const LoadCommittedDetails& load_details) override { | 177 const LoadCommittedDetails& load_details) override { |
| 176 navigation_item_committed_called_ = true; | 178 navigation_item_committed_called_ = true; |
| 177 } | 179 } |
| 178 void DidFinishNavigation(NavigationContext* navigation_context) override { | 180 void DidFinishNavigation(NavigationContext* navigation_context) override { |
| 179 did_finish_navigation_called_ = true; | 181 did_finish_navigation_called_ = true; |
| 180 } | 182 } |
| 181 void PageLoaded(PageLoadCompletionStatus load_completion_status) override { | 183 void PageLoaded(PageLoadCompletionStatus load_completion_status) override { |
| 182 page_loaded_called_with_success_ = | 184 page_loaded_called_with_success_ = |
| 183 load_completion_status == PageLoadCompletionStatus::SUCCESS; | 185 load_completion_status == PageLoadCompletionStatus::SUCCESS; |
| 184 } | 186 } |
| 185 void UrlHashChanged() override { url_hash_changed_called_ = true; } | 187 void UrlHashChanged() override { url_hash_changed_called_ = true; } |
| 186 void HistoryStateChanged() override { history_state_changed_called_ = true; } | 188 void HistoryStateChanged() override { history_state_changed_called_ = true; } |
| 189 void TitleWasSet() override { title_was_set_called_ = true; } |
| 187 void WebStateDestroyed() override { | 190 void WebStateDestroyed() override { |
| 188 EXPECT_TRUE(web_state()->IsBeingDestroyed()); | 191 EXPECT_TRUE(web_state()->IsBeingDestroyed()); |
| 189 web_state_destroyed_called_ = true; | 192 web_state_destroyed_called_ = true; |
| 190 Observe(nullptr); | 193 Observe(nullptr); |
| 191 } | 194 } |
| 192 | 195 |
| 193 bool provisional_navigation_started_called_; | 196 bool provisional_navigation_started_called_; |
| 194 bool navigation_items_pruned_called_; | 197 bool navigation_items_pruned_called_; |
| 195 bool navigation_item_changed_called_; | 198 bool navigation_item_changed_called_; |
| 196 bool navigation_item_committed_called_; | 199 bool navigation_item_committed_called_; |
| 197 bool page_loaded_called_with_success_; | 200 bool page_loaded_called_with_success_; |
| 198 bool url_hash_changed_called_; | 201 bool url_hash_changed_called_; |
| 199 bool history_state_changed_called_; | 202 bool history_state_changed_called_; |
| 200 bool did_finish_navigation_called_; | 203 bool did_finish_navigation_called_; |
| 204 bool title_was_set_called_; |
| 201 bool web_state_destroyed_called_; | 205 bool web_state_destroyed_called_; |
| 202 }; | 206 }; |
| 203 | 207 |
| 204 // Test decider to check that the WebStatePolicyDecider methods are called as | 208 // Test decider to check that the WebStatePolicyDecider methods are called as |
| 205 // expected. | 209 // expected. |
| 206 class MockWebStatePolicyDecider : public WebStatePolicyDecider { | 210 class MockWebStatePolicyDecider : public WebStatePolicyDecider { |
| 207 public: | 211 public: |
| 208 explicit MockWebStatePolicyDecider(WebState* web_state) | 212 explicit MockWebStatePolicyDecider(WebState* web_state) |
| 209 : WebStatePolicyDecider(web_state) {} | 213 : WebStatePolicyDecider(web_state) {} |
| 210 virtual ~MockWebStatePolicyDecider() {} | 214 virtual ~MockWebStatePolicyDecider() {} |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 web_state_->OnSamePageNavigation(GURL("http://test")); | 411 web_state_->OnSamePageNavigation(GURL("http://test")); |
| 408 EXPECT_TRUE(observer->did_finish_navigation_called()); | 412 EXPECT_TRUE(observer->did_finish_navigation_called()); |
| 409 | 413 |
| 410 // Reset the observer and test that DidFinishNavigation() is called | 414 // Reset the observer and test that DidFinishNavigation() is called |
| 411 // for error navigations. | 415 // for error navigations. |
| 412 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); | 416 observer = base::MakeUnique<TestWebStateObserver>(web_state_.get()); |
| 413 EXPECT_FALSE(observer->did_finish_navigation_called()); | 417 EXPECT_FALSE(observer->did_finish_navigation_called()); |
| 414 web_state_->OnErrorPageNavigation(GURL("http://test")); | 418 web_state_->OnErrorPageNavigation(GURL("http://test")); |
| 415 EXPECT_TRUE(observer->did_finish_navigation_called()); | 419 EXPECT_TRUE(observer->did_finish_navigation_called()); |
| 416 | 420 |
| 421 // Test that OnTitleChanged() is called. |
| 422 EXPECT_FALSE(observer->title_was_set_called()); |
| 423 web_state_->OnTitleChanged(); |
| 424 EXPECT_TRUE(observer->title_was_set_called()); |
| 425 |
| 417 // Test that WebStateDestroyed() is called. | 426 // Test that WebStateDestroyed() is called. |
| 418 EXPECT_FALSE(observer->web_state_destroyed_called()); | 427 EXPECT_FALSE(observer->web_state_destroyed_called()); |
| 419 web_state_.reset(); | 428 web_state_.reset(); |
| 420 EXPECT_TRUE(observer->web_state_destroyed_called()); | 429 EXPECT_TRUE(observer->web_state_destroyed_called()); |
| 421 | 430 |
| 422 EXPECT_EQ(nullptr, observer->web_state()); | 431 EXPECT_EQ(nullptr, observer->web_state()); |
| 423 } | 432 } |
| 424 | 433 |
| 425 // Tests that WebStateDelegate methods appropriately called. | 434 // Tests that WebStateDelegate methods appropriately called. |
| 426 TEST_F(WebStateTest, DelegateTest) { | 435 TEST_F(WebStateTest, DelegateTest) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 "</script>"); | 698 "</script>"); |
| 690 | 699 |
| 691 base::test::ios::WaitUntilCondition(^{ | 700 base::test::ios::WaitUntilCondition(^{ |
| 692 return message_received; | 701 return message_received; |
| 693 }); | 702 }); |
| 694 web_state_->RemoveScriptCommandCallback("test"); | 703 web_state_->RemoveScriptCommandCallback("test"); |
| 695 } | 704 } |
| 696 | 705 |
| 697 } // namespace | 706 } // namespace |
| 698 } // namespace web | 707 } // namespace web |
| OLD | NEW |