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

Unified Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2710913006: Removed -[CRWWebDelegate webController:titleDidChange:]. (Closed)
Patch Set: Rebased Created 3 years, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_web_controller_unittest.mm
diff --git a/ios/web/web_state/ui/crw_web_controller_unittest.mm b/ios/web/web_state/ui/crw_web_controller_unittest.mm
index 3a52ccdcb6c4c7aa005c2f8dace62358b52d9b78..51541e2a7a36740a546260322c36460dd15a6e3d 100644
--- a/ios/web/web_state/ui/crw_web_controller_unittest.mm
+++ b/ios/web/web_state/ui/crw_web_controller_unittest.mm
@@ -10,6 +10,7 @@
#include "base/ios/ios_util.h"
#import "base/mac/scoped_nsobject.h"
+#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h"
#import "ios/testing/ocmock_complex_type_helper.h"
#import "ios/web/navigation/crw_session_controller.h"
@@ -992,6 +993,41 @@ TEST_F(CRWWebControllerWindowOpenTest, BlockPopup) {
EXPECT_FALSE([delegate_ initiatedByUser]);
};
+// Tests page title changes.
+typedef web::WebTestWithWebState CRWWebControllerTitleTest;
+TEST_F(CRWWebControllerTitleTest, TitleChange) {
+ // Observes and waits for TitleWasSet call.
+ class TitleObserver : public web::WebStateObserver {
+ public:
+ explicit TitleObserver(web::WebState* web_state)
+ : web::WebStateObserver(web_state) {}
+ // Returns number of times |TitleWasSet| was called.
+ int title_change_count() { return title_change_count_; }
+ // WebStateObserver overrides:
+ void TitleWasSet() override { title_change_count_++; }
+
+ private:
+ int title_change_count_ = 0;
+ };
+
+ TitleObserver observer(web_state());
+ ASSERT_EQ(0, observer.title_change_count());
+
+ // Expect TitleWasSet callback after the page is loaded.
+ LoadHtml(@"<title>Title1</title>");
+ EXPECT_EQ("Title1", base::UTF16ToUTF8(web_state()->GetTitle()));
+ EXPECT_EQ(1, observer.title_change_count());
+
+ // Expect at least one more TitleWasSet callback after changing title via
+ // JavaScript. On iOS 10 WKWebView fires 3 callbacks after JS excucution
+ // with the following title changes: "Title2", "" and "Title2".
+ // TODO(crbug.com/696104): There should be only 2 calls of TitleWasSet.
+ // Fix expecteation when WKWebView stops sending extra KVO calls.
+ ExecuteJavaScript(@"window.document.title = 'Title2';");
+ EXPECT_EQ("Title2", base::UTF16ToUTF8(web_state()->GetTitle()));
+ EXPECT_GE(observer.title_change_count(), 2);
+};
+
// Fixture class to test WKWebView crashes.
class CRWWebControllerWebProcessTest : public web::WebTestWithWebController {
protected:
« 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