Commit dcffb016 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Specify an internal ID to ::-webkit-file-upload-button

This CL makes the code robust for UA shadow tree changes.
This CL has no behavior changes.

Bug: 1040828
Change-Id: I373b5c01255149890f25b194f3777199dbaad2a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2011465Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733518}
parent a3443ed2
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/core/html/forms/form_controller.h" #include "third_party/blink/renderer/core/html/forms/form_controller.h"
#include "third_party/blink/renderer/core/html/forms/form_data.h" #include "third_party/blink/renderer/core/html/forms/form_data.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input_type_names.h" #include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
...@@ -324,14 +325,17 @@ void FileInputType::CreateShadowSubtree() { ...@@ -324,14 +325,17 @@ void FileInputType::CreateShadowSubtree() {
GetElement().Multiple() ? IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL GetElement().Multiple() ? IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL
: IDS_FORM_FILE_BUTTON_LABEL))); : IDS_FORM_FILE_BUTTON_LABEL)));
button->SetShadowPseudoId(AtomicString("-webkit-file-upload-button")); button->SetShadowPseudoId(AtomicString("-webkit-file-upload-button"));
button->setAttribute(html_names::kIdAttr,
shadow_element_names::FileUploadButton());
button->SetActive(GetElement().CanReceiveDroppedFiles()); button->SetActive(GetElement().CanReceiveDroppedFiles());
GetElement().UserAgentShadowRoot()->AppendChild(button); GetElement().UserAgentShadowRoot()->AppendChild(button);
} }
HTMLInputElement* FileInputType::UploadButton() const { HTMLInputElement* FileInputType::UploadButton() const {
Node* node = GetElement().UserAgentShadowRoot()->firstChild(); Element* element = GetElement().UserAgentShadowRoot()->getElementById(
CHECK(!node || IsA<HTMLInputElement>(node)); shadow_element_names::FileUploadButton());
return To<HTMLInputElement>(node); CHECK(!element || IsA<HTMLInputElement>(element));
return To<HTMLInputElement>(element);
} }
void FileInputType::DisabledAttributeChanged() { void FileInputType::DisabledAttributeChanged() {
......
...@@ -104,6 +104,11 @@ const AtomicString& TextFieldContainer() { ...@@ -104,6 +104,11 @@ const AtomicString& TextFieldContainer() {
return name; return name;
} }
const AtomicString& FileUploadButton() {
DEFINE_STATIC_LOCAL(AtomicString, name, ("file-upload-button"));
return name;
}
const AtomicString& OptGroupLabel() { const AtomicString& OptGroupLabel() {
DEFINE_STATIC_LOCAL(AtomicString, name, ("optgroup-label")); DEFINE_STATIC_LOCAL(AtomicString, name, ("optgroup-label"));
return name; return name;
......
...@@ -52,6 +52,7 @@ const AtomicString& PasswordRevealButton(); ...@@ -52,6 +52,7 @@ const AtomicString& PasswordRevealButton();
CORE_EXPORT const AtomicString& SliderThumb(); CORE_EXPORT const AtomicString& SliderThumb();
const AtomicString& SliderTrack(); const AtomicString& SliderTrack();
const AtomicString& TextFieldContainer(); const AtomicString& TextFieldContainer();
const AtomicString& FileUploadButton();
const AtomicString& OptGroupLabel(); const AtomicString& OptGroupLabel();
} // namespace shadow_element_names } // namespace shadow_element_names
......
...@@ -10,33 +10,37 @@ ...@@ -10,33 +10,37 @@
<p>This tests the label of a file chooser button.</p> <p>This tests the label of a file chooser button.</p>
<div id="console"></div> <div id="console"></div>
<script> <script>
function uploadButton(input) {
return internals.shadowRoot(input).getElementById('file-upload-button');
}
if (window.testRunner) { if (window.testRunner) {
var file = document.getElementById('single_file'); var file = document.getElementById('single_file');
var button = internals.shadowRoot(file).firstChild; var button = uploadButton(file);
var label = button.getAttribute('value'); var label = button.getAttribute('value');
var result = 'The label of a single file chooser button is "' + label + '".'; var result = 'The label of a single file chooser button is "' + label + '".';
label == 'Choose File' ? testPassed(result) : testFailed(result); label == 'Choose File' ? testPassed(result) : testFailed(result);
file = document.getElementById('multiple_files'); file = document.getElementById('multiple_files');
button = internals.shadowRoot(file).firstChild; button = uploadButton(file);
label = button.getAttribute('value'); label = button.getAttribute('value');
result = 'The label of a multiple file chooser button is "' + label + '".'; result = 'The label of a multiple file chooser button is "' + label + '".';
label == 'Choose Files' ? testPassed(result) : testFailed(result); label == 'Choose Files' ? testPassed(result) : testFailed(result);
file = document.getElementById('single_or_multiple_file'); file = document.getElementById('single_or_multiple_file');
button = internals.shadowRoot(file).firstChild; button = uploadButton(file);
label = button.getAttribute('value'); label = button.getAttribute('value');
result = 'Initially, the label of a file chooser button is "' + label + '".'; result = 'Initially, the label of a file chooser button is "' + label + '".';
label == 'Choose File' ? testPassed(result) : testFailed(result); label == 'Choose File' ? testPassed(result) : testFailed(result);
file.setAttribute("multiple", "multiple"); file.setAttribute("multiple", "multiple");
button = internals.shadowRoot(file).firstChild; button = uploadButton(file);
label = button.getAttribute('value'); label = button.getAttribute('value');
result = 'Set "multiple" attribute, then the label of the file chooser button becomes "' + label + '".'; result = 'Set "multiple" attribute, then the label of the file chooser button becomes "' + label + '".';
label == 'Choose Files' ? testPassed(result) : testFailed(result); label == 'Choose Files' ? testPassed(result) : testFailed(result);
file.removeAttribute("multiple"); file.removeAttribute("multiple");
button = internals.shadowRoot(file).firstChild; button = uploadButton(file);
label = button.getAttribute('value'); label = button.getAttribute('value');
result = 'Unset "multiple" attribute, then the label of the file chooser button becomes "' + label + '".'; result = 'Unset "multiple" attribute, then the label of the file chooser button becomes "' + label + '".';
label == 'Choose File' ? testPassed(result) : testFailed(result); label == 'Choose File' ? testPassed(result) : testFailed(result);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment