/*
 * Copyright (C) 2013 salesforce.com, inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.auraframework.integration.test.components.auraStorage;

import org.auraframework.def.ComponentDef;
import org.auraframework.def.DefDescriptor;
import org.auraframework.test.util.WebDriverTestCase;

public class NamedAuraStorageUITest extends WebDriverTestCase {
    public NamedAuraStorageUITest(String name){
        super(name);
    }
    
    /**
     * Verify that registering duplicate named storage using auraStorage:init in a template will throw an error.
     */
    public void testDuplicateNamedStorageInTemplate() throws Exception{
        String bodyMarkup = "<aura:set attribute='auraPreInitBlock'><auraStorage:init name='dup'/><auraStorage:init name='dup'/></aura:set>";
        DefDescriptor<ComponentDef> template = addSourceAutoCleanup(ComponentDef.class, 
                String.format(baseComponentTag, "isTemplate='true' extends='aura:template'", 
                        bodyMarkup));
        DefDescriptor<ComponentDef> testCmp = addSourceAutoCleanup(ComponentDef.class, 
                String.format(baseComponentTag, "render='client' template='"+template.getDescriptorName()+"'", ""));
        
        openNoAura(getUrl(testCmp));
        String jsErrors = (String)getAuraUITestingUtil().getRawEval("return window.$A.test.getAuraErrorMessage()");
        assertNotNull("Expected to see JS errors while loading component.", jsErrors);
        assertTrue("Unexpected error message: "+jsErrors, jsErrors.contains("Storage named 'dup' already exists!"));
    }
}

@@ -813,16 +813,47 @@
 estCase;
+%0Aimport org.openqa.selenium.By;
 %0A%0Apublic
@@ -985,20 +985,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**
@@ -1408,33 +1408,32 @@
 ponentDef.class,
- 
 %0A               
@@ -1509,17 +1509,16 @@
 plate'%22,
- 
 %0A       
@@ -1634,17 +1634,16 @@
 f.class,
- 
 %0A       
@@ -1752,24 +1752,16 @@
 , %22%22));%0A
-        
 %0A       
@@ -1802,95 +1802,178 @@
     
-String jsErrors = (String)getAuraUITestingUtil().getRawEval(%22return window.$A.test.getA
+waitForElement(%22Error mask is not visible.%22, findDomElement(By.cssSelector(%22div%5Bid='auraErrorMask'%5D%22)), true);%0A        String jsErrors = getText(By.cssSelector(%22div%5Bid='a
 uraE
@@ -1987,14 +1987,16 @@
 sage
-()%22
+'%5D%22)
 );%0A
+%0A
     

Fix NamedAuraStorageUITest