Skip to content

Commit

Permalink
XWIKI-21949: Restrict the execution of script macros during a realtim…
Browse files Browse the repository at this point in the history
…e WYSIWYG editing session

* Add functional tests for limiting script right and for editing translations
* Move "multi users" tests to RealtimeWYSIWYGEditorIT and use the new multi user test "framework"
* Add page objects to interact with the macro content field on the Macro Edit modal

(cherry picked from commit 49030bf)
  • Loading branch information
mflorea authored and github-actions[bot] committed Jul 2, 2024
1 parent 3cc84ee commit 0218f80
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,49 @@ public WebElement getMacroParameterInput(String name)
By.cssSelector("[class*=-editor-modal] .macro-parameter-field input[name='" + name + "']"));
}

/**
* Set the value of the macro content.
*
* @param content the macro content
* @return this modal
* @since 15.10.12
* @since 16.4.1
* @since 16.6.0RC1
*/
public MacroDialogEditModal setMacroContent(CharSequence... content)
{
WebElement contentInput = getMacroContentInput();
contentInput.clear();
contentInput.sendKeys(content);
return this;
}

/**
* Retrieves the value of the macro content from the macro editor modal.
*
* @return the value of the macro content
* @since 15.10.12
* @since 16.4.1
* @since 16.6.0RC1
*/
public String getMacroContent()
{
return getMacroContentInput().getAttribute("value");
}

/**
* @return the text area used to edit the macro content
* @since 15.10.12
* @since 16.4.1
* @since 16.6.0RC1
*/
public WebElement getMacroContentInput()
{
return getDriver().findElementWithoutWaitingWithoutScrolling(
// We match *-editor-modal so the page object can be used both in Dashboard and CKEditor tests.
By.cssSelector("[class*=-editor-modal] .macro-parameter-field textarea[name='$content']"));
}

/**
* Click on the macro submission button.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ public void click()
}
}

/**
* Clicks somewhere on the edited content.
*
* @param contentSelector specifies an element from the edited content to click on
* @since 15.10.11
* @since 16.4.1
* @since 16.6.0RC1
*/
public void click(By contentSelector)
{
try {
WebElement rootEditableElement = getRootEditableElement();
getDriver().findElementWithoutWaiting(rootEditableElement, contentSelector).click();
} finally {
maybeSwitchToDefaultContent();
}
}

protected void maybeSwitchToEditedContent()
{
if (this.isFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.xwiki.ckeditor.test.po.CKEditorConfigurationPane;
import org.xwiki.ckeditor.test.ui.AbstractCKEditorIT;
import org.xwiki.test.docker.junit5.MultiUserTestUtils;
import org.xwiki.test.docker.junit5.TestReference;
import org.xwiki.test.ui.TestUtils;

Expand All @@ -40,15 +41,9 @@
@ExtendWith(RealtimeTestDebugger.class)
abstract class AbstractRealtimeWYSIWYGEditorIT extends AbstractCKEditorIT
{
protected static String firstTabHandle;

@BeforeAll
static void beforeAll(TestUtils setup)
{
// Store the ID of the current browser tab because we're going to open new tabs which will have to be closed
// after each test, and we need this to avoid closing all tabs.
firstTabHandle = setup.getDriver().getWindowHandle();

// Enable the real-time WYSIWYG editor.
setup.loginAsSuperAdmin();
CKEditorConfigurationPane ckeditorConfig = CKEditorConfigurationPane.open();
Expand All @@ -61,19 +56,19 @@ static void beforeAll(TestUtils setup)
}

@AfterEach
void afterEach(TestUtils setup, TestReference testReference)
void afterEach(TestUtils setup, MultiUserTestUtils multiUserSetup, TestReference testReference)
{
// Handle the edit mode leave confirmation modal (when ther are unsaved changes).
// Handle the edit mode leave confirmation modal (when there are unsaved changes).
setup.getDriver().getWindowHandles().forEach(handle -> {
setup.getDriver().switchTo().window(handle);
multiUserSetup.switchToBrowserTab(handle);
maybeLeaveEditMode(setup, testReference);
});

// Close all tabs except the first one.
setup.getDriver().getWindowHandles().stream().filter(handle -> !handle.equals(firstTabHandle))
.forEach(handle -> setup.getDriver().switchTo().window(handle).close());
multiUserSetup.closeTabs();
}

// Switch back to the first tab.
setup.getDriver().switchTo().window(firstTabHandle);
protected void loginAsBob(TestUtils setup)
{
setup.createUserAndLogin("Bob", "pass", "editor", "Wysiwyg");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

// Solr search is used to get suggestions for the link quick action.
"org.xwiki.platform:xwiki-platform-search-solr-query"
}
},
servletEngineNetworkAliases = RealtimeWYSIWYGEditorIT.XWIKI_ALIAS
)
class AllIT
{
Expand All @@ -60,10 +61,4 @@ class AllIT
class NestedRealtimeWYSIWYGEditorIT extends RealtimeWYSIWYGEditorIT
{
}

@Nested
@DisplayName("Realtime Multi-User WYSIWYG Editor Tests")
class NestedRealtimeWYSIWYGMultiUserIT extends RealtimeWYSIWYGMultiUserIT
{
}
}
Loading

0 comments on commit 0218f80

Please sign in to comment.