123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- * 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.table;
-
- import static org.hamcrest.CoreMatchers.is;
- import static org.hamcrest.MatcherAssert.assertThat;
- import static org.hamcrest.Matchers.lessThan;
-
- import java.util.List;
-
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.interactions.Actions;
- import org.openqa.selenium.remote.DesiredCapabilities;
-
- import com.vaadin.testbench.parallel.Browser;
- import com.vaadin.tests.tb3.MultiBrowserTest;
-
- /**
- * Test for context menu position and size.
- *
- * @author Vaadin Ltd
- */
- public class ContextMenuSizeTest extends MultiBrowserTest {
-
- @Override
- public List<DesiredCapabilities> getBrowsersToTest() {
- // context menu doesn't work in phantom JS and works weirdly with IE8
- // and selenium.
- return getBrowserCapabilities(Browser.IE9, Browser.IE10, Browser.IE11,
- Browser.FIREFOX, Browser.CHROME);
- }
-
- @Override
- public void setup() throws Exception {
- super.setup();
-
- openTestURL();
- }
-
- private void resizeViewPortHeightTo(int windowHeight) {
- // viewport width doesn't matter, let's use a magic number of 500.
- testBench().resizeViewPortTo(500, windowHeight);
- }
-
- private int getContextMenuY() {
- int y = openContextMenu().getLocation().getY();
-
- closeContextMenu();
-
- return y;
- }
-
- private int getContextMenuHeight() {
- int height = openContextMenu().getSize().getHeight();
-
- closeContextMenu();
-
- return height;
- }
-
- private WebElement openContextMenu() {
- Actions actions = new Actions(getDriver());
- actions.contextClick(findElement(By.className("v-table-cell-wrapper")));
- actions.perform();
- return findElement(By.className("v-contextmenu"));
- }
-
- private void closeContextMenu() {
- findElement(By.className("v-app")).click();
- }
-
- @Test
- public void contextMenuIsResizedToFitWindow() {
- int initialHeight = getContextMenuHeight();
-
- resizeViewPortHeightTo(initialHeight - 10);
- assertThat(getContextMenuHeight(), lessThan(initialHeight));
-
- resizeViewPortHeightTo(initialHeight + 100);
- assertThat(getContextMenuHeight(), is(initialHeight));
- }
-
- @Test
- public void contextMenuPositionIsChangedAfterResize() {
- int height = getContextMenuHeight();
- int y = getContextMenuY();
-
- resizeViewPortHeightTo(y + height - 10);
-
- assertThat(getContextMenuY(), lessThan(y));
- assertThat(getContextMenuHeight(), is(height));
- }
-
- }
|