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

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

Issue 2235643002: Code cleanup related to unified text checker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@EnableUnifiedTextCheckerByDefault
Patch Set: Rebased on removal of grammar-checking code Created 4 years, 4 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
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 5123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5134 registerMockedHttpURLLoad("spell.html"); 5134 registerMockedHttpURLLoad("spell.html");
5135 FrameTestHelpers::WebViewHelper webViewHelper(this); 5135 FrameTestHelpers::WebViewHelper webViewHelper(this);
5136 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5136 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5137 SpellCheckClient spellcheck; 5137 SpellCheckClient spellcheck;
5138 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5138 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5139 5139
5140 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5140 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5141 Document* document = frame->frame()->document(); 5141 Document* document = frame->frame()->document();
5142 Element* element = document->getElementById("data"); 5142 Element* element = document->getElementById("data");
5143 5143
5144 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5145 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5144 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5146 5145
5147 element->focus(); 5146 element->focus();
5148 NonThrowableExceptionState exceptionState; 5147 NonThrowableExceptionState exceptionState;
5149 document->execCommand("InsertText", false, "_wellcome_.", exceptionState); 5148 document->execCommand("InsertText", false, "_wellcome_.", exceptionState);
5150 EXPECT_FALSE(exceptionState.hadException()); 5149 EXPECT_FALSE(exceptionState.hadException());
5151 5150
5152 const int allTextBeginOffset = 0; 5151 const int allTextBeginOffset = 0;
5153 const int allTextLength = 11; 5152 const int allTextLength = 11;
5154 frame->selectRange(WebRange(allTextBeginOffset, allTextLength)); 5153 frame->selectRange(WebRange(allTextBeginOffset, allTextLength));
(...skipping 11 matching lines...) Expand all
5166 registerMockedHttpURLLoad("spell.html"); 5165 registerMockedHttpURLLoad("spell.html");
5167 FrameTestHelpers::WebViewHelper webViewHelper(this); 5166 FrameTestHelpers::WebViewHelper webViewHelper(this);
5168 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5167 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5169 SpellCheckClient spellcheck; 5168 SpellCheckClient spellcheck;
5170 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5169 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5171 5170
5172 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5171 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5173 Document* document = frame->frame()->document(); 5172 Document* document = frame->frame()->document();
5174 Element* element = document->getElementById("data"); 5173 Element* element = document->getElementById("data");
5175 5174
5176 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5177 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5175 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5178 5176
5179 element->focus(); 5177 element->focus();
5180 NonThrowableExceptionState exceptionState; 5178 NonThrowableExceptionState exceptionState;
5181 document->execCommand("InsertText", false, "_wellcome_.", exceptionState); 5179 document->execCommand("InsertText", false, "_wellcome_.", exceptionState);
5182 EXPECT_FALSE(exceptionState.hadException()); 5180 EXPECT_FALSE(exceptionState.hadException());
5183 5181
5184 frame->removeSpellingMarkers(); 5182 frame->removeSpellingMarkers();
5185 5183
5186 const int allTextBeginOffset = 0; 5184 const int allTextBeginOffset = 0;
5187 const int allTextLength = 11; 5185 const int allTextLength = 11;
5188 frame->selectRange(WebRange(allTextBeginOffset, allTextLength)); 5186 frame->selectRange(WebRange(allTextBeginOffset, allTextLength));
5189 EphemeralRange selectionRange = frame->frame()->selection().selection().toNo rmalizedEphemeralRange(); 5187 EphemeralRange selectionRange = frame->frame()->selection().selection().toNo rmalizedEphemeralRange();
5190 5188
5191 EXPECT_EQ(0U, document->markers().markersInRange(selectionRange, DocumentMar ker::Spelling).size()); 5189 EXPECT_EQ(0U, document->markers().markersInRange(selectionRange, DocumentMar ker::Spelling).size());
5192 } 5190 }
5193 5191
5194 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkersUnderWords) 5192 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkersUnderWords)
5195 { 5193 {
5196 registerMockedHttpURLLoad("spell.html"); 5194 registerMockedHttpURLLoad("spell.html");
5197 FrameTestHelpers::WebViewHelper webViewHelper(this); 5195 FrameTestHelpers::WebViewHelper webViewHelper(this);
5198 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5196 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5199 SpellCheckClient spellcheck; 5197 SpellCheckClient spellcheck;
5200 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5198 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5201 5199
5202 LocalFrame* frame = webViewHelper.webView()->mainFrameImpl()->frame(); 5200 LocalFrame* frame = webViewHelper.webView()->mainFrameImpl()->frame();
5203 Document* document = frame->document(); 5201 Document* document = frame->document();
5204 Element* element = document->getElementById("data"); 5202 Element* element = document->getElementById("data");
5205 5203
5206 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5207 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5204 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5208 5205
5209 element->focus(); 5206 element->focus();
5210 NonThrowableExceptionState exceptionState; 5207 NonThrowableExceptionState exceptionState;
5211 document->execCommand("InsertText", false, " wellcome ", exceptionState); 5208 document->execCommand("InsertText", false, " wellcome ", exceptionState);
5212 EXPECT_FALSE(exceptionState.hadException()); 5209 EXPECT_FALSE(exceptionState.hadException());
5213 5210
5214 WebVector<uint32_t> documentMarkers1; 5211 WebVector<uint32_t> documentMarkers1;
5215 webViewHelper.webView()->spellingMarkers(&documentMarkers1); 5212 webViewHelper.webView()->spellingMarkers(&documentMarkers1);
5216 EXPECT_EQ(1U, documentMarkers1.size()); 5213 EXPECT_EQ(1U, documentMarkers1.size());
(...skipping 14 matching lines...) Expand all
5231 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5228 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5232 5229
5233 static const uint32_t kHash = 42; 5230 static const uint32_t kHash = 42;
5234 SpellCheckClient spellcheck(kHash); 5231 SpellCheckClient spellcheck(kHash);
5235 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5232 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5236 5233
5237 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5234 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5238 Document* document = frame->frame()->document(); 5235 Document* document = frame->frame()->document();
5239 Element* element = document->getElementById("data"); 5236 Element* element = document->getElementById("data");
5240 5237
5241 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5242 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5238 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5243 5239
5244 element->focus(); 5240 element->focus();
5245 NonThrowableExceptionState exceptionState; 5241 NonThrowableExceptionState exceptionState;
5246 document->execCommand("InsertText", false, "wellcome.", exceptionState); 5242 document->execCommand("InsertText", false, "wellcome.", exceptionState);
5247 EXPECT_FALSE(exceptionState.hadException()); 5243 EXPECT_FALSE(exceptionState.hadException());
5248 5244
5249 WebVector<uint32_t> documentMarkers; 5245 WebVector<uint32_t> documentMarkers;
5250 webViewHelper.webView()->spellingMarkers(&documentMarkers); 5246 webViewHelper.webView()->spellingMarkers(&documentMarkers);
5251 EXPECT_EQ(1U, documentMarkers.size()); 5247 EXPECT_EQ(1U, documentMarkers.size());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5315 FrameTestHelpers::WebViewHelper webViewHelper(this); 5311 FrameTestHelpers::WebViewHelper webViewHelper(this);
5316 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5312 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5317 5313
5318 StubbornSpellCheckClient spellcheck; 5314 StubbornSpellCheckClient spellcheck;
5319 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5315 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5320 5316
5321 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5317 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5322 Document* document = frame->frame()->document(); 5318 Document* document = frame->frame()->document();
5323 Element* element = document->getElementById("data"); 5319 Element* element = document->getElementById("data");
5324 5320
5325 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5326 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5321 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5327 5322
5328 element->focus(); 5323 element->focus();
5329 NonThrowableExceptionState exceptionState; 5324 NonThrowableExceptionState exceptionState;
5330 document->execCommand("InsertText", false, "wellcome ", exceptionState); 5325 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5331 EXPECT_FALSE(exceptionState.hadException()); 5326 EXPECT_FALSE(exceptionState.hadException());
5332 document->execCommand("InsertText", false, "he", exceptionState); 5327 document->execCommand("InsertText", false, "he", exceptionState);
5333 EXPECT_FALSE(exceptionState.hadException()); 5328 EXPECT_FALSE(exceptionState.hadException());
5334 5329
5335 spellcheck.kick(); 5330 spellcheck.kick();
5336 5331
5337 WebVector<uint32_t> documentMarkers; 5332 WebVector<uint32_t> documentMarkers;
5338 webViewHelper.webView()->spellingMarkers(&documentMarkers); 5333 webViewHelper.webView()->spellingMarkers(&documentMarkers);
5339 EXPECT_EQ(0U, documentMarkers.size()); 5334 EXPECT_EQ(0U, documentMarkers.size());
5340 } 5335 }
5341 5336
5342 // This test verifies that cancelling spelling request does not cause a 5337 // This test verifies that cancelling spelling request does not cause a
5343 // write-after-free when there's no spellcheck client set. 5338 // write-after-free when there's no spellcheck client set.
5344 TEST_P(ParameterizedWebFrameTest, CancelSpellingRequestCrash) 5339 TEST_P(ParameterizedWebFrameTest, CancelSpellingRequestCrash)
5345 { 5340 {
5346 registerMockedHttpURLLoad("spell.html"); 5341 registerMockedHttpURLLoad("spell.html");
5347 FrameTestHelpers::WebViewHelper webViewHelper(this); 5342 FrameTestHelpers::WebViewHelper webViewHelper(this);
5348 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5343 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5349 webViewHelper.webView()->setSpellCheckClient(0); 5344 webViewHelper.webView()->setSpellCheckClient(0);
5350 5345
5351 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5346 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5352 Document* document = frame->frame()->document(); 5347 Document* document = frame->frame()->document();
5353 Element* element = document->getElementById("data"); 5348 Element* element = document->getElementById("data");
5354 5349
5355 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5356 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5350 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5357 5351
5358 element->focus(); 5352 element->focus();
5359 frame->frame()->editor().replaceSelectionWithText("A", false, false); 5353 frame->frame()->editor().replaceSelectionWithText("A", false, false);
5360 frame->frame()->spellChecker().cancelCheck(); 5354 frame->frame()->spellChecker().cancelCheck();
5361 } 5355 }
5362 5356
5363 TEST_P(ParameterizedWebFrameTest, SpellcheckResultErasesMarkers) 5357 TEST_P(ParameterizedWebFrameTest, SpellcheckResultErasesMarkers)
5364 { 5358 {
5365 registerMockedHttpURLLoad("spell.html"); 5359 registerMockedHttpURLLoad("spell.html");
5366 FrameTestHelpers::WebViewHelper webViewHelper(this); 5360 FrameTestHelpers::WebViewHelper webViewHelper(this);
5367 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5361 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5368 5362
5369 StubbornSpellCheckClient spellcheck; 5363 StubbornSpellCheckClient spellcheck;
5370 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5364 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5371 5365
5372 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5366 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5373 Document* document = frame->frame()->document(); 5367 Document* document = frame->frame()->document();
5374 Element* element = document->getElementById("data"); 5368 Element* element = document->getElementById("data");
5375 5369
5376 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5377 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5370 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5378 5371
5379 element->focus(); 5372 element->focus();
5380 NonThrowableExceptionState exceptionState; 5373 NonThrowableExceptionState exceptionState;
5381 document->execCommand("InsertText", false, "welcome ", exceptionState); 5374 document->execCommand("InsertText", false, "welcome ", exceptionState);
5382 5375
5383 document->updateStyleAndLayout(); 5376 document->updateStyleAndLayout();
5384 5377
5385 EXPECT_FALSE(exceptionState.hadException()); 5378 EXPECT_FALSE(exceptionState.hadException());
5386 auto range = EphemeralRange::rangeOfContents(*element); 5379 auto range = EphemeralRange::rangeOfContents(*element);
(...skipping 12 matching lines...) Expand all
5399 FrameTestHelpers::WebViewHelper webViewHelper(this); 5392 FrameTestHelpers::WebViewHelper webViewHelper(this);
5400 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5393 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5401 5394
5402 StubbornSpellCheckClient spellcheck; 5395 StubbornSpellCheckClient spellcheck;
5403 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5396 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5404 5397
5405 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); 5398 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
5406 Document* document = frame->frame()->document(); 5399 Document* document = frame->frame()->document();
5407 Element* element = document->getElementById("data"); 5400 Element* element = document->getElementById("data");
5408 5401
5409 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5410 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5402 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5411 5403
5412 element->focus(); 5404 element->focus();
5413 NonThrowableExceptionState exceptionState; 5405 NonThrowableExceptionState exceptionState;
5414 document->execCommand("InsertText", false, "wellcome ", exceptionState); 5406 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5415 EXPECT_FALSE(exceptionState.hadException()); 5407 EXPECT_FALSE(exceptionState.hadException());
5416 5408
5417 spellcheck.kick(); 5409 spellcheck.kick();
5418 ASSERT_EQ(1U, document->markers().markers().size()); 5410 ASSERT_EQ(1U, document->markers().markers().size());
5419 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ; 5411 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ;
(...skipping 3413 matching lines...) Expand 10 before | Expand all | Expand 10 after
8833 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); 8825 request.setRequestorOrigin(WebSecurityOrigin::createUnique());
8834 helper.webView()->mainFrameImpl()->loadRequest(request); 8826 helper.webView()->mainFrameImpl()->loadRequest(request);
8835 8827
8836 // Normally, the result of the JS url replaces the existing contents on the 8828 // Normally, the result of the JS url replaces the existing contents on the
8837 // Document. However, if the JS triggers a navigation, the contents should 8829 // Document. However, if the JS triggers a navigation, the contents should
8838 // not be replaced. 8830 // not be replaced.
8839 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document( )->documentElement()->innerText()); 8831 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document( )->documentElement()->innerText());
8840 } 8832 }
8841 8833
8842 } // namespace blink 8834 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebSettingsImpl.cpp ('k') | third_party/WebKit/public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698