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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2710913006: Removed -[CRWWebDelegate webController:titleDidChange:]. (Closed)
Patch Set: Rebased Created 3 years, 9 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
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | ios/web/web_state/web_state_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/ios/ios_util.h" 11 #include "base/ios/ios_util.h"
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #include "base/strings/utf_string_conversions.h"
13 #import "base/test/ios/wait_util.h" 14 #import "base/test/ios/wait_util.h"
14 #import "ios/testing/ocmock_complex_type_helper.h" 15 #import "ios/testing/ocmock_complex_type_helper.h"
15 #import "ios/web/navigation/crw_session_controller.h" 16 #import "ios/web/navigation/crw_session_controller.h"
16 #import "ios/web/navigation/crw_session_entry.h" 17 #import "ios/web/navigation/crw_session_entry.h"
17 #import "ios/web/navigation/navigation_item_impl.h" 18 #import "ios/web/navigation/navigation_item_impl.h"
18 #import "ios/web/navigation/navigation_manager_impl.h" 19 #import "ios/web/navigation/navigation_manager_impl.h"
19 #include "ios/web/public/referrer.h" 20 #include "ios/web/public/referrer.h"
20 #import "ios/web/public/test/fakes/test_native_content.h" 21 #import "ios/web/public/test/fakes/test_native_content.h"
21 #import "ios/web/public/test/fakes/test_native_content_provider.h" 22 #import "ios/web/public/test/fakes/test_native_content_provider.h"
22 #import "ios/web/public/test/fakes/test_web_client.h" 23 #import "ios/web/public/test/fakes/test_web_client.h"
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 TEST_F(CRWWebControllerWindowOpenTest, BlockPopup) { 986 TEST_F(CRWWebControllerWindowOpenTest, BlockPopup) {
986 ASSERT_FALSE([web_controller() userIsInteracting]); 987 ASSERT_FALSE([web_controller() userIsInteracting]);
987 EXPECT_NSEQ([NSNull null], OpenWindowByDOM()); 988 EXPECT_NSEQ([NSNull null], OpenWindowByDOM());
988 989
989 EXPECT_EQ(web_controller(), [delegate_ webController]); 990 EXPECT_EQ(web_controller(), [delegate_ webController]);
990 EXPECT_EQ("javascript:void(0);", [delegate_ childURL].spec()); 991 EXPECT_EQ("javascript:void(0);", [delegate_ childURL].spec());
991 EXPECT_EQ("http://test/", [delegate_ openerURL].spec()); 992 EXPECT_EQ("http://test/", [delegate_ openerURL].spec());
992 EXPECT_FALSE([delegate_ initiatedByUser]); 993 EXPECT_FALSE([delegate_ initiatedByUser]);
993 }; 994 };
994 995
996 // Tests page title changes.
997 typedef web::WebTestWithWebState CRWWebControllerTitleTest;
998 TEST_F(CRWWebControllerTitleTest, TitleChange) {
999 // Observes and waits for TitleWasSet call.
1000 class TitleObserver : public web::WebStateObserver {
1001 public:
1002 explicit TitleObserver(web::WebState* web_state)
1003 : web::WebStateObserver(web_state) {}
1004 // Returns number of times |TitleWasSet| was called.
1005 int title_change_count() { return title_change_count_; }
1006 // WebStateObserver overrides:
1007 void TitleWasSet() override { title_change_count_++; }
1008
1009 private:
1010 int title_change_count_ = 0;
1011 };
1012
1013 TitleObserver observer(web_state());
1014 ASSERT_EQ(0, observer.title_change_count());
1015
1016 // Expect TitleWasSet callback after the page is loaded.
1017 LoadHtml(@"<title>Title1</title>");
1018 EXPECT_EQ("Title1", base::UTF16ToUTF8(web_state()->GetTitle()));
1019 EXPECT_EQ(1, observer.title_change_count());
1020
1021 // Expect at least one more TitleWasSet callback after changing title via
1022 // JavaScript. On iOS 10 WKWebView fires 3 callbacks after JS excucution
1023 // with the following title changes: "Title2", "" and "Title2".
1024 // TODO(crbug.com/696104): There should be only 2 calls of TitleWasSet.
1025 // Fix expecteation when WKWebView stops sending extra KVO calls.
1026 ExecuteJavaScript(@"window.document.title = 'Title2';");
1027 EXPECT_EQ("Title2", base::UTF16ToUTF8(web_state()->GetTitle()));
1028 EXPECT_GE(observer.title_change_count(), 2);
1029 };
1030
995 // Fixture class to test WKWebView crashes. 1031 // Fixture class to test WKWebView crashes.
996 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController { 1032 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController {
997 protected: 1033 protected:
998 void SetUp() override { 1034 void SetUp() override {
999 web::WebTestWithWebController::SetUp(); 1035 web::WebTestWithWebController::SetUp();
1000 webView_.reset([web::BuildTerminatedWKWebView() retain]); 1036 webView_.reset([web::BuildTerminatedWKWebView() retain]);
1001 base::scoped_nsobject<TestWebViewContentView> webViewContentView( 1037 base::scoped_nsobject<TestWebViewContentView> webViewContentView(
1002 [[TestWebViewContentView alloc] 1038 [[TestWebViewContentView alloc]
1003 initWithMockWebView:webView_ 1039 initWithMockWebView:webView_
1004 scrollView:[webView_ scrollView]]); 1040 scrollView:[webView_ scrollView]]);
(...skipping 26 matching lines...) Expand all
1031 }; 1067 };
1032 1068
1033 RenderProcessGoneObserver observer(web_state()); 1069 RenderProcessGoneObserver observer(web_state());
1034 web::SimulateWKWebViewCrash(webView_); 1070 web::SimulateWKWebViewCrash(webView_);
1035 observer.WaitForRenderProcessGone(); 1071 observer.WaitForRenderProcessGone();
1036 1072
1037 EXPECT_FALSE([web_controller() isViewAlive]); 1073 EXPECT_FALSE([web_controller() isViewAlive]);
1038 }; 1074 };
1039 1075
1040 } // namespace 1076 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | ios/web/web_state/web_state_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698