Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 bool next(ScriptState* scriptState, 165 bool next(ScriptState* scriptState,
166 int& value, 166 int& value,
167 ExceptionState& exceptionState) override { 167 ExceptionState& exceptionState) override {
168 if (m_index >= 5) 168 if (m_index >= 5)
169 return false; 169 return false;
170 value = m_index * m_index; 170 value = m_index * m_index;
171 return true; 171 return true;
172 } 172 }
173 }; 173 };
174 174
175 class UseCounterObserverImpl final : public UseCounter::Observer {
176 WTF_MAKE_NONCOPYABLE(UseCounterObserverImpl);
177
178 public:
179 UseCounterObserverImpl(ScriptPromiseResolver* resolver,
180 UseCounter::Feature feature)
181 : m_resolver(resolver), m_feature(feature) {}
182
183 bool onCountFeature(UseCounter::Feature feature) final {
184 if (m_feature != feature)
185 return false;
186 m_resolver->resolve(feature);
187 return true;
188 }
189
190 DEFINE_INLINE_VIRTUAL_TRACE() {
191 UseCounter::Observer::trace(visitor);
192 visitor->trace(m_resolver);
193 }
194
195 private:
196 Member<ScriptPromiseResolver> m_resolver;
197 UseCounter::Feature m_feature;
198 };
199
175 } // namespace 200 } // namespace
176 201
177 static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom( 202 static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom(
178 const String& markerType) { 203 const String& markerType) {
179 if (equalIgnoringCase(markerType, "Spelling")) 204 if (equalIgnoringCase(markerType, "Spelling"))
180 return DocumentMarker::Spelling; 205 return DocumentMarker::Spelling;
181 if (equalIgnoringCase(markerType, "Grammar")) 206 if (equalIgnoringCase(markerType, "Grammar"))
182 return DocumentMarker::Grammar; 207 return DocumentMarker::Grammar;
183 if (equalIgnoringCase(markerType, "TextMatch")) 208 if (equalIgnoringCase(markerType, "TextMatch"))
184 return DocumentMarker::TextMatch; 209 return DocumentMarker::TextMatch;
(...skipping 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 return false; 3027 return false;
3003 return UseCounter::isCounted(*document, 3028 return UseCounter::isCounted(*document,
3004 static_cast<UseCounter::Feature>(feature)); 3029 static_cast<UseCounter::Feature>(feature));
3005 } 3030 }
3006 3031
3007 bool Internals::isCSSPropertyUseCounted(Document* document, 3032 bool Internals::isCSSPropertyUseCounted(Document* document,
3008 const String& propertyName) { 3033 const String& propertyName) {
3009 return UseCounter::isCounted(*document, propertyName); 3034 return UseCounter::isCounted(*document, propertyName);
3010 } 3035 }
3011 3036
3037 ScriptPromise Internals::observeUseCounter(ScriptState* scriptState,
3038 Document* document,
3039 uint32_t feature) {
3040 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
3041 ScriptPromise promise = resolver->promise();
3042 if (feature >= UseCounter::NumberOfFeatures) {
3043 resolver->reject();
3044 return promise;
3045 }
3046 UseCounter::Feature useCounterFeature =
3047 static_cast<UseCounter::Feature>(feature);
3048 if (UseCounter::isCounted(*document, useCounterFeature)) {
3049 resolver->resolve();
3050 return promise;
3051 }
3052 UseCounter::addObserver(
3053 *document, new UseCounterObserverImpl(resolver, useCounterFeature));
3054 return promise;
3055 }
3056
3012 String Internals::unscopableAttribute() { 3057 String Internals::unscopableAttribute() {
3013 return "unscopableAttribute"; 3058 return "unscopableAttribute";
3014 } 3059 }
3015 3060
3016 String Internals::unscopableMethod() { 3061 String Internals::unscopableMethod() {
3017 return "unscopableMethod"; 3062 return "unscopableMethod";
3018 } 3063 }
3019 3064
3020 ClientRectList* Internals::focusRingRects(Element* element) { 3065 ClientRectList* Internals::focusRingRects(Element* element) {
3021 Vector<LayoutRect> rects; 3066 Vector<LayoutRect> rects;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 3130
3086 void Internals::crash() { 3131 void Internals::crash() {
3087 CHECK(false) << "Intentional crash"; 3132 CHECK(false) << "Intentional crash";
3088 } 3133 }
3089 3134
3090 void Internals::setIsLowEndDevice(bool isLowEndDevice) { 3135 void Internals::setIsLowEndDevice(bool isLowEndDevice) {
3091 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice); 3136 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice);
3092 } 3137 }
3093 3138
3094 } // namespace blink 3139 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698