Skip to content

Commit

Permalink
[test] add webview-cdt-ext for #6004
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Dec 19, 2018
1 parent 2779509 commit d5a5b72
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/sanity/webview-cdt-ext/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var webview = document.createElement('webview')
var devtools = document.createElement('webview')

webview.setAttribute('style', 'height:300px;width:100%;position:absolute')
devtools.setAttribute('style', 'height:300px;width:100%;position:absolute;top:300px')
devtools.setAttribute('partition', 'trusted')

var container = global.contentDocument.getElementById('container')
container.appendChild(webview)
container.appendChild(devtools)

webview.src = 'https://mp.weixin.qq.com'

const devtoolsviewCommit = () => {
devtools.removeEventListener('loadcommit', devtoolsviewCommit)
webview.showDevTools(true, devtools)
}
devtools.addEventListener('loadcommit', devtoolsviewCommit)

devtools.src = 'about:blank'
7 changes: 7 additions & 0 deletions test/sanity/webview-cdt-ext/extensions/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
custom
</body>
</html>
19 changes: 19 additions & 0 deletions test/sanity/webview-cdt-ext/extensions/devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
</head>
<body>
<script >
"use strict"

// 添加appdata pannel
chrome.devtools.panels.create("custom",
"",
"custom.html",
function(panel) {
//console.log(panel)
}
)

</script>
</body>
</html>
17 changes: 17 additions & 0 deletions test/sanity/webview-cdt-ext/extensions/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "wechat devtools extension",
"version": "1.1",
"description": "Extends the Developer Tools, adding appdata",
"devtools_page": "devtools.html",
"webview": {
"partitions": [
{
"name": "trusted",
"accessible_resources": [
"<all_urls>"
]
}
]
},
"manifest_version": 2
}
13 changes: 13 additions & 0 deletions test/sanity/webview-cdt-ext/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="utf-8">
</head>

<body>
<div id="container" class="container"></div>
<script src="index.js"></script>
</body>

</html>
14 changes: 14 additions & 0 deletions test/sanity/webview-cdt-ext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global.contentDocument = document
require('./core.js')

if (nw.App.argv.indexOf('inspect') !== -1) {
nw.Window.open('about:blank', {
"show": false,
"width": 799,
"height": 799,
}, (inspectWin) => {
inspectWin.maximize()
inspectWin.window.location = "chrome://inspect/#devices"
inspectWin.show()
})
}
24 changes: 24 additions & 0 deletions test/sanity/webview-cdt-ext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"main": "index.html",
"name": "canhuang",
"appname": "canhuang",
"version": "1.0.0",
"window": {
"title": "v1.0.0",
"toolbar": true,
"width": 800,
"height": 800,
"frame": true
},
"chromium-args": "-load-extension=./extensions/ -ignore-certificate-errors",
"webview": {
"partitions": [
{
"name": "trusted",
"accessible_resources": [
"<all_urls>"
]
}
]
}
}
46 changes: 46 additions & 0 deletions test/sanity/webview-cdt-ext/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time
import os
import urlparse, urllib
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

def path2url(path):
return urlparse.urljoin(
'file:', urllib.pathname2url(path))

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

chrome_options = Options()
chrome_options.add_argument("nwapp=" + testdir)
chrome_options.add_experimental_option("windowTypes", ["webview"])

capabilities = {"pageLoadStrategy": "none"}

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, desired_capabilities = capabilities, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
time.sleep(1)
try:
print driver.current_url
#driver.find_element_by_id('testbtn').click()
timeout = 10
found = False
while timeout > 0 and not found:
for handle in driver.window_handles:
driver.switch_to_window(handle)
if driver.current_url.startswith('chrome-devtools://'):
found = True
break
timeout = timeout - 1
time.sleep(1)
assert(found)
driver.execute_script('UI.inspectorView._tabbedPane.selectTab(UI.inspectorView._tabbedPane._tabs[9]._id)')
title = driver.execute_script('return UI.inspectorView._tabbedPane._tabs[9]._title')
print "title:", title
assert('custom' in title)
finally:
driver.quit()

0 comments on commit d5a5b72

Please sign in to comment.