diff --git a/test/sanity/webview-cdt-ext/core.js b/test/sanity/webview-cdt-ext/core.js new file mode 100644 index 0000000000..a7f4ebf701 --- /dev/null +++ b/test/sanity/webview-cdt-ext/core.js @@ -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' diff --git a/test/sanity/webview-cdt-ext/extensions/custom.html b/test/sanity/webview-cdt-ext/extensions/custom.html new file mode 100644 index 0000000000..c4d8364b5a --- /dev/null +++ b/test/sanity/webview-cdt-ext/extensions/custom.html @@ -0,0 +1,7 @@ + + + + +custom + + diff --git a/test/sanity/webview-cdt-ext/extensions/devtools.html b/test/sanity/webview-cdt-ext/extensions/devtools.html new file mode 100644 index 0000000000..2d5e4f2af0 --- /dev/null +++ b/test/sanity/webview-cdt-ext/extensions/devtools.html @@ -0,0 +1,19 @@ + + + + + + + diff --git a/test/sanity/webview-cdt-ext/extensions/manifest.json b/test/sanity/webview-cdt-ext/extensions/manifest.json new file mode 100644 index 0000000000..cb03547a6b --- /dev/null +++ b/test/sanity/webview-cdt-ext/extensions/manifest.json @@ -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": [ + "" + ] + } + ] + }, + "manifest_version": 2 +} diff --git a/test/sanity/webview-cdt-ext/index.html b/test/sanity/webview-cdt-ext/index.html new file mode 100644 index 0000000000..c62187d68c --- /dev/null +++ b/test/sanity/webview-cdt-ext/index.html @@ -0,0 +1,13 @@ + + + + + + + + +
+ + + + diff --git a/test/sanity/webview-cdt-ext/index.js b/test/sanity/webview-cdt-ext/index.js new file mode 100644 index 0000000000..25932c3f4b --- /dev/null +++ b/test/sanity/webview-cdt-ext/index.js @@ -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() + }) +} diff --git a/test/sanity/webview-cdt-ext/package.json b/test/sanity/webview-cdt-ext/package.json new file mode 100644 index 0000000000..d669a2ed64 --- /dev/null +++ b/test/sanity/webview-cdt-ext/package.json @@ -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": [ + "" + ] + } + ] + } +} diff --git a/test/sanity/webview-cdt-ext/test.py b/test/sanity/webview-cdt-ext/test.py new file mode 100644 index 0000000000..c445150124 --- /dev/null +++ b/test/sanity/webview-cdt-ext/test.py @@ -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()