Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: ios/web/web_state/web_state_impl_unittest.mm

Issue 1851003003: [ios] Added web// public API to let embedder observe loading progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "ios/web/public/load_committed_details.h" 11 #include "ios/web/public/load_committed_details.h"
12 #include "ios/web/public/ssl_status.h"
12 #include "ios/web/public/test/test_browser_state.h" 13 #include "ios/web/public/test/test_browser_state.h"
13 #include "ios/web/public/web_state/global_web_state_observer.h" 14 #include "ios/web/public/web_state/global_web_state_observer.h"
15 #include "ios/web/public/web_state/web_state_delegate.h"
14 #include "ios/web/public/web_state/web_state_observer.h" 16 #include "ios/web/public/web_state/web_state_observer.h"
15 #include "ios/web/public/web_state/web_state_policy_decider.h" 17 #include "ios/web/public/web_state/web_state_policy_decider.h"
16 #include "ios/web/web_state/global_web_state_event_tracker.h" 18 #include "ios/web/web_state/global_web_state_event_tracker.h"
17 #include "ios/web/web_state/web_state_impl.h" 19 #include "ios/web/web_state/web_state_impl.h"
18 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
19 #include "net/http/http_util.h" 21 #include "net/http/http_util.h"
20 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/gtest_mac.h" 24 #include "testing/gtest_mac.h"
23 #include "testing/platform_test.h" 25 #include "testing/platform_test.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 99
98 bool navigation_items_pruned_called_; 100 bool navigation_items_pruned_called_;
99 bool navigation_item_changed_called_; 101 bool navigation_item_changed_called_;
100 bool navigation_item_committed_called_; 102 bool navigation_item_committed_called_;
101 bool did_start_loading_called_; 103 bool did_start_loading_called_;
102 bool did_stop_loading_called_; 104 bool did_stop_loading_called_;
103 bool page_loaded_called_with_success_; 105 bool page_loaded_called_with_success_;
104 bool web_state_destroyed_called_; 106 bool web_state_destroyed_called_;
105 }; 107 };
106 108
109 // Test delegate to check that the WebStateDelegate methods are called as
110 // expected.
111 class TestWebStateDelegate : public WebStateDelegate {
112 public:
113 TestWebStateDelegate() : load_progress_changed_called_(false) {}
114
115 // Methods returning true if the corresponding WebStateObserver method has
116 // been called.
117 bool load_progress_changed_called() const {
118 return load_progress_changed_called_;
119 }
120
121 private:
122 // WebStateObserver implementation:
123 void LoadProgressChanged(WebState* source, double progress) override {
124 load_progress_changed_called_ = true;
125 }
126
127 bool load_progress_changed_called_;
128 };
129
107 // Test observer to check that the WebStateObserver methods are called as 130 // Test observer to check that the WebStateObserver methods are called as
108 // expected. 131 // expected.
109 class TestWebStateObserver : public WebStateObserver { 132 class TestWebStateObserver : public WebStateObserver {
110 public: 133 public:
111 TestWebStateObserver(WebState* web_state) 134 TestWebStateObserver(WebState* web_state)
112 : WebStateObserver(web_state), 135 : WebStateObserver(web_state),
113 provisional_navigation_started_called_(false), 136 provisional_navigation_started_called_(false),
114 navigation_items_pruned_called_(false), 137 navigation_items_pruned_called_(false),
115 navigation_item_changed_called_(false), 138 navigation_item_changed_called_(false),
116 navigation_item_committed_called_(false), 139 navigation_item_committed_called_(false),
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 EXPECT_TRUE(observer->history_state_changed_called()); 359 EXPECT_TRUE(observer->history_state_changed_called());
337 360
338 // Test that WebStateDestroyed() is called. 361 // Test that WebStateDestroyed() is called.
339 EXPECT_FALSE(observer->web_state_destroyed_called()); 362 EXPECT_FALSE(observer->web_state_destroyed_called());
340 web_state_.reset(); 363 web_state_.reset();
341 EXPECT_TRUE(observer->web_state_destroyed_called()); 364 EXPECT_TRUE(observer->web_state_destroyed_called());
342 365
343 EXPECT_EQ(nullptr, observer->web_state()); 366 EXPECT_EQ(nullptr, observer->web_state());
344 } 367 }
345 368
369 // Tests that WebStateDelegate methods appropriately called.
370 TEST_F(WebStateTest, DelegateTest) {
371 TestWebStateDelegate delegate;
372 web_state_->SetDelegate(&delegate);
373
374 // Test that LoadProgressChanged() is called.
375 EXPECT_FALSE(delegate.load_progress_changed_called());
376 web_state_->SendChangeLoadProgress(0.0);
377 EXPECT_TRUE(delegate.load_progress_changed_called());
378 }
379
346 // Verifies that GlobalWebStateObservers are called when expected. 380 // Verifies that GlobalWebStateObservers are called when expected.
347 TEST_F(WebStateTest, GlobalObserverTest) { 381 TEST_F(WebStateTest, GlobalObserverTest) {
348 scoped_ptr<TestGlobalWebStateObserver> observer( 382 scoped_ptr<TestGlobalWebStateObserver> observer(
349 new TestGlobalWebStateObserver()); 383 new TestGlobalWebStateObserver());
350 384
351 // Test that NavigationItemsPruned() is called. 385 // Test that NavigationItemsPruned() is called.
352 EXPECT_FALSE(observer->navigation_items_pruned_called()); 386 EXPECT_FALSE(observer->navigation_items_pruned_called());
353 web_state_->OnNavigationItemsPruned(1); 387 web_state_->OnNavigationItemsPruned(1);
354 EXPECT_TRUE(observer->navigation_items_pruned_called()); 388 EXPECT_TRUE(observer->navigation_items_pruned_called());
355 389
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 EXPECT_FALSE( 527 EXPECT_FALSE(
494 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false)); 528 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false));
495 EXPECT_FALSE(is_called_1); 529 EXPECT_FALSE(is_called_1);
496 EXPECT_TRUE(is_called_2); 530 EXPECT_TRUE(is_called_2);
497 531
498 web_state_->RemoveScriptCommandCallback(kPrefix2); 532 web_state_->RemoveScriptCommandCallback(kPrefix2);
499 } 533 }
500 534
501 } // namespace 535 } // namespace
502 } // namespace web 536 } // namespace web
OLDNEW
« ios/web/shell/view_controller.mm ('K') | « ios/web/web_state/web_state_impl.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698