Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| 11 #include "core/dom/URLSearchParams.h" | 11 #include "core/dom/URLSearchParams.h" |
| 12 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
| 13 #include "core/html/FormData.h" | 13 #include "core/html/FormData.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 "platform/RuntimeEnabledFeatures.h" | |
| 17 #include "platform/wtf/text/StringBuilder.h" | 18 #include "platform/wtf/text/StringBuilder.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class PasswordCredentialTest : public ::testing::Test { | 23 class PasswordCredentialTest : public ::testing::Test { |
| 23 protected: | 24 protected: |
| 24 void SetUp() override { | 25 void SetUp() override { |
| 25 dummy_page_holder_ = DummyPageHolder::Create(); | 26 dummy_page_holder_ = DummyPageHolder::Create(); |
| 26 document_ = &dummy_page_holder_->GetDocument(); | 27 document_ = &dummy_page_holder_->GetDocument(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 "<input type='text' name='theExtraField' value='extra'>" | 61 "<input type='text' name='theExtraField' value='extra'>" |
| 61 "<input type='text' name='theName' value='friendly name' " | 62 "<input type='text' name='theName' value='friendly name' " |
| 62 "autocomplete='name'>"); | 63 "autocomplete='name'>"); |
| 63 PasswordCredential* credential = | 64 PasswordCredential* credential = |
| 64 PasswordCredential::Create(form, ASSERT_NO_EXCEPTION); | 65 PasswordCredential::Create(form, ASSERT_NO_EXCEPTION); |
| 65 ASSERT_NE(nullptr, credential); | 66 ASSERT_NE(nullptr, credential); |
| 66 EXPECT_EQ("theId", credential->idName()); | 67 EXPECT_EQ("theId", credential->idName()); |
| 67 EXPECT_EQ("thePassword", credential->passwordName()); | 68 EXPECT_EQ("thePassword", credential->passwordName()); |
| 68 | 69 |
| 69 EXPECT_EQ("musterman", credential->id()); | 70 EXPECT_EQ("musterman", credential->id()); |
| 70 EXPECT_EQ("sekrit", credential->Password()); | 71 if (RuntimeEnabledFeatures::passwordCredentialPasswordEnabled()) |
| 72 EXPECT_EQ("sekrit", credential->password()); | |
| 71 EXPECT_EQ(KURL(kParsedURLString, "https://example.com/photo"), | 73 EXPECT_EQ(KURL(kParsedURLString, "https://example.com/photo"), |
| 72 credential->iconURL()); | 74 credential->iconURL()); |
| 73 EXPECT_EQ("friendly name", credential->name()); | 75 EXPECT_EQ("friendly name", credential->name()); |
| 74 EXPECT_EQ("password", credential->type()); | 76 EXPECT_EQ("password", credential->type()); |
| 75 | 77 |
| 76 FormDataOrURLSearchParams additional_data; | 78 FormDataOrURLSearchParams additional_data; |
| 77 credential->additionalData(additional_data); | 79 credential->additionalData(additional_data); |
| 78 ASSERT_TRUE(additional_data.isFormData()); | 80 ASSERT_TRUE(additional_data.isFormData()); |
| 79 EXPECT_TRUE(additional_data.getAsFormData()->has("theId")); | 81 EXPECT_TRUE(additional_data.getAsFormData()->has("theId")); |
| 80 EXPECT_TRUE(additional_data.getAsFormData()->has("thePassword")); | 82 EXPECT_TRUE(additional_data.getAsFormData()->has("thePassword")); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 "<input type='text' name='theExtraField' value='extra'>" | 97 "<input type='text' name='theExtraField' value='extra'>" |
| 96 "<input type='text' name='theName' value='friendly name' " | 98 "<input type='text' name='theName' value='friendly name' " |
| 97 "autocomplete='name'>"); | 99 "autocomplete='name'>"); |
| 98 PasswordCredential* credential = | 100 PasswordCredential* credential = |
| 99 PasswordCredential::Create(form, ASSERT_NO_EXCEPTION); | 101 PasswordCredential::Create(form, ASSERT_NO_EXCEPTION); |
| 100 ASSERT_NE(nullptr, credential); | 102 ASSERT_NE(nullptr, credential); |
| 101 EXPECT_EQ("theId", credential->idName()); | 103 EXPECT_EQ("theId", credential->idName()); |
| 102 EXPECT_EQ("thePassword", credential->passwordName()); | 104 EXPECT_EQ("thePassword", credential->passwordName()); |
| 103 | 105 |
| 104 EXPECT_EQ("musterman", credential->id()); | 106 EXPECT_EQ("musterman", credential->id()); |
| 105 EXPECT_EQ("sekrit", credential->Password()); | 107 if (RuntimeEnabledFeatures::passwordCredentialPasswordEnabled()) |
|
Mike West
2017/05/16 09:30:45
I'd drop these `if`s, as per the discussion above.
jdoerrie
2017/05/17 15:39:22
Done.
| |
| 108 EXPECT_EQ("sekrit", credential->password()); | |
| 106 EXPECT_EQ(KURL(kParsedURLString, "https://example.com/photo"), | 109 EXPECT_EQ(KURL(kParsedURLString, "https://example.com/photo"), |
| 107 credential->iconURL()); | 110 credential->iconURL()); |
| 108 EXPECT_EQ("friendly name", credential->name()); | 111 EXPECT_EQ("friendly name", credential->name()); |
| 109 EXPECT_EQ("password", credential->type()); | 112 EXPECT_EQ("password", credential->type()); |
| 110 | 113 |
| 111 FormDataOrURLSearchParams additional_data; | 114 FormDataOrURLSearchParams additional_data; |
| 112 credential->additionalData(additional_data); | 115 credential->additionalData(additional_data); |
| 113 ASSERT_TRUE(additional_data.isURLSearchParams()); | 116 ASSERT_TRUE(additional_data.isURLSearchParams()); |
| 114 EXPECT_TRUE(additional_data.getAsURLSearchParams()->has("theId")); | 117 EXPECT_TRUE(additional_data.getAsURLSearchParams()->has("theId")); |
| 115 EXPECT_TRUE(additional_data.getAsURLSearchParams()->has("thePassword")); | 118 EXPECT_TRUE(additional_data.getAsURLSearchParams()->has("thePassword")); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 DummyExceptionStateForTesting exception_state; | 153 DummyExceptionStateForTesting exception_state; |
| 151 PasswordCredential* credential = | 154 PasswordCredential* credential = |
| 152 PasswordCredential::Create(form, exception_state); | 155 PasswordCredential::Create(form, exception_state); |
| 153 EXPECT_EQ(nullptr, credential); | 156 EXPECT_EQ(nullptr, credential); |
| 154 EXPECT_TRUE(exception_state.HadException()); | 157 EXPECT_TRUE(exception_state.HadException()); |
| 155 EXPECT_EQ(kV8TypeError, exception_state.Code()); | 158 EXPECT_EQ(kV8TypeError, exception_state.Code()); |
| 156 EXPECT_EQ("'id' must not be empty.", exception_state.Message()); | 159 EXPECT_EQ("'id' must not be empty.", exception_state.Message()); |
| 157 } | 160 } |
| 158 | 161 |
| 159 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |