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

Side by Side Diff: Source/web/tests/WebViewTest.cpp

Issue 23671002: Refactoring: Add toWebFrameImpl() interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Corrected as per review commments. Created 7 years, 3 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 | « Source/web/tests/WebFrameTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 webView->close(); 258 webView->close();
259 } 259 }
260 260
261 TEST_F(WebViewTest, FocusIsInactive) 261 TEST_F(WebViewTest, FocusIsInactive)
262 { 262 {
263 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), "visible_iframe.html"); 263 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), "visible_iframe.html");
264 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visib le_iframe.html"); 264 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visib le_iframe.html");
265 265
266 webView->setFocus(true); 266 webView->setFocus(true);
267 webView->setIsActive(true); 267 webView->setIsActive(true);
268 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 268 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
269 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); 269 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
270 270
271 WebCore::HTMLDocument* document = static_cast<WebCore::HTMLDocument*>(frame- >frame()->document()); 271 WebCore::HTMLDocument* document = static_cast<WebCore::HTMLDocument*>(frame- >frame()->document());
272 EXPECT_TRUE(document->hasFocus()); 272 EXPECT_TRUE(document->hasFocus());
273 webView->setFocus(false); 273 webView->setFocus(false);
274 webView->setIsActive(false); 274 webView->setIsActive(false);
275 EXPECT_FALSE(document->hasFocus()); 275 EXPECT_FALSE(document->hasFocus());
276 webView->setFocus(true); 276 webView->setFocus(true);
277 webView->setIsActive(true); 277 webView->setIsActive(true);
278 EXPECT_TRUE(document->hasFocus()); 278 EXPECT_TRUE(document->hasFocus());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 const std::string& pageWidth, const std::string & pageHeight, 333 const std::string& pageWidth, const std::string & pageHeight,
334 int expectedWidth, int expectedHeight, 334 int expectedWidth, int expectedHeight,
335 HorizontalScrollbarState expectedHorizontalStat e, VerticalScrollbarState expectedVerticalState) 335 HorizontalScrollbarState expectedHorizontalStat e, VerticalScrollbarState expectedVerticalState)
336 { 336 {
337 AutoResizeWebViewClient client; 337 AutoResizeWebViewClient client;
338 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH eight; 338 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH eight;
339 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); 339 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html");
340 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0, &cli ent); 340 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0, &cli ent);
341 client.testData().setWebView(webView); 341 client.testData().setWebView(webView);
342 342
343 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 343 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
344 WebCore::FrameView* frameView = frame->frame()->view(); 344 WebCore::FrameView* frameView = frame->frame()->view();
345 frameView->layout(); 345 frameView->layout();
346 EXPECT_FALSE(frameView->layoutPending()); 346 EXPECT_FALSE(frameView->layoutPending());
347 EXPECT_FALSE(frameView->needsLayout()); 347 EXPECT_FALSE(frameView->needsLayout());
348 348
349 webView->enableAutoResizeMode(minAutoResize, maxAutoResize); 349 webView->enableAutoResizeMode(minAutoResize, maxAutoResize);
350 EXPECT_TRUE(frameView->layoutPending()); 350 EXPECT_TRUE(frameView->layoutPending());
351 EXPECT_TRUE(frameView->needsLayout()); 351 EXPECT_TRUE(frameView->needsLayout());
352 frameView->layout(); 352 frameView->layout();
353 353
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 testInputMode(WebString(), "input_mode_type_url_verbatim.html"); 474 testInputMode(WebString(), "input_mode_type_url_verbatim.html");
475 testInputMode(WebString("verbatim"), "input_mode_textarea_verbatim.html"); 475 testInputMode(WebString("verbatim"), "input_mode_textarea_verbatim.html");
476 } 476 }
477 477
478 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) 478 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
479 { 479 {
480 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 480 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
481 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html"); 481 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html");
482 webView->setInitialFocus(false); 482 webView->setInitialFocus(false);
483 webView->setEditableSelectionOffsets(5, 13); 483 webView->setEditableSelectionOffsets(5, 13);
484 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 484 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
485 EXPECT_EQ("56789abc", frame->selectionAsText()); 485 EXPECT_EQ("56789abc", frame->selectionAsText());
486 WebTextInputInfo info = webView->textInputInfo(); 486 WebTextInputInfo info = webView->textInputInfo();
487 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); 487 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
488 EXPECT_EQ(5, info.selectionStart); 488 EXPECT_EQ(5, info.selectionStart);
489 EXPECT_EQ(13, info.selectionEnd); 489 EXPECT_EQ(13, info.selectionEnd);
490 EXPECT_EQ(-1, info.compositionStart); 490 EXPECT_EQ(-1, info.compositionStart);
491 EXPECT_EQ(-1, info.compositionEnd); 491 EXPECT_EQ(-1, info.compositionEnd);
492 webView->close(); 492 webView->close();
493 493
494 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("content_editable_populated.html")); 494 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("content_editable_populated.html"));
495 webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editab le_populated.html"); 495 webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editab le_populated.html");
496 webView->setInitialFocus(false); 496 webView->setInitialFocus(false);
497 webView->setEditableSelectionOffsets(8, 19); 497 webView->setEditableSelectionOffsets(8, 19);
498 frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 498 frame = toWebFrameImpl(webView->mainFrame());
499 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); 499 EXPECT_EQ("89abcdefghi", frame->selectionAsText());
500 info = webView->textInputInfo(); 500 info = webView->textInputInfo();
501 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); 501 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
502 EXPECT_EQ(8, info.selectionStart); 502 EXPECT_EQ(8, info.selectionStart);
503 EXPECT_EQ(19, info.selectionEnd); 503 EXPECT_EQ(19, info.selectionEnd);
504 EXPECT_EQ(-1, info.compositionStart); 504 EXPECT_EQ(-1, info.compositionStart);
505 EXPECT_EQ(-1, info.compositionEnd); 505 EXPECT_EQ(-1, info.compositionEnd);
506 webView->close(); 506 webView->close();
507 } 507 }
508 508
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 { 932 {
933 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("longpress_selection.html")); 933 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("longpress_selection.html"));
934 934
935 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longp ress_selection.html", true); 935 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longp ress_selection.html", true);
936 webView->resize(WebSize(500, 300)); 936 webView->resize(WebSize(500, 300));
937 webView->layout(); 937 webView->layout();
938 runPendingTasks(); 938 runPendingTasks();
939 939
940 WebString target = WebString::fromUTF8("target"); 940 WebString target = WebString::fromUTF8("target");
941 WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse"); 941 WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse");
942 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 942 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
943 943
944 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselec tstartfalse)); 944 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselec tstartfalse));
945 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); 945 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data()));
946 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target) ); 946 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target) );
947 EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data())); 947 EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data()));
948 webView->close(); 948 webView->close();
949 } 949 }
950 #endif 950 #endif
951 951
952 TEST_F(WebViewTest, SelectionOnDisabledInput) 952 TEST_F(WebViewTest, SelectionOnDisabledInput)
953 { 953 {
954 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_disabled.html")); 954 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_disabled.html"));
955 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec tion_disabled.html", true); 955 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec tion_disabled.html", true);
956 webView->resize(WebSize(640, 480)); 956 webView->resize(WebSize(640, 480));
957 webView->layout(); 957 webView->layout();
958 runPendingTasks(); 958 runPendingTasks();
959 959
960 std::string testWord = "This text should be selected."; 960 std::string testWord = "This text should be selected.";
961 961
962 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 962 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
963 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); 963 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data()));
964 964
965 size_t location; 965 size_t location;
966 size_t length; 966 size_t length;
967 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length )); 967 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length ));
968 EXPECT_EQ(location, 0UL); 968 EXPECT_EQ(location, 0UL);
969 EXPECT_EQ(length, testWord.length()); 969 EXPECT_EQ(length, testWord.length());
970 970
971 webView->close(); 971 webView->close();
972 } 972 }
973 973
974 TEST_F(WebViewTest, SelectionOnReadOnlyInput) 974 TEST_F(WebViewTest, SelectionOnReadOnlyInput)
975 { 975 {
976 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_readonly.html")); 976 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_readonly.html"));
977 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec tion_readonly.html", true); 977 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec tion_readonly.html", true);
978 webView->resize(WebSize(640, 480)); 978 webView->resize(WebSize(640, 480));
979 webView->layout(); 979 webView->layout();
980 runPendingTasks(); 980 runPendingTasks();
981 981
982 std::string testWord = "This text should be selected."; 982 std::string testWord = "This text should be selected.";
983 983
984 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 984 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
985 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); 985 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data()));
986 986
987 size_t location; 987 size_t location;
988 size_t length; 988 size_t length;
989 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length )); 989 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length ));
990 EXPECT_EQ(location, 0UL); 990 EXPECT_EQ(location, 0UL);
991 EXPECT_EQ(length, testWord.length()); 991 EXPECT_EQ(length, testWord.length());
992 992
993 webView->close(); 993 webView->close();
994 } 994 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 EXPECT_TRUE(shadowRoot.isNull()); 1132 EXPECT_TRUE(shadowRoot.isNull());
1133 } 1133 }
1134 webViewImpl->close(); 1134 webViewImpl->close();
1135 } 1135 }
1136 1136
1137 TEST_F(WebViewTest, HelperPlugin) 1137 TEST_F(WebViewTest, HelperPlugin)
1138 { 1138 {
1139 HelperPluginCreatingWebViewClient client; 1139 HelperPluginCreatingWebViewClient client;
1140 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(tru e, 0, &client)); 1140 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(tru e, 0, &client));
1141 1141
1142 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webViewImpl->mainFrame()); 1142 WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame());
1143 client.setWebFrameClient(frame->client()); 1143 client.setWebFrameClient(frame->client());
1144 1144
1145 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p lugin-type", frame->document()); 1145 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p lugin-type", frame->document());
1146 EXPECT_TRUE(helperPlugin); 1146 EXPECT_TRUE(helperPlugin);
1147 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu gin. 1147 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu gin.
1148 1148
1149 webViewImpl->closeHelperPluginSoon(helperPlugin); 1149 webViewImpl->closeHelperPluginSoon(helperPlugin);
1150 1150
1151 webViewImpl->close(); 1151 webViewImpl->close();
1152 } 1152 }
1153 1153
1154 } 1154 }
OLDNEW
« no previous file with comments | « Source/web/tests/WebFrameTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698