Search in sources :

Example 1 with NlEditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.

the class ChooseResourceDialogTest method testDrawable.

/**
   * Test looking at the attributes for a drawable
   */
@Test
public void testDrawable() throws IOException {
    guiTest.importSimpleApplication();
    // Open file as XML and switch to design tab, wait for successful render
    EditorFixture editor = guiTest.ideFrame().getEditor();
    editor.open("app/src/main/res/layout/frames.xml", EditorFixture.Tab.DESIGN);
    NlEditorFixture layout = editor.getLayoutEditor(false);
    layout.waitForRenderToFinish();
    // Find and click the first text view
    NlComponentFixture imageView = layout.findView("ImageView", 0);
    imageView.click();
    layout.requireSelection(Collections.singletonList(imageView));
    // Get property sheet, find srcCompat property, open customizer
    NlPropertyInspectorFixture fixture = layout.getPropertyInspector();
    NlPropertyFixture property = fixture.findProperty("srcCompat");
    property.clickCustomizer();
    ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    JTabbedPaneFixture tabs = dialog.getTabs();
    tabs.requireTabTitles("Drawable", "Color", "ID", "String", "Style");
    dialog.getSearchField().enterText("che");
    JListFixture projectList = dialog.getList("Project");
    JListFixture frameworkList = dialog.getList("android");
    assertEquals("ic_launcher                             \n", listToString(projectList));
    assertEquals("checkbox_off_background                 \n" + "checkbox_on_background                  \n", listToString(frameworkList));
    // This should jump to the project list and select the first one: ic_launcher
    dialog.getSearchField().pressAndReleaseKeys(KeyEvent.VK_DOWN);
    dialog.getDrawablePreviewName().requireText("ic_launcher");
    assertThat(dialog.getDrawableResolutionChain()).isEqualTo("@drawable/ic_launcher\n" + " ⇒ ic_launcher.xml\n");
    // Ensure that the pixel in the middle of the preview area is red
    JLabelFixture previewLabel = dialog.getDrawablePreviewLabel();
    Icon icon = previewLabel.target().getIcon();
    //noinspection UndesirableClassUsage
    BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = img.getGraphics();
    icon.paintIcon(previewLabel.target(), graphics, 0, 0);
    graphics.dispose();
    assertEquals(0xFFFF0000, img.getRGB(icon.getIconWidth() / 2, icon.getIconHeight() / 2));
    dialog.clickOK();
    Wait.seconds(2).expecting("property to have the new value").until(() -> property.getValue().equals("@drawable/ic_launcher"));
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlPropertyInspectorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) NlComponentFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture) NlPropertyFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyFixture) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 2 with NlEditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.

the class ConvertToConstraintLayoutTest method testConvert2.

