use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.
the class ManifestEditorTest method testRemoveFromManifest.
@Test
public void testRemoveFromManifest() throws IOException {
guiTest.importMultiModule();
IdeFrameFixture projectFrame = guiTest.ideFrame();
EditorFixture editor = projectFrame.getEditor();
editor.open("app/src/main/AndroidManifest.xml");
String addedText = " <activity\n" + " android:name=\"com.android.mylibrary.MainActivity\"\n" + " tools:remove=\"android:label\" />\n";
assertThat(editor.getCurrentFileContents()).doesNotContain(addedText);
editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
MergedManifestFixture mergedManifestFixture = editor.getMergedManifestEditor();
JTreeFixture tree = mergedManifestFixture.getTree();
// row 28 = "manifest/application/activity/android:name = com.android.mylibrary.MainActivity"
JPopupMenuFixture popup = tree.showPopupMenuAt(22);
popup.menuItemWithPath("Remove").click();
editor.selectEditorTab(EditorFixture.Tab.EDITOR);
assertThat(editor.getCurrentFileContents()).contains(addedText);
}
use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.
the class ManifestEditorTest method testManifestGoToSource.
@Test
public void testManifestGoToSource() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture projectFrame = guiTest.ideFrame();
EditorFixture editor = projectFrame.getEditor();
editor.open("app/src/main/AndroidManifest.xml");
editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
MergedManifestFixture mergedManifestFixture = editor.getMergedManifestEditor();
JTreeFixture tree = mergedManifestFixture.getTree();
tree.clickPath("manifest/application/android:allowBackup = true");
mergedManifestFixture.checkAllRowsColored();
Color defaultBackgroundColor = mergedManifestFixture.getDefaultBackgroundColor();
assertEquals(defaultBackgroundColor, mergedManifestFixture.getSelectedNodeColor());
mergedManifestFixture.clickLinkText("app main manifest (this file), line 5");
assertThat(editor.getCurrentLine().trim()).isEqualTo("android:allowBackup=\"true\"");
}
use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.
the class NlEditorTest method testSelectComponent.
@Test
public void testSelectComponent() throws Exception {
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));
}
use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.
the class NlPreviewTest method testCopyAndPaste.
@Test
public void testCopyAndPaste() throws Exception {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
EditorFixture editor = ideFrame.getEditor().open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.EDITOR);
NlPreviewFixture layout = editor.getLayoutPreview(true);
layout.dragComponentToSurface("Widgets", "Button").dragComponentToSurface("Widgets", "CheckBox").waitForRenderToFinish();
// Find and click the first text view
NlComponentFixture checkBox = layout.findView("CheckBox", 0);
checkBox.click();
// It should be selected now
layout.requireSelection(Collections.singletonList(checkBox));
// 4 = root layout + 3 widgets
assertEquals(4, layout.getAllComponents().size());
ideFrame.invokeMenuPath("Edit", "Cut");
assertEquals(3, layout.getAllComponents().size());
layout.findView("Button", 0).click();
ideFrame.invokeMenuPath("Edit", "Paste");
layout.findView("CheckBox", 0).click();
ideFrame.invokeMenuPath("Edit", "Copy");
ideFrame.invokeMenuPath("Edit", "Paste");
assertEquals(5, layout.getAllComponents().size());
}
use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.
the class NlPreviewTest method testEditCustomView.
@RunIn(TestGroup.UNRELIABLE)
@Test
public void testEditCustomView() throws Exception {
// Opens the LayoutTest project, opens a layout with a custom view, checks
// that it can't render yet (because the project hasn't been built),
// builds the project, checks that the render works, edits the custom view
// source code, ensures that the render lists the custom view as out of date,
// applies the suggested fix to build the project, and finally asserts that the
// build is now successful.
EditorFixture editor = guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest").getEditor().open("app/src/main/res/layout/layout1.xml", EditorFixture.Tab.EDITOR);
NlPreviewFixture preview = editor.getLayoutPreview(false);
preview.waitForRenderToFinish();
assertTrue(preview.hasRenderErrors());
preview.waitForErrorPanelToContain("The following classes could not be found");
preview.waitForErrorPanelToContain("com.android.tools.tests.layout.MyButton");
preview.waitForErrorPanelToContain("Change to android.widget.Button");
GradleInvocationResult result = guiTest.ideFrame().invokeProjectMake();
assertTrue(result.isBuildSuccessful());
// Build completion should trigger re-render
preview.waitForRenderToFinish();
assertFalse(preview.hasRenderErrors());
editor.open("app/src/main/java/com/android/tools/tests/layout/MyButton.java", EditorFixture.Tab.EDITOR).moveBetween("extends Button {", "").enterText(// Next let's edit the custom view source file
" // test").open("app/src/main/res/layout/layout1.xml", // Switch back; should trigger render
EditorFixture.Tab.EDITOR);
preview.waitForRenderToFinish();
preview.waitForErrorPanelToContain("The MyButton custom view has been edited more recently than the last build");
result = guiTest.ideFrame().invokeProjectMake();
assertTrue(result.isBuildSuccessful());
preview.waitForRenderToFinish();
assertFalse(preview.hasRenderErrors());
// Now make some changes to the file which updates the modification timestamp of the source. However,
// also edit them back and save again (which still leaves a new modification timestamp). Gradle will
// *not* rebuild if the file contents have not changed (it uses checksums rather than file timestamps).
// Make sure that we don't get render errors in this scenario! (Regression test for http://b.android.com/76676)
editor.open("app/src/main/java/com/android/tools/tests/layout/MyButton.java", EditorFixture.Tab.EDITOR).moveBetween("extends Button {", "").enterText(" ").invokeAction(EditorFixture.EditorAction.SAVE).invokeAction(EditorFixture.EditorAction.BACK_SPACE).invokeAction(EditorFixture.EditorAction.SAVE);
waitForBackgroundTasks(guiTest.robot());
editor.open("app/src/main/res/layout/layout1.xml", EditorFixture.Tab.EDITOR);
preview.waitForRenderToFinish();
preview.waitForErrorPanelToContain("The MyButton custom view has been edited more recently than the last build");
// this build won't do anything this time, since Gradle notices checksum has not changed
result = guiTest.ideFrame().invokeProjectMake();
assertTrue(result.isBuildSuccessful());
preview.waitForRenderToFinish();
// but our build timestamp check this time will mask the out of date warning
assertFalse(preview.hasRenderErrors());
}
Aggregations