Skip to content

Commit

Permalink
[test] add test for #7503
Browse files Browse the repository at this point in the history
  • Loading branch information
hrocha1 authored and rogerwang committed Jun 14, 2020
1 parent adc11cc commit eabb61c
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/sanity/issue7503-close/local.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<title>local file</title>
</head>
<body>
</body>
</html>
9 changes: 9 additions & 0 deletions test/sanity/issue7503-close/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>main window</title>
</head>
<body>
<p id="result_local"></p>
<p id="result_remote"></p>
</body>
</html>
39 changes: 39 additions & 0 deletions test/sanity/issue7503-close/main.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
4 changes: 4 additions & 0 deletions test/sanity/issue7503-close/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "winonclose",
"main": "main.js"
}
41 changes: 41 additions & 0 deletions test/sanity/issue7503-close/test.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit eabb61c

Please sign in to comment.