| OLD | NEW |
| 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 5107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5118 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5118 FrameTestHelpers::WebViewHelper webViewHelper(this); |
| 5119 webViewHelper.initializeAndLoad("about:blank", true); | 5119 webViewHelper.initializeAndLoad("about:blank", true); |
| 5120 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 5120 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 5121 | 5121 |
| 5122 // This test passes if this doesn't crash. | 5122 // This test passes if this doesn't crash. |
| 5123 frame->toWebLocalFrame()->moveCaretSelection(WebPoint(0, 0)); | 5123 frame->toWebLocalFrame()->moveCaretSelection(WebPoint(0, 0)); |
| 5124 } | 5124 } |
| 5125 | 5125 |
| 5126 class SpellCheckClient : public WebSpellCheckClient { | 5126 class SpellCheckClient : public WebSpellCheckClient { |
| 5127 public: | 5127 public: |
| 5128 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_
hash(hash) { } | 5128 explicit SpellCheckClient() : m_numberOfTimesChecked(0) { } |
| 5129 virtual ~SpellCheckClient() { } | 5129 virtual ~SpellCheckClient() { } |
| 5130 void requestCheckingOfText(const WebString&, const WebVector<uint32_t>&, con
st WebVector<unsigned>&, WebTextCheckingCompletion* completion) override | 5130 void requestCheckingOfText(const WebString&, WebTextCheckingCompletion* comp
letion) override |
| 5131 { | 5131 { |
| 5132 ++m_numberOfTimesChecked; | 5132 ++m_numberOfTimesChecked; |
| 5133 Vector<WebTextCheckingResult> results; | 5133 Vector<WebTextCheckingResult> results; |
| 5134 const int misspellingStartOffset = 1; | 5134 const int misspellingStartOffset = 1; |
| 5135 const int misspellingLength = 8; | 5135 const int misspellingLength = 8; |
| 5136 results.append(WebTextCheckingResult(WebTextDecorationTypeSpelling, miss
pellingStartOffset, misspellingLength, WebString(), m_hash)); | 5136 results.append(WebTextCheckingResult(WebTextDecorationTypeSpelling, miss
pellingStartOffset, misspellingLength, WebString())); |
| 5137 completion->didFinishCheckingText(results); | 5137 completion->didFinishCheckingText(results); |
| 5138 } | 5138 } |
| 5139 int numberOfTimesChecked() const { return m_numberOfTimesChecked; } | 5139 int numberOfTimesChecked() const { return m_numberOfTimesChecked; } |
| 5140 private: | 5140 private: |
| 5141 int m_numberOfTimesChecked; | 5141 int m_numberOfTimesChecked; |
| 5142 uint32_t m_hash; | |
| 5143 }; | 5142 }; |
| 5144 | 5143 |
| 5145 TEST_P(ParameterizedWebFrameTest, ReplaceMisspelledRange) | 5144 TEST_P(ParameterizedWebFrameTest, ReplaceMisspelledRange) |
| 5146 { | 5145 { |
| 5147 registerMockedHttpURLLoad("spell.html"); | 5146 registerMockedHttpURLLoad("spell.html"); |
| 5148 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5147 FrameTestHelpers::WebViewHelper webViewHelper(this); |
| 5149 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); | 5148 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 5150 SpellCheckClient spellcheck; | 5149 SpellCheckClient spellcheck; |
| 5151 webViewHelper.webView()->setSpellCheckClient(&spellcheck); | 5150 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
| 5152 | 5151 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5217 Element* element = document->getElementById("data"); | 5216 Element* element = document->getElementById("data"); |
| 5218 | 5217 |
| 5219 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); | 5218 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 5220 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); | 5219 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 5221 | 5220 |
| 5222 element->focus(); | 5221 element->focus(); |
| 5223 NonThrowableExceptionState exceptionState; | 5222 NonThrowableExceptionState exceptionState; |
| 5224 document->execCommand("InsertText", false, " wellcome ", exceptionState); | 5223 document->execCommand("InsertText", false, " wellcome ", exceptionState); |
| 5225 EXPECT_FALSE(exceptionState.hadException()); | 5224 EXPECT_FALSE(exceptionState.hadException()); |
| 5226 | 5225 |
| 5227 WebVector<uint32_t> documentMarkers1; | 5226 ASSERT_EQ(1U, document->markers().markers().size()); |
| 5228 webViewHelper.webView()->spellingMarkers(&documentMarkers1); | |
| 5229 EXPECT_EQ(1U, documentMarkers1.size()); | |
| 5230 | 5227 |
| 5231 Vector<String> words; | 5228 Vector<String> words; |
| 5232 words.append("wellcome"); | 5229 words.append("wellcome"); |
| 5233 frame->removeSpellingMarkersUnderWords(words); | 5230 frame->removeSpellingMarkersUnderWords(words); |
| 5234 | 5231 |
| 5235 WebVector<uint32_t> documentMarkers2; | 5232 ASSERT_EQ(0U, document->markers().markers().size()); |
| 5236 webViewHelper.webView()->spellingMarkers(&documentMarkers2); | |
| 5237 EXPECT_EQ(0U, documentMarkers2.size()); | |
| 5238 } | |
| 5239 | |
| 5240 TEST_P(ParameterizedWebFrameTest, MarkerHashIdentifiers) | |
| 5241 { | |
| 5242 registerMockedHttpURLLoad("spell.html"); | |
| 5243 FrameTestHelpers::WebViewHelper webViewHelper(this); | |
| 5244 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); | |
| 5245 | |
| 5246 static const uint32_t kHash = 42; | |
| 5247 SpellCheckClient spellcheck(kHash); | |
| 5248 webViewHelper.webView()->setSpellCheckClient(&spellcheck); | |
| 5249 | |
| 5250 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); | |
| 5251 Document* document = frame->frame()->document(); | |
| 5252 Element* element = document->getElementById("data"); | |
| 5253 | |
| 5254 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); | |
| 5255 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); | |
| 5256 | |
| 5257 element->focus(); | |
| 5258 NonThrowableExceptionState exceptionState; | |
| 5259 document->execCommand("InsertText", false, "wellcome.", exceptionState); | |
| 5260 EXPECT_FALSE(exceptionState.hadException()); | |
| 5261 | |
| 5262 WebVector<uint32_t> documentMarkers; | |
| 5263 webViewHelper.webView()->spellingMarkers(&documentMarkers); | |
| 5264 EXPECT_EQ(1U, documentMarkers.size()); | |
| 5265 EXPECT_EQ(kHash, documentMarkers[0]); | |
| 5266 } | 5233 } |
| 5267 | 5234 |
| 5268 class StubbornSpellCheckClient : public WebSpellCheckClient { | 5235 class StubbornSpellCheckClient : public WebSpellCheckClient { |
| 5269 public: | 5236 public: |
| 5270 StubbornSpellCheckClient() : m_completion(0) { } | 5237 StubbornSpellCheckClient() : m_completion(0) { } |
| 5271 virtual ~StubbornSpellCheckClient() { } | 5238 virtual ~StubbornSpellCheckClient() { } |
| 5272 | 5239 |
| 5273 virtual void requestCheckingOfText( | 5240 virtual void requestCheckingOfText( |
| 5274 const WebString&, | 5241 const WebString&, |
| 5275 const WebVector<uint32_t>&, | |
| 5276 const WebVector<unsigned>&, | |
| 5277 WebTextCheckingCompletion* completion) override | 5242 WebTextCheckingCompletion* completion) override |
| 5278 { | 5243 { |
| 5279 m_completion = completion; | 5244 m_completion = completion; |
| 5280 } | 5245 } |
| 5281 | 5246 |
| 5282 void kickNoResults() | 5247 void kickNoResults() |
| 5283 { | 5248 { |
| 5284 kick(-1, -1, WebTextDecorationTypeSpelling); | 5249 kick(-1, -1, WebTextDecorationTypeSpelling); |
| 5285 } | 5250 } |
| 5286 | 5251 |
| 5287 void kick() | 5252 void kick() |
| 5288 { | 5253 { |
| 5289 kick(1, 8, WebTextDecorationTypeSpelling); | 5254 kick(1, 8, WebTextDecorationTypeSpelling); |
| 5290 } | 5255 } |
| 5291 | 5256 |
| 5292 void kickInvisibleSpellcheck() | |
| 5293 { | |
| 5294 kick(1, 8, WebTextDecorationTypeInvisibleSpellcheck); | |
| 5295 } | |
| 5296 | |
| 5297 private: | 5257 private: |
| 5298 void kick(int misspellingStartOffset, int misspellingLength, WebTextDecorati
onType type) | 5258 void kick(int misspellingStartOffset, int misspellingLength, WebTextDecorati
onType type) |
| 5299 { | 5259 { |
| 5300 if (!m_completion) | 5260 if (!m_completion) |
| 5301 return; | 5261 return; |
| 5302 Vector<WebTextCheckingResult> results; | 5262 Vector<WebTextCheckingResult> results; |
| 5303 if (misspellingStartOffset >= 0 && misspellingLength > 0) | 5263 if (misspellingStartOffset >= 0 && misspellingLength > 0) |
| 5304 results.append(WebTextCheckingResult(type, misspellingStartOffset, m
isspellingLength)); | 5264 results.append(WebTextCheckingResult(type, misspellingStartOffset, m
isspellingLength)); |
| 5305 m_completion->didFinishCheckingText(results); | 5265 m_completion->didFinishCheckingText(results); |
| 5306 m_completion = 0; | 5266 m_completion = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5327 | 5287 |
| 5328 element->focus(); | 5288 element->focus(); |
| 5329 NonThrowableExceptionState exceptionState; | 5289 NonThrowableExceptionState exceptionState; |
| 5330 document->execCommand("InsertText", false, "wellcome ", exceptionState); | 5290 document->execCommand("InsertText", false, "wellcome ", exceptionState); |
| 5331 EXPECT_FALSE(exceptionState.hadException()); | 5291 EXPECT_FALSE(exceptionState.hadException()); |
| 5332 document->execCommand("InsertText", false, "he", exceptionState); | 5292 document->execCommand("InsertText", false, "he", exceptionState); |
| 5333 EXPECT_FALSE(exceptionState.hadException()); | 5293 EXPECT_FALSE(exceptionState.hadException()); |
| 5334 | 5294 |
| 5335 spellcheck.kick(); | 5295 spellcheck.kick(); |
| 5336 | 5296 |
| 5337 WebVector<uint32_t> documentMarkers; | 5297 ASSERT_EQ(0U, document->markers().markers().size()); |
| 5338 webViewHelper.webView()->spellingMarkers(&documentMarkers); | |
| 5339 EXPECT_EQ(0U, documentMarkers.size()); | |
| 5340 } | 5298 } |
| 5341 | 5299 |
| 5342 // This test verifies that cancelling spelling request does not cause a | 5300 // This test verifies that cancelling spelling request does not cause a |
| 5343 // write-after-free when there's no spellcheck client set. | 5301 // write-after-free when there's no spellcheck client set. |
| 5344 TEST_P(ParameterizedWebFrameTest, CancelSpellingRequestCrash) | 5302 TEST_P(ParameterizedWebFrameTest, CancelSpellingRequestCrash) |
| 5345 { | 5303 { |
| 5346 registerMockedHttpURLLoad("spell.html"); | 5304 registerMockedHttpURLLoad("spell.html"); |
| 5347 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5305 FrameTestHelpers::WebViewHelper webViewHelper(this); |
| 5348 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); | 5306 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 5349 webViewHelper.webView()->setSpellCheckClient(0); | 5307 webViewHelper.webView()->setSpellCheckClient(0); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5378 | 5336 |
| 5379 element->focus(); | 5337 element->focus(); |
| 5380 NonThrowableExceptionState exceptionState; | 5338 NonThrowableExceptionState exceptionState; |
| 5381 document->execCommand("InsertText", false, "welcome ", exceptionState); | 5339 document->execCommand("InsertText", false, "welcome ", exceptionState); |
| 5382 | 5340 |
| 5383 document->updateStyleAndLayout(); | 5341 document->updateStyleAndLayout(); |
| 5384 | 5342 |
| 5385 EXPECT_FALSE(exceptionState.hadException()); | 5343 EXPECT_FALSE(exceptionState.hadException()); |
| 5386 auto range = EphemeralRange::rangeOfContents(*element); | 5344 auto range = EphemeralRange::rangeOfContents(*element); |
| 5387 document->markers().addMarker(range.startPosition(), range.endPosition(), Do
cumentMarker::Spelling); | 5345 document->markers().addMarker(range.startPosition(), range.endPosition(), Do
cumentMarker::Spelling); |
| 5388 document->markers().addMarker(range.startPosition(), range.endPosition(), Do
cumentMarker::InvisibleSpellcheck); | 5346 EXPECT_EQ(1U, document->markers().markers().size()); |
| 5389 EXPECT_EQ(2U, document->markers().markers().size()); | |
| 5390 | 5347 |
| 5391 spellcheck.kickNoResults(); | 5348 spellcheck.kickNoResults(); |
| 5392 EXPECT_EQ(0U, document->markers().markers().size()); | 5349 EXPECT_EQ(0U, document->markers().markers().size()); |
| 5393 } | 5350 } |
| 5394 | 5351 |
| 5395 TEST_P(ParameterizedWebFrameTest, SpellcheckResultsSavedInDocument) | 5352 TEST_P(ParameterizedWebFrameTest, SpellcheckResultsSavedInDocument) |
| 5396 { | 5353 { |
| 5397 registerMockedHttpURLLoad("spell.html"); | 5354 registerMockedHttpURLLoad("spell.html"); |
| 5398 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5355 FrameTestHelpers::WebViewHelper webViewHelper(this); |
| 5399 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); | 5356 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5413 document->execCommand("InsertText", false, "wellcome ", exceptionState); | 5370 document->execCommand("InsertText", false, "wellcome ", exceptionState); |
| 5414 EXPECT_FALSE(exceptionState.hadException()); | 5371 EXPECT_FALSE(exceptionState.hadException()); |
| 5415 | 5372 |
| 5416 spellcheck.kick(); | 5373 spellcheck.kick(); |
| 5417 ASSERT_EQ(1U, document->markers().markers().size()); | 5374 ASSERT_EQ(1U, document->markers().markers().size()); |
| 5418 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0])
; | 5375 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0])
; |
| 5419 EXPECT_EQ(DocumentMarker::Spelling, document->markers().markers()[0]->type()
); | 5376 EXPECT_EQ(DocumentMarker::Spelling, document->markers().markers()[0]->type()
); |
| 5420 | 5377 |
| 5421 document->execCommand("InsertText", false, "wellcome ", exceptionState); | 5378 document->execCommand("InsertText", false, "wellcome ", exceptionState); |
| 5422 EXPECT_FALSE(exceptionState.hadException()); | 5379 EXPECT_FALSE(exceptionState.hadException()); |
| 5423 | |
| 5424 spellcheck.kickInvisibleSpellcheck(); | |
| 5425 ASSERT_EQ(1U, document->markers().markers().size()); | |
| 5426 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0])
; | |
| 5427 EXPECT_EQ(DocumentMarker::InvisibleSpellcheck, document->markers().markers()
[0]->type()); | |
| 5428 } | 5380 } |
| 5429 | 5381 |
| 5430 class TestAccessInitialDocumentWebFrameClient : public FrameTestHelpers::TestWeb
FrameClient { | 5382 class TestAccessInitialDocumentWebFrameClient : public FrameTestHelpers::TestWeb
FrameClient { |
| 5431 public: | 5383 public: |
| 5432 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false
) | 5384 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false
) |
| 5433 { | 5385 { |
| 5434 } | 5386 } |
| 5435 | 5387 |
| 5436 virtual void didAccessInitialDocument() | 5388 virtual void didAccessInitialDocument() |
| 5437 { | 5389 { |
| (...skipping 3386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8824 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); | 8776 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); |
| 8825 helper.webView()->mainFrameImpl()->loadRequest(request); | 8777 helper.webView()->mainFrameImpl()->loadRequest(request); |
| 8826 | 8778 |
| 8827 // Normally, the result of the JS url replaces the existing contents on the | 8779 // Normally, the result of the JS url replaces the existing contents on the |
| 8828 // Document. However, if the JS triggers a navigation, the contents should | 8780 // Document. However, if the JS triggers a navigation, the contents should |
| 8829 // not be replaced. | 8781 // not be replaced. |
| 8830 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document(
)->documentElement()->innerText()); | 8782 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document(
)->documentElement()->innerText()); |
| 8831 } | 8783 } |
| 8832 | 8784 |
| 8833 } // namespace blink | 8785 } // namespace blink |
| OLD | NEW |