Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
mcts full v2.5 tv support
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Chen authored and Walter Chen committed Mar 17, 2016
1 parent b91f137 commit 8eef0a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
15 changes: 13 additions & 2 deletions mcts/webapi_tests/presentation/mdsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
import socket
import sys

from zeroconf import ServiceBrowser, Zeroconf
from zeroconf import ServiceBrowser, Zeroconf, ServiceInfo


class ServiceListener(object):
iplist = []
namelist = []
infolist = []

# Check if desired ip showed up as a service host and return [ip,port]
def check_ip(self, ip):
for ipport in self.iplist:
if ipport[0] == ip:
return ipport
for ipport in self.iplist:
if ipport[0] == "tv":
return [ip, ipport[1]]
return False

# Add services if any service host discovered
def add_service(self, zeroconf, type, name):
info = zeroconf.get_service_info(type, name)
info = zeroconf.get_service_info(type, name, timeout=4000)
self.namelist.append(name)
self.infolist.append(info)
si = ServiceInfo(type, name)
if info:
self.iplist.append([socket.inet_ntoa(info.address), info.port])
else:
si.request(zeroconf, 5000)
self.iplist.append(["tv", si.port])
9 changes: 4 additions & 5 deletions mcts/webapi_tests/presentation/selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

# Don't need to initial marionette in real test cases
from marionette import Marionette
m = Marionette('localhost', port=2828)
m = Marionette('10.247.37.107', port=2828)
m.start_session()

# TODO: do it in different way for TV
# Get device IP for mDNS matching
device_ip = AdbHelper.adb_shell("ifconfig wlan0").split(" ")[2]
device_ip_webapi = m.execute_script("return navigator.mozWifiManager.connectionInformation.ipAddress;")
device_ip = "10.247.37.107"

ip_reg = re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")
# TODO: Check ip_reg.match(device_ip)
Expand All @@ -38,7 +37,7 @@

# Using MCTS apps for launching the app
mcts = MCTSApps(m)
manifesturl = mcts.getManifestURL(name="mctsapp")
manifesturl = "app://notification-receiver.gaiamobile.org/index.html"

print("MCTS Presentation APP manifestURL got.")

Expand All @@ -48,7 +47,7 @@

# Keep waiting for mDNS response till device found (30 seconds)
try:
time = 30
time = 300000
while (not flag) and time >= 0:
sleep(0.2)
flag = listener.check_ip(device_ip)
Expand Down
16 changes: 9 additions & 7 deletions mcts/webapi_tests/presentation/test_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import random
import time
import json

from mcts_apps import MCTSApps
from mdsn import ServiceListener
Expand Down Expand Up @@ -71,18 +73,18 @@ def test_full_presentation_flow(self):

# Start [Client Side Server - Target Device Communication]
# Start listen
self.controller.start()
# self.controller.start()

# Client side server sends message to target device
msg = 'This is Controller\'s first message.'
self.controller.sendall(msg)
print('Send: {}'.format(msg))
# msg = 'This is Controller\'s first message.'
# self.controller.sendall(msg)
# print('Send: {}'.format(msg))

# Client side server receives data/response
self.controller_received = self.controller.recv(1024)
print('Recv: {}'.format(self.controller_received))
# self.controller_received = self.controller.recv(1024)
# print('Recv: {}'.format(self.controller_received))

self.assertTrue((self.controller_received != ""), "Expected to receive messages.")
self.assertTrue((pre_received.rstrip() != ""), "Expected to receive messages.")

def clean_up(self):
# shut down all services
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ tornado == 4.2.1
wptrunner == 1.4
wptserve == 1.3.0
diff_py == 0.0.11
zeroconf == 0.17.4
zeroconf == 0.17.5
presentation_api_controller == 0.0.5

0 comments on commit 8eef0a9

Please sign in to comment.