/*
 * Copyright 2000-2014 Vaadin Ltd.
 * 
 * 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 com.vaadin.tests.components.notification;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Test to check notification delay.
 * 
 * @author Vaadin Ltd
 */
public class NotificationDelayTest extends MultiBrowserTest {

    @Test
    public void testDelay() throws InterruptedException {
        openTestURL();

        Assert.assertTrue("No notification found", hasNotification());
        Actions actions = new Actions(getDriver());
        actions.moveByOffset(10, 10).build().perform();
        long start = System.currentTimeMillis();
        boolean hidden = false;
        while (System.currentTimeMillis() <= start + 5000) {
            Thread.sleep(500);
            hidden = !hasNotification();
            if (hidden) {
                break;
            }
        }

        Assert.assertTrue("Notification is still visible after 5 seconds",
                hidden);
    }

    private boolean hasNotification() {
        return isElementPresent(By.className("v-Notification"));
    }

}

@@ -643,16 +643,62 @@
 ation;%0A%0A
+import com.vaadin.tests.tb3.MultiBrowserTest;%0A
 import o
@@ -768,16 +768,54 @@
 ium.By;%0A
+import org.openqa.selenium.WebDriver;%0A
 import o
@@ -859,53 +859,63 @@
 ns;%0A
-%0A
 import 
-com.vaadin.tests.tb3.MultiBrowserTest
+org.openqa.selenium.support.ui.ExpectedCondition
 ;%0A%0A/
@@ -1210,24 +1210,25 @@
 ion());%0A
+%0A
         
 Actions 
@@ -1223,384 +1223,201 @@
     
-Actions actions = new Actions(getDriver());%0A        actions.moveByOffset(10, 10).build().perform();%0A        long start = System.currentTimeMillis();%0A        boolean hidden = false;%0A        while (System.currentTimeMillis() %3C= start + 5000) %7B%0A            Thread.sleep(500);%0A            hidden = !hasNotification();%0A            if (hidden) %7B%0A                break;%0A            %7D
+waitUntil(new ExpectedCondition%3CBoolean%3E() %7B%0A%0A            @Override%0A            public Boolean apply(WebDriver input) %7B%0A                new Actions(getDriver()).moveByOffset(10, 10).perform();%0A
 %0A   
@@ -1425,19 +1425,16 @@
     
-%7D%0A%0A
         
 Asse
@@ -1433,97 +1433,58 @@
     
-Assert.assertTrue(%22Notification is still visible after 5 seconds%22,%0A                hidden
+return !hasNotification();%0A            %7D%0A        %7D
 );%0A 

Fix NotificationDelayTest for IE8 and Chrome. (#14689)