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

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

Issue 1155353002: Throw DOMException when invoked Document::execCommand on non-{X,}HTML documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert accidental edit Created 5 years, 6 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
« no previous file with comments | « Source/core/dom/Document.idl ('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) 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 4959 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 4970
4971 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 4971 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
4972 Document* document = frame->frame()->document(); 4972 Document* document = frame->frame()->document();
4973 Element* element = document->getElementById("data"); 4973 Element* element = document->getElementById("data");
4974 4974
4975 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 4975 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
4976 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 4976 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
4977 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 4977 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
4978 4978
4979 element->focus(); 4979 element->focus();
4980 document->execCommand("InsertText", false, "_wellcome_."); 4980 NonThrowableExceptionState exceptionState;
4981 document->execCommand("InsertText", false, "_wellcome_.", exceptionState);
4982 EXPECT_FALSE(exceptionState.hadException());
4981 4983
4982 const int allTextBeginOffset = 0; 4984 const int allTextBeginOffset = 0;
4983 const int allTextLength = 11; 4985 const int allTextLength = 11;
4984 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength)); 4986 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength));
4985 RefPtrWillBeRawPtr<Range> selectionRange = frame->frame()->selection().toNor malizedRange(); 4987 RefPtrWillBeRawPtr<Range> selectionRange = frame->frame()->selection().toNor malizedRange();
4986 4988
4987 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); 4989 EXPECT_EQ(1, spellcheck.numberOfTimesChecked());
4988 EXPECT_EQ(1U, document->markers().markersInRange(selectionRange.get(), Docum entMarker::Spelling).size()); 4990 EXPECT_EQ(1U, document->markers().markersInRange(selectionRange.get(), Docum entMarker::Spelling).size());
4989 4991
4990 frame->replaceMisspelledRange("welcome"); 4992 frame->replaceMisspelledRange("welcome");
(...skipping 10 matching lines...) Expand all
5001 5003
5002 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 5004 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
5003 Document* document = frame->frame()->document(); 5005 Document* document = frame->frame()->document();
5004 Element* element = document->getElementById("data"); 5006 Element* element = document->getElementById("data");
5005 5007
5006 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5008 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5007 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5009 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5008 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5010 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5009 5011
5010 element->focus(); 5012 element->focus();
5011 document->execCommand("InsertText", false, "_wellcome_."); 5013 NonThrowableExceptionState exceptionState;
5014 document->execCommand("InsertText", false, "_wellcome_.", exceptionState);
5015 EXPECT_FALSE(exceptionState.hadException());
5012 5016
5013 frame->removeSpellingMarkers(); 5017 frame->removeSpellingMarkers();
5014 5018
5015 const int allTextBeginOffset = 0; 5019 const int allTextBeginOffset = 0;
5016 const int allTextLength = 11; 5020 const int allTextLength = 11;
5017 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength)); 5021 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength));
5018 RefPtrWillBeRawPtr<Range> selectionRange = frame->frame()->selection().toNor malizedRange(); 5022 RefPtrWillBeRawPtr<Range> selectionRange = frame->frame()->selection().toNor malizedRange();
5019 5023
5020 EXPECT_EQ(0U, document->markers().markersInRange(selectionRange.get(), Docum entMarker::Spelling).size()); 5024 EXPECT_EQ(0U, document->markers().markersInRange(selectionRange.get(), Docum entMarker::Spelling).size());
5021 } 5025 }
5022 5026
5023 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkersUnderWords) 5027 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkersUnderWords)
5024 { 5028 {
5025 registerMockedHttpURLLoad("spell.html"); 5029 registerMockedHttpURLLoad("spell.html");
5026 FrameTestHelpers::WebViewHelper webViewHelper(this); 5030 FrameTestHelpers::WebViewHelper webViewHelper(this);
5027 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5031 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5028 SpellCheckClient spellcheck; 5032 SpellCheckClient spellcheck;
5029 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5033 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5030 5034
5031 LocalFrame* frame = toWebLocalFrameImpl(webViewHelper.webView()->mainFrame() )->frame(); 5035 LocalFrame* frame = toWebLocalFrameImpl(webViewHelper.webView()->mainFrame() )->frame();
5032 Document* document = frame->document(); 5036 Document* document = frame->document();
5033 Element* element = document->getElementById("data"); 5037 Element* element = document->getElementById("data");
5034 5038
5035 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5039 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5036 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5040 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5037 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5041 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5038 5042
5039 element->focus(); 5043 element->focus();
5040 document->execCommand("InsertText", false, " wellcome "); 5044 NonThrowableExceptionState exceptionState;
5045 document->execCommand("InsertText", false, " wellcome ", exceptionState);
5046 EXPECT_FALSE(exceptionState.hadException());
5041 5047
5042 WebVector<uint32_t> documentMarkers1; 5048 WebVector<uint32_t> documentMarkers1;
5043 webViewHelper.webView()->spellingMarkers(&documentMarkers1); 5049 webViewHelper.webView()->spellingMarkers(&documentMarkers1);
5044 EXPECT_EQ(1U, documentMarkers1.size()); 5050 EXPECT_EQ(1U, documentMarkers1.size());
5045 5051
5046 Vector<String> words; 5052 Vector<String> words;
5047 words.append("wellcome"); 5053 words.append("wellcome");
5048 frame->removeSpellingMarkersUnderWords(words); 5054 frame->removeSpellingMarkersUnderWords(words);
5049 5055
5050 WebVector<uint32_t> documentMarkers2; 5056 WebVector<uint32_t> documentMarkers2;
(...skipping 13 matching lines...) Expand all
5064 5070
5065 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 5071 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
5066 Document* document = frame->frame()->document(); 5072 Document* document = frame->frame()->document();
5067 Element* element = document->getElementById("data"); 5073 Element* element = document->getElementById("data");
5068 5074
5069 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5075 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5070 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5076 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5071 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5077 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5072 5078
5073 element->focus(); 5079 element->focus();
5074 document->execCommand("InsertText", false, "wellcome."); 5080 NonThrowableExceptionState exceptionState;
5081 document->execCommand("InsertText", false, "wellcome.", exceptionState);
5082 EXPECT_FALSE(exceptionState.hadException());
5075 5083
5076 WebVector<uint32_t> documentMarkers; 5084 WebVector<uint32_t> documentMarkers;
5077 webViewHelper.webView()->spellingMarkers(&documentMarkers); 5085 webViewHelper.webView()->spellingMarkers(&documentMarkers);
5078 EXPECT_EQ(1U, documentMarkers.size()); 5086 EXPECT_EQ(1U, documentMarkers.size());
5079 EXPECT_EQ(kHash, documentMarkers[0]); 5087 EXPECT_EQ(kHash, documentMarkers[0]);
5080 } 5088 }
5081 5089
5082 class StubbornSpellCheckClient : public WebSpellCheckClient { 5090 class StubbornSpellCheckClient : public WebSpellCheckClient {
5083 public: 5091 public:
5084 StubbornSpellCheckClient() : m_completion(0) { } 5092 StubbornSpellCheckClient() : m_completion(0) { }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5140 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 5148 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
5141 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>(); 5149 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>();
5142 Document* document = frame->frame()->document(); 5150 Document* document = frame->frame()->document();
5143 Element* element = document->getElementById("data"); 5151 Element* element = document->getElementById("data");
5144 5152
5145 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5153 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5146 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5154 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5147 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5155 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5148 5156
5149 element->focus(); 5157 element->focus();
5150 document->execCommand("InsertText", false, "wellcome "); 5158 NonThrowableExceptionState exceptionState;
5159 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5160 EXPECT_FALSE(exceptionState.hadException());
5151 webInputElement.setSelectionRange(0, 0); 5161 webInputElement.setSelectionRange(0, 0);
5152 document->execCommand("InsertText", false, "he"); 5162 document->execCommand("InsertText", false, "he", exceptionState);
5163 EXPECT_FALSE(exceptionState.hadException());
5153 5164
5154 spellcheck.kick(); 5165 spellcheck.kick();
5155 5166
5156 WebVector<uint32_t> documentMarkers; 5167 WebVector<uint32_t> documentMarkers;
5157 webViewHelper.webView()->spellingMarkers(&documentMarkers); 5168 webViewHelper.webView()->spellingMarkers(&documentMarkers);
5158 EXPECT_EQ(0U, documentMarkers.size()); 5169 EXPECT_EQ(0U, documentMarkers.size());
5159 } 5170 }
5160 5171
5161 // This test verifies that cancelling spelling request does not cause a 5172 // This test verifies that cancelling spelling request does not cause a
5162 // write-after-free when there's no spellcheck client set. 5173 // write-after-free when there's no spellcheck client set.
(...skipping 29 matching lines...) Expand all
5192 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 5203 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
5193 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>(); 5204 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>();
5194 Document* document = frame->frame()->document(); 5205 Document* document = frame->frame()->document();
5195 Element* element = document->getElementById("data"); 5206 Element* element = document->getElementById("data");
5196 5207
5197 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5208 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5198 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5209 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5199 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5210 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5200 5211
5201 element->focus(); 5212 element->focus();
5202 document->execCommand("InsertText", false, "welcome "); 5213 NonThrowableExceptionState exceptionState;
5214 document->execCommand("InsertText", false, "welcome ", exceptionState);
5215 EXPECT_FALSE(exceptionState.hadException());
5203 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::Spelling); 5216 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::Spelling);
5204 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::Grammar); 5217 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::Grammar);
5205 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::InvisibleSpellcheck); 5218 document->markers().addMarker(rangeOfContents(element->toNode()).get(), Docu mentMarker::InvisibleSpellcheck);
5206 EXPECT_EQ(3U, document->markers().markers().size()); 5219 EXPECT_EQ(3U, document->markers().markers().size());
5207 5220
5208 spellcheck.kickNoResults(); 5221 spellcheck.kickNoResults();
5209 EXPECT_EQ(0U, document->markers().markers().size()); 5222 EXPECT_EQ(0U, document->markers().markers().size());
5210 } 5223 }
5211 5224
5212 TEST_P(ParameterizedWebFrameTest, SpellcheckResultsSavedInDocument) 5225 TEST_P(ParameterizedWebFrameTest, SpellcheckResultsSavedInDocument)
5213 { 5226 {
5214 registerMockedHttpURLLoad("spell.html"); 5227 registerMockedHttpURLLoad("spell.html");
5215 FrameTestHelpers::WebViewHelper webViewHelper(this); 5228 FrameTestHelpers::WebViewHelper webViewHelper(this);
5216 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); 5229 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
5217 5230
5218 StubbornSpellCheckClient spellcheck; 5231 StubbornSpellCheckClient spellcheck;
5219 webViewHelper.webView()->setSpellCheckClient(&spellcheck); 5232 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
5220 5233
5221 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame()); 5234 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewHelper.webView()->main Frame());
5222 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>(); 5235 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>();
5223 Document* document = frame->frame()->document(); 5236 Document* document = frame->frame()->document();
5224 Element* element = document->getElementById("data"); 5237 Element* element = document->getElementById("data");
5225 5238
5226 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e); 5239 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
5227 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); 5240 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
5228 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin); 5241 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
5229 5242
5230 element->focus(); 5243 element->focus();
5231 document->execCommand("InsertText", false, "wellcome "); 5244 NonThrowableExceptionState exceptionState;
5245 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5246 EXPECT_FALSE(exceptionState.hadException());
5232 5247
5233 spellcheck.kick(); 5248 spellcheck.kick();
5234 ASSERT_EQ(1U, document->markers().markers().size()); 5249 ASSERT_EQ(1U, document->markers().markers().size());
5235 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ; 5250 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ;
5236 EXPECT_EQ(DocumentMarker::Spelling, document->markers().markers()[0]->type() ); 5251 EXPECT_EQ(DocumentMarker::Spelling, document->markers().markers()[0]->type() );
5237 5252
5238 document->execCommand("InsertText", false, "wellcome "); 5253 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5254 EXPECT_FALSE(exceptionState.hadException());
5239 5255
5240 spellcheck.kickGrammar(); 5256 spellcheck.kickGrammar();
5241 ASSERT_EQ(1U, document->markers().markers().size()); 5257 ASSERT_EQ(1U, document->markers().markers().size());
5242 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ; 5258 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ;
5243 EXPECT_EQ(DocumentMarker::Grammar, document->markers().markers()[0]->type()) ; 5259 EXPECT_EQ(DocumentMarker::Grammar, document->markers().markers()[0]->type()) ;
5244 5260
5245 document->execCommand("InsertText", false, "wellcome "); 5261 document->execCommand("InsertText", false, "wellcome ", exceptionState);
5262 EXPECT_FALSE(exceptionState.hadException());
5246 5263
5247 spellcheck.kickInvisibleSpellcheck(); 5264 spellcheck.kickInvisibleSpellcheck();
5248 ASSERT_EQ(1U, document->markers().markers().size()); 5265 ASSERT_EQ(1U, document->markers().markers().size());
5249 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ; 5266 ASSERT_NE(static_cast<DocumentMarker*>(0), document->markers().markers()[0]) ;
5250 EXPECT_EQ(DocumentMarker::InvisibleSpellcheck, document->markers().markers() [0]->type()); 5267 EXPECT_EQ(DocumentMarker::InvisibleSpellcheck, document->markers().markers() [0]->type());
5251 } 5268 }
5252 5269
5253 class TestAccessInitialDocumentWebFrameClient : public FrameTestHelpers::TestWeb FrameClient { 5270 class TestAccessInitialDocumentWebFrameClient : public FrameTestHelpers::TestWeb FrameClient {
5254 public: 5271 public:
5255 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false ) 5272 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false )
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after
7448 7465
7449 EXPECT_EQ(parent, firstFrame->parent()); 7466 EXPECT_EQ(parent, firstFrame->parent());
7450 EXPECT_EQ(parent, secondFrame->parent()); 7467 EXPECT_EQ(parent, secondFrame->parent());
7451 EXPECT_EQ(parent, thirdFrame->parent()); 7468 EXPECT_EQ(parent, thirdFrame->parent());
7452 EXPECT_EQ(parent, fourthFrame->parent()); 7469 EXPECT_EQ(parent, fourthFrame->parent());
7453 7470
7454 view->close(); 7471 view->close();
7455 } 7472 }
7456 7473
7457 } // namespace blink 7474 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Document.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698