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

Side by Side Diff: third_party/WebKit/Source/modules/credentialmanager/PasswordCredentialTest.cpp

Issue 2197953002: Remove unnecessary uses of HTMLDocument (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplify 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/credentialmanager/PasswordCredential.h" 5 #include "modules/credentialmanager/PasswordCredential.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
9 #include "core/dom/Document.h"
9 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
10 #include "core/dom/URLSearchParams.h" 11 #include "core/dom/URLSearchParams.h"
11 #include "core/frame/FrameView.h" 12 #include "core/frame/FrameView.h"
12 #include "core/html/FormData.h" 13 #include "core/html/FormData.h"
13 #include "core/html/HTMLDocument.h"
14 #include "core/html/HTMLFormElement.h" 14 #include "core/html/HTMLFormElement.h"
15 #include "core/html/forms/FormController.h" 15 #include "core/html/forms/FormController.h"
16 #include "core/testing/DummyPageHolder.h" 16 #include "core/testing/DummyPageHolder.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "wtf/text/StringBuilder.h" 18 #include "wtf/text/StringBuilder.h"
19 #include <memory> 19 #include <memory>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 class PasswordCredentialTest : public ::testing::Test { 23 class PasswordCredentialTest : public ::testing::Test {
24 protected: 24 protected:
25 void SetUp() override 25 void SetUp() override
26 { 26 {
27 m_dummyPageHolder = DummyPageHolder::create(); 27 m_dummyPageHolder = DummyPageHolder::create();
28 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 28 m_document = &m_dummyPageHolder->document();
29 } 29 }
30 30
31 HTMLDocument& document() const { return *m_document; } 31 Document& document() const { return *m_document; }
32 32
33 HTMLFormElement* populateForm(const char* enctype, const char* html) 33 HTMLFormElement* populateForm(const char* enctype, const char* html)
34 { 34 {
35 StringBuilder b; 35 StringBuilder b;
36 b.append("<!DOCTYPE html><html><body><form id='theForm' enctype='"); 36 b.append("<!DOCTYPE html><html><body><form id='theForm' enctype='");
37 b.append(enctype); 37 b.append(enctype);
38 b.append("'>"); 38 b.append("'>");
39 b.append(html); 39 b.append(html);
40 b.append("</form></body></html>"); 40 b.append("</form></body></html>");
41 document().documentElement()->setInnerHTML(b.toString(), ASSERT_NO_EXCEP TION); 41 document().documentElement()->setInnerHTML(b.toString(), ASSERT_NO_EXCEP TION);
42 document().view()->updateAllLifecyclePhases(); 42 document().view()->updateAllLifecyclePhases();
43 HTMLFormElement* form = toHTMLFormElement(document().getElementById("the Form")); 43 HTMLFormElement* form = toHTMLFormElement(document().getElementById("the Form"));
44 EXPECT_NE(nullptr, form); 44 EXPECT_NE(nullptr, form);
45 return form; 45 return form;
46 } 46 }
47 47
48 private: 48 private:
49 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 49 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
50 Persistent<HTMLDocument> m_document; 50 Persistent<Document> m_document;
51 }; 51 };
52 52
53 TEST_F(PasswordCredentialTest, CreateFromMultipartForm) 53 TEST_F(PasswordCredentialTest, CreateFromMultipartForm)
54 { 54 {
55 HTMLFormElement* form = populateForm("multipart/form-data", 55 HTMLFormElement* form = populateForm("multipart/form-data",
56 "<input type='text' name='theId' value='musterman' autocomplete='usernam e'>" 56 "<input type='text' name='theId' value='musterman' autocomplete='usernam e'>"
57 "<input type='text' name='thePassword' value='sekrit' autocomplete='curr ent-password'>" 57 "<input type='text' name='thePassword' value='sekrit' autocomplete='curr ent-password'>"
58 "<input type='text' name='theIcon' value='https://example.com/photo' aut ocomplete='photo'>" 58 "<input type='text' name='theIcon' value='https://example.com/photo' aut ocomplete='photo'>"
59 "<input type='text' name='theExtraField' value='extra'>" 59 "<input type='text' name='theExtraField' value='extra'>"
60 "<input type='text' name='theName' value='friendly name' autocomplete='n ame'>"); 60 "<input type='text' name='theName' value='friendly name' autocomplete='n ame'>");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 "<input type='text' name='theName' value='friendly name' autocomplete='n ame'>"); 132 "<input type='text' name='theName' value='friendly name' autocomplete='n ame'>");
133 TrackExceptionState exceptionState; 133 TrackExceptionState exceptionState;
134 PasswordCredential* credential = PasswordCredential::create(form, exceptionS tate); 134 PasswordCredential* credential = PasswordCredential::create(form, exceptionS tate);
135 EXPECT_EQ(nullptr, credential); 135 EXPECT_EQ(nullptr, credential);
136 EXPECT_TRUE(exceptionState.hadException()); 136 EXPECT_TRUE(exceptionState.hadException());
137 EXPECT_EQ(V8TypeError, exceptionState.code()); 137 EXPECT_EQ(V8TypeError, exceptionState.code());
138 EXPECT_EQ("'id' must not be empty.", exceptionState.message()); 138 EXPECT_EQ("'id' must not be empty.", exceptionState.message());
139 } 139 }
140 140
141 } // namespace blink 141 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698