@Ignore("http://b.android.com/211200")
@Test
public void testConvert2() throws Exception {
    guiTest.importSimpleApplication();
    EditorFixture editor = guiTest.ideFrame().getEditor();
    editor.open("app/src/main/res/layout/frames.xml", EditorFixture.Tab.DESIGN);
    NlEditorFixture layout = editor.getLayoutEditor(false);
    layout.waitForRenderToFinish();
    // Find and click the first text View
    NlComponentFixture button = layout.findView("TextView", 0);
    button.invokeContextMenuAction("Convert LinearLayout to ConstraintLayout");
    // Confirm dialog
    DialogFixture quickFixDialog = WindowFinder.findDialog(Matchers.byTitle(Dialog.class, "Convert to ConstraintLayout")).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(guiTest.robot());
    // Press OK
    JButtonFixture finish = quickFixDialog.button(withText("OK"));
    finish.click();
    // Check that we've converted to what we expected
    layout.waitForRenderToFinish();
    editor.selectEditorTab(EditorFixture.Tab.EDITOR);
    waitForScout();
    editor.invokeAction(EditorFixture.EditorAction.FORMAT);
    @Language("XML") String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<android.support.constraint.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n" + "    xmlns:tools=\"http://schemas.android.com/tools\"\n" + "    android:id=\"@+id/constraintLayout\"\n" + "    android:layout_width=\"match_parent\"\n" + "    android:layout_height=\"wrap_content\"\n" + "    android:orientation=\"vertical\"\n" + "    tools:layout_editor_absoluteX=\"<test>\"\n" + "    tools:layout_editor_absoluteY=\"<test>\">\n" + "\n" + "    <TextView\n" + "        android:id=\"@+id/title\"\n" + "        android:layout_width=\"wrap_content\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:text=\"Welcome\"\n" + "        app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + "        tools:layout_constraintBottom_creator=\"1\"\n" + "        tools:layout_constraintLeft_creator=\"1\"\n" + "        tools:layout_constraintRight_creator=\"1\"\n" + "        tools:layout_constraintTop_creator=\"1\"\n" + "        tools:layout_editor_absoluteX=\"<test>\"\n" + "        tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "    <FrameLayout\n" + "        android:id=\"@+id/attending_remotely\"\n" + "        android:layout_width=\"0dp\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:foreground=\"?android:selectableItemBackground\"\n" + "        app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + "        tools:layout_constraintBottom_creator=\"1\"\n" + "        tools:layout_constraintLeft_creator=\"1\"\n" + "        tools:layout_constraintRight_creator=\"1\"\n" + "        tools:layout_constraintTop_creator=\"1\"\n" + "        tools:layout_editor_absoluteX=\"<test>\"\n" + "        tools:layout_editor_absoluteY=\"<test>\">\n" + "\n" + "        <ImageView\n" + "            android:layout_width=\"100dp\"\n" + "            android:layout_height=\"100dp\"\n" + "            android:adjustViewBounds=\"true\"\n" + "            android:scaleType=\"centerInside\"\n" + "            app:layout_constraintLeft_toLeftOf=\"@+id/attending_remotely\"\n" + "            tools:layout_constraintLeft_creator=\"1\"\n" + "            tools:layout_editor_absoluteX=\"<test>\"\n" + "            tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "        <TextView\n" + "            android:layout_width=\"wrap_content\"\n" + "            android:layout_height=\"wrap_content\"\n" + "            android:layout_gravity=\"bottom|end|right\"\n" + "            android:text=\"Remotely\"\n" + "            tools:layout_editor_absoluteX=\"<test>\"\n" + "            tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "    </FrameLayout>\n" + "\n" + "    <FrameLayout\n" + "        android:id=\"@+id/attending_in_person\"\n" + "        android:layout_width=\"0dp\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:foreground=\"?android:selectableItemBackground\"\n" + "        app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + "        app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + "        tools:layout_constraintBottom_creator=\"1\"\n" + "        tools:layout_constraintLeft_creator=\"1\"\n" + "        tools:layout_constraintRight_creator=\"1\"\n" + "        tools:layout_constraintTop_creator=\"1\"\n" + "        tools:layout_editor_absoluteX=\"<test>\"\n" + "        tools:layout_editor_absoluteY=\"<test>\">\n" + "\n" + "        <ImageView\n" + "            android:layout_width=\"100dp\"\n" + "            android:layout_height=\"100dp\"\n" + "            android:adjustViewBounds=\"true\"\n" + "            android:scaleType=\"centerInside\"\n" + "            app:layout_constraintLeft_toLeftOf=\"@+id/attending_in_person\"\n" + "            tools:layout_constraintLeft_creator=\"1\"\n" + "            tools:layout_editor_absoluteX=\"<test>\"\n" + "            tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "        <TextView\n" + "            android:layout_width=\"wrap_content\"\n" + "            android:layout_height=\"wrap_content\"\n" + "            android:layout_gravity=\"bottom|end|right\"\n" + "            android:text=\"In Person\"\n" + "            tools:layout_editor_absoluteX=\"<test>\"\n" + "            tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "    </FrameLayout>\n" + "\n" + "</android.support.constraint.ConstraintLayout>\n";
    assertThat(wipeDimensions(editor.getCurrentFileContents())).isEqualTo(wipeDimensions(xml));
}
Also used : JButtonFixture(org.fest.swing.fixture.JButtonFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) DialogFixture(org.fest.swing.fixture.DialogFixture) Language(org.intellij.lang.annotations.Language) NlComponentFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with NlEditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.

the class NewProjectTest method testStillBuildingMessage.

@RunIn(TestGroup.UNRELIABLE)
@Test
public void testStillBuildingMessage() throws Exception {
    // Create a new project and open a layout file.
    // If the first build is still going on when the rendering happens, simply show a message that a build is going on,
    // and check that the message disappears at the end of the build.
    newProject("Test Application").withBriefNames().withMinSdk("15").withoutSync().create();
    final EditorFixture editor = guiTest.ideFrame().getEditor();
    Wait.seconds(5).expecting("file to open").until(() -> "A.java".equals(editor.getCurrentFileName()));
    editor.open("app/src/main/res/layout/activity_a.xml", EditorFixture.Tab.EDITOR);
    NlEditorFixture layoutEditor = editor.getLayoutEditor(true);
    layoutEditor.waitForRenderToFinish();
    if (layoutEditor.hasRenderErrors()) {
        layoutEditor.waitForErrorPanelToContain("still building");
        assertThat(layoutEditor.getErrorText()).doesNotContain("Missing styles");
        guiTest.ideFrame().waitForGradleProjectSyncToFinish();
        layoutEditor.waitForRenderToFinish();
        assertThat(layoutEditor.hasRenderErrors()).isFalse();
    }
}
Also used : NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) Test(org.junit.Test) RunIn(com.android.tools.idea.tests.gui.framework.RunIn)

