diff --git a/test/sanity/issue7503-close/local.html b/test/sanity/issue7503-close/local.html new file mode 100644 index 0000000000..941f5c8bcb --- /dev/null +++ b/test/sanity/issue7503-close/local.html @@ -0,0 +1,7 @@ + + + local file + + + + diff --git a/test/sanity/issue7503-close/main.html b/test/sanity/issue7503-close/main.html new file mode 100644 index 0000000000..01de04be79 --- /dev/null +++ b/test/sanity/issue7503-close/main.html @@ -0,0 +1,9 @@ + + + main window + + +

+

+ + diff --git a/test/sanity/issue7503-close/main.js b/test/sanity/issue7503-close/main.js new file mode 100644 index 0000000000..1ba384976a --- /dev/null +++ b/test/sanity/issue7503-close/main.js @@ -0,0 +1,39 @@ +function addButton(win) { + let button = win.window.document.createElement("button"); + button.id = "close"; + button.innerHTML = "close NW.js"; + + button.onclick = function() { + win.close(); + }; + + win.window.document.getElementsByTagName("body")[0].appendChild(button); +} + +var mainWindow; + +nw.Window.open("main.html", {}, function (win) { + mainWindow = win; +}); + +nw.Window.open("local.html", {}, function (win) { + win.on("close", function () { + mainWindow.window.document.getElementById("result_local").textContent = "local"; + this.close(true); + }); + + win.on("loaded", function () { + addButton(win); + }); +}); + +nw.Window.open("http://example.org", {}, function (win) { + win.on("close", function () { + mainWindow.window.document.getElementById("result_remote").textContent = "remote"; + this.close(true); + }); + + win.on("loaded", function () { + addButton(win); + }); +}); \ No newline at end of file diff --git a/test/sanity/issue7503-close/package.json b/test/sanity/issue7503-close/package.json new file mode 100644 index 0000000000..230ace272d --- /dev/null +++ b/test/sanity/issue7503-close/package.json @@ -0,0 +1,4 @@ +{ + "name": "winonclose", + "main": "main.js" +} \ No newline at end of file diff --git a/test/sanity/issue7503-close/test.py b/test/sanity/issue7503-close/test.py new file mode 100644 index 0000000000..fc208b4ee8 --- /dev/null +++ b/test/sanity/issue7503-close/test.py @@ -0,0 +1,41 @@ +import time +import os +import sys + +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from nw_util import * + +def close_window(title): + for handle in driver.window_handles: + driver.switch_to_window(handle) + if title in driver.title: + driver.find_element_by_id("close").click() + break + +def switch_to_window(title): + for handle in driver.window_handles: + driver.switch_to_window(handle) + if title == driver.title: + break + +chrome_options = Options() +chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__))) + +driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options) +driver.implicitly_wait(5) + +try: + wait_window_handles(driver, 3) + close_window("local file"); + close_window("Example"); + switch_to_window("main window") + + result_local = driver.find_element_by_id('result_local').get_attribute('innerHTML') + result_remote = driver.find_element_by_id('result_remote').get_attribute('innerHTML') + + assert(result_local == "local") + assert(result_remote == "remote") +finally: + driver.quit()