Skip to content

Commit

Permalink
test update with remoting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Jun 4, 2015
1 parent 5a80736 commit fc6d996
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 5 deletions.
12 changes: 12 additions & 0 deletions test/remoting/start-page/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import time
import os

from selenium import webdriver

driver = webdriver.Chrome(os.environ['CHROMEDRIVER'])
try:
print driver.current_url
id = driver.find_element_by_id('nwjsver')
print id.text
finally:
driver.quit()
92 changes: 92 additions & 0 deletions test/remoting/testcfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import test
import os
from os.path import join, dirname, exists, basename, isdir
import re
import utils

class RemotingTestCase(test.TestCase):

def __init__(self, path, file, arch, mode, context, config, additional=[]):
super(RemotingTestCase, self).__init__(context, path, arch, mode)
self.file = file
self.config = config
self.arch = arch
self.mode = mode
self.additional_flags = additional

def GetTmpDir(self):
return "%s.%d" % (self.tmpdir, self.thread_id)

def GetChromeDriver(self, arch, mode):
if arch == 'none':
name = 'out/Debug/chromedriver' if mode == 'debug' else 'out/Release/chromedriver'
else:
name = 'out/%s_%s/chromedriver' % (mode, arch)
# Currently GYP does not support output_dir for MSVS.
# http://code.google.com/p/gyp/issues/detail?id=40
# It will put the builds into Release/iojs.exe or Debug/iojs.exe
if utils.IsWindows():
name = os.path.abspath(name + '.exe')

return name

def AfterRun(self, result):
return

def BeforeRun(self):
return

def GetLabel(self):
return "%s %s" % (self.mode, self.GetName())

def GetName(self):
return self.path[-1]

def GetEnv(self):
libpath = join(self.file, '..', '..', '..', '..', '..', 'third_party/webdriver/pylib')
return {'PYTHONPATH': libpath, 'CHROMEDRIVER': self.GetChromeDriver(self.arch, self.mode)}

def GetCommand(self):
result = ['python']
result += [self.file + '/test.py']

return result

def IsFailureOutput(self, output):
return output.exit_code != 0

def GetSource(self):
return open(self.file).read()

class RemotingTestConfiguration(test.TestConfiguration):

def __init__(self, context, root, section, additional=[]):
super(RemotingTestConfiguration, self).__init__(context, root)
self.section = section
self.additional_flags = additional

def Ls(self, path):
def SelectTest(name):
return os.path.isdir(os.path.join(path, name))
return [f[0:] for f in os.listdir(path) if SelectTest(f)]

def ListTests(self, current_path, path, arch, mode):
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
result = []
for test in all_tests:
if self.Contains(path, test):
file_path = join(self.root, reduce(join, test[1:], ""))
result.append(RemotingTestCase(test, file_path, arch, mode, self.context,
self, self.additional_flags))
return result

def GetBuildRequirements(self):
return ['sample', 'sample=shell']

def GetTestStatus(self, sections, defs):
status_file = join(self.root, '%s.status' % (self.section))
if exists(status_file):
test.ReadConfigurationInto(status_file, sections, defs)

def GetConfiguration(context, root):
return RemotingTestConfiguration(context, root, 'remoting')
13 changes: 8 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ def RunCommand(self, command, env):
output,
self.context.store_unexpected_output)

def GetEnv(self):
return {}

def BeforeRun(self):
pass

Expand All @@ -432,9 +435,9 @@ def Run(self):
self.BeforeRun()

try:
result = self.RunCommand(self.GetCommand(), {
"TEST_THREAD_ID": "%d" % self.thread_id
})
env = self.GetEnv()
env.update({"TEST_THREAD_ID": "%d" % self.thread_id})
result = self.RunCommand(self.GetCommand(), env)
finally:
# Tests can leave the tty in non-blocking mode. If the test runner
# tries to print to stdout/stderr after that and the tty buffer is
Expand Down Expand Up @@ -749,13 +752,13 @@ def GetVm(self, arch, mode):
if arch == 'none':
name = 'out/Debug/nw' if mode == 'debug' else 'out/Release/nw'
else:
name = 'out/%s.%s/iojs' % (arch, mode)
name = 'out/%s_%s/nw' % (mode, arch)

# Currently GYP does not support output_dir for MSVS.
# http://code.google.com/p/gyp/issues/detail?id=40
# It will put the builds into Release/iojs.exe or Debug/iojs.exe
if utils.IsWindows():
out_dir = os.path.join(dirname(__file__), "..", "out")
out_dir = os.path.join(dirname(__file__), "..", "..", "..", "out")
if not exists(out_dir):
if mode == 'debug':
name = os.path.abspath('Debug/nw.exe')
Expand Down
11 changes: 11 additions & 0 deletions tests/auto/process-exit-with-42/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>process-exit-with-42</title>
<script>
nw.process.exit(42);
</script>
</head>
<body>

</body>
</html>
5 changes: 5 additions & 0 deletions tests/auto/process-exit-with-42/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name":"test",
"expect_exit_code": 42,
"main": "index.html"
}
6 changes: 6 additions & 0 deletions tests/auto/testcfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import testpy

def GetConfiguration(context, root):
return testpy.SimpleTestConfiguration(context, root, 'auto')

0 comments on commit fc6d996

Please sign in to comment.