blob: e74aa17fb045b81cbad65d2b0906a6e0400373a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/html/forms/internal_popup_menu.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
namespace blink {
// InternalPopupMenuTest is not used on Android, and its Platform implementation
// does not provide the resources (as in GetDataResource) needed by
// InternalPopupMenu::WriteDocument.
#if !defined(OS_ANDROID)
TEST(InternalPopupMenuTest, WriteDocumentInStyleDirtyTree) {
auto dummy_page_holder_ =
std::make_unique<DummyPageHolder>(IntSize(800, 600));
Document& document = dummy_page_holder_->GetDocument();
document.body()->setInnerHTML(R"HTML(
<select id="select">
<option value="foo">Foo</option>
<option value="bar" style="display:none">Bar</option>
</select>
)HTML");
document.View()->UpdateAllLifecyclePhases(DocumentUpdateReason::kTest);
auto* select = To<HTMLSelectElement>(document.getElementById("select"));
ASSERT_TRUE(select);
auto* menu = MakeGarbageCollected<InternalPopupMenu>(
MakeGarbageCollected<EmptyChromeClient>(), *select);
document.body()->SetInlineStyleProperty(CSSPropertyID::kColor, "blue");
scoped_refptr<SharedBuffer> buffer = SharedBuffer::Create();
// Don't DCHECK in Element::EnsureComputedStyle.
static_cast<PagePopupClient*>(menu)->WriteDocument(buffer.get());
}
TEST(InternalPopupMenuTest, ShowSelectDisplayNone) {
auto dummy_page_holder_ =
std::make_unique<DummyPageHolder>(IntSize(800, 600));
Document& document = dummy_page_holder_->GetDocument();
document.body()->setInnerHTML(R"HTML(
<div id="container">
<select id="select">
<option>1</option>
<option>2</option>
</select>
</div>
)HTML");
document.View()->UpdateAllLifecyclePhases(DocumentUpdateReason::kTest);
auto* div = document.getElementById("container");
auto* select = To<HTMLSelectElement>(document.getElementById("select"));
ASSERT_TRUE(select);
auto* menu = MakeGarbageCollected<InternalPopupMenu>(
MakeGarbageCollected<EmptyChromeClient>(), *select);
div->SetInlineStyleProperty(CSSPropertyID::kDisplay, "none");
// This call should not cause a crash.
menu->Show();
}
#endif // defined(OS_ANDROID)
} // namespace blink
|