Example 4 with NlEditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.

the class NewProjectTest method testRenderResourceInitialization.

@RunIn(TestGroup.UNRELIABLE)
@Test
public void testRenderResourceInitialization() throws IOException {
    // Regression test for https://code.google.com/p/android/issues/detail?id=76966
    newProject("Test Application").withBriefNames().withMinSdk("9").create();
    EditorFixture editor = guiTest.ideFrame().getEditor();
    assertThat(editor.getCurrentFileName()).isEqualTo("A.java");
    editor.close();
    assertThat(editor.getCurrentFileName()).isEqualTo("activity_a.xml");
    NlEditorFixture layoutEditor = editor.getLayoutEditor(true);
    layoutEditor.waitForRenderToFinish();
    guiTest.ideFrame().invokeProjectMake();
    layoutEditor.waitForRenderToFinish();
    assertFalse(layoutEditor.hasRenderErrors());
    guiTest.waitForBackgroundTasks();
}
Also used : NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) Test(org.junit.Test) RunIn(com.android.tools.idea.tests.gui.framework.RunIn)

Example 5 with NlEditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.

the class ChooseResourceDialogTest method testEditString.

/**
   * Test the resource table editor, filtering and selection
   */
@Test
public void testEditString() throws IOException {
    guiTest.importSimpleApplication();
    // Open file as XML and switch to design tab, wait for successful render
    EditorFixture editor = guiTest.ideFrame().getEditor();
    editor.open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.DESIGN);
    NlEditorFixture layout = editor.getLayoutEditor(false);
    layout.waitForRenderToFinish();
    // Find and click the first text view
    NlComponentFixture textView = layout.findView("TextView", 0);
    textView.click();
    // It should be selected now
    layout.requireSelection(Collections.singletonList(textView));
    // Get property sheet, find text property, open customizer
    layout.getPropertyInspector().findProperty("text").clickCustomizer();
    ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    JTableFixture nameTable = dialog.getResourceNameTable();
    assertEquals("Project                                                     \n" + "action_settings               Settings                      \n" + "app_name                      Simple Application            \n" + "cancel                        取消                            \n" + "hello_world                   Hello world!                  \n" + "android                                                     \n", tableToString(nameTable, 0, 6, 0, 5, 30));
    // Search for "app" and confirm that we only show the header nodes as well as resource names
    // that match. We also used to check that we were highlighting the right portion of the
    // string here, but after switching away from HTML labels to IntelliJ's ColoredTableCellRenderer,
    // this is no longer visible from the table fixture.
    dialog.getSearchField().enterText("app");
    assertEquals("Project                                                                         \n" + "app_name                                                                        \n" + "android                                                                         \n" + "Theme attributes                                                                \n", tableToString(nameTable, 0, 6, 0, 1, 80));
    JTableFixture valueTable = dialog.getResourceValueTable();
    assertEquals("Default                                 Simple Application                      \n" + "English                                 Simple Application                      \n" + "Hebrew                                                                          \n" + "Tamil                                   Simple Application                      \n" + "English, United Kingdom                 Simple Application                      \n" + "Chinese, China                          谷歌 I/O                                  \n", tableToString(valueTable));
    dialog.clickOK();
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) NlComponentFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture) Test(org.junit.Test)

Aggregations

NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)10 Test (org.junit.Test)9 EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)6 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)6 RunIn (com.android.tools.idea.tests.gui.framework.RunIn)2 ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)2 DialogFixture (org.fest.swing.fixture.DialogFixture)2 JButtonFixture (org.fest.swing.fixture.JButtonFixture)2 Language (org.intellij.lang.annotations.Language)2 Ignore (org.junit.Ignore)2 IdeFrameFixture (com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture)1 NlPropertyFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyFixture)1 NlPropertyInspectorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture)1 NlEditor (com.android.tools.idea.uibuilder.editor.NlEditor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 BufferedImage (java.awt.image.BufferedImage)1 NotNull (org.jetbrains.annotations.NotNull)1