Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / testing / DictionaryTest.cpp
blob5545867abf5c690cffadb9e8a21387545b6d33f9
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "DictionaryTest.h"
8 #include "bindings/core/v8/V8ObjectBuilder.h"
9 #include "core/testing/InternalDictionary.h"
10 #include "core/testing/InternalDictionaryDerived.h"
12 namespace blink {
14 DictionaryTest::DictionaryTest()
15 : m_requiredBooleanMember(false)
19 DictionaryTest::~DictionaryTest()
23 void DictionaryTest::set(const InternalDictionary& testingDictionary)
25 reset();
26 if (testingDictionary.hasLongMember())
27 m_longMember = testingDictionary.longMember();
28 if (testingDictionary.hasLongMemberWithClamp())
29 m_longMemberWithClamp = testingDictionary.longMemberWithClamp();
30 if (testingDictionary.hasLongMemberWithEnforceRange())
31 m_longMemberWithEnforceRange = testingDictionary.longMemberWithEnforceRange();
32 m_longMemberWithDefault = testingDictionary.longMemberWithDefault();
33 if (testingDictionary.hasLongOrNullMember())
34 m_longOrNullMember = testingDictionary.longOrNullMember();
35 // |longOrNullMemberWithDefault| has a default value but can be null, so
36 // we need to check availability.
37 if (testingDictionary.hasLongOrNullMemberWithDefault())
38 m_longOrNullMemberWithDefault = testingDictionary.longOrNullMemberWithDefault();
39 if (testingDictionary.hasBooleanMember())
40 m_booleanMember = testingDictionary.booleanMember();
41 if (testingDictionary.hasDoubleMember())
42 m_doubleMember = testingDictionary.doubleMember();
43 if (testingDictionary.hasUnrestrictedDoubleMember())
44 m_unrestrictedDoubleMember = testingDictionary.unrestrictedDoubleMember();
45 m_stringMember = testingDictionary.stringMember();
46 m_stringMemberWithDefault = testingDictionary.stringMemberWithDefault();
47 m_byteStringMember = testingDictionary.byteStringMember();
48 m_usvStringMember = testingDictionary.usvStringMember();
49 if (testingDictionary.hasStringSequenceMember())
50 m_stringSequenceMember = testingDictionary.stringSequenceMember();
51 m_stringSequenceMemberWithDefault = testingDictionary.stringSequenceMemberWithDefault();
52 if (testingDictionary.hasStringSequenceOrNullMember())
53 m_stringSequenceOrNullMember = testingDictionary.stringSequenceOrNullMember();
54 m_enumMember = testingDictionary.enumMember();
55 m_enumMemberWithDefault = testingDictionary.enumMemberWithDefault();
56 m_enumOrNullMember = testingDictionary.enumOrNullMember();
57 if (testingDictionary.hasEnumArrayMember())
58 m_enumArrayMember = testingDictionary.enumArrayMember();
59 if (testingDictionary.hasElementMember())
60 m_elementMember = testingDictionary.elementMember();
61 if (testingDictionary.hasElementOrNullMember())
62 m_elementOrNullMember = testingDictionary.elementOrNullMember();
63 m_objectMember = testingDictionary.objectMember();
64 m_objectOrNullMemberWithDefault = testingDictionary.objectOrNullMemberWithDefault();
65 if (testingDictionary.hasDoubleOrStringMember())
66 m_doubleOrStringMember = testingDictionary.doubleOrStringMember();
67 if (testingDictionary.hasDoubleOrStringSequenceMember())
68 m_doubleOrStringSequenceMember = testingDictionary.doubleOrStringSequenceMember();
69 m_eventTargetOrNullMember = testingDictionary.eventTargetOrNullMember();
70 if (testingDictionary.hasDictionaryMember()) {
71 HashMap<String, String> properties;
72 testingDictionary.dictionaryMember().getOwnPropertiesAsStringHashMap(properties);
73 m_dictionaryMemberProperties = properties;
77 void DictionaryTest::get(InternalDictionary& result)
79 if (m_longMember)
80 result.setLongMember(m_longMember.get());
81 if (m_longMemberWithClamp)
82 result.setLongMemberWithClamp(m_longMemberWithClamp.get());
83 if (m_longMemberWithEnforceRange)
84 result.setLongMemberWithEnforceRange(m_longMemberWithEnforceRange.get());
85 result.setLongMemberWithDefault(m_longMemberWithDefault);
86 if (m_longOrNullMember)
87 result.setLongOrNullMember(m_longOrNullMember.get());
88 if (m_longOrNullMemberWithDefault)
89 result.setLongOrNullMemberWithDefault(m_longOrNullMemberWithDefault.get());
90 if (m_booleanMember)
91 result.setBooleanMember(m_booleanMember.get());
92 if (m_doubleMember)
93 result.setDoubleMember(m_doubleMember.get());
94 if (m_unrestrictedDoubleMember)
95 result.setUnrestrictedDoubleMember(m_unrestrictedDoubleMember.get());
96 result.setStringMember(m_stringMember);
97 result.setStringMemberWithDefault(m_stringMemberWithDefault);
98 result.setByteStringMember(m_byteStringMember);
99 result.setUsvStringMember(m_usvStringMember);
100 if (m_stringSequenceMember)
101 result.setStringSequenceMember(m_stringSequenceMember.get());
102 result.setStringSequenceMemberWithDefault(m_stringSequenceMemberWithDefault);
103 if (m_stringSequenceOrNullMember)
104 result.setStringSequenceOrNullMember(m_stringSequenceOrNullMember.get());
105 result.setEnumMember(m_enumMember);
106 result.setEnumMemberWithDefault(m_enumMemberWithDefault);
107 result.setEnumOrNullMember(m_enumOrNullMember);
108 if (m_enumArrayMember)
109 result.setEnumArrayMember(m_enumArrayMember.get());
110 if (m_elementMember)
111 result.setElementMember(m_elementMember);
112 if (m_elementOrNullMember)
113 result.setElementOrNullMember(m_elementOrNullMember);
114 result.setObjectMember(m_objectMember);
115 result.setObjectOrNullMemberWithDefault(m_objectOrNullMemberWithDefault);
116 if (!m_doubleOrStringMember.isNull())
117 result.setDoubleOrStringMember(m_doubleOrStringMember);
118 if (!m_doubleOrStringSequenceMember.isNull())
119 result.setDoubleOrStringSequenceMember(m_doubleOrStringSequenceMember.get());
120 result.setEventTargetOrNullMember(m_eventTargetOrNullMember);
123 ScriptValue DictionaryTest::getDictionaryMemberProperties(ScriptState* scriptState)
125 if (!m_dictionaryMemberProperties)
126 return ScriptValue();
127 V8ObjectBuilder builder(scriptState);
128 HashMap<String, String> properties = m_dictionaryMemberProperties.get();
129 for (HashMap<String, String>::iterator it = properties.begin(); it != properties.end(); ++it)
130 builder.addString(it->key, it->value);
131 return builder.scriptValue();
134 void DictionaryTest::setDerived(const InternalDictionaryDerived& derived)
136 ASSERT(derived.hasRequiredBooleanMember());
137 set(derived);
138 if (derived.hasDerivedStringMember())
139 m_derivedStringMember = derived.derivedStringMember();
140 m_derivedStringMemberWithDefault = derived.derivedStringMemberWithDefault();
141 m_requiredBooleanMember = derived.requiredBooleanMember();
144 void DictionaryTest::getDerived(InternalDictionaryDerived& result)
146 get(result);
147 result.setDerivedStringMember(m_derivedStringMember);
148 result.setDerivedStringMemberWithDefault(m_derivedStringMemberWithDefault);
149 result.setRequiredBooleanMember(m_requiredBooleanMember);
152 void DictionaryTest::reset()
154 m_longMember = nullptr;
155 m_longMemberWithClamp = nullptr;
156 m_longMemberWithEnforceRange = nullptr;
157 m_longMemberWithDefault = -1; // This value should not be returned.
158 m_longOrNullMember = nullptr;
159 m_longOrNullMemberWithDefault = nullptr;
160 m_booleanMember = nullptr;
161 m_doubleMember = nullptr;
162 m_unrestrictedDoubleMember = nullptr;
163 m_stringMember = String();
164 m_stringMemberWithDefault = String("Should not be returned");
165 m_stringSequenceMember = nullptr;
166 m_stringSequenceMemberWithDefault.fill("Should not be returned", 1);
167 m_stringSequenceOrNullMember = nullptr;
168 m_enumMember = String();
169 m_enumMemberWithDefault = String();
170 m_enumOrNullMember = String();
171 m_enumArrayMember = nullptr;
172 m_elementMember = nullptr;
173 m_elementOrNullMember = nullptr;
174 m_objectMember = ScriptValue();
175 m_objectOrNullMemberWithDefault = ScriptValue();
176 m_doubleOrStringMember = DoubleOrString();
177 m_eventTargetOrNullMember = nullptr;
178 m_derivedStringMember = String();
179 m_derivedStringMemberWithDefault = String();
180 m_requiredBooleanMember = false;
181 m_dictionaryMemberProperties = nullptr;
184 DEFINE_TRACE(DictionaryTest)
186 visitor->trace(m_elementMember);
187 visitor->trace(m_elementOrNullMember);
188 visitor->trace(m_doubleOrStringSequenceMember);
189 visitor->trace(m_eventTargetOrNullMember);