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

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

Issue 1433103002: Use FocusParams in FocusController::setFocusedElement and Document::setFocusedElement arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « third_party/WebKit/Source/web/WebViewImpl.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 2420 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); 2431 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client);
2432 webViewImpl->setInitialFocus(false); 2432 webViewImpl->setInitialFocus(false);
2433 2433
2434 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); 2434 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
2435 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); 2435 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
2436 2436
2437 // (A) <input> 2437 // (A) <input>
2438 // (A.1) Verifies autocorrect/autocomplete/spellcheck flags are Off and 2438 // (A.1) Verifies autocorrect/autocomplete/spellcheck flags are Off and
2439 // autocapitalize is set to none. 2439 // autocapitalize is set to none.
2440 HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById ("input")); 2440 HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById ("input"));
2441 document->setFocusedElement(inputElement); 2441 document->setFocusedElement(inputElement, FocusParams(SelectionBehaviorOnFoc us::None, WebFocusTypeNone, nullptr));
2442 webViewImpl->setFocus(true); 2442 webViewImpl->setFocus(true);
2443 WebTextInputInfo info = webViewImpl->textInputInfo(); 2443 WebTextInputInfo info = webViewImpl->textInputInfo();
2444 EXPECT_EQ( 2444 EXPECT_EQ(
2445 WebTextInputFlagAutocompleteOff | WebTextInputFlagAutocorrectOff | WebTe xtInputFlagSpellcheckOff | WebTextInputFlagAutocapitalizeNone, 2445 WebTextInputFlagAutocompleteOff | WebTextInputFlagAutocorrectOff | WebTe xtInputFlagSpellcheckOff | WebTextInputFlagAutocapitalizeNone,
2446 info.flags); 2446 info.flags);
2447 2447
2448 // (A.2) Verifies autocorrect/autocomplete/spellcheck flags are On and 2448 // (A.2) Verifies autocorrect/autocomplete/spellcheck flags are On and
2449 // autocapitalize is set to sentences. 2449 // autocapitalize is set to sentences.
2450 inputElement = toHTMLInputElement(document->getElementById("input2")); 2450 inputElement = toHTMLInputElement(document->getElementById("input2"));
2451 document->setFocusedElement(inputElement); 2451 document->setFocusedElement(inputElement, FocusParams(SelectionBehaviorOnFoc us::None, WebFocusTypeNone, nullptr));
2452 webViewImpl->setFocus(true); 2452 webViewImpl->setFocus(true);
2453 info = webViewImpl->textInputInfo(); 2453 info = webViewImpl->textInputInfo();
2454 EXPECT_EQ( 2454 EXPECT_EQ(
2455 WebTextInputFlagAutocompleteOn | WebTextInputFlagAutocorrectOn | WebText InputFlagSpellcheckOn | WebTextInputFlagAutocapitalizeSentences, 2455 WebTextInputFlagAutocompleteOn | WebTextInputFlagAutocorrectOn | WebText InputFlagSpellcheckOn | WebTextInputFlagAutocapitalizeSentences,
2456 info.flags); 2456 info.flags);
2457 2457
2458 // (B) <textarea> Verifies the default text input flags are 2458 // (B) <textarea> Verifies the default text input flags are
2459 // WebTextInputFlagAutocapitalizeSentences. 2459 // WebTextInputFlagAutocapitalizeSentences.
2460 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getEl ementById("textarea")); 2460 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getEl ementById("textarea"));
2461 document->setFocusedElement(textAreaElement); 2461 document->setFocusedElement(textAreaElement, FocusParams(SelectionBehaviorOn Focus::None, WebFocusTypeNone, nullptr));
2462 webViewImpl->setFocus(true); 2462 webViewImpl->setFocus(true);
2463 info = webViewImpl->textInputInfo(); 2463 info = webViewImpl->textInputInfo();
2464 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info.flags); 2464 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info.flags);
2465 2465
2466 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. 2466 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient.
2467 m_webViewHelper.reset(); 2467 m_webViewHelper.reset();
2468 } 2468 }
2469 2469
2470 // This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUs erInput is 2470 // This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUs erInput is
2471 // called iff value of a focused element is modified via script. 2471 // called iff value of a focused element is modified via script.
2472 TEST_F(WebViewTest, NonUserInputTextUpdate) 2472 TEST_F(WebViewTest, NonUserInputTextUpdate)
2473 { 2473 {
2474 NonUserInputTextUpdateWebViewClient client; 2474 NonUserInputTextUpdateWebViewClient client;
2475 std::string url = m_baseURL + "non_user_input_text_update.html"; 2475 std::string url = m_baseURL + "non_user_input_text_update.html";
2476 URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_upda te.html"); 2476 URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_upda te.html");
2477 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); 2477 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client);
2478 webViewImpl->setInitialFocus(false); 2478 webViewImpl->setInitialFocus(false);
2479 2479
2480 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); 2480 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
2481 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); 2481 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
2482 2482
2483 // (A) <input> 2483 // (A) <input>
2484 // (A.1) Focused and value is changed by script. 2484 // (A.1) Focused and value is changed by script.
2485 client.reset(); 2485 client.reset();
2486 EXPECT_FALSE(client.textIsUpdated()); 2486 EXPECT_FALSE(client.textIsUpdated());
2487 2487
2488 HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById ("input")); 2488 HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById ("input"));
2489 document->setFocusedElement(inputElement); 2489 document->setFocusedElement(inputElement, FocusParams(SelectionBehaviorOnFoc us::None, WebFocusTypeNone, nullptr));
2490 webViewImpl->setFocus(true); 2490 webViewImpl->setFocus(true);
2491 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement)); 2491 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement));
2492 2492
2493 // Emulate value change from script. 2493 // Emulate value change from script.
2494 inputElement->setValue("testA"); 2494 inputElement->setValue("testA");
2495 EXPECT_TRUE(client.textIsUpdated()); 2495 EXPECT_TRUE(client.textIsUpdated());
2496 WebTextInputInfo info = webViewImpl->textInputInfo(); 2496 WebTextInputInfo info = webViewImpl->textInputInfo();
2497 EXPECT_EQ("testA", std::string(info.value.utf8().data())); 2497 EXPECT_EQ("testA", std::string(info.value.utf8().data()));
2498 2498
2499 // (A.2) Focused and user input modifies value. 2499 // (A.2) Focused and user input modifies value.
2500 client.reset(); 2500 client.reset();
2501 EXPECT_FALSE(client.textIsUpdated()); 2501 EXPECT_FALSE(client.textIsUpdated());
2502 2502
2503 WebVector<WebCompositionUnderline> emptyUnderlines; 2503 WebVector<WebCompositionUnderline> emptyUnderlines;
2504 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ; 2504 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ;
2505 webViewImpl->confirmComposition(WebWidget::KeepSelection); 2505 webViewImpl->confirmComposition(WebWidget::KeepSelection);
2506 EXPECT_FALSE(client.textIsUpdated()); 2506 EXPECT_FALSE(client.textIsUpdated());
2507 info = webViewImpl->textInputInfo(); 2507 info = webViewImpl->textInputInfo();
2508 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); 2508 EXPECT_EQ("testA2", std::string(info.value.utf8().data()));
2509 2509
2510 // (A.3) Unfocused and value is changed by script. 2510 // (A.3) Unfocused and value is changed by script.
2511 client.reset(); 2511 client.reset();
2512 EXPECT_FALSE(client.textIsUpdated()); 2512 EXPECT_FALSE(client.textIsUpdated());
2513 document->setFocusedElement(nullptr); 2513 document->clearFocusedElement();
2514 webViewImpl->setFocus(false); 2514 webViewImpl->setFocus(false);
2515 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); 2515 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement));
2516 inputElement->setValue("testA3"); 2516 inputElement->setValue("testA3");
2517 EXPECT_FALSE(client.textIsUpdated()); 2517 EXPECT_FALSE(client.textIsUpdated());
2518 2518
2519 // (B) <textarea> 2519 // (B) <textarea>
2520 // (B.1) Focused and value is changed by script. 2520 // (B.1) Focused and value is changed by script.
2521 client.reset(); 2521 client.reset();
2522 EXPECT_FALSE(client.textIsUpdated()); 2522 EXPECT_FALSE(client.textIsUpdated());
2523 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getEl ementById("textarea")); 2523 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getEl ementById("textarea"));
2524 document->setFocusedElement(textAreaElement); 2524 document->setFocusedElement(textAreaElement, FocusParams(SelectionBehaviorOn Focus::None, WebFocusTypeNone, nullptr));
2525 webViewImpl->setFocus(true); 2525 webViewImpl->setFocus(true);
2526 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement) ); 2526 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement) );
2527 textAreaElement->setValue("testB"); 2527 textAreaElement->setValue("testB");
2528 EXPECT_TRUE(client.textIsUpdated()); 2528 EXPECT_TRUE(client.textIsUpdated());
2529 info = webViewImpl->textInputInfo(); 2529 info = webViewImpl->textInputInfo();
2530 EXPECT_EQ("testB", std::string(info.value.utf8().data())); 2530 EXPECT_EQ("testB", std::string(info.value.utf8().data()));
2531 2531
2532 // (B.2) Focused and user input modifies value. 2532 // (B.2) Focused and user input modifies value.
2533 client.reset(); 2533 client.reset();
2534 EXPECT_FALSE(client.textIsUpdated()); 2534 EXPECT_FALSE(client.textIsUpdated());
2535 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ; 2535 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1) ;
2536 webViewImpl->confirmComposition(WebWidget::KeepSelection); 2536 webViewImpl->confirmComposition(WebWidget::KeepSelection);
2537 info = webViewImpl->textInputInfo(); 2537 info = webViewImpl->textInputInfo();
2538 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); 2538 EXPECT_EQ("testB2", std::string(info.value.utf8().data()));
2539 2539
2540 // (B.3) Unfocused and value is changed by script. 2540 // (B.3) Unfocused and value is changed by script.
2541 client.reset(); 2541 client.reset();
2542 EXPECT_FALSE(client.textIsUpdated()); 2542 EXPECT_FALSE(client.textIsUpdated());
2543 document->setFocusedElement(nullptr); 2543 document->clearFocusedElement();
2544 webViewImpl->setFocus(false); 2544 webViewImpl->setFocus(false);
2545 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement) ); 2545 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement) );
2546 inputElement->setValue("testB3"); 2546 inputElement->setValue("testB3");
2547 EXPECT_FALSE(client.textIsUpdated()); 2547 EXPECT_FALSE(client.textIsUpdated());
2548 2548
2549 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. 2549 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient.
2550 m_webViewHelper.reset(); 2550 m_webViewHelper.reset();
2551 } 2551 }
2552 2552
2553 // Check that the WebAutofillClient is correctly notified about first user 2553 // Check that the WebAutofillClient is correctly notified about first user
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 WebFrame* frame = mainWebView.webView()->mainFrame(); 3141 WebFrame* frame = mainWebView.webView()->mainFrame();
3142 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3142 v8::HandleScope scope(v8::Isolate::GetCurrent());
3143 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document")); 3143 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document"));
3144 ASSERT_TRUE(v8Value->IsObject()); 3144 ASSERT_TRUE(v8Value->IsObject());
3145 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value); 3145 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value);
3146 ASSERT_TRUE(document); 3146 ASSERT_TRUE(document);
3147 EXPECT_FALSE(document->frame()->isLoading()); 3147 EXPECT_FALSE(document->frame()->isLoading());
3148 } 3148 }
3149 3149
3150 } // namespace blink 3150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698