109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/* 209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (c) 2014, Google Inc. All rights reserved. 309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions 609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * are met: 709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 3. Neither the name of Opera Software ASA nor the names of its 1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * contributors may be used to endorse or promote products derived 1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * from this software without specific prior written permission. 1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THE POSSIBILITY OF SUCH DAMAGE. 2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */ 2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "config.h" 315d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/css/CSSTestHelper.h" 3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/css/CSSRuleList.h" 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/css/CSSStyleSheet.h" 3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/css/RuleSet.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/css/StyleSheetContents.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/Document.h" 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/text/WTFString.h" 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include <gtest/gtest.h> 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 42c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)CSSTestHelper::~CSSTestHelper() 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)CSSTestHelper::CSSTestHelper() 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_document = Document::create(); 5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) TextPosition position; 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_styleSheet = CSSStyleSheet::createInline(m_document.get(), KURL(), position, "UTF-8"); 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)RuleSet& CSSTestHelper::ruleSet() 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RuleSet& ruleSet = m_styleSheet->contents()->ensureRuleSet(MediaQueryEvaluator(), RuleHasNoSpecialState); 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ruleSet.compactRulesIfNeeded(); 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return ruleSet; 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void CSSTestHelper::addCSSRules(const char* cssText) 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) TextPosition position; 6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) unsigned sheetLength = m_styleSheet->length(); 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT_TRUE(m_styleSheet->contents()->parseStringAtPosition(cssText, position, true)); 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT_TRUE(m_styleSheet->length() > sheetLength); 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 70c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 71