Search in sources :

Example 11 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture 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 12 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture 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 13 with EditorFixture

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

the class ThemeSelectorTest method testRenameTheme.

/**
   * Tests the theme renaming functionality of the theme selector
   * and that IntelliJ's Undo works can revert this action
   */
@Ignore("go/studio-builder/builders/ubuntu-studio-master-dev-uitests/builds/257")
@Test
public void testRenameTheme() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(ideFrame);
    final JComboBoxFixture themesComboBox = themeEditor.getThemesComboBox();
    themesComboBox.selectItem("Rename AppTheme");
    RenameRefactoringDialogFixture renameRefactoringDialog = RenameRefactoringDialogFixture.find(guiTest.robot());
    renameRefactoringDialog.setNewName("NewAppTheme").clickRefactor();
    themeEditor.waitForThemeSelection("NewAppTheme");
    themesComboBox.requireSelection("NewAppTheme");
    List<String> themeList = themeEditor.getThemesList();
    assertThat(themeList).hasSize(9);
    assertThat(themeList.get(0)).isEqualTo("NewAppTheme");
    assertThat(themeList.get(8)).isEqualTo("Rename NewAppTheme");
    guiTest.robot().waitForIdle();
    // AppCompat is read-only, being a library theme
    themesComboBox.selectItem("Theme.AppCompat.NoActionBar");
    themeList = themeEditor.getThemesList();
    assertThat(themeList).hasSize(8);
    assertThat(themeList.get(0)).isEqualTo("NewAppTheme");
    assertThat(themeList.get(3)).isEqualTo("Theme.AppCompat.Light.NoActionBar");
    assertThat(themeList.get(4)).isEqualTo("Theme.AppCompat.NoActionBar");
    assertThat(themeList.get(5)).isEqualTo("Show all themes");
    assertThat(themeList.get(7)).isEqualTo("Create New Theme");
    EditorFixture editor = ideFrame.invokeMenuPath("Window", "Editor Tabs", "Select Previous Tab").getEditor();
    assertThat(editor.getCurrentFileContents()).doesNotContain("name=\"AppTheme");
    editor.moveBetween("", "name=\"NewAppTheme");
    assertThat(editor.getCurrentLine().trim()).isEqualTo("<style name=\"NewAppTheme\" parent=\"android:Theme.Holo.Light.DarkActionBar\">");
    // Testing Undo
    ideFrame.invokeMenuPath("Window", "Editor Tabs", "Select Next Tab");
    themesComboBox.selectItem("NewAppTheme");
    ideFrame.invokeMenuPath("Edit", "Undo Renaming attribute value AppTh...").findMessageDialog("Undo").clickOk();
    themeEditor.waitForThemeSelection("AppTheme");
    // required to ensure that the Select Previous Tab action is available
    themeEditor.focus();
    ideFrame.invokeMenuPath("Window", "Editor Tabs", "Select Previous Tab");
    assertThat(editor.getCurrentFileContents()).doesNotContain("name=\"NewAppTheme");
    editor.moveBetween("", "name=\"AppTheme");
    assertThat(editor.getCurrentLine().trim()).isEqualTo("<style name=\"AppTheme\" parent=\"android:Theme.Holo.Light.DarkActionBar\">");
}
Also used : RenameRefactoringDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) ThemeEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) ThemeEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture 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)

Example 15 with EditorFixture

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

the class ManifestEditorTest method testNonPrimaryManifest.

@Test
public void testNonPrimaryManifest() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("Flavoredapp");
    IdeFrameFixture projectFrame = guiTest.ideFrame();
    EditorFixture editor = projectFrame.getEditor();
    editor.open("src/main/AndroidManifest.xml");
    editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
    MergedManifestFixture mergedManifestFixture = editor.getMergedManifestEditor();
    Color defaultBackgroundColor = mergedManifestFixture.getDefaultBackgroundColor();
    mergedManifestFixture.getTree().clickRow(1);
    assertThat(mergedManifestFixture.getSelectedNodeColor()).isNotEqualTo(defaultBackgroundColor);
    mergedManifestFixture.getTree().clickRow(3);
    assertThat(mergedManifestFixture.getSelectedNodeColor()).isEqualTo(defaultBackgroundColor);
    mergedManifestFixture.getTree().clickRow(2);
    mergedManifestFixture.requireText("Manifest Sources \n" + "\n" + "Flavoredapp main manifest (this file)\n" + "\n" + "myaarlibrary manifest\n" + "\n" + "build.gradle injection\n" + " Other Manifest Files (Included in merge, but did not contribute any elements)\n" + "locallib manifest, Flavoredapp debug manifest, Flavoredapp flavor1 manifest,\n" + "support-compat:25.0.0 manifest, support-core-ui:25.0.0 manifest,\n" + "support-core-utils:25.0.0 manifest, support-fragment:25.0.0 manifest,\n" + "support-media-compat:25.0.0 manifest, support-v4:25.0.0 manifest  Merging Log\n" + "Value provided by Gradle Added from the Flavoredapp main manifest (this file),\n" + "line 1 Value provided by Gradle\n", true);
    editor.open("src/debug/AndroidManifest.xml");
    editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
    mergedManifestFixture = editor.getMergedManifestEditor();
    mergedManifestFixture.getTree().clickRow(3);
    assertNotEquals(defaultBackgroundColor, mergedManifestFixture.getSelectedNodeColor());
    editor.open("src/flavor1/AndroidManifest.xml");
    editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
    mergedManifestFixture = editor.getMergedManifestEditor();
    mergedManifestFixture.getTree().clickRow(3);
    assertNotEquals(defaultBackgroundColor, mergedManifestFixture.getSelectedNodeColor());
}
Also used : MergedManifestFixture(com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) Test(org.junit.Test)

Aggregations

EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)41 Test (org.junit.Test)37 IdeFrameFixture (com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture)9 Ignore (org.junit.Ignore)7 GradleBuildModelFixture (com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture)6 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)6 NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)6 ArtifactDependencySpec (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)4 MergedManifestFixture (com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture)4 RunIn (com.android.tools.idea.tests.gui.framework.RunIn)3 RenameRefactoringDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DialogFixture (org.fest.swing.fixture.DialogFixture)3 JButtonFixture (org.fest.swing.fixture.JButtonFixture)3 JTreeFixture (org.fest.swing.fixture.JTreeFixture)3 ExpectedModuleDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ExpectedModuleDependency)2 ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)2 ConflictsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture.ConflictsDialogFixture)2 ThemeEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture)2 Project (com.intellij.openapi.project.Project)2