OLD | NEW |
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/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
10 #include "core/dom/URLSearchParams.h" | 10 #include "core/dom/URLSearchParams.h" |
11 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
12 #include "core/html/FormData.h" | 12 #include "core/html/FormData.h" |
13 #include "core/html/HTMLDocument.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> | |
20 | 19 |
21 namespace blink { | 20 namespace blink { |
22 | 21 |
23 class PasswordCredentialTest : public ::testing::Test { | 22 class PasswordCredentialTest : public ::testing::Test { |
24 protected: | 23 protected: |
25 void SetUp() override | 24 void SetUp() override |
26 { | 25 { |
27 m_dummyPageHolder = DummyPageHolder::create(); | 26 m_dummyPageHolder = DummyPageHolder::create(); |
28 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 27 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
29 } | 28 } |
30 | 29 |
31 HTMLDocument& document() const { return *m_document; } | 30 HTMLDocument& document() const { return *m_document; } |
32 | 31 |
33 HTMLFormElement* populateForm(const char* enctype, const char* html) | 32 HTMLFormElement* populateForm(const char* enctype, const char* html) |
34 { | 33 { |
35 StringBuilder b; | 34 StringBuilder b; |
36 b.append("<!DOCTYPE html><html><body><form id='theForm' enctype='"); | 35 b.append("<!DOCTYPE html><html><body><form id='theForm' enctype='"); |
37 b.append(enctype); | 36 b.append(enctype); |
38 b.append("'>"); | 37 b.append("'>"); |
39 b.append(html); | 38 b.append(html); |
40 b.append("</form></body></html>"); | 39 b.append("</form></body></html>"); |
41 document().documentElement()->setInnerHTML(b.toString(), ASSERT_NO_EXCEP
TION); | 40 document().documentElement()->setInnerHTML(b.toString(), ASSERT_NO_EXCEP
TION); |
42 document().view()->updateAllLifecyclePhases(); | 41 document().view()->updateAllLifecyclePhases(); |
43 HTMLFormElement* form = toHTMLFormElement(document().getElementById("the
Form")); | 42 HTMLFormElement* form = toHTMLFormElement(document().getElementById("the
Form")); |
44 EXPECT_NE(nullptr, form); | 43 EXPECT_NE(nullptr, form); |
45 return form; | 44 return form; |
46 } | 45 } |
47 | 46 |
48 private: | 47 private: |
49 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 48 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
50 Persistent<HTMLDocument> m_document; | 49 Persistent<HTMLDocument> m_document; |
51 }; | 50 }; |
52 | 51 |
53 TEST_F(PasswordCredentialTest, CreateFromMultipartForm) | 52 TEST_F(PasswordCredentialTest, CreateFromMultipartForm) |
54 { | 53 { |
55 HTMLFormElement* form = populateForm("multipart/form-data", | 54 HTMLFormElement* form = populateForm("multipart/form-data", |
56 "<input type='text' name='theId' value='musterman' autocomplete='usernam
e'>" | 55 "<input type='text' name='theId' value='musterman' autocomplete='usernam
e'>" |
57 "<input type='text' name='thePassword' value='sekrit' autocomplete='curr
ent-password'>" | 56 "<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'>" | 57 "<input type='text' name='theIcon' value='https://example.com/photo' aut
ocomplete='photo'>" |
59 "<input type='text' name='theExtraField' value='extra'>" | 58 "<input type='text' name='theExtraField' value='extra'>" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 "<input type='text' name='theName' value='friendly name' autocomplete='n
ame'>"); | 131 "<input type='text' name='theName' value='friendly name' autocomplete='n
ame'>"); |
133 TrackExceptionState exceptionState; | 132 TrackExceptionState exceptionState; |
134 PasswordCredential* credential = PasswordCredential::create(form, exceptionS
tate); | 133 PasswordCredential* credential = PasswordCredential::create(form, exceptionS
tate); |
135 EXPECT_EQ(nullptr, credential); | 134 EXPECT_EQ(nullptr, credential); |
136 EXPECT_TRUE(exceptionState.hadException()); | 135 EXPECT_TRUE(exceptionState.hadException()); |
137 EXPECT_EQ(V8TypeError, exceptionState.code()); | 136 EXPECT_EQ(V8TypeError, exceptionState.code()); |
138 EXPECT_EQ("'id' must not be empty.", exceptionState.message()); | 137 EXPECT_EQ("'id' must not be empty.", exceptionState.message()); |
139 } | 138 } |
140 | 139 |
141 } // namespace blink | 140 } // namespace blink |
OLD | NEW |