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

Side by Side Diff: Source/WebKit/chromium/tests/WebFrameTest.cpp

Issue 15017002: WebFrame::selectRange and moveCaret should behave like mouse selection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comment Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 } 2192 }
2193 2193
2194 TEST_F(WebFrameTest, SelectRange) 2194 TEST_F(WebFrameTest, SelectRange)
2195 { 2195 {
2196 WebFrame* frame; 2196 WebFrame* frame;
2197 WebRect startWebRect; 2197 WebRect startWebRect;
2198 WebRect endWebRect; 2198 WebRect endWebRect;
2199 2199
2200 registerMockedHttpURLLoad("select_range_basic.html"); 2200 registerMockedHttpURLLoad("select_range_basic.html");
2201 registerMockedHttpURLLoad("select_range_scroll.html"); 2201 registerMockedHttpURLLoad("select_range_scroll.html");
2202 registerMockedHttpURLLoad("select_range_iframe.html");
2203 registerMockedHttpURLLoad("select_range_editable.html");
2204 2202
2205 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_basic.ht ml"); 2203 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_basic.ht ml");
2206 frame = m_webView->mainFrame(); 2204 frame = m_webView->mainFrame();
2207 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); 2205 EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
2208 m_webView->selectionBounds(startWebRect, endWebRect); 2206 m_webView->selectionBounds(startWebRect, endWebRect);
2209 frame->executeCommand(WebString::fromUTF8("Unselect")); 2207 frame->executeCommand(WebString::fromUTF8("Unselect"));
2210 EXPECT_EQ("", selectionAsString(frame)); 2208 EXPECT_EQ("", selectionAsString(frame));
2211 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2209 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2212 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); 2210 EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
2213 m_webView->close(); 2211 m_webView->close();
2214 m_webView = 0; 2212 m_webView = 0;
2215 2213
2216 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_scroll.h tml"); 2214 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_scroll.h tml");
2217 frame = m_webView->mainFrame(); 2215 frame = m_webView->mainFrame();
2218 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ; 2216 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ;
2219 m_webView->selectionBounds(startWebRect, endWebRect); 2217 m_webView->selectionBounds(startWebRect, endWebRect);
2220 frame->executeCommand(WebString::fromUTF8("Unselect")); 2218 frame->executeCommand(WebString::fromUTF8("Unselect"));
2221 EXPECT_EQ("", selectionAsString(frame)); 2219 EXPECT_EQ("", selectionAsString(frame));
2222 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2220 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2223 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ; 2221 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ;
2224 m_webView->close(); 2222 m_webView->close();
2225 m_webView = 0; 2223 m_webView = 0;
2224 }
2225
2226 TEST_F(WebFrameTest, SelectRangeInIframe)
2227 {
2228 WebFrame* frame;
2229 WebRect startWebRect;
2230 WebRect endWebRect;
2231
2232 registerMockedHttpURLLoad("select_range_iframe.html");
2233 registerMockedHttpURLLoad("select_range_basic.html");
2226 2234
2227 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_iframe.h tml"); 2235 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_iframe.h tml");
2228 frame = m_webView->mainFrame(); 2236 frame = m_webView->mainFrame();
2229 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html /body/iframe")); 2237 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html /body/iframe"));
2230 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); 2238 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
2231 m_webView->selectionBounds(startWebRect, endWebRect); 2239 m_webView->selectionBounds(startWebRect, endWebRect);
2232 subframe->executeCommand(WebString::fromUTF8("Unselect")); 2240 subframe->executeCommand(WebString::fromUTF8("Unselect"));
2233 EXPECT_EQ("", selectionAsString(subframe)); 2241 EXPECT_EQ("", selectionAsString(subframe));
2234 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect) ); 2242 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect) );
2235 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); 2243 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
2236 m_webView->close(); 2244 m_webView->close();
2237 m_webView = 0; 2245 m_webView = 0;
2246 }
2247
2248 TEST_F(WebFrameTest, SelectRangeDivContentEditable)
2249 {
2250 WebFrame* frame;
2251 WebRect startWebRect;
2252 WebRect endWebRect;
2253
2254 registerMockedHttpURLLoad("select_range_div_editable.html");
2238 2255
2239 // Select the middle of an editable element, then try to extend the selectio n to the top of the document. 2256 // Select the middle of an editable element, then try to extend the selectio n to the top of the document.
2240 // The selection range should be clipped to the bounds of the editable eleme nt. 2257 // The selection range should be clipped to the bounds of the editable eleme nt.
2241 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_editable .html"); 2258 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html");
2242 frame = m_webView->mainFrame(); 2259 frame = m_webView->mainFrame();
2243 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2260 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2244 m_webView->selectionBounds(startWebRect, endWebRect); 2261 m_webView->selectionBounds(startWebRect, endWebRect);
2262
2245 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); 2263 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0));
2246 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame)); 2264 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame));
2247 m_webView->close(); 2265 m_webView->close();
2248 m_webView = 0; 2266 m_webView = 0;
2249 2267
2250 // As above, but extending the selection to the bottom of the document. 2268 // As above, but extending the selection to the bottom of the document.
2251 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_editable .html"); 2269 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html");
2270 frame = m_webView->mainFrame();
2271
2272 m_webView->selectionBounds(startWebRect, endWebRect);
2273 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2274 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2275 m_webView->selectionBounds(startWebRect, endWebRect);
2276
2277 m_webView->selectionBounds(startWebRect, endWebRect);
2278 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480));
2279 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame));
2280 m_webView->close();
2281 m_webView = 0;
2282 }
2283
2284 // positionForPoint returns the wrong values for contenteditable spans. See
2285 // http://crbug.com/238334.
2286 TEST_F(WebFrameTest, DISABLED_SelectRangeSpanContentEditable)
2287 {
2288 WebFrame* frame;
2289 WebRect startWebRect;
2290 WebRect endWebRect;
2291
2292 registerMockedHttpURLLoad("select_range_span_editable.html");
2293
2294 // Select the middle of an editable element, then try to extend the selectio n to the top of the document.
2295 // The selection range should be clipped to the bounds of the editable eleme nt.
2296 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html");
2252 frame = m_webView->mainFrame(); 2297 frame = m_webView->mainFrame();
2253 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2298 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2254 m_webView->selectionBounds(startWebRect, endWebRect); 2299 m_webView->selectionBounds(startWebRect, endWebRect);
2300
2301 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0));
2302 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame));
2303 m_webView->close();
2304 m_webView = 0;
2305
2306 // As above, but extending the selection to the bottom of the document.
2307 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html");
2308 frame = m_webView->mainFrame();
2309
2310 m_webView->selectionBounds(startWebRect, endWebRect);
2311 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2312 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2313 m_webView->selectionBounds(startWebRect, endWebRect);
2314
2315 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2316 m_webView->selectionBounds(startWebRect, endWebRect);
2255 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); 2317 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480));
2256 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame)); 2318 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame));
2257 m_webView->close(); 2319 m_webView->close();
2258 m_webView = 0; 2320 m_webView = 0;
2259 } 2321 }
2260 2322
2261 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart) 2323 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart)
2262 { 2324 {
2263 registerMockedHttpURLLoad("text_selection.html"); 2325 registerMockedHttpURLLoad("text_selection.html");
2264 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ; 2326 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ;
(...skipping 28 matching lines...) Expand all
2293 // Can extend the selection completely across editable elements. 2355 // Can extend the selection completely across editable elements.
2294 frame->executeScript(WebScriptSource("selectElement('footer_2');")); 2356 frame->executeScript(WebScriptSource("selectElement('footer_2');"));
2295 EXPECT_EQ("Footer 2.", selectionAsString(frame)); 2357 EXPECT_EQ("Footer 2.", selectionAsString(frame));
2296 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "footer_2")), to pLeft(elementBounds(frame, "header_2"))); 2358 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "footer_2")), to pLeft(elementBounds(frame, "header_2")));
2297 EXPECT_EQ("Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1. Footer 2.", s electionAsString(frame)); 2359 EXPECT_EQ("Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1. Footer 2.", s electionAsString(frame));
2298 2360
2299 // If the selection is editable text, we can't extend it into non-editable t ext. 2361 // If the selection is editable text, we can't extend it into non-editable t ext.
2300 frame->executeScript(WebScriptSource("selectElement('editable_2');")); 2362 frame->executeScript(WebScriptSource("selectElement('editable_2');"));
2301 EXPECT_EQ("Editable 2.", selectionAsString(frame)); 2363 EXPECT_EQ("Editable 2.", selectionAsString(frame));
2302 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")), topLeft(elementBounds(frame, "header_2"))); 2364 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")), topLeft(elementBounds(frame, "header_2")));
2303 EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); 2365 // positionForPoint returns the wrong values for contenteditable spans. See
2366 // http://crbug.com/238334.
2367 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame));
2304 } 2368 }
2305 2369
2306 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd) 2370 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd)
2307 { 2371 {
2308 registerMockedHttpURLLoad("text_selection.html"); 2372 registerMockedHttpURLLoad("text_selection.html");
2309 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ; 2373 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ;
2310 WebFrame* frame = m_webView->mainFrame(); 2374 WebFrame* frame = m_webView->mainFrame();
2311 2375
2312 // Select first span. We can move the end to include the second span. 2376 // Select first span. We can move the end to include the second span.
2313 frame->executeScript(WebScriptSource("selectElement('header_1');")); 2377 frame->executeScript(WebScriptSource("selectElement('header_1');"));
(...skipping 24 matching lines...) Expand all
2338 // Can extend the selection completely across editable elements. 2402 // Can extend the selection completely across editable elements.
2339 frame->executeScript(WebScriptSource("selectElement('header_1');")); 2403 frame->executeScript(WebScriptSource("selectElement('header_1');"));
2340 EXPECT_EQ("Header 1.", selectionAsString(frame)); 2404 EXPECT_EQ("Header 1.", selectionAsString(frame));
2341 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin usOne(elementBounds(frame, "footer_1"))); 2405 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin usOne(elementBounds(frame, "footer_1")));
2342 EXPECT_EQ("Header 1. Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1.", s electionAsString(frame)); 2406 EXPECT_EQ("Header 1. Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1.", s electionAsString(frame));
2343 2407
2344 // If the selection is editable text, we can't extend it into non-editable t ext. 2408 // If the selection is editable text, we can't extend it into non-editable t ext.
2345 frame->executeScript(WebScriptSource("selectElement('editable_1');")); 2409 frame->executeScript(WebScriptSource("selectElement('editable_1');"));
2346 EXPECT_EQ("Editable 1.", selectionAsString(frame)); 2410 EXPECT_EQ("Editable 1.", selectionAsString(frame));
2347 frame->selectRange(topLeft(elementBounds(frame, "editable_1")), bottomRightM inusOne(elementBounds(frame, "footer_1"))); 2411 frame->selectRange(topLeft(elementBounds(frame, "editable_1")), bottomRightM inusOne(elementBounds(frame, "footer_1")));
2348 EXPECT_EQ("Editable 1. Editable 2. ]", selectionAsString(frame)); 2412 // positionForPoint returns the wrong values for contenteditable spans. See
2413 // http://crbug.com/238334.
2414 // EXPECT_EQ("Editable 1. Editable 2. ]", selectionAsString(frame));
2415 }
2416
2417 // positionForPoint returns the wrong values for contenteditable spans. See
2418 // http://crbug.com/238334.
2419 TEST_F(WebFrameTest, DISABLED_PositionForPointTest)
2420 {
2421 registerMockedHttpURLLoad("select_range_span_editable.html");
2422 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html");
2423 WebFrameImpl* mainFrame = static_cast<WebFrameImpl*>(m_webView->mainFrame()) ;
2424 WebCore::RenderObject* renderer = mainFrame->frame()->selection()->rootEdita bleElement()->renderer();
2425 EXPECT_EQ(0, renderer->positionForPoint(WebCore::LayoutPoint(-1, -1)).deepEq uivalent().computeOffsetInContainerNode());
2426 EXPECT_EQ(64, renderer->positionForPoint(WebCore::LayoutPoint(1000, 1000)).d eepEquivalent().computeOffsetInContainerNode());
2427
2428 registerMockedHttpURLLoad("select_range_div_editable.html");
2429 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html");
2430 mainFrame = static_cast<WebFrameImpl*>(m_webView->mainFrame());
2431 renderer = mainFrame->frame()->selection()->rootEditableElement()->renderer( );
2432 EXPECT_EQ(0, renderer->positionForPoint(WebCore::LayoutPoint(-1, -1)).deepEq uivalent().computeOffsetInContainerNode());
2433 EXPECT_EQ(64, renderer->positionForPoint(WebCore::LayoutPoint(1000, 1000)).d eepEquivalent().computeOffsetInContainerNode());
2349 } 2434 }
2350 2435
2351 #if OS(ANDROID) 2436 #if OS(ANDROID)
2437 TEST_F(WebFrameTest, SelectRangeStaysHorizontallyAlignedWhenMoved)
2438 {
2439 WebFrameImpl* frame;
2440 registerMockedHttpURLLoad("move_caret.html");
2441
2442 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html");
2443 frame = (WebFrameImpl*)m_webView->mainFrame();
2444
2445 WebRect initialStartRect;
2446 WebRect initialEndRect;
2447 WebRect startRect;
2448 WebRect endRect;
2449
2450 frame->executeScript(WebScriptSource("selectRange();"));
2451 m_webView->selectionBounds(initialStartRect, initialEndRect);
2452 WebPoint movedStart(topLeft(initialStartRect));
2453
2454 movedStart.y += 40;
2455 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect));
2456 m_webView->selectionBounds(startRect, endRect);
2457 EXPECT_EQ(startRect, initialStartRect);
2458 EXPECT_EQ(endRect, initialEndRect);
2459
2460 movedStart.y -= 80;
2461 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect));
2462 m_webView->selectionBounds(startRect, endRect);
2463 EXPECT_EQ(startRect, initialStartRect);
2464 EXPECT_EQ(endRect, initialEndRect);
2465
2466 WebPoint movedEnd(bottomRightMinusOne(initialEndRect));
2467
2468 movedEnd.y += 40;
2469 frame->selectRange(topLeft(initialStartRect), movedEnd);
2470 m_webView->selectionBounds(startRect, endRect);
2471 EXPECT_EQ(startRect, initialStartRect);
2472 EXPECT_EQ(endRect, initialEndRect);
2473
2474 movedEnd.y -= 80;
2475 frame->selectRange(topLeft(initialStartRect), movedEnd);
2476 m_webView->selectionBounds(startRect, endRect);
2477 EXPECT_EQ(startRect, initialStartRect);
2478 EXPECT_EQ(endRect, initialEndRect);
2479 }
2480
2352 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved) 2481 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved)
2353 { 2482 {
2354 WebFrameImpl* frame; 2483 WebFrameImpl* frame;
2355 registerMockedHttpURLLoad("move_caret.html"); 2484 registerMockedHttpURLLoad("move_caret.html");
2356 2485
2357 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html"); 2486 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html");
2358 frame = (WebFrameImpl*)m_webView->mainFrame(); 2487 frame = (WebFrameImpl*)m_webView->mainFrame();
2359 2488
2360 WebRect initialStartRect; 2489 WebRect initialStartRect;
2361 WebRect initialEndRect; 2490 WebRect initialEndRect;
2362 WebRect startRect; 2491 WebRect startRect;
2363 WebRect endRect; 2492 WebRect endRect;
2364 2493
2365 frame->executeScript(WebScriptSource("select();")); 2494 frame->executeScript(WebScriptSource("selectCaret();"));
2366 m_webView->selectionBounds(initialStartRect, initialEndRect); 2495 m_webView->selectionBounds(initialStartRect, initialEndRect);
2367 WebPoint moveTo(topLeft(initialStartRect)); 2496 WebPoint moveTo(topLeft(initialStartRect));
2368 2497
2369 moveTo.y += 40; 2498 moveTo.y += 40;
2370 frame->moveCaretSelectionTowardsWindowPoint(moveTo); 2499 frame->moveCaretSelectionTowardsWindowPoint(moveTo);
2371 m_webView->selectionBounds(startRect, endRect); 2500 m_webView->selectionBounds(startRect, endRect);
2372 EXPECT_EQ(startRect, initialStartRect); 2501 EXPECT_EQ(startRect, initialStartRect);
2373 EXPECT_EQ(endRect, initialEndRect); 2502 EXPECT_EQ(endRect, initialEndRect);
2374 2503
2375 moveTo.y -= 80; 2504 moveTo.y -= 80;
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 EXPECT_FALSE(client.wasProgrammaticScroll()); 3121 EXPECT_FALSE(client.wasProgrammaticScroll());
2993 EXPECT_TRUE(client.wasUserScroll()); 3122 EXPECT_TRUE(client.wasUserScroll());
2994 client.reset(); 3123 client.reset();
2995 3124
2996 m_webView->close(); 3125 m_webView->close();
2997 m_webView = 0; 3126 m_webView = 0;
2998 } 3127 }
2999 3128
3000 3129
3001 } // namespace 3130 } // namespace
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebFrameImpl.cpp ('k') | Source/WebKit/chromium/tests/data/move_caret.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698